diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
new file mode 100644
index 0000000..5b87f4c
--- /dev/null
+++ b/.github/FUNDING.yml
@@ -0,0 +1 @@
+ko_fi: traurige
diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md
new file mode 100644
index 0000000..f1e3750
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/bug_report.md
@@ -0,0 +1,16 @@
+---
+name: Bug report
+about: Report a bug to help improve Kayoko
+title: ''
+labels: bug
+assignees: Traurige
+
+---
+
+**Describe the bug:**
+
+**Steps to reproduce the behavior:**
+
+**System information:**
+- iOS version:
+- Jailbreak:
diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md
new file mode 100644
index 0000000..724bb06
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/feature_request.md
@@ -0,0 +1,14 @@
+---
+name: Feature request
+about: Suggest a feature that can help make Kayoko even better
+title: ''
+labels: enhancement
+assignees: Traurige
+
+---
+
+**Describe the requested feature:**
+
+**System information:**
+- iOS version:
+- Jailbreak:
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..a57b0ff
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+.DS_Store
+.theos
+packages/
+.vscode
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..f288702
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,674 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+
+ Copyright (C)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ Copyright (C)
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+.
diff --git a/Daemon/KayokoDaemon.h b/Daemon/KayokoDaemon.h
new file mode 100644
index 0000000..3771795
--- /dev/null
+++ b/Daemon/KayokoDaemon.h
@@ -0,0 +1,7 @@
+#import
+#import
+
+@interface KayokoDaemon : NSObject {
+ int _token;
+}
+@end
diff --git a/Daemon/KayokoDaemon.m b/Daemon/KayokoDaemon.m
new file mode 100644
index 0000000..9833994
--- /dev/null
+++ b/Daemon/KayokoDaemon.m
@@ -0,0 +1,27 @@
+#import "KayokoDaemon.h"
+
+@implementation KayokoDaemon
+- (instancetype)init {
+ self = [super init];
+
+ if (self) {
+ notify_register_dispatch("com.apple.pasteboard.notify.changed", &(_token), dispatch_get_main_queue(), ^(int _) {
+ CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), (CFStringRef)@"dev.traurige.kayoko.daemon.pasteboard.changed", nil, nil, YES);
+ });
+ }
+
+ return self;
+}
+
+- (void)dealloc {
+ notify_cancel(_token);
+ [super dealloc];
+}
+@end
+
+int main(int argc, char** argv, char** envp) {
+ [[KayokoDaemon alloc] init];
+ [[NSRunLoop currentRunLoop] run];
+
+ return 0;
+}
diff --git a/Daemon/Makefile b/Daemon/Makefile
new file mode 100644
index 0000000..5c6abbc
--- /dev/null
+++ b/Daemon/Makefile
@@ -0,0 +1,7 @@
+TOOL_NAME = kayokod
+kayokod_FILES = KayokoDaemon.m
+kayokod_INSTALL_PATH = /usr/libexec
+kayokod_CODESIGN_FLAGS = -Sentitlements.plist
+
+include $(THEOS)/makefiles/common.mk
+include $(THEOS_MAKE_PATH)/tool.mk
diff --git a/Daemon/entitlements.plist b/Daemon/entitlements.plist
new file mode 100644
index 0000000..8ee1fab
--- /dev/null
+++ b/Daemon/entitlements.plist
@@ -0,0 +1,7 @@
+
+
+
+ com.apple.springboard.launchapplications
+
+
+
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..d860d64
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,10 @@
+export ARCHS = arm64 arm64e
+export TARGET = iphone:clang:14.4:13.0
+export SYSROOT = $(THEOS)/sdks/iPhoneOS14.4.sdk
+export PREFIX = $(THEOS)/toolchain/Xcode.xctoolchain/usr/bin/
+
+INSTALL_TARGET_PROCESSES = SpringBoard
+SUBPROJECTS = Tweak/Core Tweak/Helper Daemon Preferences
+
+include $(THEOS)/makefiles/common.mk
+include $(THEOS_MAKE_PATH)/aggregate.mk
diff --git a/Manager/PasteboardItem.h b/Manager/PasteboardItem.h
new file mode 100644
index 0000000..a097b07
--- /dev/null
+++ b/Manager/PasteboardItem.h
@@ -0,0 +1,15 @@
+#import
+
+@interface PasteboardItem : NSObject
+@property(atomic, assign)NSString* bundleIdentifier;
+@property(atomic, assign)NSString* displayName;
+@property(atomic, assign)NSString* content;
+@property(atomic, assign)NSString* imageName;
+@property(atomic, assign)BOOL hasPlainText;
+@property(atomic, assign)BOOL hasLink;
+@property(atomic, assign)BOOL hasMusicLink;
+@property(atomic, assign)BOOL hasColor;
+@property(atomic, assign)BOOL hasImage;
+- (instancetype)initWithBundleIdentifier:(NSString *)bundleIdentifier andContent:(NSString *)content withImageNamed:(NSString *)imageName;
++ (PasteboardItem *)itemFromDictionary:(NSDictionary *)dictionary;
+@end
diff --git a/Manager/PasteboardItem.m b/Manager/PasteboardItem.m
new file mode 100644
index 0000000..24a12ee
--- /dev/null
+++ b/Manager/PasteboardItem.m
@@ -0,0 +1,63 @@
+#import "PasteboardItem.h"
+
+@implementation PasteboardItem
+- (instancetype)initWithBundleIdentifier:(NSString *)bundleIdentifier andContent:(NSString *)content withImageNamed:(NSString *)imageName {
+ self = [super init];
+
+ if (self) {
+ [self setBundleIdentifier:bundleIdentifier];
+ [self setContent:content];
+ [self setImageName:imageName];
+ [self setHasLink:[content hasPrefix:@"http://"] || [content hasPrefix:@"https://"]];
+ [self setHasMusicLink:[self contentHasMusicLink:content]];
+ [self setHasColor:![self hasLink] && ![self hasMusicLink] && [self contentHasColor:content]];
+ [self setHasImage:imageName && ![imageName isEqualToString:@""]];
+ [self setHasPlainText:![self hasLink] && ![self hasMusicLink] && ![self hasColor] && ![self hasImage]];
+ }
+
+ return self;
+}
+
++ (PasteboardItem *)itemFromDictionary:(NSDictionary *)dictionary {
+ return [[PasteboardItem alloc] initWithBundleIdentifier:dictionary[@"bundleIdentifier"] andContent:dictionary[@"content"] withImageNamed:dictionary[@"imageName"]];
+}
+
+- (BOOL)contentHasMusicLink:(NSString *)content {
+ NSArray* linkPrefixes = @[
+ @"https://music.apple.com/",
+ @"https://open.spotify.com/",
+ @"https://music.youtube.com/",
+ @"https://soundcloud.com/",
+ @"https://music.amazon.com/",
+ @"https://www.pandora.com/",
+ @"https://www.deezer.com/",
+ @"https://napster.com/",
+ @"https://listen.tidal.com/",
+ @"https://music.yandex.ru/"
+ ];
+
+ for (NSString* prefix in linkPrefixes) {
+ if ([content hasPrefix:prefix]) {
+ return YES;
+ }
+ }
+
+ return NO;
+}
+
+- (BOOL)contentHasColor:(NSString *)content {
+ NSString* hexRegex = @"^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$";
+ NSString* rgbRegex = @"^rgb\\(\\s*([0-9]{1,3})\\s*,\\s*([0-9]{1,3})\\s*,\\s*([0-9]{1,3})\\s*\\)$";
+ NSString* rgbaRegex = @"^rgba\\(\\s*([0-9]{1,3})\\s*,\\s*([0-9]{1,3})\\s*,\\s*([0-9]{1,3})\\s*,\\s*([0-9]{1,3}|[0-9]{1,3}\\.[0-9]{1,3})\\s*\\)$";
+ NSArray* regexes = @[hexRegex, rgbRegex, rgbaRegex];
+
+ for (NSString* regex in regexes) {
+ NSRegularExpression* expression = [NSRegularExpression regularExpressionWithPattern:regex options:0 error:nil];
+ if ([expression firstMatchInString:content options:0 range:NSMakeRange(0, [content length])]) {
+ return YES;
+ }
+ }
+
+ return NO;
+}
+@end
diff --git a/Manager/PasteboardManager.h b/Manager/PasteboardManager.h
new file mode 100644
index 0000000..4feb19e
--- /dev/null
+++ b/Manager/PasteboardManager.h
@@ -0,0 +1,44 @@
+//
+// PasteboardManager.h
+// Kayoko
+//
+// Created by Alexandra (@Traurige)
+//
+
+#import
+#import "PasteboardItem.h"
+#import "../Utils/CommonUtil.h"
+#import "../Utils/ImageUtil.h"
+#import "../Preferences/PreferenceKeys.h"
+
+static NSString* const kHistoryPath = @"/var/mobile/Documents/dev.traurige/Kayoko/history.json";
+static NSString* const kHistoryImagesPath = @"/var/mobile/Documents/dev.traurige/Kayoko/images/";
+static NSString* const kHistoryKeyHistory = @"history";
+static NSString* const kHistoryKeyFavorites = @"favorites";
+
+@interface PasteboardManager : NSObject {
+ UIPasteboard* _pasteboard;
+ NSUInteger _lastChangeCount;
+ NSFileManager* _fileManager;
+}
+@property(atomic, assign)NSUInteger maximumHistoryAmount;
+@property(atomic, assign)BOOL saveText;
+@property(atomic, assign)BOOL saveImages;
+@property(atomic, assign)BOOL automaticallyPaste;
++ (instancetype)sharedInstance;
+- (void)pullPasteboardChanges;
+- (void)addPasteboardItem:(PasteboardItem *)item toHistoryWithKey:(NSString *)historyKey;
+- (void)addSongDotLinkItemFromItem:(PasteboardItem *)item;
+- (void)addTranslateItemFromItem:(PasteboardItem *)item;
+- (void)updatePasteboardWithItem:(PasteboardItem *)item fromHistoryWithKey:(NSString *)historyKey shouldAutoPaste:(BOOL)shouldAutoPaste;
+- (void)removePasteboardItem:(PasteboardItem *)item fromHistoryWithKey:(NSString *)historyKey shouldRemoveImage:(BOOL)shouldRemoveImage;
+- (NSMutableArray *)itemsFromHistoryWithKey:(NSString *)historyKey;
+@end
+
+@interface SBApplication : NSObject
+@property(nonatomic, readonly)NSString* bundleIdentifier;
+@end
+
+@interface UIApplication (Private)
+- (SBApplication *)_accessibilityFrontMostApplication;
+@end
diff --git a/Manager/PasteboardManager.m b/Manager/PasteboardManager.m
new file mode 100644
index 0000000..6913e3f
--- /dev/null
+++ b/Manager/PasteboardManager.m
@@ -0,0 +1,226 @@
+//
+// PasteboardManager.m
+// Kayoko
+//
+// Created by Alexandra (@Traurige)
+//
+
+#import "PasteboardManager.h"
+
+@implementation PasteboardManager
++ (instancetype)sharedInstance {
+ static PasteboardManager* sharedInstance;
+ static dispatch_once_t onceToken;
+
+ dispatch_once(&onceToken, ^{
+ sharedInstance = [PasteboardManager alloc];
+ sharedInstance->_pasteboard = [UIPasteboard generalPasteboard];
+ sharedInstance->_lastChangeCount = [sharedInstance->_pasteboard changeCount];
+ sharedInstance->_fileManager = [NSFileManager defaultManager];
+ });
+
+ return sharedInstance;
+}
+
+- (instancetype)init {
+ return [PasteboardManager sharedInstance];
+}
+
+- (void)pullPasteboardChanges {
+ if ([_pasteboard changeCount] == _lastChangeCount || (![_pasteboard hasStrings] && ![_pasteboard hasImages])) {
+ return;
+ }
+
+ [self ensureResourcesExist];
+
+ if ([self saveText]) {
+ // don't store the strings if the pasteboard contains images as well (e.g. an image from the web)
+ if (!([_pasteboard hasStrings] && [_pasteboard hasImages])) {
+ for (NSString* string in [_pasteboard strings]) {
+ @autoreleasepool {
+ // the core only runs on the springboard process, thus mainbundle can't provide the bundle identifier
+ // uiapplication/springboard can provide the front most application to get the bundle identifier
+ SBApplication* frontMostApplication = [[UIApplication sharedApplication] _accessibilityFrontMostApplication];
+ PasteboardItem* item = [[PasteboardItem alloc] initWithBundleIdentifier:[frontMostApplication bundleIdentifier] andContent:string withImageNamed:nil];
+ [self addPasteboardItem:item toHistoryWithKey:kHistoryKeyHistory];
+ }
+ }
+ }
+ }
+
+ if ([self saveImages]) {
+ for (UIImage* image in [_pasteboard images]) {
+ @autoreleasepool {
+ NSString* imageName = [CommonUtil randomStringWithLength:32];
+
+ // jpg uses less space
+ // save as png if an alpha channel is present though
+ if ([ImageUtil imageHasAlpha:image]) {
+ imageName = [imageName stringByAppendingString:@".png"];
+ NSString* filePath = [kHistoryImagesPath stringByAppendingString:imageName];
+ [UIImagePNGRepresentation([ImageUtil rotatedImageFromImage:image]) writeToFile:filePath atomically:YES];
+ } else {
+ imageName = [imageName stringByAppendingString:@".jpg"];
+ NSString* filePath = [kHistoryImagesPath stringByAppendingString:imageName];
+ [UIImageJPEGRepresentation(image, 1) writeToFile:filePath atomically:YES];
+ }
+
+ // see the loop above
+ SBApplication* frontMostApplication = [[UIApplication sharedApplication] _accessibilityFrontMostApplication];
+ PasteboardItem* item = [[PasteboardItem alloc] initWithBundleIdentifier:[frontMostApplication bundleIdentifier] andContent:imageName withImageNamed:imageName];
+ [self addPasteboardItem:item toHistoryWithKey:kHistoryKeyHistory];
+ }
+ }
+ }
+
+ _lastChangeCount = [_pasteboard changeCount];
+}
+
+- (void)addPasteboardItem:(PasteboardItem *)item toHistoryWithKey:(NSString *)historyKey {
+ if ([[item content] isEqualToString:@""]) {
+ return;
+ }
+
+ NSMutableDictionary* json = [self getJson];
+ NSMutableArray* history = json[historyKey] ?: [[NSMutableArray alloc] init];
+
+ // remove duplicates
+ [self removePasteboardItem:item fromHistoryWithKey:historyKey shouldRemoveImage:NO];
+
+ [history insertObject:@{
+ @"bundleIdentifier": [item bundleIdentifier] ?: @"com.apple.springboard",
+ @"content": [item content] ?: @"",
+ @"imageName": [item imageName] ?: @"",
+ @"hasPlainText": @([item hasPlainText]),
+ @"hasLink": @([item hasLink]),
+ @"hasMusicLink": @([item hasMusicLink]),
+ @"hasColor": @([item hasColor]),
+ @"hasImage": @([item hasImage])
+ } atIndex:0];
+
+ // remove the oldest items if the history contains more items than the set maximum amount
+ while ([history count] > [self maximumHistoryAmount]) {
+ [history removeLastObject];
+ }
+
+ json[historyKey] = history;
+
+ [self setJsonFromDictionary:json];
+}
+
+- (void)addSongDotLinkItemFromItem:(PasteboardItem *)item {
+ NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.song.link/v1-alpha.1/links?url=%@", [item content]]];
+ NSURLSessionDataTask* task = [[NSURLSession sharedSession] dataTaskWithURL:url completionHandler:^(NSData* _Nullable data, NSURLResponse* _Nullable response, NSError* _Nullable error) {
+ @try {
+ NSDictionary* json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
+ NSString* link = json[@"pageUrl"];
+ if (link) {
+ PasteboardItem* songDotLinkItem = [[PasteboardItem alloc] initWithBundleIdentifier:[item bundleIdentifier] andContent:link withImageNamed:nil];
+ [self addPasteboardItem:songDotLinkItem toHistoryWithKey:kHistoryKeyHistory];
+ [self updatePasteboardWithItem:songDotLinkItem fromHistoryWithKey:kHistoryKeyHistory shouldAutoPaste:NO];
+ } else {
+ [CommonUtil showAlertWithTitle:@"Kayoko" andMessage:[NSString stringWithFormat:@"The server didn't return the expected result.\n\nReason: \"%@\"", json[@"code"]] withDismissButtonTitle:@"Dismiss"];
+ }
+ } @catch (NSException* exception) {
+ [CommonUtil showAlertWithTitle:@"Kayoko" andMessage:[NSString stringWithFormat:@"An error occurred while trying to get the song.link link.\n\n%@", exception] withDismissButtonTitle:@"Dismiss"];
+ }
+ }];
+ [task resume];
+}
+
+- (void)addTranslateItemFromItem:(PasteboardItem *)item {
+ NSString* encodedString = [[item content] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
+ NSString* targetLanguageCode = [[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode];
+ NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.traurige.dev/v1/deepl/translate?text=%@&target_lang=%@", encodedString, targetLanguageCode]];
+ NSURLSessionDataTask* task = [[NSURLSession sharedSession] dataTaskWithURL:url completionHandler:^(NSData* _Nullable data, NSURLResponse* _Nullable response, NSError* _Nullable error) {
+ @try {
+ NSDictionary* json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
+ NSString* translation = json[@"text"];
+ if (translation) {
+ PasteboardItem* translationItem = [[PasteboardItem alloc] initWithBundleIdentifier:[item bundleIdentifier] andContent:translation withImageNamed:nil];
+ [self addPasteboardItem:translationItem toHistoryWithKey:kHistoryKeyHistory];
+ [self updatePasteboardWithItem:translationItem fromHistoryWithKey:kHistoryKeyHistory shouldAutoPaste:NO];
+ } else {
+ [CommonUtil showAlertWithTitle:@"Kayoko" andMessage:[NSString stringWithFormat:@"The server didn't return the expected result.\n\nReason: \"%@\"", json[@"message"]] withDismissButtonTitle:@"Dismiss"];
+ }
+ } @catch (NSException* exception) {
+ [CommonUtil showAlertWithTitle:@"Kayoko" andMessage:[NSString stringWithFormat:@"An error occurred while trying to translate the text.\n\n%@", exception] withDismissButtonTitle:@"Dismiss"];
+ }
+ }];
+ [task resume];
+}
+
+- (void)removePasteboardItem:(PasteboardItem *)item fromHistoryWithKey:(NSString *)historyKey shouldRemoveImage:(BOOL)shouldRemoveImage {
+ NSMutableDictionary* json = [self getJson];
+ NSMutableArray* history = json[historyKey];
+
+ for (NSDictionary* dictionary in history) {
+ @autoreleasepool {
+ PasteboardItem* historyItem = [PasteboardItem itemFromDictionary:dictionary];
+ if ([[historyItem content] isEqualToString:[item content]]) {
+ [history removeObject:dictionary];
+ if ([item hasImage] && shouldRemoveImage) {
+ NSString* filePath = [kHistoryImagesPath stringByAppendingString:[item imageName]];
+ [_fileManager removeItemAtPath:filePath error:nil];
+ }
+ break;
+ }
+ }
+ }
+
+ json[historyKey] = history;
+
+ [self setJsonFromDictionary:json];
+}
+
+- (void)updatePasteboardWithItem:(PasteboardItem *)item fromHistoryWithKey:(NSString *)historyKey shouldAutoPaste:(BOOL)shouldAutoPaste {
+ if ([item hasImage] && ![item hasPlainText] && ![item hasLink] && ![item hasMusicLink] && ![item hasColor]) {
+ NSString* filePath = [kHistoryImagesPath stringByAppendingString:[item imageName]];
+ UIImage* image = [UIImage imageWithContentsOfFile:filePath];
+ [_pasteboard setImage:image];
+ } else {
+ [_pasteboard setString:[item content]];
+ }
+
+ // the given item gets removed, as the pasteboard is updated with the same item
+ [self removePasteboardItem:item fromHistoryWithKey:historyKey shouldRemoveImage:YES];
+
+ // automatic paste should not occur for asynchronous operations
+ if ([self automaticallyPaste] && shouldAutoPaste) {
+ CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), (CFStringRef)@"dev.traurige.kayoko.helper.paste", nil, nil, YES);
+ }
+}
+
+- (NSArray *)itemsFromHistoryWithKey:(NSString *)historyKey {
+ NSDictionary* json = [self getJson];
+ return json[historyKey] ?: [[NSArray alloc] init];
+}
+
+- (NSMutableDictionary *)getJson {
+ [self ensureResourcesExist];
+
+ NSData* jsonData = [NSData dataWithContentsOfFile:kHistoryPath];
+ NSMutableDictionary* json = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
+
+ return json;
+}
+
+- (void)setJsonFromDictionary:(NSMutableDictionary *)dictionary {
+ NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dictionary options:NSJSONWritingPrettyPrinted error:nil];
+ [jsonData writeToFile:kHistoryPath atomically:YES];
+
+ CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), (CFStringRef)@"dev.traurige.kayoko.core.reload", nil, nil, YES);
+}
+
+- (void)ensureResourcesExist {
+ BOOL isDirectory;
+ if (![_fileManager fileExistsAtPath:kHistoryImagesPath isDirectory:&isDirectory]) {
+ [_fileManager createDirectoryAtPath:kHistoryImagesPath withIntermediateDirectories:YES attributes:nil error:nil];
+ }
+
+ if (![_fileManager fileExistsAtPath:kHistoryPath]) {
+ NSData* jsonData = [NSJSONSerialization dataWithJSONObject:[[NSMutableDictionary alloc] init] options:NSJSONWritingPrettyPrinted error:nil];
+ [jsonData writeToFile:kHistoryPath options:NSDataWritingAtomic error:nil];
+ }
+}
+@end
diff --git a/Preferences/Cells/CallaLinkCell.h b/Preferences/Cells/CallaLinkCell.h
new file mode 100644
index 0000000..0bc2cdc
--- /dev/null
+++ b/Preferences/Cells/CallaLinkCell.h
@@ -0,0 +1,19 @@
+//
+// CallaLinkCell.h
+// Calla Utils
+//
+// Created by Alexandra (@Traurige)
+//
+
+#import
+#import
+
+@interface CallaLinkCell : PSTableCell
+@property(nonatomic, retain)UILabel* label;
+@property(nonatomic, retain)UILabel* subtitleLabel;
+@property(nonatomic, retain)UIView* tapRecognizerView;
+@property(nonatomic, retain)UITapGestureRecognizer* tap;
+@property(nonatomic, retain)NSString* title;
+@property(nonatomic, retain)NSString* subtitle;
+@property(nonatomic, retain)NSString* url;
+@end
diff --git a/Preferences/Cells/CallaLinkCell.m b/Preferences/Cells/CallaLinkCell.m
new file mode 100644
index 0000000..7eb49cf
--- /dev/null
+++ b/Preferences/Cells/CallaLinkCell.m
@@ -0,0 +1,73 @@
+//
+// CallaLinkCell.m
+// Calla Utils
+//
+// Created by Alexandra (@Traurige)
+//
+
+#import "CallaLinkCell.h"
+
+@implementation CallaLinkCell
+- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier specifier:(PSSpecifier *)specifier {
+ self = [super initWithStyle:style reuseIdentifier:reuseIdentifier specifier:specifier];
+
+ if (self) {
+ [self setTitle:[specifier properties][@"label"]];
+ [self setSubtitle:[specifier properties][@"subtitle"]];
+ [self setUrl:[specifier properties][@"url"]];
+
+ // title label
+ [self setLabel:[[UILabel alloc] init]];
+ [[self label] setText:[self title]];
+ [[self label] setFont:[UIFont systemFontOfSize:17]];
+ [[self label] setTextColor:[UIColor systemBlueColor]];
+ [self addSubview:[self label]];
+
+ [[self label] setTranslatesAutoresizingMaskIntoConstraints:NO];
+ [NSLayoutConstraint activateConstraints:@[
+ [[[self label] centerYAnchor] constraintEqualToAnchor:[self centerYAnchor] constant:-10],
+ [[[self label] leadingAnchor] constraintEqualToAnchor:[self leadingAnchor] constant:16],
+ [[[self label] trailingAnchor] constraintEqualToAnchor:[self trailingAnchor] constant:-16]
+ ]];
+
+
+ // subtitle label
+ [self setSubtitleLabel:[[UILabel alloc] init]];
+ [[self subtitleLabel] setText:[NSString stringWithFormat:@"%@", [self subtitle]]];
+ [[self subtitleLabel] setFont:[UIFont systemFontOfSize:11]];
+ [[self subtitleLabel] setTextColor:[[UIColor labelColor] colorWithAlphaComponent:0.6]];
+ [self addSubview:[self subtitleLabel]];
+
+ [[self subtitleLabel] setTranslatesAutoresizingMaskIntoConstraints:NO];
+ [NSLayoutConstraint activateConstraints:@[
+ [[[self subtitleLabel] centerYAnchor] constraintEqualToAnchor:[self centerYAnchor] constant:10],
+ [[[self subtitleLabel] leadingAnchor] constraintEqualToAnchor:[self leadingAnchor] constant:16],
+ [[[self subtitleLabel] trailingAnchor] constraintEqualToAnchor:[self trailingAnchor] constant:-16]
+ ]];
+
+
+ // tap view
+ [self setTapRecognizerView:[[UIView alloc] init]];
+ [self addSubview:[self tapRecognizerView]];
+
+ [[self tapRecognizerView] setTranslatesAutoresizingMaskIntoConstraints:NO];
+ [NSLayoutConstraint activateConstraints:@[
+ [[[self tapRecognizerView] topAnchor] constraintEqualToAnchor:[self topAnchor]],
+ [[[self tapRecognizerView] leadingAnchor] constraintEqualToAnchor:[self leadingAnchor]],
+ [[[self tapRecognizerView] trailingAnchor] constraintEqualToAnchor:[self trailingAnchor]],
+ [[[self tapRecognizerView] bottomAnchor] constraintEqualToAnchor:[self bottomAnchor]]
+ ]];
+
+
+ // tap
+ [self setTap:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(openUrl)]];
+ [[self tapRecognizerView] addGestureRecognizer:[self tap]];
+ }
+
+ return self;
+}
+
+- (void)openUrl {
+ [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[self url]] options:@{} completionHandler:nil];
+}
+@end
diff --git a/Preferences/Cells/CallaSingleContactCell.h b/Preferences/Cells/CallaSingleContactCell.h
new file mode 100644
index 0000000..a4add6f
--- /dev/null
+++ b/Preferences/Cells/CallaSingleContactCell.h
@@ -0,0 +1,21 @@
+//
+// CallaSingleContactCell.h
+// Calla Utils
+//
+// Created by Alexandra (@Traurige)
+//
+
+#import
+#import
+
+@interface CallaSingleContactCell : PSTableCell
+@property(nonatomic, retain)UIImageView* avatarImageView;
+@property(nonatomic, retain)UILabel* displayNameLabel;
+@property(nonatomic, retain)UILabel* usernameLabel;
+@property(nonatomic, retain)UIView* tapRecognizerView;
+@property(nonatomic, retain)UITapGestureRecognizer* tap;
+@property(nonatomic, retain)NSString* displayName;
+@property(nonatomic, retain)NSString* username;
+@property(nonatomic, retain)NSString* url;
+- (void)openUserProfile;
+@end
diff --git a/Preferences/Cells/CallaSingleContactCell.m b/Preferences/Cells/CallaSingleContactCell.m
new file mode 100644
index 0000000..bad383e
--- /dev/null
+++ b/Preferences/Cells/CallaSingleContactCell.m
@@ -0,0 +1,101 @@
+//
+// CallaSingleContactCell.m
+// Calla Utils
+//
+// Created by Alexandra (@Traurige)
+//
+
+#import "CallaSingleContactCell.h"
+
+@implementation CallaSingleContactCell
+- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier specifier:(PSSpecifier *)specifier {
+ self = [super initWithStyle:style reuseIdentifier:reuseIdentifier specifier:specifier];
+
+ if (self) {
+ [self setDisplayName:[specifier properties][@"DisplayName"]];
+ [self setUsername:[specifier properties][@"Username"]];
+ [self setUrl:[specifier properties][@"Url"]];
+
+ // avatar image view
+ [self setAvatarImageView:[[UIImageView alloc] init]];
+
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul), ^{
+ UIImage* avatar = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.traurige.dev/v1/avatar?username=%@", [self username]]]]];
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [UIView transitionWithView:[self avatarImageView] duration:0.2 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
+ [[self avatarImageView] setImage:avatar];
+ } completion:nil];
+ });
+ });
+
+ [[self avatarImageView] setContentMode:UIViewContentModeScaleAspectFill];
+ [[self avatarImageView] setClipsToBounds:YES];
+ [[[self avatarImageView] layer] setCornerRadius:21.5];
+ [[[self avatarImageView] layer] setBorderWidth:2];
+ [[[self avatarImageView] layer] setBorderColor:[[[UIColor labelColor] colorWithAlphaComponent:0.1] CGColor]];
+ [self addSubview:[self avatarImageView]];
+
+ [[self avatarImageView] setTranslatesAutoresizingMaskIntoConstraints:NO];
+ [NSLayoutConstraint activateConstraints:@[
+ [[[self avatarImageView] centerYAnchor] constraintEqualToAnchor:[self centerYAnchor]],
+ [[[self avatarImageView] leadingAnchor] constraintEqualToAnchor:[self leadingAnchor] constant:16],
+ [[[self avatarImageView] widthAnchor] constraintEqualToConstant:43],
+ [[[self avatarImageView] heightAnchor] constraintEqualToConstant:43]
+ ]];
+
+
+ // display name label
+ [self setDisplayNameLabel:[[UILabel alloc] init]];
+ [[self displayNameLabel] setText:[self displayName]];
+ [[self displayNameLabel] setFont:[UIFont systemFontOfSize:17 weight:UIFontWeightSemibold]];
+ [[self displayNameLabel] setTextColor:[UIColor labelColor]];
+ [self addSubview:[self displayNameLabel]];
+
+ [[self displayNameLabel] setTranslatesAutoresizingMaskIntoConstraints:NO];
+ [NSLayoutConstraint activateConstraints:@[
+ [[[self displayNameLabel] topAnchor] constraintEqualToAnchor:[[self avatarImageView] topAnchor] constant:4],
+ [[[self displayNameLabel] leadingAnchor] constraintEqualToAnchor:[[self avatarImageView] trailingAnchor] constant:8],
+ [[[self displayNameLabel] trailingAnchor] constraintEqualToAnchor:[self trailingAnchor] constant:-16]
+ ]];
+
+
+ // username label
+ [self setUsernameLabel:[[UILabel alloc] init]];
+ [[self usernameLabel] setText:[NSString stringWithFormat:@"@%@", [self username]]];
+ [[self usernameLabel] setFont:[UIFont systemFontOfSize:11 weight:UIFontWeightRegular]];
+ [[self usernameLabel] setTextColor:[[UIColor labelColor] colorWithAlphaComponent:0.6]];
+ [self addSubview:[self usernameLabel]];
+
+ [[self usernameLabel] setTranslatesAutoresizingMaskIntoConstraints:NO];
+ [NSLayoutConstraint activateConstraints:@[
+ [[[self usernameLabel] leadingAnchor] constraintEqualToAnchor:[[self avatarImageView] trailingAnchor] constant:8],
+ [[[self usernameLabel] trailingAnchor] constraintEqualToAnchor:[[self displayNameLabel] trailingAnchor]],
+ [[[self usernameLabel] bottomAnchor] constraintEqualToAnchor:[[self avatarImageView] bottomAnchor] constant:-4]
+ ]];
+
+
+ // tap view
+ [self setTapRecognizerView:[[UIView alloc] init]];
+ [self addSubview:[self tapRecognizerView]];
+
+ [[self tapRecognizerView] setTranslatesAutoresizingMaskIntoConstraints:NO];
+ [NSLayoutConstraint activateConstraints:@[
+ [[[self tapRecognizerView] topAnchor] constraintEqualToAnchor:[self topAnchor]],
+ [[[self tapRecognizerView] leadingAnchor] constraintEqualToAnchor:[self leadingAnchor]],
+ [[[self tapRecognizerView] trailingAnchor] constraintEqualToAnchor:[self trailingAnchor]],
+ [[[self tapRecognizerView] bottomAnchor] constraintEqualToAnchor:[self bottomAnchor]]
+ ]];
+
+
+ // tap
+ [self setTap:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(openUserProfile)]];
+ [[self tapRecognizerView] addGestureRecognizer:[self tap]];
+ }
+
+ return self;
+}
+
+- (void)openUserProfile {
+ [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[self url]] options:@{} completionHandler:nil];
+}
+@end
diff --git a/Preferences/Controllers/KayokoCreditsListController.h b/Preferences/Controllers/KayokoCreditsListController.h
new file mode 100644
index 0000000..ae5171d
--- /dev/null
+++ b/Preferences/Controllers/KayokoCreditsListController.h
@@ -0,0 +1,12 @@
+//
+// KayokoCreditsListController.m
+// Kayoko
+//
+// Created by Alexandra (@Traurige)
+//
+
+#import
+#import
+
+@interface KayokoCreditsListController : PSListController
+@end
diff --git a/Preferences/Controllers/KayokoCreditsListController.m b/Preferences/Controllers/KayokoCreditsListController.m
new file mode 100644
index 0000000..5be12dc
--- /dev/null
+++ b/Preferences/Controllers/KayokoCreditsListController.m
@@ -0,0 +1,11 @@
+//
+// KayokoCreditsListController.m
+// Kayoko
+//
+// Created by Alexandra (@Traurige)
+//
+
+#include "KayokoCreditsListController.h"
+
+@implementation KayokoCreditsListController
+@end
diff --git a/Preferences/Controllers/KayokoRootListController.h b/Preferences/Controllers/KayokoRootListController.h
new file mode 100644
index 0000000..6a97304
--- /dev/null
+++ b/Preferences/Controllers/KayokoRootListController.h
@@ -0,0 +1,20 @@
+#import
+#import
+#import
+#import "../../Manager/PasteboardManager.h"
+
+@interface NSConcreteNotification : NSNotification
+@end
+
+@interface PSListController (Private)
+- (void)_returnKeyPressed:(NSConcreteNotification *)notification;
+@end
+
+@interface KayokoRootListController : PSListController
+@end
+
+@interface NSTask : NSObject
+@property(copy)NSArray* arguments;
+@property(copy)NSString* launchPath;
+- (void)launch;
+@end
diff --git a/Preferences/Controllers/KayokoRootListController.m b/Preferences/Controllers/KayokoRootListController.m
new file mode 100644
index 0000000..23926e7
--- /dev/null
+++ b/Preferences/Controllers/KayokoRootListController.m
@@ -0,0 +1,92 @@
+#include "KayokoRootListController.h"
+
+@implementation KayokoRootListController
+- (NSArray *)specifiers {
+ if (!_specifiers) {
+ _specifiers = [self loadSpecifiersFromPlistName:@"Root" target:self];
+ }
+
+ return _specifiers;
+}
+
+- (void)setPreferenceValue:(id)value specifier:(PSSpecifier *)specifier {
+ [super setPreferenceValue:value specifier:specifier];
+
+ if ([[specifier propertyForKey:@"key"] isEqualToString:kPreferenceKeyEnabled] ||
+ [[specifier propertyForKey:@"key"] isEqualToString:kPreferenceKeyActivationMethod] ||
+ [[specifier propertyForKey:@"key"] isEqualToString:kPreferenceKeyAutomaticallyPaste]
+ ) {
+ [self promptToRespring];
+ }
+}
+
+- (void)_returnKeyPressed:(NSConcreteNotification *)notification {
+ [[self view] endEditing:YES];
+ [super _returnKeyPressed:notification];
+}
+
+- (void)promptToRespring {
+ UIAlertController* resetAlert = [UIAlertController alertControllerWithTitle:@"Kayoko" message:@"This option requires a respring to apply. To you want to respring now?" preferredStyle:UIAlertControllerStyleAlert];
+
+ UIAlertAction* yesAction = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * action) {
+ [self respring];
+ }];
+
+ UIAlertAction* noAction = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:nil];
+
+ [resetAlert addAction:yesAction];
+ [resetAlert addAction:noAction];
+
+ [self presentViewController:resetAlert animated:YES completion:nil];
+}
+
+- (void)respring {
+ NSTask* task = [[NSTask alloc] init];
+ [task setLaunchPath:@"/usr/bin/killall"];
+ [task setArguments:[NSArray arrayWithObjects:@"backboardd", nil]];
+ [task launch];
+}
+
+- (void)resetPrompt {
+ UIAlertController* resetAlert = [UIAlertController alertControllerWithTitle:@"Kayoko" message:@"Are you sure you want to reset your preferences?" preferredStyle:UIAlertControllerStyleAlert];
+
+ UIAlertAction* yesAction = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * action) {
+ [self resetPreferences];
+ }];
+
+ UIAlertAction* noAction = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:nil];
+
+ [resetAlert addAction:yesAction];
+ [resetAlert addAction:noAction];
+
+ [self presentViewController:resetAlert animated:YES completion:nil];
+}
+
+- (void)resetPreferences {
+ NSUserDefaults* userDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"dev.traurige.kayoko.preferences"];
+ for (NSString* key in [userDefaults dictionaryRepresentation]) {
+ [userDefaults removeObjectForKey:key];
+ }
+
+ [self reloadSpecifiers];
+ CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), (CFStringRef)@"dev.traurige.kayoko.preferences.reload", nil, nil, YES);
+}
+
+- (void)clearHistoryPrompt {
+ UIAlertController* resetAlert = [UIAlertController alertControllerWithTitle:@"Kayoko" message:@"This will clear your clipboard history and favorites. Do you want to continue?" preferredStyle:UIAlertControllerStyleAlert];
+
+ UIAlertAction* yesAction = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * action) {
+ NSFileManager* fileManager = [NSFileManager defaultManager];
+ for (NSString* path in @[kHistoryPath, kHistoryImagesPath]) {
+ [fileManager removeItemAtPath:path error:nil];
+ }
+ }];
+
+ UIAlertAction* noAction = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:nil];
+
+ [resetAlert addAction:yesAction];
+ [resetAlert addAction:noAction];
+
+ [self presentViewController:resetAlert animated:YES completion:nil];
+}
+@end
diff --git a/Preferences/Makefile b/Preferences/Makefile
new file mode 100644
index 0000000..c193647
--- /dev/null
+++ b/Preferences/Makefile
@@ -0,0 +1,9 @@
+BUNDLE_NAME = KayokoPreferences
+KayokoPreferences_FILES = $(wildcard Controllers/*.m Cells/*.m ../Manager/*.m) ../Utils/CommonUtil.m ../Utils/ImageUtil.m
+KayokoPreferences_FRAMEWORKS = UIKit
+KayokoPreferences_PRIVATE_FRAMEWORKS = Preferences
+KayokoPreferences_INSTALL_PATH = /Library/PreferenceBundles
+KayokoPreferences_CFLAGS = -fobjc-arc -DTHEOS_LEAN_AND_MEAN
+
+include $(THEOS)/makefiles/common.mk
+include $(THEOS_MAKE_PATH)/bundle.mk
diff --git a/Preferences/PreferenceKeys.h b/Preferences/PreferenceKeys.h
new file mode 100644
index 0000000..1df0551
--- /dev/null
+++ b/Preferences/PreferenceKeys.h
@@ -0,0 +1,27 @@
+//
+// PreferenceKeys.h
+// Kayoko
+//
+// Created by Alexandra (@Traurige)
+//
+
+static NSString* const kPreferenceKeyEnabled = @"Enabled";
+static NSString* const kPreferenceKeyMaximumHistoryAmount = @"MaximumHistoryAmount";
+static NSString* const kPreferenceKeySaveText = @"SaveText";
+static NSString* const kPreferenceKeySaveImages = @"SaveImages";
+static NSString* const kPreferenceKeyActivationMethod = @"ActivationMethod";
+static NSString* const kPreferenceKeyAutomaticallyPaste = @"AutomaticallyPaste";
+static NSString* const kPreferenceKeyAddSongDotLinkOption = @"AddSongDotLinkOption";
+static NSString* const kPreferenceKeyAddTranslateOption = @"AddTranslateOption";
+
+static NSUInteger const kActivationMethodPredictionBar = 0;
+static NSUInteger const kActivationMethodDictationKey = 1;
+
+static BOOL const kPreferenceKeyEnabledDefaultValue = YES;
+static NSUInteger const kPreferenceKeyMaximumHistoryAmountDefaultValue = 200;
+static BOOL const kPreferenceKeySaveTextDefaultValue = YES;
+static BOOL const kPreferenceKeySaveImagesDefaultValue = YES;
+static NSUInteger const kPreferenceKeyActivationMethodDefaultValue = kActivationMethodPredictionBar;
+static BOOL const kPreferenceKeyAutomaticallyPasteDefaultValue = YES;
+static BOOL const kPreferenceKeyAddSongDotLinkOptionDefaultValue = YES;
+static BOOL const kPreferenceKeyAddTranslateOptionDefaultValue = YES;
diff --git a/Preferences/Resources/Credits.plist b/Preferences/Resources/Credits.plist
new file mode 100644
index 0000000..f86f36c
--- /dev/null
+++ b/Preferences/Resources/Credits.plist
@@ -0,0 +1,35 @@
+
+
+
+
+ items
+
+
+ cell
+ PSGroupCell
+ footerText
+ Daemon example - @uroboro
+ isStaticText
+
+
+
+ cell
+ PSGroupCell
+ footerText
+ Provided the Pasteboard Darwin notification - @absidue
+ isStaticText
+
+
+
+ cell
+ PSGroupCell
+ footerText
+ Testing - 0xilis, denial, flower and MrGcGamer
+ isStaticText
+
+
+
+ title
+ Credits
+
+
diff --git a/Preferences/Resources/Icon.png b/Preferences/Resources/Icon.png
new file mode 100644
index 0000000..5776b66
Binary files /dev/null and b/Preferences/Resources/Icon.png differ
diff --git a/Preferences/Resources/Icon@2x.png b/Preferences/Resources/Icon@2x.png
new file mode 100644
index 0000000..d0f570f
Binary files /dev/null and b/Preferences/Resources/Icon@2x.png differ
diff --git a/Preferences/Resources/Info.plist b/Preferences/Resources/Info.plist
new file mode 100644
index 0000000..a893aa1
--- /dev/null
+++ b/Preferences/Resources/Info.plist
@@ -0,0 +1,24 @@
+
+
+
+
+ CFBundleDevelopmentRegion
+ English
+ CFBundleExecutable
+ KayokoPreferences
+ CFBundleIdentifier
+ dev.traurige.kayoko.preferences
+ CFBundleInfoDictionaryVersion
+ 6.0
+ CFBundlePackageType
+ BNDL
+ CFBundleShortVersionString
+ 1.0.0
+ CFBundleSignature
+ ????
+ CFBundleVersion
+ 1.0
+ NSPrincipalClass
+ KayokoRootListController
+
+
diff --git a/Preferences/Resources/Root.plist b/Preferences/Resources/Root.plist
new file mode 100644
index 0000000..d98c8ab
--- /dev/null
+++ b/Preferences/Resources/Root.plist
@@ -0,0 +1,296 @@
+
+
+
+
+ items
+
+
+ cell
+ PSGroupCell
+
+
+ cellClass
+ CallaSingleContactCell
+ DisplayName
+ Alexandra
+ Username
+ Traurige
+ Url
+ https://github.com/Traurige
+ height
+ 58
+
+
+ cell
+ PSSwitchCell
+ default
+
+ defaults
+ dev.traurige.kayoko.preferences
+ key
+ Enabled
+ label
+ Enable Kayoko
+ PostNotification
+ dev.traurige.kayoko.preferences.reload
+
+
+
+ cell
+ PSGroupCell
+ label
+ History
+
+
+ cell
+ PSStaticTextCell
+ label
+ Maximum Amount
+
+
+ cell
+ PSSliderCell
+ default
+ 200
+ defaults
+ dev.traurige.kayoko.preferences
+ key
+ MaximumHistoryAmount
+ min
+ 50
+ max
+ 500
+ showValue
+
+ isSegmented
+
+ segmentCount
+ 9
+ PostNotification
+ dev.traurige.kayoko.preferences.reload
+
+
+ cell
+ PSSwitchCell
+ default
+
+ defaults
+ dev.traurige.kayoko.preferences
+ key
+ SaveText
+ label
+ Save Text
+ PostNotification
+ dev.traurige.kayoko.preferences.reload
+
+
+ cell
+ PSSwitchCell
+ default
+
+ defaults
+ dev.traurige.kayoko.preferences
+ key
+ SaveImages
+ label
+ Save Images
+ PostNotification
+ dev.traurige.kayoko.preferences.reload
+
+
+
+ cell
+ PSGroupCell
+ label
+ Behavior
+ footerText
+ The "Prediction Bar" method displays custom suggestions on the "More Keyboard Keyplane" (123).
+ isStaticText
+
+
+
+ cell
+ PSLinkListCell
+ default
+ 0
+ detail
+ PSListItemsController
+ defaults
+ dev.traurige.kayoko.preferences
+ label
+ Activation Method:
+ key
+ ActivationMethod
+ validValues
+
+ 0
+ 1
+
+ validTitles
+
+ Prediction Bar
+ Dictation Key
+
+
+
+ cell
+ PSSwitchCell
+ default
+
+ defaults
+ dev.traurige.kayoko.preferences
+ key
+ AutomaticallyPaste
+ label
+ Automatically Paste
+ PostNotification
+ dev.traurige.kayoko.preferences.reload
+
+
+
+ cell
+ PSGroupCell
+ label
+ Extras
+
+
+ cell
+ PSSwitchCell
+ default
+
+ defaults
+ dev.traurige.kayoko.preferences
+ key
+ AddSongDotLinkOption
+ label
+ Add a Song.Link Option
+ PostNotification
+ dev.traurige.kayoko.preferences.reload
+
+
+ cell
+ PSSwitchCell
+ default
+
+ defaults
+ dev.traurige.kayoko.preferences
+ key
+ AddTranslateOption
+ label
+ Add a Translate Option
+ PostNotification
+ dev.traurige.kayoko.preferences.reload
+
+
+
+ cell
+ PSGroupCell
+ footerText
+ Try out your changes by typing, copying and pasting text.
+ isStaticText
+
+
+
+ cell
+ PSEditTextCell
+ placeholder
+ Butterflies are pretty...
+
+
+
+ cell
+ PSGroupCell
+ label
+ Tools
+
+
+ cell
+ PSButtonCell
+ label
+ Respring
+ action
+ respring
+
+
+ cell
+ PSButtonCell
+ label
+ Reset Preferences
+ action
+ resetPrompt
+
+
+ cell
+ PSButtonCell
+ label
+ Clear History
+ action
+ clearHistoryPrompt
+
+
+
+ cell
+ PSGroupCell
+ footerText
+ Thanks to you and everyone who has helped in any way.
+ isStaticText
+
+
+
+ cell
+ PSLinkCell
+ label
+ Credits
+ detail
+ KayokoCreditsListController
+
+
+
+ cell
+ PSGroupCell
+ footerText
+ Kayoko by Traurige
+ isStaticText
+
+
+
+ cellClass
+ CallaLinkCell
+ label
+ Source Code
+ subtitle
+ It's on GitHub
+ url
+ https://github.com/Traurige/Kayoko
+ height
+ 52
+
+
+ cellClass
+ CallaLinkCell
+ label
+ Bug/Feature
+ subtitle
+ Submit an issue
+ url
+ https://github.com/Traurige/Kayoko/issues/new/choose
+ height
+ 52
+
+
+ cellClass
+ CallaLinkCell
+ label
+ Donate
+ subtitle
+ I got a Ko-fi
+ url
+ https://ko-fi.com/traurige
+ height
+ 52
+
+
+ title
+ Kayoko
+
+
diff --git a/Preferences/layout/Library/PreferenceLoader/Preferences/KayokoPreferences.plist b/Preferences/layout/Library/PreferenceLoader/Preferences/KayokoPreferences.plist
new file mode 100644
index 0000000..6de067b
--- /dev/null
+++ b/Preferences/layout/Library/PreferenceLoader/Preferences/KayokoPreferences.plist
@@ -0,0 +1,21 @@
+
+
+
+
+ entry
+
+ bundle
+ KayokoPreferences
+ cell
+ PSLinkCell
+ detail
+ KayokoRootListController
+ icon
+ Icon.png
+ isController
+
+ label
+ Kayoko
+
+
+
diff --git a/Preview.png b/Preview.png
new file mode 100644
index 0000000..f27b251
Binary files /dev/null and b/Preview.png differ
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..4622d70
--- /dev/null
+++ b/README.md
@@ -0,0 +1,19 @@
+# Kayoko
+Feature rich clipboard manager for iOS
+
+## Preview
+
+
+## Installation
+1. Download the latest `deb` from the [releases](https://github.com/Traurige/Kayoko/releases)
+2. Install Kayoko
+
+## Compatibility
+iPhone, iPad and iPod running iOS/iPadOS 13 or later
+
+## Compiling
+ - [Theos](https://theos.dev/) is required to compile the project
+ - You may want to edit the root `Makefile` to use your Theos SDK and toolchain
+
+## License
+[GPLv3](https://github.com/Traurige/Kayoko/blob/main/COPYING)
diff --git a/Tweak/Core/KayokoCore.h b/Tweak/Core/KayokoCore.h
new file mode 100644
index 0000000..bc95768
--- /dev/null
+++ b/Tweak/Core/KayokoCore.h
@@ -0,0 +1,28 @@
+//
+// KayokoCore.h
+// Kayoko
+//
+// Created by Alexandra (@Traurige)
+//
+
+#import "substrate.h"
+#import "../../Manager/PasteboardManager.h"
+#import "Views/KayokoView.h"
+#import
+
+static CGFloat const kHeight = 480;
+
+KayokoView* kayokoView;
+
+HBPreferences* preferences;
+BOOL pfEnabled;
+
+NSUInteger pfMaximumHistoryAmount;
+BOOL pfSaveText;
+BOOL pfSaveImages;
+BOOL pfAutomaticallyPaste;
+BOOL pfAddTranslateOption;
+BOOL pfAddSongDotLinkOption;
+
+@interface UIStatusBarWindow : UIWindow
+@end
diff --git a/Tweak/Core/KayokoCore.m b/Tweak/Core/KayokoCore.m
new file mode 100644
index 0000000..a454c13
--- /dev/null
+++ b/Tweak/Core/KayokoCore.m
@@ -0,0 +1,88 @@
+//
+// KayokoCore.m
+// Kayoko
+//
+// Created by Alexandra (@Traurige)
+//
+
+#import "KayokoCore.h"
+
+#pragma mark - Class hooks
+
+// UIStatusBarWindow is sick because it's present everywhere and doesn't need uikit injection
+// it also prevents sandbox issues as the core runs on springboard (which has fs r/w)
+void (* orig_UIStatusBarWindow_initWithFrame)(UIStatusBarWindow* self, SEL _cmd, CGRect frame);
+void override_UIStatusBarWindow_initWithFrame(UIStatusBarWindow* self, SEL _cmd, CGRect frame) {
+ orig_UIStatusBarWindow_initWithFrame(self, _cmd, frame);
+
+ if (!kayokoView) {
+ CGRect bounds = [[UIScreen mainScreen] bounds];
+ kayokoView = [[KayokoView alloc] initWithFrame:CGRectMake(0, bounds.size.height - kHeight, bounds.size.width, kHeight)];
+ [kayokoView setAddTranslateOption:pfAddTranslateOption];
+ [kayokoView setAddSongDotLinkOption:pfAddSongDotLinkOption];
+ [self addSubview:kayokoView];
+ }
+}
+
+#pragma mark - Notification callbacks
+
+static void kayokod_pasteboard_changed_notification() {
+ [[PasteboardManager sharedInstance] pullPasteboardChanges];
+}
+
+static void show() {
+ if ([kayokoView isHidden]) {
+ [kayokoView show];
+ }
+}
+
+static void hide() {
+ if (![kayokoView isHidden]) {
+ [kayokoView hide];
+ }
+}
+
+static void reload() {
+ if (![kayokoView isHidden]) {
+ [kayokoView reload];
+ }
+}
+
+#pragma mark - Preferences
+
+static void load_preferences() {
+ preferences = [[HBPreferences alloc] initWithIdentifier:@"dev.traurige.kayoko.preferences"];
+ [preferences registerBool:&pfEnabled default:kPreferenceKeyEnabledDefaultValue forKey:kPreferenceKeyEnabled];
+ [preferences registerUnsignedInteger:&pfMaximumHistoryAmount default:kPreferenceKeyMaximumHistoryAmountDefaultValue forKey:kPreferenceKeyMaximumHistoryAmount];
+ [preferences registerBool:&pfSaveText default:kPreferenceKeySaveTextDefaultValue forKey:kPreferenceKeySaveText];
+ [preferences registerBool:&pfSaveImages default:kPreferenceKeySaveImagesDefaultValue forKey:kPreferenceKeySaveImages];
+ [preferences registerBool:&pfAutomaticallyPaste default:kPreferenceKeyAutomaticallyPaste forKey:kPreferenceKeyAutomaticallyPaste];
+ [preferences registerBool:&pfAddSongDotLinkOption default:kPreferenceKeyAddSongDotLinkOptionDefaultValue forKey:kPreferenceKeyAddSongDotLinkOption];
+ [preferences registerBool:&pfAddTranslateOption default:kPreferenceKeyAddTranslateOptionDefaultValue forKey:kPreferenceKeyAddTranslateOption];
+
+ [[PasteboardManager sharedInstance] setMaximumHistoryAmount:pfMaximumHistoryAmount];
+ [[PasteboardManager sharedInstance] setSaveText:pfSaveText];
+ [[PasteboardManager sharedInstance] setSaveImages:pfSaveImages];
+ [[PasteboardManager sharedInstance] setAutomaticallyPaste:pfAutomaticallyPaste];
+
+ [kayokoView setAddTranslateOption:pfAddTranslateOption];
+ [kayokoView setAddSongDotLinkOption:pfAddSongDotLinkOption];
+}
+
+#pragma mark - Constructor
+
+__attribute((constructor)) static void initialize() {
+ load_preferences();
+
+ if (!pfEnabled) {
+ return;
+ }
+
+ MSHookMessageEx(NSClassFromString(@"UIStatusBarWindow"), @selector(initWithFrame:), (IMP)&override_UIStatusBarWindow_initWithFrame, (IMP *)&orig_UIStatusBarWindow_initWithFrame);
+
+ CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)kayokod_pasteboard_changed_notification, (CFStringRef)@"dev.traurige.kayoko.daemon.pasteboard.changed", NULL, (CFNotificationSuspensionBehavior)kNilOptions);
+ CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)show, (CFStringRef)@"dev.traurige.kayoko.core.show", NULL, (CFNotificationSuspensionBehavior)kNilOptions);
+ CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)hide, (CFStringRef)@"dev.traurige.kayoko.core.hide", NULL, (CFNotificationSuspensionBehavior)kNilOptions);
+ CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)reload, (CFStringRef)@"dev.traurige.kayoko.core.reload", NULL, (CFNotificationSuspensionBehavior)kNilOptions);
+ CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)load_preferences, (CFStringRef)@"dev.traurige.kayoko.preferences.reload", NULL, (CFNotificationSuspensionBehavior)kNilOptions);
+}
diff --git a/Tweak/Core/KayokoCore.plist b/Tweak/Core/KayokoCore.plist
new file mode 100644
index 0000000..10dc654
--- /dev/null
+++ b/Tweak/Core/KayokoCore.plist
@@ -0,0 +1 @@
+{ Filter = { Bundles = ( "com.apple.springboard" ); }; }
diff --git a/Tweak/Core/Makefile b/Tweak/Core/Makefile
new file mode 100644
index 0000000..ea91519
--- /dev/null
+++ b/Tweak/Core/Makefile
@@ -0,0 +1,9 @@
+TWEAK_NAME = KayokoCore
+KayokoCore_FILES = KayokoCore.m $(wildcard ../../Manager/*.m Views/*.m ../../Utils/*.m)
+KayokoCore_CFLAGS = -fobjc-arc -DTHEOS_LEAN_AND_MEAN
+KayokoCore_FRAMEWORKS = UIKit
+KayokoCore_EXTRA_FRAMEWORKS = Cephei
+
+include $(THEOS)/makefiles/common.mk
+include $(THEOS_MAKE_PATH)/aggregate.mk
+include $(THEOS_MAKE_PATH)/tweak.mk
diff --git a/Tweak/Core/Views/KayokoFavoritesTableView.h b/Tweak/Core/Views/KayokoFavoritesTableView.h
new file mode 100644
index 0000000..a2e0f6a
--- /dev/null
+++ b/Tweak/Core/Views/KayokoFavoritesTableView.h
@@ -0,0 +1,11 @@
+//
+// KayokoFavoritesTableView.h
+// Kayoko
+//
+// Created by Alexandra (@Traurige)
+//
+
+#import "KayokoTableView.h"
+
+@interface KayokoFavoritesTableView : KayokoTableView
+@end
diff --git a/Tweak/Core/Views/KayokoFavoritesTableView.m b/Tweak/Core/Views/KayokoFavoritesTableView.m
new file mode 100644
index 0000000..90ad6ea
--- /dev/null
+++ b/Tweak/Core/Views/KayokoFavoritesTableView.m
@@ -0,0 +1,71 @@
+//
+// KayokoFavoritesTableView.m
+// Kayoko
+//
+// Created by Alexandra (@Traurige)
+//
+
+#import "KayokoFavoritesTableView.h"
+
+@implementation KayokoFavoritesTableView
+- (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView leadingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath {
+ NSMutableArray* actions = [[NSMutableArray alloc] init];
+ PasteboardItem* item = [PasteboardItem itemFromDictionary:[self items][[indexPath row]]];
+
+ UIContextualAction* unfavorite = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"" handler:^(UIContextualAction* _Nonnull action, __kindof UIView* _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
+ [[PasteboardManager sharedInstance] addPasteboardItem:item toHistoryWithKey:kHistoryKeyHistory];
+ [[PasteboardManager sharedInstance] removePasteboardItem:item fromHistoryWithKey:kHistoryKeyFavorites shouldRemoveImage:NO];
+ completionHandler(YES);
+ }];
+ [unfavorite setImage:[UIImage systemImageNamed:@"heart.slash.fill"]];
+ [unfavorite setBackgroundColor:[UIColor systemPinkColor]];
+ [actions addObject:unfavorite];
+
+ if ([item hasLink]) {
+ UIContextualAction* linkAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"" handler:^(UIContextualAction* _Nonnull action, __kindof UIView* _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
+ [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[item content]] options:@{} completionHandler:nil];
+ completionHandler(YES);
+ }];
+ [linkAction setImage:[UIImage systemImageNamed:@"arrow.up"]];
+ [linkAction setBackgroundColor:[UIColor systemGreenColor]];
+ [actions addObject:linkAction];
+ }
+
+ if ([self addSongDotLinkOption] && [item hasMusicLink]) {
+ UIContextualAction* songDotLinkAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"" handler:^(UIContextualAction* _Nonnull action, __kindof UIView* _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
+ [[PasteboardManager sharedInstance] addSongDotLinkItemFromItem:item];
+ completionHandler(YES);
+ }];
+ [songDotLinkAction setImage:[UIImage systemImageNamed:@"music.note"]];
+ [songDotLinkAction setBackgroundColor:[UIColor systemPurpleColor]];
+ [actions addObject:songDotLinkAction];
+ }
+
+ if ([self addTranslateOption] && [item hasPlainText]) {
+ UIContextualAction* translateAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"" handler:^(UIContextualAction* _Nonnull action, __kindof UIView* _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
+ [[PasteboardManager sharedInstance] addTranslateItemFromItem:item];
+ completionHandler(YES);
+ }];
+ [translateAction setImage:[UIImage systemImageNamed:@"globe"]];
+ [translateAction setBackgroundColor:[UIColor systemBlueColor]];
+ [actions addObject:translateAction];
+ }
+
+ return [UISwipeActionsConfiguration configurationWithActions:actions];
+}
+
+- (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath {
+ NSMutableArray* actions = [[NSMutableArray alloc] init];
+ PasteboardItem* item = [PasteboardItem itemFromDictionary:[self items][[indexPath row]]];
+
+ UIContextualAction* deleteAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"" handler:^(UIContextualAction* _Nonnull action, __kindof UIView* _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
+ [[PasteboardManager sharedInstance] removePasteboardItem:item fromHistoryWithKey:kHistoryKeyFavorites shouldRemoveImage:YES];
+ completionHandler(YES);
+ }];
+ [deleteAction setImage:[UIImage systemImageNamed:@"trash.fill"]];
+ [deleteAction setBackgroundColor:[UIColor systemRedColor]];
+ [actions addObject:deleteAction];
+
+ return [UISwipeActionsConfiguration configurationWithActions:actions];
+}
+@end
diff --git a/Tweak/Core/Views/KayokoHistoryTableView.h b/Tweak/Core/Views/KayokoHistoryTableView.h
new file mode 100644
index 0000000..49f7062
--- /dev/null
+++ b/Tweak/Core/Views/KayokoHistoryTableView.h
@@ -0,0 +1,11 @@
+//
+// KayokoHistoryTableView.h
+// Kayoko
+//
+// Created by Alexandra (@Traurige)
+//
+
+#import "KayokoTableView.h"
+
+@interface KayokoHistoryTableView : KayokoTableView
+@end
diff --git a/Tweak/Core/Views/KayokoHistoryTableView.m b/Tweak/Core/Views/KayokoHistoryTableView.m
new file mode 100644
index 0000000..1be49bd
--- /dev/null
+++ b/Tweak/Core/Views/KayokoHistoryTableView.m
@@ -0,0 +1,71 @@
+//
+// KayokoHistoryTableView.m
+// Kayoko
+//
+// Created by Alexandra (@Traurige)
+//
+
+#import "KayokoHistoryTableView.h"
+
+@implementation KayokoHistoryTableView
+- (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView leadingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath {
+ NSMutableArray* actions = [[NSMutableArray alloc] init];
+ PasteboardItem* item = [PasteboardItem itemFromDictionary:[self items][[indexPath row]]];
+
+ UIContextualAction* favoriteAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"" handler:^(UIContextualAction* _Nonnull action, __kindof UIView* _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
+ [[PasteboardManager sharedInstance] addPasteboardItem:item toHistoryWithKey:kHistoryKeyFavorites];
+ [[PasteboardManager sharedInstance] removePasteboardItem:item fromHistoryWithKey:kHistoryKeyHistory shouldRemoveImage:NO];
+ completionHandler(YES);
+ }];
+ [favoriteAction setImage:[UIImage systemImageNamed:@"heart.fill"]];
+ [favoriteAction setBackgroundColor:[UIColor systemPinkColor]];
+ [actions addObject:favoriteAction];
+
+ if ([item hasLink]) {
+ UIContextualAction* linkAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"" handler:^(UIContextualAction* _Nonnull action, __kindof UIView* _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
+ [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[item content]] options:@{} completionHandler:nil];
+ completionHandler(YES);
+ }];
+ [linkAction setImage:[UIImage systemImageNamed:@"arrow.up"]];
+ [linkAction setBackgroundColor:[UIColor systemGreenColor]];
+ [actions addObject:linkAction];
+ }
+
+ if ([self addSongDotLinkOption] && [item hasMusicLink]) {
+ UIContextualAction* songDotLinkAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"" handler:^(UIContextualAction* _Nonnull action, __kindof UIView* _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
+ [[PasteboardManager sharedInstance] addSongDotLinkItemFromItem:item];
+ completionHandler(YES);
+ }];
+ [songDotLinkAction setImage:[UIImage systemImageNamed:@"music.note"]];
+ [songDotLinkAction setBackgroundColor:[UIColor systemPurpleColor]];
+ [actions addObject:songDotLinkAction];
+ }
+
+ if ([self addTranslateOption] && [item hasPlainText]) {
+ UIContextualAction* translateAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"" handler:^(UIContextualAction* _Nonnull action, __kindof UIView* _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
+ [[PasteboardManager sharedInstance] addTranslateItemFromItem:item];
+ completionHandler(YES);
+ }];
+ [translateAction setImage:[UIImage systemImageNamed:@"globe"]];
+ [translateAction setBackgroundColor:[UIColor systemBlueColor]];
+ [actions addObject:translateAction];
+ }
+
+ return [UISwipeActionsConfiguration configurationWithActions:actions];
+}
+
+- (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath {
+ NSMutableArray* actions = [[NSMutableArray alloc] init];
+ PasteboardItem* item = [PasteboardItem itemFromDictionary:[self items][[indexPath row]]];
+
+ UIContextualAction* deleteAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"" handler:^(UIContextualAction* _Nonnull action, __kindof UIView* _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
+ [[PasteboardManager sharedInstance] removePasteboardItem:item fromHistoryWithKey:kHistoryKeyHistory shouldRemoveImage:YES];
+ completionHandler(YES);
+ }];
+ [deleteAction setImage:[UIImage systemImageNamed:@"trash.fill"]];
+ [deleteAction setBackgroundColor:[UIColor systemRedColor]];
+ [actions addObject:deleteAction];
+
+ return [UISwipeActionsConfiguration configurationWithActions:actions];
+}
+@end
diff --git a/Tweak/Core/Views/KayokoTableView.h b/Tweak/Core/Views/KayokoTableView.h
new file mode 100644
index 0000000..6ef91f6
--- /dev/null
+++ b/Tweak/Core/Views/KayokoTableView.h
@@ -0,0 +1,17 @@
+//
+// KayokoTableView.h
+// Kayoko
+//
+// Created by Alexandra (@Traurige)
+//
+
+#import
+#import "KayokoTableViewCell.h"
+#import "../../../Manager/PasteboardManager.h"
+
+@interface KayokoTableView : UITableView
+@property(nonatomic, retain)NSArray* items;
+@property(atomic, assign)BOOL addTranslateOption;
+@property(atomic, assign)BOOL addSongDotLinkOption;
+- (void)reloadDataWithItems:(NSArray *)items;
+@end
diff --git a/Tweak/Core/Views/KayokoTableView.m b/Tweak/Core/Views/KayokoTableView.m
new file mode 100644
index 0000000..19ee76c
--- /dev/null
+++ b/Tweak/Core/Views/KayokoTableView.m
@@ -0,0 +1,51 @@
+//
+// KayokoTableView.m
+// Kayoko
+//
+// Created by Alexandra (@Traurige)
+//
+
+#import "KayokoTableView.h"
+
+@implementation KayokoTableView
+- (instancetype)initWithFrame:(CGRect)frame {
+ self = [super initWithFrame:frame];
+
+ if (self) {
+ [self setDelegate:self];
+ [self setDataSource:self];
+ [self setBackgroundColor:[UIColor clearColor]];
+ [self setRowHeight:80];
+ }
+
+ return self;
+}
+
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
+ return [[self items] count] ?: 0;
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
+ NSDictionary* dictionary = [self items][[indexPath row]];
+ PasteboardItem* item = [PasteboardItem itemFromDictionary:dictionary];
+
+ KayokoTableViewCell* cell = [[KayokoTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault andItem:item reuseIdentifier:@"KayokoTableViewCell"];
+
+ return cell;
+}
+
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
+ [[tableView cellForRowAtIndexPath:indexPath] setSelected:NO animated:YES];
+
+ NSDictionary* dictionary = [self items][[indexPath row]];
+ PasteboardItem* item = [PasteboardItem itemFromDictionary:dictionary];
+ [[PasteboardManager sharedInstance] updatePasteboardWithItem:item fromHistoryWithKey:kHistoryKeyHistory shouldAutoPaste:YES];
+
+ [[self superview] performSelector:@selector(hide)];
+}
+
+- (void)reloadDataWithItems:(NSArray *)items {
+ [self setItems:items];
+ [self reloadData];
+}
+@end
diff --git a/Tweak/Core/Views/KayokoTableViewCell.h b/Tweak/Core/Views/KayokoTableViewCell.h
new file mode 100644
index 0000000..f9ce719
--- /dev/null
+++ b/Tweak/Core/Views/KayokoTableViewCell.h
@@ -0,0 +1,29 @@
+//
+// KayokoTableViewCell.h
+// Kayoko
+//
+// Created by Alexandra (@Traurige)
+//
+
+#import
+#import
+#import "../../../Manager/PasteboardManager.h"
+#import "../../../Utils/ImageUtil.h"
+#import "../../../Utils/ColorUtil.h"
+
+@interface KayokoTableViewCell : UITableViewCell
+@property(nonatomic, retain)UIImageView* iconImageView;
+@property(nonatomic, retain)UILabel* headerLabel;
+@property(nonatomic, retain)UILabel* contentLabel;
+@property(nonatomic, retain)UIImageView* contentImageView;
+- (instancetype)initWithStyle:(UITableViewCellStyle)style andItem:(PasteboardItem *)item reuseIdentifier:(NSString *)reuseIdentifier;
+@end
+
+@interface UIImage (Private)
++ (instancetype)_applicationIconImageForBundleIdentifier:(NSString *)bundleIdentifier format:(int)format scale:(CGFloat)scale;
+@end
+
+@interface SBApplicationController : NSObject
++ (id)sharedInstance;
+- (id)applicationWithBundleIdentifier:(id)arg1;
+@end
diff --git a/Tweak/Core/Views/KayokoTableViewCell.m b/Tweak/Core/Views/KayokoTableViewCell.m
new file mode 100644
index 0000000..6ef91fe
--- /dev/null
+++ b/Tweak/Core/Views/KayokoTableViewCell.m
@@ -0,0 +1,117 @@
+//
+// KayokoTableViewCell.m
+// Kayoko
+//
+// Created by Alexandra (@Traurige)
+//
+
+#import "KayokoTableViewCell.h"
+
+@implementation KayokoTableViewCell
+- (instancetype)initWithStyle:(UITableViewCellStyle)style andItem:(PasteboardItem *)item reuseIdentifier:(NSString *)reuseIdentifier {
+ self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
+
+ if (self) {
+ [self setBackgroundColor:[UIColor clearColor]];
+
+ // icon image view
+ [self setIconImageView:[[UIImageView alloc] init]];
+
+ UIImage* icon = [UIImage _applicationIconImageForBundleIdentifier:[item bundleIdentifier] format:2 scale:[[UIScreen mainScreen] scale]];
+ if (!icon) {
+ icon = [UIImage _applicationIconImageForBundleIdentifier:@"com.apple.WebSheet" format:2 scale:[[UIScreen mainScreen] scale]];
+ }
+ [[self iconImageView] setImage:icon];
+
+ [[self iconImageView] setContentMode:UIViewContentModeScaleAspectFit];
+ [[self iconImageView] setClipsToBounds:YES];
+ [[[self iconImageView] layer] setCornerRadius:10];
+ [self addSubview:[self iconImageView]];
+
+ [[self iconImageView] setTranslatesAutoresizingMaskIntoConstraints:NO];
+ [NSLayoutConstraint activateConstraints:@[
+ [[[self iconImageView] widthAnchor] constraintEqualToConstant:50],
+ [[[self iconImageView] heightAnchor] constraintEqualToConstant:50],
+ [[[self iconImageView] centerYAnchor] constraintEqualToAnchor:[self centerYAnchor]],
+ [[[self iconImageView] leadingAnchor] constraintEqualToAnchor:[self leadingAnchor] constant:24]
+ ]];
+
+
+ // content image view
+ if ([item hasImage] || [item hasColor]) {
+ [self setContentImageView:[[UIImageView alloc] init]];
+
+ if (![item hasColor]) {
+ NSData* imageData = [[NSFileManager defaultManager] contentsAtPath:[NSString stringWithFormat:@"%@%@", kHistoryImagesPath, [item imageName]]];
+ UIImage* originalImage = [UIImage imageWithData:imageData];
+ // there's no need to display the image in full resolution in the table view
+ UIImage* scaledImage = [ImageUtil imageWithImage:originalImage scaledToSize:CGSizeMake(originalImage.size.width / 4, originalImage.size.height / 4)];
+ [[self contentImageView] setImage:scaledImage];
+ } else {
+ if ([[item content] hasPrefix:@"#"]) {
+ [[self contentImageView] setBackgroundColor:[ColorUtil colorFromHex:[item content]]];
+ } else if ([[item content] hasPrefix:@"rgb("]) {
+ [[self contentImageView] setBackgroundColor:[ColorUtil colorFromRgb:[item content]]];
+ } else if ([[item content] hasPrefix:@"rgba("]) {
+ [[self contentImageView] setBackgroundColor:[ColorUtil colorFromRgba:[item content]]];
+ }
+ }
+
+ [[self contentImageView] setContentMode:UIViewContentModeScaleAspectFill];
+ [[self contentImageView] setClipsToBounds:YES];
+ [[[self contentImageView] layer] setCornerRadius:4];
+ [self addSubview:[self contentImageView]];
+
+ [[self contentImageView] setTranslatesAutoresizingMaskIntoConstraints:NO];
+ [NSLayoutConstraint activateConstraints:@[
+ [[[self contentImageView] widthAnchor] constraintEqualToConstant:80],
+ [[[self contentImageView] heightAnchor] constraintEqualToConstant:45],
+ [[[self contentImageView] centerYAnchor] constraintEqualToAnchor:[self centerYAnchor]],
+ [[[self contentImageView] trailingAnchor] constraintEqualToAnchor:[self trailingAnchor] constant:-24]
+ ]];
+ }
+
+
+ // header label
+ [self setHeaderLabel:[[UILabel alloc] init]];
+ [[self headerLabel] setText:[[[objc_getClass("SBApplicationController") sharedInstance] applicationWithBundleIdentifier:[item bundleIdentifier]] displayName] ?: @"SpringBoard"];
+ [[self headerLabel] setFont:[UIFont systemFontOfSize:17 weight:UIFontWeightMedium]];
+ [[self headerLabel] setTextColor:[UIColor labelColor]];
+ [self addSubview:[self headerLabel]];
+
+ [[self headerLabel] setTranslatesAutoresizingMaskIntoConstraints:NO];
+ if (![item hasImage] && ![item hasColor]) {
+ [NSLayoutConstraint activateConstraints:@[
+ [[[self headerLabel] topAnchor] constraintEqualToAnchor:[[self iconImageView] topAnchor] constant:-4],
+ [[[self headerLabel] leadingAnchor] constraintEqualToAnchor:[[self iconImageView] trailingAnchor] constant:16],
+ [[[self headerLabel] trailingAnchor] constraintEqualToAnchor:[self trailingAnchor] constant:-24]
+ ]];
+ } else {
+ [NSLayoutConstraint activateConstraints:@[
+ [[[self headerLabel] topAnchor] constraintEqualToAnchor:[[self iconImageView] topAnchor] constant:-4],
+ [[[self headerLabel] leadingAnchor] constraintEqualToAnchor:[[self iconImageView] trailingAnchor] constant:16],
+ [[[self headerLabel] trailingAnchor] constraintEqualToAnchor:[[self contentImageView] leadingAnchor] constant:-16]
+ ]];
+ }
+
+
+ // content label
+ [self setContentLabel:[[UILabel alloc] init]];
+ [[self contentLabel] setText:[item content]];
+ [[self contentLabel] setFont:[UIFont systemFontOfSize:14]];
+ [[self contentLabel] setTextColor:[[UIColor labelColor] colorWithAlphaComponent:0.9]];
+ [[self contentLabel] setNumberOfLines:2];
+ [[self contentLabel] setLineBreakMode:NSLineBreakByTruncatingTail];
+ [self addSubview:[self contentLabel]];
+
+ [[self contentLabel] setTranslatesAutoresizingMaskIntoConstraints:NO];
+ [NSLayoutConstraint activateConstraints:@[
+ [[[self contentLabel] topAnchor] constraintEqualToAnchor:[[self headerLabel] bottomAnchor] constant:2],
+ [[[self contentLabel] leadingAnchor] constraintEqualToAnchor:[[self headerLabel] leadingAnchor]],
+ [[[self contentLabel] trailingAnchor] constraintEqualToAnchor:[[self headerLabel] trailingAnchor]]
+ ]];
+ }
+
+ return self;
+}
+@end
diff --git a/Tweak/Core/Views/KayokoView.h b/Tweak/Core/Views/KayokoView.h
new file mode 100644
index 0000000..242dbcf
--- /dev/null
+++ b/Tweak/Core/Views/KayokoView.h
@@ -0,0 +1,32 @@
+//
+// KayokoView.h
+// Kayoko
+//
+// Created by Alexandra (@Traurige)
+//
+
+#import
+#import "KayokoHistoryTableView.h"
+#import "KayokoFavoritesTableView.h"
+
+@interface _UIGrabber : UIControl
+@end
+
+@interface KayokoView : UIView
+@property(nonatomic, retain)UIBlurEffect* blurEffect;
+@property(nonatomic, retain)UIVisualEffectView* blurEffectView;
+@property(nonatomic, retain)UIView* headerView;
+@property(nonatomic, retain)_UIGrabber* grabber;
+@property(nonatomic, retain)UILabel* titleLabel;
+@property(nonatomic, retain)UILabel* subtitleLabel;
+@property(nonatomic, retain)UIButton* favoritesButton;
+@property(nonatomic, retain)UIPanGestureRecognizer* panGesture;
+@property(nonatomic, retain)KayokoHistoryTableView* historyTableView;
+@property(nonatomic, retain)KayokoFavoritesTableView* favoritesTableView;
+@property(atomic, assign)BOOL isAnimating;
+@property(atomic, assign)BOOL addTranslateOption;
+@property(atomic, assign)BOOL addSongDotLinkOption;
+- (void)show;
+- (void)hide;
+- (void)reload;
+@end
diff --git a/Tweak/Core/Views/KayokoView.m b/Tweak/Core/Views/KayokoView.m
new file mode 100644
index 0000000..768b438
--- /dev/null
+++ b/Tweak/Core/Views/KayokoView.m
@@ -0,0 +1,276 @@
+//
+// KayokoView.m
+// Kayoko
+//
+// Created by Alexandra (@Traurige)
+//
+
+#import "KayokoView.h"
+
+@implementation KayokoView
+- (instancetype)initWithFrame:(CGRect)frame {
+ self = [super initWithFrame:frame];
+
+ if (self) {
+ [self hide];
+
+ [[self layer] setShadowColor:[[UIColor blackColor] CGColor]];
+ [[self layer] setShadowOffset:CGSizeZero];
+ [[self layer] setShadowRadius:10];
+ [[self layer] setShadowOpacity:0.5];
+
+ // background blur
+ [self setBlurEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleRegular]];
+ [self setBlurEffectView:[[UIVisualEffectView alloc] initWithEffect:[self blurEffect]]];
+ [self addSubview:[self blurEffectView]];
+
+ [[self blurEffectView] setTranslatesAutoresizingMaskIntoConstraints:NO];
+ [NSLayoutConstraint activateConstraints:@[
+ [[[self blurEffectView] topAnchor] constraintEqualToAnchor:[self topAnchor]],
+ [[[self blurEffectView] leadingAnchor] constraintEqualToAnchor:[self leadingAnchor]],
+ [[[self blurEffectView] trailingAnchor] constraintEqualToAnchor:[self trailingAnchor]],
+ [[[self blurEffectView] bottomAnchor] constraintEqualToAnchor:[self bottomAnchor]]
+ ]];
+
+
+ // header view
+ [self setHeaderView:[[UIView alloc] init]];
+ [self addSubview:[self headerView]];
+
+ [[self headerView] setTranslatesAutoresizingMaskIntoConstraints:NO];
+ [NSLayoutConstraint activateConstraints:@[
+ [[[self headerView] heightAnchor] constraintEqualToConstant:90],
+ [[[self headerView] topAnchor] constraintEqualToAnchor:[self topAnchor]],
+ [[[self headerView] leadingAnchor] constraintEqualToAnchor:[self leadingAnchor]],
+ [[[self headerView] trailingAnchor] constraintEqualToAnchor:[self trailingAnchor]]
+ ]];
+
+
+ // grabber
+ [self setGrabber:[[_UIGrabber alloc] init]];
+ [[self headerView] addSubview:[self grabber]];
+
+ [[self grabber] setTranslatesAutoresizingMaskIntoConstraints:NO];
+ [NSLayoutConstraint activateConstraints:@[
+ [[[self grabber] topAnchor] constraintEqualToAnchor:[[self headerView] topAnchor] constant:12],
+ [[[self grabber] centerXAnchor] constraintEqualToAnchor:[[self headerView] centerXAnchor]],
+ ]];
+
+
+ // title label
+ [self setTitleLabel:[[UILabel alloc] init]];
+ [[self titleLabel] setText:@"Kayoko"];
+ [[self titleLabel] setFont:[UIFont systemFontOfSize:32 weight:UIFontWeightMedium]];
+ [[self titleLabel] setTextColor:[UIColor labelColor]];
+ [[self headerView] addSubview:[self titleLabel]];
+
+ [[self titleLabel] setTranslatesAutoresizingMaskIntoConstraints:NO];
+ [NSLayoutConstraint activateConstraints:@[
+ [[[self titleLabel] topAnchor] constraintEqualToAnchor:[[self grabber] bottomAnchor] constant:12],
+ [[[self titleLabel] leadingAnchor] constraintEqualToAnchor:[[self headerView] leadingAnchor] constant:24],
+ ]];
+
+
+ // subtitle label
+ [self setSubtitleLabel:[[UILabel alloc] init]];
+ [[self subtitleLabel] setFont:[UIFont systemFontOfSize:17 weight:UIFontWeightMedium]];
+ [[self subtitleLabel] setTextColor:[[UIColor labelColor] colorWithAlphaComponent:0.8]];
+ [[self headerView] addSubview:[self subtitleLabel]];
+
+ [[self subtitleLabel] setTranslatesAutoresizingMaskIntoConstraints:NO];
+ [NSLayoutConstraint activateConstraints:@[
+ [[[self subtitleLabel] topAnchor] constraintEqualToAnchor:[[self titleLabel] bottomAnchor] constant:2],
+ [[[self subtitleLabel] leadingAnchor] constraintEqualToAnchor:[[self titleLabel] leadingAnchor]],
+ ]];
+
+
+ // favorites button
+ [self setFavoritesButton:[[UIButton alloc] init]];
+ [[self favoritesButton] addTarget:self action:@selector(showFavorites) forControlEvents:UIControlEventTouchUpInside];
+
+ UIImageSymbolConfiguration* configuration = [UIImageSymbolConfiguration configurationWithPointSize:21 weight:UIImageSymbolWeightMedium];
+ [[self favoritesButton] setImage:[[UIImage systemImageNamed:@"heart"] imageWithConfiguration:configuration] forState:UIControlStateNormal];
+
+ [[self favoritesButton] setTintColor:[UIColor labelColor]];
+ [[self headerView] addSubview:[self favoritesButton]];
+
+ [[self favoritesButton] setTranslatesAutoresizingMaskIntoConstraints:NO];
+ [NSLayoutConstraint activateConstraints:@[
+ [[[self favoritesButton] centerYAnchor] constraintEqualToAnchor:[[self titleLabel] centerYAnchor]],
+ [[[self favoritesButton] trailingAnchor] constraintEqualToAnchor:[[self headerView] trailingAnchor] constant:-24],
+ ]];
+
+
+ // pan gesture
+ [self setPanGesture:[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGestureRecognizer:)]];
+ [[self headerView] addGestureRecognizer:[self panGesture]];
+
+
+ // history table view
+ [self setHistoryTableView:[[KayokoHistoryTableView alloc] init]];
+ [self addSubview:[self historyTableView]];
+
+ [[self historyTableView] setTranslatesAutoresizingMaskIntoConstraints:NO];
+ [NSLayoutConstraint activateConstraints:@[
+ [[[self historyTableView] topAnchor] constraintEqualToAnchor:[[self headerView] bottomAnchor] constant:8],
+ [[[self historyTableView] leadingAnchor] constraintEqualToAnchor:[self leadingAnchor]],
+ [[[self historyTableView] trailingAnchor] constraintEqualToAnchor:[self trailingAnchor]],
+ [[[self historyTableView] bottomAnchor] constraintEqualToAnchor:[self bottomAnchor]]
+ ]];
+
+
+ // favorites table view
+ [self setFavoritesTableView:[[KayokoFavoritesTableView alloc] init]];
+ [self addSubview:[self favoritesTableView]];
+
+ [[self favoritesTableView] setHidden:YES];
+ [[self favoritesTableView] reloadDataWithItems:nil];
+
+ [[self favoritesTableView] setTranslatesAutoresizingMaskIntoConstraints:NO];
+ [NSLayoutConstraint activateConstraints:@[
+ [[[self favoritesTableView] topAnchor] constraintEqualToAnchor:[[self headerView] bottomAnchor] constant:8],
+ [[[self favoritesTableView] leadingAnchor] constraintEqualToAnchor:[self leadingAnchor]],
+ [[[self favoritesTableView] trailingAnchor] constraintEqualToAnchor:[self trailingAnchor]],
+ [[[self favoritesTableView] bottomAnchor] constraintEqualToAnchor:[self bottomAnchor]]
+ ]];
+ }
+
+ return self;
+}
+
+- (void)showFavorites {
+ if (![[self historyTableView] isHidden]) {
+ UIImageSymbolConfiguration* configuration = [UIImageSymbolConfiguration configurationWithPointSize:21 weight:UIImageSymbolWeightMedium];
+ [[self favoritesButton] setImage:[[UIImage systemImageNamed:@"heart.fill"] imageWithConfiguration:configuration] forState:UIControlStateNormal];
+
+ NSArray* items = [[PasteboardManager sharedInstance] itemsFromHistoryWithKey:kHistoryKeyFavorites];
+ [[self favoritesTableView] reloadDataWithItems:items];
+ [[self favoritesTableView] setHidden:NO];
+
+ [self updateSubtitleWithHistoryLabel:@"Favorites" andItemCount:[items count]];
+
+ [UIView animateWithDuration:0.3 delay:0 usingSpringWithDamping:1 initialSpringVelocity:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
+ [[self historyTableView] setTransform:CGAffineTransformMakeScale(0.95, 0.95)];
+ [[self historyTableView] setAlpha:0];
+
+ [[self favoritesTableView] setTransform:CGAffineTransformIdentity];
+ [[self favoritesTableView] setAlpha:1];
+
+ [[self favoritesButton] setTintColor:[UIColor systemPinkColor]];
+ } completion:^(BOOL finished) {
+ [[self historyTableView] reloadDataWithItems:nil];
+ [[self historyTableView] setHidden:YES];
+ }];
+ } else {
+ UIImageSymbolConfiguration* configuration = [UIImageSymbolConfiguration configurationWithPointSize:21 weight:UIImageSymbolWeightMedium];
+ [[self favoritesButton] setImage:[[UIImage systemImageNamed:@"heart"] imageWithConfiguration:configuration] forState:UIControlStateNormal];
+
+ NSArray* items = [[PasteboardManager sharedInstance] itemsFromHistoryWithKey:kHistoryKeyHistory];
+ [[self historyTableView] reloadDataWithItems:items];
+ [[self historyTableView] setHidden:NO];
+
+ [self updateSubtitleWithHistoryLabel:@"History" andItemCount:[items count]];
+
+ [UIView animateWithDuration:0.3 delay:0 usingSpringWithDamping:1 initialSpringVelocity:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
+ [[self historyTableView] setTransform:CGAffineTransformIdentity];
+ [[self historyTableView] setAlpha:1];
+
+ [[self favoritesTableView] setTransform:CGAffineTransformMakeScale(1.05, 1.05)];
+ [[self favoritesTableView] setAlpha:0];
+
+ [[self favoritesButton] setTintColor:[UIColor labelColor]];
+ } completion:^(BOOL finished) {
+ [[self favoritesTableView] reloadDataWithItems:nil];
+ [[self favoritesTableView] setHidden:YES];
+ }];
+ }
+}
+
+- (void)updateSubtitleWithHistoryLabel:(NSString *)label andItemCount:(NSUInteger)count {
+ if (count == 1) {
+ [[self subtitleLabel] setText:[NSString stringWithFormat:@"%@ – 1 Item", label]];
+ } else {
+ [[self subtitleLabel] setText:[NSString stringWithFormat:@"%@ – %lu Items", label, count]];
+ }
+}
+
+- (void)handlePanGestureRecognizer:(UIPanGestureRecognizer *)recognizer {
+ CGPoint translation = CGPointMake(0, 0);
+ const NSUInteger kMaxTranslation = 150;
+
+ if ([recognizer state] == UIGestureRecognizerStateChanged) {
+ translation = [recognizer translationInView:self];
+
+ if (translation.y < 0) {
+ return;
+ }
+
+ double alpha = fabs(translation.y / kMaxTranslation);
+ [UIView animateWithDuration:0.1 delay:0 usingSpringWithDamping:0.7 initialSpringVelocity:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
+ [self setTransform:CGAffineTransformMakeTranslation(0, translation.y)];
+ [self setAlpha:1 - alpha];
+ } completion:nil];
+
+ if (translation.y >= kMaxTranslation) {
+ [self hide];
+ return;
+ }
+ } else if ([recognizer state] == UIGestureRecognizerStateEnded) {
+ if (translation.y < kMaxTranslation) {
+ [UIView animateWithDuration:0.4 delay:0 usingSpringWithDamping:1 initialSpringVelocity:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
+ [self setTransform:CGAffineTransformIdentity];
+ [self setAlpha:1];
+ } completion:nil];
+ }
+ }
+}
+
+- (void)show {
+ if ([self isAnimating]) {
+ return;
+ }
+
+ [[self historyTableView] setAddSongDotLinkOption:[self addSongDotLinkOption]];
+ [[self historyTableView] setAddTranslateOption:[self addTranslateOption]];
+ [[self favoritesTableView] setAddSongDotLinkOption:[self addSongDotLinkOption]];
+ [[self favoritesTableView] setAddTranslateOption:[self addTranslateOption]];
+
+ [self reload];
+
+ [self setTransform:CGAffineTransformMakeTranslation(0, [self bounds].size.height / 3)];
+ [self setAlpha:0];
+ [self setHidden:NO];
+
+ [self setIsAnimating:YES];
+ [UIView animateWithDuration:0.3 delay:0 usingSpringWithDamping:1 initialSpringVelocity:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
+ [self setTransform:CGAffineTransformIdentity];
+ [self setAlpha:1];
+ } completion:^(BOOL finished) {
+ [self setIsAnimating:NO];
+ }];
+}
+
+- (void)hide {
+ [UIView animateWithDuration:0.2 delay:0 usingSpringWithDamping:1 initialSpringVelocity:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
+ [self setAlpha:0];
+ } completion:^(BOOL finished) {
+ [self setHidden:YES];
+ [[self historyTableView] reloadDataWithItems:nil];
+ [[self favoritesTableView] reloadDataWithItems:nil];
+ }];
+}
+
+- (void)reload {
+ if (![[self historyTableView] isHidden]) {
+ NSArray* items = [[PasteboardManager sharedInstance] itemsFromHistoryWithKey:kHistoryKeyHistory];
+ [[self historyTableView] reloadDataWithItems:items];
+
+ [self updateSubtitleWithHistoryLabel:@"History" andItemCount:[items count]];
+ } else {
+ NSArray* items = [[PasteboardManager sharedInstance] itemsFromHistoryWithKey:kHistoryKeyFavorites];
+ [[self favoritesTableView] reloadDataWithItems:items];
+
+ [self updateSubtitleWithHistoryLabel:@"Favorites" andItemCount:[items count]];
+ }
+}
+@end
diff --git a/Tweak/Helper/KayokoHelper.h b/Tweak/Helper/KayokoHelper.h
new file mode 100644
index 0000000..e60b95b
--- /dev/null
+++ b/Tweak/Helper/KayokoHelper.h
@@ -0,0 +1,76 @@
+//
+// KayokoHelper.h
+// Kayoko
+//
+// Created by Alexandra (@Traurige)
+//
+
+#import "substrate.h"
+#import
+#import "../../Preferences/PreferenceKeys.h"
+#import
+
+#define iOS15 [[[UIDevice currentDevice] systemVersion] floatValue] >= 15.0
+
+BOOL shouldShowCustomSuggestions = NO;
+
+HBPreferences* preferences;
+BOOL pfEnabled;
+NSUInteger pfActivationMethod;
+BOOL pfAutomaticallyPaste;
+
+static void paste();
+
+@interface TIKeyboardCandidate : NSObject
+@end
+
+@interface TIAutocorrectionList : NSObject
++ (TIAutocorrectionList *)listWithAutocorrection:(TIKeyboardCandidate *)arg1 predictions:(NSArray *)predictions emojiList:(NSArray *)emojiList;
+@end
+
+@interface UIKeyboardAutocorrectionController : NSObject
+- (void)setTextSuggestionList:(TIAutocorrectionList *)textSuggestionList;
+- (void)setAutocorrectionList:(TIAutocorrectionList *)textSuggestionList;
+@end
+
+@interface TUIPredictionView : UIView
+@end
+
+@interface TIKeyboardCandidateSingle : TIKeyboardCandidate
+@end
+
+@interface TIZephyrCandidate : TIKeyboardCandidateSingle
+@property(nonatomic, copy)NSString* label;
+@property(nonatomic, copy)NSString* fromBundleId;
+@end
+
+@interface UIPredictionViewController : UIViewController
+@end
+
+@interface UIKeyboardLayout : UIView
+@end
+
+@interface UIKeyboardLayoutStar : UIKeyboardLayout
+@end
+
+@interface UISystemKeyboardDockController : NSObject
+@end
+
+@interface UIKBInputDelegateManager : NSObject
+- (UITextRange *)selectedTextRange;
+- (NSString *)textInRange:(UITextRange *)range;
+- (void)insertText:(NSString *)text;
+@end
+
+@interface UIKeyboardImpl : UIView
+@property(nonatomic, readonly)UIKeyboardAutocorrectionController* autocorrectionController;
+@property(nonatomic, retain)UIKBInputDelegateManager* inputDelegateManager;
+@property(nonatomic, readonly)UIResponder * inputDelegate;
++ (instancetype)activeInstance;
+- (void)insertText:(NSString *)text;
+@end
+
+@interface UIKBTree : NSObject
+@property(nonatomic, retain)NSString* name;
+@property(nonatomic, retain)NSMutableDictionary* properties;
+@end
diff --git a/Tweak/Helper/KayokoHelper.m b/Tweak/Helper/KayokoHelper.m
new file mode 100644
index 0000000..aef832f
--- /dev/null
+++ b/Tweak/Helper/KayokoHelper.m
@@ -0,0 +1,217 @@
+//
+// KayokoHelper.m
+// Kayoko
+//
+// Created by Alexandra (@Traurige)
+//
+
+#import "KayokoHelper.h"
+
+#pragma mark - Class hooks
+
+void (* orig_UIKeyboardAutocorrectionController_setTextSuggestionList)(UIKeyboardAutocorrectionController* self, SEL _cmd, TIAutocorrectionList* textSuggestionList);
+void override_UIKeyboardAutocorrectionController_setTextSuggestionList(UIKeyboardAutocorrectionController* self, SEL _cmd, TIAutocorrectionList* textSuggestionList) {
+ if (shouldShowCustomSuggestions) {
+ TIZephyrCandidate* historyCandidate = [[objc_getClass("TIZephyrCandidate") alloc] init];
+ [historyCandidate setLabel:@"History"];
+ [historyCandidate setFromBundleId:@"dev.traurige.kayoko"];
+
+ TIZephyrCandidate* copyCandidate = [[objc_getClass("TIZephyrCandidate") alloc] init];
+ [copyCandidate setLabel:@"Copy"];
+ [copyCandidate setFromBundleId:@"dev.traurige.kayoko"];
+
+ TIZephyrCandidate* pasteCandidate = [[objc_getClass("TIZephyrCandidate") alloc] init];
+ [pasteCandidate setLabel:@"Paste"];
+ [pasteCandidate setFromBundleId:@"dev.traurige.kayoko"];
+
+ NSArray* predictions = @[historyCandidate, copyCandidate, pasteCandidate];
+ TIAutocorrectionList* list = [objc_getClass("TIAutocorrectionList") listWithAutocorrection:nil predictions:predictions emojiList:nil];
+ orig_UIKeyboardAutocorrectionController_setTextSuggestionList(self, _cmd, list);
+ } else {
+ orig_UIKeyboardAutocorrectionController_setTextSuggestionList(self, _cmd, textSuggestionList);
+ }
+}
+
+void (* orig_UIKeyboardAutocorrectionController_setAutocorrectionList)(UIKeyboardAutocorrectionController* self, SEL _cmd, TIAutocorrectionList* textSuggestionList);
+void override_UIKeyboardAutocorrectionController_setAutocorrectionList(UIKeyboardAutocorrectionController* self, SEL _cmd, TIAutocorrectionList* textSuggestionList) {
+ if (shouldShowCustomSuggestions) {
+ TIZephyrCandidate* historyCandidate = [[objc_getClass("TIZephyrCandidate") alloc] init];
+ [historyCandidate setLabel:@"History"];
+ [historyCandidate setFromBundleId:@"dev.traurige.kayoko"];
+
+ TIZephyrCandidate* copyCandidate = [[objc_getClass("TIZephyrCandidate") alloc] init];
+ [copyCandidate setLabel:@"Copy"];
+ [copyCandidate setFromBundleId:@"dev.traurige.kayoko"];
+
+ TIZephyrCandidate* pasteCandidate = [[objc_getClass("TIZephyrCandidate") alloc] init];
+ [pasteCandidate setLabel:@"Paste"];
+ [pasteCandidate setFromBundleId:@"dev.traurige.kayoko"];
+
+ NSArray* predictions = @[historyCandidate, copyCandidate, pasteCandidate];
+ TIAutocorrectionList* list = [objc_getClass("TIAutocorrectionList") listWithAutocorrection:nil predictions:predictions emojiList:nil];
+ orig_UIKeyboardAutocorrectionController_setAutocorrectionList(self, _cmd, list);
+ } else {
+ orig_UIKeyboardAutocorrectionController_setAutocorrectionList(self, _cmd, textSuggestionList);
+ }
+}
+
+void (* orig_UIPredictionViewController_predictionView_didSelectCandidate)(UIPredictionViewController* self, SEL _cmd, TUIPredictionView* predictionView, TIZephyrCandidate* candidate);
+void override_UIPredictionViewController_predictionView_didSelectCandidate(UIPredictionViewController* self, SEL _cmd, TUIPredictionView* predictionView, TIZephyrCandidate* candidate) {
+ if ([candidate respondsToSelector:@selector(fromBundleId)] && [[candidate fromBundleId] isEqualToString:@"dev.traurige.kayoko"]) {
+ if ([[candidate label] isEqualToString:@"History"]) {
+ CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), (CFStringRef)@"dev.traurige.kayoko.core.show", nil, nil, YES);
+ } else if ([[candidate label] isEqualToString:@"Copy"]) {
+ if (iOS15) {
+ UIKBInputDelegateManager* delegateManager = [[objc_getClass("UIKeyboardImpl") activeInstance] inputDelegateManager];
+ UITextRange* range = [delegateManager selectedTextRange];
+ NSString* text = [delegateManager textInRange:range];
+
+ if (![text isEqualToString:@""]) {
+ [[UIPasteboard generalPasteboard] setString:text];
+ }
+ } else {
+ id delegate = [[objc_getClass("UIKeyboardImpl") activeInstance] inputDelegate];
+ UITextRange* range = [delegate selectedTextRange];
+ NSString* text = [delegate textInRange:range];
+
+ if (![text isEqualToString:@""]) {
+ [[UIPasteboard generalPasteboard] setString:text];
+ }
+ }
+ } else if ([[candidate label] isEqualToString:@"Paste"]) {
+ paste();
+ }
+ } else {
+ orig_UIPredictionViewController_predictionView_didSelectCandidate(self, _cmd, predictionView, candidate);
+ }
+}
+
+BOOL override_UIPredictionViewController_isVisibleForInputDelegate_inputViews(UIPredictionViewController* self, SEL _cmd, id delegate, id inputViews) {
+ return YES;
+}
+
+void (* orig_UIKeyboardLayoutStar_setKeyplaneName)(UIKeyboardLayoutStar* self, SEL _cmd, NSString* name);
+void override_UIKeyboardLayoutStar_setKeyplaneName(UIKeyboardLayoutStar* self, SEL _cmd, NSString* name) {
+ orig_UIKeyboardLayoutStar_setKeyplaneName(self, _cmd, name);
+
+ // the custom candidates should only be shown on the more (123) and more-alternate (#+=) keyplane
+ shouldShowCustomSuggestions = [name isEqualToString:@"numbers-and-punctuation"] || [name isEqualToString:@"numbers-and-punctuation-alternate"];
+
+ if (iOS15) {
+ [[[objc_getClass("UIKeyboardImpl") activeInstance] autocorrectionController] setAutocorrectionList:nil];
+ } else {
+ [[[objc_getClass("UIKeyboardImpl") activeInstance] autocorrectionController] setTextSuggestionList:nil];
+ }
+}
+
+BOOL override_UIKeyboardImpl_shouldShowDictationKey(UIKeyboardImpl* self, SEL _cmd) {
+ return YES;
+}
+
+// notch devices
+void override_UISystemKeyboardDockController_dictationItemButtonWasPressed_withEvent(UISystemKeyboardDockController* self, SEL _cmd, UIEvent* event) {
+ CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), (CFStringRef)@"dev.traurige.kayoko.core.show", nil, nil, YES);
+}
+
+// home button devices
+UIKBTree* (* orig_UIKeyboardLayoutStar_keyHitTest)(UIKeyboardLayoutStar* self, SEL _cmd, CGPoint point);
+UIKBTree* override_UIKeyboardLayoutStar_keyHitTest(UIKeyboardLayoutStar* self, SEL _cmd, CGPoint point) {
+ UIKBTree* orig = orig_UIKeyboardLayoutStar_keyHitTest(self, _cmd, point);
+
+ if ([[orig name] isEqualToString:@"Dictation-Key"]) {
+ [[orig properties] setValue:@(0) forKey:@"KBinteractionType"];
+ CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), (CFStringRef)@"dev.traurige.kayoko.core.show", nil, nil, YES);
+ }
+
+ return orig;
+}
+
+void (* orig_UIKeyboardLayoutStar_didMoveToWindow)(UIKeyboardLayoutStar* self, SEL _cmd);
+void override_UIKeyboardLayoutStar_didMoveToWindow(UIKeyboardLayoutStar* self, SEL _cmd) {
+ orig_UIKeyboardLayoutStar_didMoveToWindow(self, _cmd);
+ CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), (CFStringRef)@"dev.traurige.kayoko.core.hide", nil, nil, YES);
+}
+
+#pragma mark - Notification callbacks
+
+static void paste() {
+ UIPasteboard* pasteboard = [UIPasteboard generalPasteboard];
+ if ([pasteboard hasStrings]) {
+ if (iOS15) {
+ UIKBInputDelegateManager* delegateManager = [[objc_getClass("UIKeyboardImpl") activeInstance] inputDelegateManager];
+ [delegateManager insertText:[pasteboard string]];
+ } else {
+ [[objc_getClass("UIKeyboardImpl") activeInstance] insertText:[pasteboard string]];
+ }
+ }
+}
+
+#pragma mark - Preferences
+
+static void load_preferences() {
+ preferences = [[HBPreferences alloc] initWithIdentifier:@"dev.traurige.kayoko.preferences"];
+ [preferences registerBool:&pfEnabled default:kPreferenceKeyEnabledDefaultValue forKey:kPreferenceKeyEnabled];
+ [preferences registerUnsignedInteger:&pfActivationMethod default:kPreferenceKeyActivationMethodDefaultValue forKey:kPreferenceKeyActivationMethod];
+ [preferences registerBool:&pfAutomaticallyPaste default:kPreferenceKeyAutomaticallyPasteDefaultValue forKey:kPreferenceKeyAutomaticallyPaste];
+}
+
+#pragma mark - Constructor
+
+__attribute((constructor)) static void initialize() {
+ load_preferences();
+
+ if (!pfEnabled) {
+ return;
+ }
+
+ if (![NSProcessInfo processInfo]) {
+ return;
+ }
+
+ NSString* processName = [[NSProcessInfo processInfo] processName];
+ BOOL isSpringBoard = [@"SpringBoard" isEqualToString:processName];
+
+ BOOL shouldLoad = NO;
+ NSArray* args = [[NSClassFromString(@"NSProcessInfo") processInfo] arguments];
+ NSUInteger count = [args count];
+ if (count != 0) {
+ NSString* executablePath = args[0];
+ if (executablePath) {
+ NSString* processName = [executablePath lastPathComponent];
+ BOOL isApplication = [executablePath rangeOfString:@"/Application/"].location != NSNotFound || [executablePath rangeOfString:@"/Applications/"].location != NSNotFound;
+ BOOL isFileProvider = [[processName lowercaseString] rangeOfString:@"fileprovider"].location != NSNotFound;
+ BOOL skip = [processName isEqualToString:@"AdSheet"] ||
+ [processName isEqualToString:@"CoreAuthUI"] ||
+ [processName isEqualToString:@"InCallService"] ||
+ [processName isEqualToString:@"MessagesNotificationViewService"] ||
+ [executablePath rangeOfString:@".appex/"].location != NSNotFound;
+ if ((!isFileProvider && isApplication && !skip) || isSpringBoard) {
+ shouldLoad = YES;
+ }
+ }
+ }
+
+ if (!shouldLoad) {
+ return;
+ }
+
+ if (pfActivationMethod == kActivationMethodPredictionBar) {
+ if (iOS15) {
+ MSHookMessageEx(NSClassFromString(@"UIKeyboardAutocorrectionController"), @selector(setAutocorrectionList:), (IMP)&override_UIKeyboardAutocorrectionController_setAutocorrectionList, (IMP *)&orig_UIKeyboardAutocorrectionController_setAutocorrectionList);
+ } else {
+ MSHookMessageEx(NSClassFromString(@"UIKeyboardAutocorrectionController"), @selector(setTextSuggestionList:), (IMP)&override_UIKeyboardAutocorrectionController_setTextSuggestionList, (IMP *)&orig_UIKeyboardAutocorrectionController_setTextSuggestionList);
+ }
+ MSHookMessageEx(NSClassFromString(@"UIPredictionViewController"), @selector(isVisibleForInputDelegate:inputViews:), (IMP)&override_UIPredictionViewController_isVisibleForInputDelegate_inputViews, (IMP *)nil);
+ MSHookMessageEx(NSClassFromString(@"UIKeyboardLayoutStar"), @selector(setKeyplaneName:), (IMP)&override_UIKeyboardLayoutStar_setKeyplaneName, (IMP *)&orig_UIKeyboardLayoutStar_setKeyplaneName);
+ MSHookMessageEx(NSClassFromString(@"UIPredictionViewController"), @selector(predictionView:didSelectCandidate:), (IMP)&override_UIPredictionViewController_predictionView_didSelectCandidate, (IMP *)&orig_UIPredictionViewController_predictionView_didSelectCandidate);
+ } else if (pfActivationMethod == kActivationMethodDictationKey) {
+ MSHookMessageEx(NSClassFromString(@"UISystemKeyboardDockController"), @selector(dictationItemButtonWasPressed:withEvent:), (IMP)&override_UISystemKeyboardDockController_dictationItemButtonWasPressed_withEvent, nil);
+ MSHookMessageEx(NSClassFromString(@"UIKeyboardImpl"), @selector(shouldShowDictationKey), (IMP)&override_UIKeyboardImpl_shouldShowDictationKey, nil);
+ MSHookMessageEx(NSClassFromString(@"UIKeyboardLayoutStar"), @selector(keyHitTest:), (IMP)&override_UIKeyboardLayoutStar_keyHitTest, (IMP *)&orig_UIKeyboardLayoutStar_keyHitTest);
+ }
+ MSHookMessageEx(NSClassFromString(@"UIKeyboardLayoutStar"), @selector(didMoveToWindow), (IMP)&override_UIKeyboardLayoutStar_didMoveToWindow, (IMP *)&orig_UIKeyboardLayoutStar_didMoveToWindow);
+
+ if (pfAutomaticallyPaste) {
+ CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)paste, (CFStringRef)@"dev.traurige.kayoko.helper.paste", NULL, (CFNotificationSuspensionBehavior)kNilOptions);
+ }
+}
diff --git a/Tweak/Helper/KayokoHelper.plist b/Tweak/Helper/KayokoHelper.plist
new file mode 100644
index 0000000..e5c60ee
--- /dev/null
+++ b/Tweak/Helper/KayokoHelper.plist
@@ -0,0 +1 @@
+{ Filter = { Bundles = ( "com.apple.UIKit" ); }; }
diff --git a/Tweak/Helper/Makefile b/Tweak/Helper/Makefile
new file mode 100644
index 0000000..de54bc5
--- /dev/null
+++ b/Tweak/Helper/Makefile
@@ -0,0 +1,9 @@
+TWEAK_NAME = KayokoHelper
+KayokoHelper_FILES = KayokoHelper.m
+KayokoHelper_CFLAGS = -fobjc-arc -DTHEOS_LEAN_AND_MEAN
+KayokoHelper_FRAMEWORKS = UIKit
+KayokoHelper_EXTRA_FRAMEWORKS = Cephei
+
+include $(THEOS)/makefiles/common.mk
+include $(THEOS_MAKE_PATH)/aggregate.mk
+include $(THEOS_MAKE_PATH)/tweak.mk
diff --git a/Utils/ColorUtil.h b/Utils/ColorUtil.h
new file mode 100644
index 0000000..8096373
--- /dev/null
+++ b/Utils/ColorUtil.h
@@ -0,0 +1,7 @@
+#import
+
+@interface ColorUtil : NSObject
++ (UIColor *)colorFromHex:(NSString *)hex;
++ (UIColor *)colorFromRgb:(NSString *)rgb;
++ (UIColor *)colorFromRgba:(NSString *)rgba;
+@end
diff --git a/Utils/ColorUtil.m b/Utils/ColorUtil.m
new file mode 100644
index 0000000..9586448
--- /dev/null
+++ b/Utils/ColorUtil.m
@@ -0,0 +1,32 @@
+#import "ColorUtil.h"
+
+@implementation ColorUtil
++ (UIColor *)colorFromHex:(NSString *)hex {
+ if ([hex length] == 4) {
+ hex = [NSString stringWithFormat:@"#%@%@%@%@%@%@", [hex substringWithRange:NSMakeRange(1, 1)], [hex substringWithRange:NSMakeRange(1, 1)], [hex substringWithRange:NSMakeRange(2, 1)], [hex substringWithRange:NSMakeRange(2, 1)], [hex substringWithRange:NSMakeRange(3, 1)], [hex substringWithRange:NSMakeRange(3, 1)]];
+ }
+
+ unsigned rgbValue = 0;
+ NSScanner* scanner = [NSScanner scannerWithString:hex];
+ [scanner setScanLocation:1];
+ [scanner scanHexInt:&rgbValue];
+
+ return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16) / 255 green:((rgbValue & 0xFF00) >> 8) / 255 blue:(rgbValue & 0xFF) / 255 alpha:1];
+}
+
++ (UIColor *)colorFromRgb:(NSString *)rgb {
+ rgb = [rgb stringByReplacingOccurrencesOfString:@" " withString:@""];
+ rgb = [rgb stringByReplacingOccurrencesOfString:@"rgb(" withString:@""];
+ rgb = [rgb stringByReplacingOccurrencesOfString:@")" withString:@""];
+ NSArray* rgbComponents = [rgb componentsSeparatedByString:@","];
+ return [UIColor colorWithRed:[rgbComponents[0] floatValue] / 255 green:[rgbComponents[1] floatValue] / 255 blue:[rgbComponents[2] floatValue] / 255 alpha:1];
+}
+
++ (UIColor *)colorFromRgba:(NSString *)rgba {
+ rgba = [rgba stringByReplacingOccurrencesOfString:@" " withString:@""];
+ rgba = [rgba stringByReplacingOccurrencesOfString:@"rgba(" withString:@""];
+ rgba = [rgba stringByReplacingOccurrencesOfString:@")" withString:@""];
+ NSArray* rgbaComponents = [rgba componentsSeparatedByString:@","];
+ return [UIColor colorWithRed:[rgbaComponents[0] floatValue] / 255 green:[rgbaComponents[1] floatValue] / 255 blue:[rgbaComponents[2] floatValue] / 255 alpha:[rgbaComponents[3] floatValue]];
+}
+@end
diff --git a/Utils/CommonUtil.h b/Utils/CommonUtil.h
new file mode 100644
index 0000000..85fa525
--- /dev/null
+++ b/Utils/CommonUtil.h
@@ -0,0 +1,6 @@
+#import
+
+@interface CommonUtil : NSObject
++ (NSString *)randomStringWithLength:(NSUInteger)length;
++ (void)showAlertWithTitle:(NSString *)title andMessage:(NSString *)message withDismissButtonTitle:(NSString *)dismissButtonTitle;
+@end
diff --git a/Utils/CommonUtil.m b/Utils/CommonUtil.m
new file mode 100644
index 0000000..0ddb09c
--- /dev/null
+++ b/Utils/CommonUtil.m
@@ -0,0 +1,26 @@
+#import "CommonUtil.h"
+
+@implementation CommonUtil
++ (NSString *)randomStringWithLength:(NSUInteger)length {
+ NSString* characters = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+ NSMutableString* string = [NSMutableString stringWithCapacity:length];
+
+ for (NSUInteger i = 0; i < length; i++) {
+ [string appendFormat: @"%c", [characters characterAtIndex: arc4random_uniform([characters length])]];
+ }
+
+ return string;
+}
+
++ (void)showAlertWithTitle:(NSString *)title andMessage:(NSString *)message withDismissButtonTitle:(NSString *)dismissButtonTitle {
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
+ NSMutableDictionary* dictionary = [NSMutableDictionary dictionary];
+ [dictionary setObject:title forKey:(__bridge NSString *)kCFUserNotificationAlertHeaderKey];
+ [dictionary setObject:message forKey:(__bridge NSString *)kCFUserNotificationAlertMessageKey];
+ [dictionary setObject:dismissButtonTitle forKey:(__bridge NSString *)kCFUserNotificationDefaultButtonTitleKey];
+
+ CFUserNotificationRef alert = CFUserNotificationCreate(NULL, 0, kCFUserNotificationPlainAlertLevel, nil, (__bridge CFDictionaryRef)dictionary);
+ CFRelease(alert);
+ });
+}
+@end
diff --git a/Utils/ImageUtil.h b/Utils/ImageUtil.h
new file mode 100644
index 0000000..5c33555
--- /dev/null
+++ b/Utils/ImageUtil.h
@@ -0,0 +1,7 @@
+#import
+
+@interface ImageUtil : NSObject
++ (BOOL)imageHasAlpha:(UIImage *)image;
++ (UIImage *)rotatedImageFromImage:(UIImage *)image;
++ (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize;
+@end
diff --git a/Utils/ImageUtil.m b/Utils/ImageUtil.m
new file mode 100644
index 0000000..12d92f1
--- /dev/null
+++ b/Utils/ImageUtil.m
@@ -0,0 +1,28 @@
+#import "ImageUtil.h"
+
+@implementation ImageUtil
++ (BOOL)imageHasAlpha:(UIImage *)image {
+ CGImageAlphaInfo alpha = CGImageGetAlphaInfo([image CGImage]);
+ return (alpha == kCGImageAlphaFirst || alpha == kCGImageAlphaLast || alpha == kCGImageAlphaPremultipliedFirst || alpha == kCGImageAlphaPremultipliedLast);
+}
+
++ (UIImage *)rotatedImageFromImage:(UIImage *)image {
+ if ([image imageOrientation] == UIImageOrientationUp) {
+ return image;
+ }
+
+ UIGraphicsBeginImageContext([image size]);
+ [image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
+ UIImage* rotatedImage = UIGraphicsGetImageFromCurrentImageContext();
+ UIGraphicsEndImageContext();
+ return rotatedImage;
+}
+
++ (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
+ UIGraphicsBeginImageContext(newSize);
+ [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
+ UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
+ UIGraphicsEndImageContext();
+ return newImage;
+}
+@end
diff --git a/control b/control
new file mode 100644
index 0000000..0c59970
--- /dev/null
+++ b/control
@@ -0,0 +1,9 @@
+Package: dev.traurige.kayoko
+Name: Kayoko
+Depends: firmware (>= 13.0), mobilesubstrate, preferenceloader, ws.hbang.common (>= 1.14)
+Version: 1.0
+Architecture: iphoneos-arm
+Description: Feature rich clipboard manager for iOS
+Maintainer: Traurige
+Author: Traurige
+Section: Tweaks
diff --git a/layout/DEBIAN/postinst b/layout/DEBIAN/postinst
new file mode 100755
index 0000000..e1a7eb1
--- /dev/null
+++ b/layout/DEBIAN/postinst
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+if [ -d /var/mobile/Documents/dev.traurige/ ]; then
+ chown -R mobile:mobile /var/mobile/Documents/dev.traurige/
+fi
+
+launchctl load /Library/LaunchDaemons/dev.traurige.kayokod.plist;
diff --git a/layout/DEBIAN/prerm b/layout/DEBIAN/prerm
new file mode 100755
index 0000000..7c2e522
--- /dev/null
+++ b/layout/DEBIAN/prerm
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+launchctl unload /Library/LaunchDaemons/dev.traurige.kayokod.plist;
diff --git a/layout/Library/LaunchDaemons/dev.traurige.kayokod.plist b/layout/Library/LaunchDaemons/dev.traurige.kayokod.plist
new file mode 100644
index 0000000..ff9ff52
--- /dev/null
+++ b/layout/Library/LaunchDaemons/dev.traurige.kayokod.plist
@@ -0,0 +1,14 @@
+
+
+
+
+ RunAtLoad
+
+ KeepAlive
+
+ Label
+ dev.traurige.kayokod
+ Program
+ /usr/libexec/kayokod
+
+