├── .gitignore ├── LICENSE ├── README.md ├── browser-addon ├── .vscode │ └── settings.json ├── package.json ├── src │ ├── background.js │ ├── nativeBridge.js │ ├── popup.html │ ├── popup │ │ ├── app.js │ │ ├── assets │ │ │ └── icon-back.svg │ │ ├── backgroundApi.js │ │ ├── components │ │ │ ├── MenuItem.js │ │ │ ├── MenuLabel.js │ │ │ ├── MenuSeparator.js │ │ │ └── NavigationHeader.js │ │ └── routes │ │ │ ├── InstalledPackets.js │ │ │ └── MainMenu.js │ ├── popupApi.js │ ├── store.js │ ├── tabManagement.js │ ├── touchbar-packets │ │ ├── facebook.touchbar-packet │ │ ├── github.touchbar-packet │ │ ├── google.touchbar-packet │ │ └── youtube.touchbar-packet │ ├── touchbarPackets.js │ └── touchbarScriptAPI.js ├── static │ ├── icons │ │ └── touchbar-icon.svg │ └── manifest.json ├── touchbar_browser_helper.json └── yarn.lock ├── demo.gif ├── touchbar-browser-helper.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ ├── IDEWorkspaceChecks.plist │ │ └── swiftpm │ │ └── Package.resolved └── xcshareddata │ └── xcschemes │ └── touchbar-browser-helper.xcscheme └── touchbar-browser-helper ├── AppDelegate.swift ├── BrowserCommunication.swift ├── MessageHandler.swift ├── Models └── TouchBarComponent.swift ├── TouchBar ├── TouchBar.h └── touchbar-browser-helper-Bridging-Header.h ├── TouchBarHandler.swift ├── Utils └── NSColor+webhex.swift └── main.swift /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | 3 | ## User settings 4 | xcuserdata/ 5 | 6 | # Node 7 | 8 | node_modules/ 9 | *.log 10 | 11 | ## Build 12 | build/ 13 | dist/ 14 | .cache/ 15 | web-ext-artifacts/ 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Native Touchbar Addon 2 | 3 | Native macOS touchbar controls for webpages 4 | 5 | 6 | 7 | ## How it works 8 | 9 | The project consists of two parts, a regular browser extension and a native binary that controls the touchbar. 10 | The two parts communicate back and fourth using [Native Messaging](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_messaging). 11 | 12 | The browser extension exposes a bridging API to small JavaScript scripts that are injected into webpages using [URL pattern matching](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/content_scripts#Matching_URL_patterns). 13 | These small scripts are called [touchbar packets](./browser-addon/src/touchbar-packets/), and are formatted much like [Userscripts](https://en.wikipedia.org/wiki/Userscript), with a header describing the name of the packet and one or more url matches. 14 | 15 | The binary is a small CLI app written mostly in Swift, its purpose is to receive configurations for the touchbar from the browser extension, update the touchbar accordingly and send any user interaction events back to the browser. 16 | The binary uses a private system API to show the new touchbar on top of the original. Thanks to [Touch Bär](https://github.com/a2/touch-baer). 17 | 18 | ## Installing 19 | 20 | ### Build and install the binary 21 | 22 | Clone the repository, and navigate into it. 23 | 24 | ```sh 25 | $ git clone https://github.com/viktorstrate/native-touchbar-addon 26 | $ cd native-touchbar-addon 27 | ``` 28 | 29 | Make sure you have the newest version of Xcode installed. 30 | Then run the following command to build and install the binary. 31 | 32 | Alternatively you can open the xcode project and click on `Product` -> `Build` 33 | 34 | ```sh 35 | $ xcodebuild -scheme touchbar-browser-helper 36 | ``` 37 | 38 | This will build the binary and copy it to `~/Library/Application Support/touchbar-browser-helper/` 39 | 40 | ### Configure the Native Messaging Host 41 | 42 | Next we need to tell Firefox where the binary is located. 43 | To do this, copy the [touchbar-browser-helper.json](./browser-addon/touchbar_browser_helper.json) file to `~/Library/Application Support/Mozilla/NativeMessagingHosts/`. Then change the path attribute in the json file to match the username of your account. 44 | 45 | You can do all this by run the following commands. 46 | 47 | ```sh 48 | $ mkdir -p ~/Library/Application\ Support/Mozilla/NativeMessagingHosts/ 49 | $ cp ./browser-addon/touchbar_browser_helper.json ~/Library/Application\ Support/Mozilla/NativeMessagingHosts/ 50 | $ sed -i '' "s/YOUR_USERNAME/$USER/g" ~/Library/Application\ Support/Mozilla/NativeMessagingHosts/touchbar_browser_helper.json 51 | ``` 52 | 53 | ### Install the browser extension 54 | 55 | Install the browser extension from 56 | https://addons.mozilla.org/en-US/firefox/addon/native-touchbar/ 57 | 58 | The extension will automatically start the helper program in the background. 59 | -------------------------------------------------------------------------------- /browser-addon/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "*.touchbar-packet": "javascript" 4 | } 5 | } -------------------------------------------------------------------------------- /browser-addon/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "native-touchbar", 3 | "version": "0.1.0", 4 | "main": "index.js", 5 | "author": "viktorstrate ", 6 | "license": "GPL-3.0", 7 | "private": false, 8 | "scripts": { 9 | "start": "parcel src/background.js src/popup.html src/touchbarScriptAPI.js", 10 | "launch": "web-ext run -s ./dist", 11 | "build": "rm -rf dist/ && parcel build src/background.js src/popup.html src/touchbarScriptAPI.js && web-ext build -s ./dist", 12 | "lint": "rm -rf dist/ && parcel build src/background.js src/popup.html src/touchbarScriptAPI.js && web-ext lint -s ./dist" 13 | }, 14 | "devDependencies": { 15 | "@babel/core": "^7.12.3", 16 | "@babel/plugin-transform-runtime": "^7.12.1", 17 | "@babel/preset-env": "^7.12.1", 18 | "eslint": "^7.13.0", 19 | "eslint-plugin-react": "^7.21.5", 20 | "parcel-plugin-static-files-copy": "^2.5.0", 21 | "parcel-plugin-text": "^0.9.7", 22 | "prettier": "^2.1.2", 23 | "react-router-dom": "^5.2.0", 24 | "web-ext": "^5.3.0" 25 | }, 26 | "dependencies": { 27 | "parcel-bundler": "^1.12.4", 28 | "react": "^16.8.0", 29 | "react-dom": "^16.8.0", 30 | "react-router": "^5.2.0", 31 | "styled-components": "^5.2.1", 32 | "uuid": "^8.3.1" 33 | }, 34 | "eslintConfig": { 35 | "env": { 36 | "browser": true, 37 | "es6": true, 38 | "webextensions": true, 39 | "node": true 40 | }, 41 | "extends": [ 42 | "eslint:recommended", 43 | "plugin:react/recommended" 44 | ], 45 | "parserOptions": { 46 | "sourceType": "module", 47 | "ecmaVersion": 2018 48 | }, 49 | "rules": { 50 | "react/prop-types": "off", 51 | "no-unused-vars": "warn", 52 | "no-extra-semi": "off" 53 | } 54 | }, 55 | "babel": { 56 | "presets": [ 57 | "@babel/preset-env" 58 | ], 59 | "plugins": [ 60 | "@babel/plugin-transform-runtime" 61 | ] 62 | }, 63 | "prettier": { 64 | "trailingComma": "es5", 65 | "tabWidth": 2, 66 | "semi": false, 67 | "singleQuote": true, 68 | "arrowParens": "avoid" 69 | }, 70 | "parcel-plugin-text": { 71 | "extensions": [ 72 | "txt", 73 | "touchbar-packet" 74 | ] 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /browser-addon/src/background.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Entry point for background script 3 | * Configures and loads everything 4 | */ 5 | 6 | import { loadNativePort } from './nativeBridge' 7 | import { loadTabManagement } from './tabManagement' 8 | import { loadTouchbarPackets } from './touchbarPackets' 9 | import { loadPopupAPI } from './popupApi' 10 | 11 | const nativePort = browser.runtime.connectNative('touchbar_browser_helper') 12 | 13 | console.log('background start') 14 | 15 | loadTouchbarPackets() 16 | loadPopupAPI() 17 | 18 | loadTabManagement({ nativePort }) 19 | loadNativePort({ nativePort }) 20 | -------------------------------------------------------------------------------- /browser-addon/src/nativeBridge.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Load native binary and communication to and from it 3 | */ 4 | 5 | import * as tabManagement from './tabManagement' 6 | 7 | export const loadNativePort = ({ nativePort }) => { 8 | nativePort.onDisconnect.addListener(p => { 9 | if (p.error) { 10 | console.log(`Disconnected due to an error: ${p.error.message}`) 11 | } 12 | }) 13 | 14 | browser.runtime.onMessage.addListener((message, sender) => { 15 | if (message.scope != 'native_bridge') return 16 | 17 | if (message.type == 'send_native_message') { 18 | if (message.nativeMessage.type == 'change_layout') { 19 | tabManagement.setTabTouchbarLayout( 20 | sender.tab.id, 21 | message.nativeMessage.layout 22 | ) 23 | } 24 | 25 | if (message.nativeMessage.type == 'update_item') { 26 | console.log('update item save state') 27 | 28 | tabManagement.updateTabTouchbarLayout( 29 | sender.tab.id, 30 | message.nativeMessage.name, 31 | message.nativeMessage.values 32 | ) 33 | } 34 | 35 | // Only update touchbar if tab is active 36 | browser.tabs 37 | .query({ active: true, windowId: browser.windows.WINDOW_ID_CURRENT }) 38 | .then(tabs => browser.tabs.get(tabs[0].id)) 39 | .then(activeTab => { 40 | if (activeTab.id === sender.tab.id) { 41 | console.log('sending native message', message.nativeMessage) 42 | nativePort.postMessage(message.nativeMessage) 43 | } 44 | }) 45 | } 46 | }) 47 | 48 | nativePort.onMessage.addListener(response => { 49 | console.log('Received', response) 50 | 51 | const activeTouchbarTab = tabManagement.getActiveTouchbarTab() 52 | 53 | if (activeTouchbarTab) { 54 | console.log('sending message to tab', activeTouchbarTab) 55 | browser.tabs.sendMessage(activeTouchbarTab, { 56 | ...response, 57 | scope: 'native_bridge_response', 58 | }) 59 | } 60 | }) 61 | } 62 | -------------------------------------------------------------------------------- /browser-addon/src/popup.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /browser-addon/src/popup/app.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect } from 'react' 2 | import ReactDOM from 'react-dom' 3 | import { createGlobalStyle } from 'styled-components' 4 | import { MemoryRouter as Router, Route, Switch } from 'react-router-dom' 5 | import MainMenu from './routes/MainMenu' 6 | import NavigationHeader from './components/NavigationHeader' 7 | import { 8 | addPopupMessageListener, 9 | getTouchbarPackets, 10 | removePopupMessageListener, 11 | } from './backgroundApi' 12 | import InstalledPackets from './routes/InstalledPackets' 13 | 14 | const GlobalStyles = createGlobalStyle` 15 | body { 16 | margin: 0; 17 | padding: 0; 18 | 19 | width: 100%; 20 | min-width: 360px; 21 | } 22 | ` 23 | 24 | export const PopupContext = React.createContext({ 25 | touchbarPackets: [], 26 | }) 27 | 28 | const SubRoutes = route => ( 29 |
30 | 31 | 32 | 33 | 34 | 35 | 36 |
37 | ) 38 | 39 | const App = () => { 40 | const [packets, setPackets] = useState([]) 41 | const [activePacket, setActivePacket] = useState(null) 42 | 43 | useEffect(() => { 44 | getTouchbarPackets().then(setPackets) 45 | 46 | const popupListener = (message /* sender, sendResponse */) => { 47 | if (message.type === 'active_packet_changed') { 48 | setActivePacket(message.payload) 49 | } 50 | } 51 | 52 | addPopupMessageListener(popupListener) 53 | 54 | return () => { 55 | removePopupMessageListener(popupListener) 56 | } 57 | }, []) 58 | 59 | return ( 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | ) 70 | } 71 | 72 | const appElement = document.querySelector('#app') 73 | ReactDOM.render(, appElement) 74 | -------------------------------------------------------------------------------- /browser-addon/src/popup/assets/icon-back.svg: -------------------------------------------------------------------------------- 1 | 4 | -------------------------------------------------------------------------------- /browser-addon/src/popup/backgroundApi.js: -------------------------------------------------------------------------------- 1 | /** 2 | * API to get information from background script 3 | */ 4 | 5 | const sendPopupMessage = (type, payload) => 6 | browser.runtime.sendMessage({ 7 | scope: 'popup_message', 8 | type, 9 | payload, 10 | }) 11 | 12 | export const addPopupMessageListener = listener => { 13 | browser.runtime.onMessage.addListener((message, sender, sendResponse) => { 14 | if (message.scope === 'popup_message') { 15 | listener(message, sender, sendResponse) 16 | } 17 | }) 18 | } 19 | 20 | export const removePopupMessageListener = listener => { 21 | browser.runtime.onMessage.removeListener(listener) 22 | } 23 | 24 | /** 25 | * Get all installed touchbar-packets 26 | * @return Promise a prosimse resolving to a list of touchbar-packets 27 | */ 28 | export const getTouchbarPackets = () => sendPopupMessage('get_touchbar_packets') 29 | -------------------------------------------------------------------------------- /browser-addon/src/popup/components/MenuItem.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { Link } from 'react-router-dom' 3 | import styled from 'styled-components' 4 | 5 | const ItemWrapper = styled.div` 6 | padding: 4px 8px; 7 | margin: 2px 0; 8 | 9 | &:hover { 10 | background-color: #eee; 11 | } 12 | ` 13 | 14 | const StyledLink = styled(Link)` 15 | color: black; 16 | text-decoration: none; 17 | ` 18 | 19 | const MenuItem = ({ label, navigateTo }) => { 20 | const item = {label} 21 | 22 | if (navigateTo) { 23 | return {item} 24 | } 25 | 26 | return item 27 | } 28 | 29 | export default MenuItem 30 | -------------------------------------------------------------------------------- /browser-addon/src/popup/components/MenuLabel.js: -------------------------------------------------------------------------------- 1 | import styled from 'styled-components' 2 | 3 | const MenuLabel = styled.small` 4 | display: block; 5 | padding: 4px 8px; 6 | margin: 2px 0; 7 | color: #888; 8 | font-size: 0.9em; 9 | ` 10 | 11 | export default MenuLabel 12 | -------------------------------------------------------------------------------- /browser-addon/src/popup/components/MenuSeparator.js: -------------------------------------------------------------------------------- 1 | import styled from 'styled-components' 2 | 3 | const Separator = styled.hr` 4 | height: 1px; 5 | background-color: #dfdfe0; 6 | border: none; 7 | margin: 4px 0; 8 | display: block; 9 | ` 10 | 11 | export default Separator 12 | -------------------------------------------------------------------------------- /browser-addon/src/popup/components/NavigationHeader.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import styled from 'styled-components' 3 | 4 | import iconBack from '../assets/icon-back.svg' 5 | 6 | const Navbar = styled.nav` 7 | padding: 4px; 8 | height: 40px; 9 | border-bottom: 1px solid #dfdfe0; 10 | display: flex; 11 | align-items: center; 12 | ` 13 | 14 | const BackLink = styled.a` 15 | padding: 8px; 16 | margin-right: 8px; 17 | width: 32px; 18 | height: 32px; 19 | position: absolute; 20 | 21 | &:hover { 22 | background-color: #eee; 23 | } 24 | ` 25 | 26 | const Title = styled.h1` 27 | margin: 0; 28 | padding: 0; 29 | font-weight: bold; 30 | font-size: 1rem; 31 | text-align: center; 32 | width: 100%; 33 | ` 34 | 35 | const NavigationHeader = ({ history, title }) => { 36 | return ( 37 | 38 | history.goBack()} aria-label="Back"> 39 | 40 | 41 | {title} 42 | 43 | ) 44 | } 45 | 46 | export default NavigationHeader 47 | -------------------------------------------------------------------------------- /browser-addon/src/popup/routes/InstalledPackets.js: -------------------------------------------------------------------------------- 1 | import React, { useContext } from 'react' 2 | import { PopupContext } from '../app' 3 | 4 | import MenuItem from '../components/MenuItem' 5 | 6 | const InstalledPackets = () => { 7 | const popup = useContext(PopupContext) 8 | 9 | const packets = popup.touchbarPackets.map((packet, idx) => ( 10 | 11 | )) 12 | 13 | return
{packets}
14 | } 15 | 16 | export default InstalledPackets 17 | -------------------------------------------------------------------------------- /browser-addon/src/popup/routes/MainMenu.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | import MenuItem from '../components/MenuItem' 4 | import MenuLabel from '../components/MenuLabel' 5 | import Separator from '../components/MenuSeparator' 6 | 7 | const MainMenu = () => { 8 | return ( 9 |
10 | Active packet 11 | 12 | 13 | 14 | 15 | 16 |
17 | ) 18 | } 19 | 20 | export default MainMenu 21 | -------------------------------------------------------------------------------- /browser-addon/src/popupApi.js: -------------------------------------------------------------------------------- 1 | import { touchbarPackets } from './touchbarPackets' 2 | 3 | /** 4 | * API for popup to get information from background script 5 | */ 6 | 7 | const sendPopupMessage = (type, payload) => 8 | browser.runtime.sendMessage({ 9 | scope: 'popup_message', 10 | type, 11 | payload, 12 | }) 13 | 14 | export const loadPopupAPI = () => { 15 | browser.runtime.onMessage.addListener((message, sender, sendResponse) => { 16 | if (message.scope != 'popup_message') return 17 | 18 | switch (message.type) { 19 | case 'get_touchbar_packets': 20 | sendResponse(touchbarPackets) 21 | } 22 | }) 23 | } 24 | 25 | export const activePacketChanged = newActivePacket => { 26 | sendPopupMessage('active_packet_changed', newActivePacket) 27 | } 28 | -------------------------------------------------------------------------------- /browser-addon/src/store.js: -------------------------------------------------------------------------------- 1 | import { v4 as uuid } from 'uuid' 2 | 3 | const storage = browser.storage.local 4 | 5 | export const addPacket = async ({ name, script, enabled = true, path }) => { 6 | const packet = { name, script, enabled, path } 7 | const key = uuid() 8 | 9 | const packets = await storage.get('packets') 10 | packets[key] = packet 11 | 12 | await storage.set({ 13 | packets, 14 | }) 15 | 16 | return { 17 | key, 18 | packet, 19 | } 20 | } 21 | 22 | export const getPacket = async key => 23 | (await storage.get('packets')).packets[key] 24 | -------------------------------------------------------------------------------- /browser-addon/src/tabManagement.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Keeps the touch bar in sync with browser tabs 3 | */ 4 | 5 | let tabTouchbarLayouts = {} 6 | let activeTouchbarTab = null 7 | 8 | export const setTabTouchbarLayout = (tabId, layout) => { 9 | tabTouchbarLayouts[tabId] = layout 10 | activeTouchbarTab = tabId 11 | } 12 | 13 | export const updateTabTouchbarLayout = (tabId, name, changes) => { 14 | const itemIndex = tabTouchbarLayouts[tabId].findIndex(x => x.name == name) 15 | Object.assign(tabTouchbarLayouts[tabId][itemIndex], changes) 16 | } 17 | 18 | export const getActiveTouchbarTab = () => activeTouchbarTab 19 | 20 | export const loadTabManagement = ({ nativePort }) => { 21 | browser.tabs.onRemoved.addListener(({ tabId }) => { 22 | console.log('tab closed cleaning up', tabId) 23 | tabTouchbarLayouts[tabId] = undefined 24 | }) 25 | 26 | browser.tabs.onActivated.addListener(({ tabId }) => { 27 | console.log('tab activated') 28 | if (tabTouchbarLayouts[tabId]) { 29 | console.log('tab changed changing layout', tabId) 30 | 31 | activeTouchbarTab = tabId 32 | 33 | nativePort.postMessage({ 34 | type: 'change_layout', 35 | layout: tabTouchbarLayouts[tabId], 36 | }) 37 | } else { 38 | console.log('close touchbar') 39 | activeTouchbarTab = null 40 | nativePort.postMessage({ 41 | type: 'dismiss_touchbar', 42 | }) 43 | } 44 | }) 45 | 46 | // Reset touchbar if domain changes 47 | browser.tabs.onUpdated.addListener(async (tabId, changes, tab) => { 48 | if (changes.url) { 49 | console.log('getting old url') 50 | const oldUrl = await browser.sessions.getTabValue(tabId, 'configured_url') 51 | 52 | console.log('got old url', oldUrl) 53 | 54 | if (oldUrl) { 55 | const oldHost = new URL(oldUrl).host 56 | const newHost = new URL(changes.url).host 57 | 58 | console.log('url changed', oldUrl, tab.url) 59 | 60 | if (oldHost != newHost) { 61 | console.log('url host changed') 62 | nativePort.postMessage({ 63 | type: 'dismiss_touchbar', 64 | }) 65 | } 66 | } 67 | 68 | browser.sessions.setTabValue(tabId, 'configured_url', changes.url) 69 | } 70 | }) 71 | } 72 | -------------------------------------------------------------------------------- /browser-addon/src/touchbar-packets/facebook.touchbar-packet: -------------------------------------------------------------------------------- 1 | // ==TouchbarPacket== 2 | // @name Facebook 3 | // @match https://www.facebook.com/* 4 | // @match https://facebook.com/* 5 | // ==/TouchbarPacket== 6 | 7 | /* global touchbar:readonly */ 8 | 9 | const ACTION_HOME = 'navigate-home' 10 | const ACTION_EVENTS = 'navigate-events' 11 | const ACTION_GROUPS = 'navigate-groups' 12 | 13 | touchbar.changeLayout([ 14 | { 15 | type: 'button', 16 | name: ACTION_HOME, 17 | label: 'Home', 18 | }, 19 | { 20 | type: 'button', 21 | name: ACTION_EVENTS, 22 | label: 'Events', 23 | }, 24 | { 25 | type: 'button', 26 | name: ACTION_GROUPS, 27 | label: 'Groups', 28 | }, 29 | ]) 30 | 31 | touchbar.addEventListener(message => { 32 | if (message.type == 'action') { 33 | switch (message.name) { 34 | case ACTION_HOME: 35 | location.href = '/' 36 | break 37 | case ACTION_EVENTS: 38 | location.href = '/events' 39 | break 40 | case ACTION_GROUPS: 41 | location.href = '/groups/feed' 42 | break 43 | } 44 | } 45 | }) 46 | -------------------------------------------------------------------------------- /browser-addon/src/touchbar-packets/github.touchbar-packet: -------------------------------------------------------------------------------- 1 | // ==TouchbarPacket== 2 | // @name GitHub 3 | // @match https://github.com/* 4 | // ==/TouchbarPacket== 5 | 6 | /* global touchbar:readonly */ 7 | 8 | const githubPaths = [ 9 | '/pulls', 10 | '/issues', 11 | '/marketplace', 12 | '/explore', 13 | '/topics', 14 | '/trending', 15 | '/collections', 16 | '/events', 17 | '/sponsors', 18 | ] 19 | 20 | console.log('LOADING GITHUB SCRIPT') 21 | 22 | console.log( 23 | 'PATHNAME', 24 | location.pathname, 25 | location.pathname == '/', 26 | githubPaths.find(x => location.pathname.startsWith(x)) 27 | ) 28 | 29 | if ( 30 | location.pathname == '/' || 31 | githubPaths.find(x => location.pathname.startsWith(x)) 32 | ) { 33 | loadGeneral() 34 | } else { 35 | loadRepo() 36 | } 37 | 38 | function loadGeneral() { 39 | console.log('not repo') 40 | 41 | const ACTION_HOME = 'navigate-home' 42 | const ACTION_PULL_REQUESTS = 'navigate-pull-requests' 43 | const ACTION_ISSUES = 'navigate-issues' 44 | const ACTION_MARKETPLACE = 'navigate-marketplace' 45 | const ACTION_EXPLORE = 'navigate-explore' 46 | 47 | touchbar.changeLayout([ 48 | { 49 | type: 'button', 50 | name: ACTION_HOME, 51 | label: 'Home', 52 | }, 53 | { 54 | type: 'button', 55 | name: ACTION_PULL_REQUESTS, 56 | label: 'Pull requests', 57 | }, 58 | { 59 | type: 'button', 60 | name: ACTION_ISSUES, 61 | label: 'Issues', 62 | }, 63 | { 64 | type: 'button', 65 | name: ACTION_MARKETPLACE, 66 | label: 'Marketplace', 67 | }, 68 | { 69 | type: 'button', 70 | name: ACTION_EXPLORE, 71 | label: 'Explore', 72 | }, 73 | ]) 74 | 75 | touchbar.addEventListener(message => { 76 | if (message.type == 'action') { 77 | switch (message.name) { 78 | case ACTION_HOME: 79 | location.href = '/' 80 | break 81 | case ACTION_PULL_REQUESTS: 82 | location.href = '/pulls' 83 | break 84 | case ACTION_ISSUES: 85 | location.href = '/issues' 86 | break 87 | case ACTION_MARKETPLACE: 88 | location.href = '/marketplace' 89 | break 90 | case ACTION_EXPLORE: 91 | location.href = '/explore' 92 | break 93 | } 94 | } 95 | }) 96 | } 97 | 98 | function loadRepo() { 99 | // Repository 100 | console.log('repo here') 101 | 102 | const repoMenu = document.querySelector( 103 | 'main nav[aria-label="Repository"] ul' 104 | ) 105 | 106 | console.log('REPO MENU', repoMenu) 107 | 108 | const menuItemElements = repoMenu.querySelectorAll('li') 109 | 110 | console.log(menuItemElements) 111 | 112 | const menuItems = [...menuItemElements].map(elm => ({ 113 | link: elm.querySelector('a').href, 114 | label: elm.querySelector('span').textContent, 115 | })) 116 | 117 | console.log(menuItems) 118 | 119 | const layout = menuItems.map(item => ({ 120 | type: 'button', 121 | name: `navigate-repo-${item.label}`, 122 | label: item.label, 123 | })) 124 | 125 | console.log(menuItems, layout) 126 | 127 | touchbar.changeLayout(layout) 128 | 129 | touchbar.addEventListener(message => { 130 | if (message.type == 'action') { 131 | const item = menuItems.find( 132 | x => message.name == `navigate-repo-${x.label}` 133 | ) 134 | if (item) { 135 | location.href = item.link 136 | } 137 | } 138 | }) 139 | } 140 | -------------------------------------------------------------------------------- /browser-addon/src/touchbar-packets/google.touchbar-packet: -------------------------------------------------------------------------------- 1 | // ==TouchbarPacket== 2 | // @name Google 3 | // @match https://www.google.com/?* 4 | // @match https://www.google.com/webhp?* 5 | // @match https://www.google.com/search?* 6 | // ==/TouchbarPacket== 7 | 8 | /* global touchbar:readonly */ 9 | 10 | const googleServices = [ 11 | { 12 | name: 'Gmail', 13 | link: 'https://mail.google.com/mail', 14 | }, 15 | { 16 | name: 'Drive', 17 | link: 'https://drive.google.com/', 18 | }, 19 | { 20 | name: 'Photos', 21 | link: 'https://photos.google.com/', 22 | }, 23 | { 24 | name: 'Calendar', 25 | link: 'https://google.com/calendar', 26 | }, 27 | ] 28 | 29 | touchbar.changeLayout( 30 | googleServices.map(x => ({ 31 | type: 'button', 32 | name: `navigate-${x.name}`, 33 | label: x.name, 34 | })) 35 | ) 36 | 37 | touchbar.addEventListener(message => { 38 | if (message.type == 'action') { 39 | const item = googleServices.find(x => message.name == `navigate-${x.name}`) 40 | if (item) { 41 | location.href = item.link 42 | } 43 | } 44 | }) 45 | -------------------------------------------------------------------------------- /browser-addon/src/touchbar-packets/youtube.touchbar-packet: -------------------------------------------------------------------------------- 1 | // ==TouchbarPacket== 2 | // @name YouTube 3 | // @match https://www.youtube.com/* 4 | // ==/TouchbarPacket== 5 | 6 | /* global touchbar:readonly */ 7 | 8 | console.log('TOUCHBAR SCRIPT EXECUTING on', window.location.href) 9 | 10 | let onEventFunction = null 11 | touchbar.addEventListener(message => { 12 | if (onEventFunction) onEventFunction(message) 13 | }) 14 | 15 | configureTouchbar() 16 | function configureTouchbar() { 17 | console.log('Configuring touchbar') 18 | if (window.location.pathname === '/watch') { 19 | // Video page 20 | setupVideoPage() 21 | } else { 22 | // Home page 23 | setupGeneralNavigation() 24 | } 25 | } 26 | 27 | function setupGeneralNavigation() { 28 | const ACTION_HOME = 'navigate-home' 29 | const ACTION_TRENDING = 'navigate-trending' 30 | const ACTION_SUBSCRIPTIONS = 'navigate-subscriptions' 31 | const ACTION_SHORTS = 'navigate-shorts' 32 | 33 | touchbar.changeLayout([ 34 | { 35 | type: 'button', 36 | name: ACTION_HOME, 37 | label: 'Home', 38 | }, 39 | { 40 | type: 'button', 41 | name: ACTION_TRENDING, 42 | label: 'Trending', 43 | }, 44 | { 45 | type: 'button', 46 | name: ACTION_SHORTS, 47 | label: 'Shorts', 48 | }, 49 | { 50 | type: 'button', 51 | name: ACTION_SUBSCRIPTIONS, 52 | label: 'Subscriptions', 53 | }, 54 | ]) 55 | 56 | onEventFunction = message => { 57 | if (message.type == 'action') { 58 | const menuItems = document.querySelectorAll( 59 | '#items > ytd-guide-entry-renderer' 60 | ) 61 | switch (message.name) { 62 | case ACTION_HOME: 63 | if (menuItems) { 64 | menuItems[0].click() 65 | } else { 66 | location.href = '/' 67 | } 68 | break 69 | case ACTION_TRENDING: 70 | if (menuItems) { 71 | menuItems[1].click() 72 | } else { 73 | location.href = '/feed/trending' 74 | } 75 | break 76 | case ACTION_SHORTS: 77 | if (menuItems) { 78 | menuItems[2].click() 79 | } 80 | break 81 | case ACTION_SUBSCRIPTIONS: 82 | if (menuItems) { 83 | menuItems[3].click() 84 | } else { 85 | location.href = '/feed/subscriptions' 86 | } 87 | break 88 | } 89 | } 90 | } 91 | } 92 | 93 | function formatTimestamp(time) { 94 | let minutes = Math.floor(time / 60) 95 | let seconds = Math.floor(time - 60 * minutes) 96 | 97 | if (seconds < 10) seconds = '0' + seconds 98 | 99 | return `${minutes}:${seconds}` 100 | } 101 | 102 | function setupVideoPage() { 103 | console.log('configuring touchbar for video page') 104 | 105 | const PLAYBACK_SLIDER = 'playback-slider' 106 | const MEDIA_PLAYPAUSE_BUTTON = 'media-playpause' 107 | const ICON_PLAY = 'NSTouchBarPlayTemplate' 108 | const ICON_PAUSE = 'NSTouchBarPauseTemplate' 109 | 110 | const video = document.querySelector('video.video-stream') 111 | if (!video) { 112 | console.log('video page not loaded yet, waiting...') 113 | setTimeout(setupVideoPage, 1000) 114 | return 115 | } 116 | 117 | const updateLayout = () => { 118 | let playPauseButton 119 | if (video.paused) { 120 | playPauseButton = { 121 | type: 'button', 122 | name: MEDIA_PLAYPAUSE_BUTTON, 123 | icon: ICON_PLAY, 124 | } 125 | } else { 126 | playPauseButton = { 127 | type: 'button', 128 | name: MEDIA_PLAYPAUSE_BUTTON, 129 | icon: ICON_PAUSE, 130 | } 131 | } 132 | 133 | const playbackSlider = { 134 | type: 'slider', 135 | name: PLAYBACK_SLIDER, 136 | label: formatTimestamp(video.currentTime), 137 | value: video.currentTime / video.duration, 138 | color: '#ff0000', 139 | } 140 | 141 | console.log(playbackSlider) 142 | 143 | touchbar.changeLayout([playPauseButton, playbackSlider]) 144 | } 145 | 146 | updateLayout() 147 | 148 | let updateInterval = null 149 | 150 | video.addEventListener('play', () => { 151 | onPlayEvent() 152 | }) 153 | 154 | if (!video.paused) { 155 | onPlayEvent() 156 | } 157 | 158 | function onPlayEvent() { 159 | touchbar.updateItem(MEDIA_PLAYPAUSE_BUTTON, { 160 | icon: ICON_PAUSE, 161 | }) 162 | 163 | updateInterval = setInterval(() => { 164 | touchbar.updateItem(PLAYBACK_SLIDER, { 165 | value: video.currentTime / video.duration, 166 | label: formatTimestamp(video.currentTime), 167 | }) 168 | }, 500) 169 | } 170 | 171 | video.addEventListener('pause', () => { 172 | touchbar.updateItem(MEDIA_PLAYPAUSE_BUTTON, { 173 | icon: ICON_PLAY, 174 | }) 175 | 176 | clearInterval(updateInterval) 177 | }) 178 | 179 | onEventFunction = message => { 180 | if (message.type == 'action' && message.target == 'button') { 181 | switch (message.name) { 182 | case MEDIA_PLAYPAUSE_BUTTON: 183 | if (video.paused) { 184 | video.play() 185 | } else { 186 | video.pause() 187 | } 188 | break 189 | } 190 | } 191 | 192 | if (message.type == 'action' && message.target == 'slider') { 193 | if (message.name == PLAYBACK_SLIDER) { 194 | console.log('new slider position', message.value) 195 | 196 | const newTime = video.duration * message.value 197 | video.currentTime = newTime 198 | updateLayout() 199 | } 200 | } 201 | } 202 | } 203 | 204 | hookPageChanges() 205 | function hookPageChanges() { 206 | let oldHref = location.href 207 | 208 | const observer = new MutationObserver(() => { 209 | if (oldHref != document.location.href) { 210 | oldHref = document.location.href 211 | console.log('page changed') 212 | configureTouchbar() 213 | } 214 | }) 215 | 216 | observer.observe(document.querySelector('body'), { 217 | childList: true, 218 | subtree: true, 219 | }) 220 | } 221 | -------------------------------------------------------------------------------- /browser-addon/src/touchbarPackets.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Configure and load touchbar packet scripts 3 | */ 4 | 5 | /** 6 | * Parses the header of a touchbar packet 7 | * @param {string} packet a raw touchbar-packet string 8 | */ 9 | export function parseTouchbarPacket(packet) { 10 | const [_, header, body] = packet.match( 11 | /^[\n\s]*\/\/\s+==TouchbarPacket==([^]+)==\/TouchbarPacket==\n([^]+)/ 12 | ) 13 | 14 | const headerFields = header 15 | .match(/@\w+\s.+/g) 16 | .map(fieldLine => { 17 | const [_, key, value] = fieldLine.match(/@(\w+)\s(.+)/) 18 | return [key, value] 19 | }) 20 | .reduce((result, field) => { 21 | if (result[field[0]]) { 22 | result[field[0]].push(field[1]) 23 | } else { 24 | result[field[0]] = [field[1]] 25 | } 26 | return result 27 | }, {}) 28 | 29 | headerFields.name = headerFields.name[0] 30 | 31 | return { 32 | headers: headerFields, 33 | script: body, 34 | } 35 | } 36 | 37 | export const touchbarPackets = [ 38 | require('./touchbar-packets/youtube.touchbar-packet'), 39 | require('./touchbar-packets/github.touchbar-packet'), 40 | require('./touchbar-packets/google.touchbar-packet'), 41 | require('./touchbar-packets/facebook.touchbar-packet'), 42 | ].map(parseTouchbarPacket) 43 | 44 | export const loadTouchbarPackets = async function () { 45 | const packetRegisterPromises = touchbarPackets.map(packet => { 46 | return browser.userScripts.register({ 47 | matches: packet.headers.match, 48 | js: [ 49 | { 50 | code: packet.script, 51 | }, 52 | ], 53 | scriptMetadata: {}, 54 | }) 55 | }) 56 | 57 | await Promise.all(packetRegisterPromises) 58 | 59 | console.log('All touchbar packets loaded') 60 | } 61 | -------------------------------------------------------------------------------- /browser-addon/src/touchbarScriptAPI.js: -------------------------------------------------------------------------------- 1 | /** 2 | * API for touchbar packets 3 | */ 4 | 5 | browser.userScripts.onBeforeScript.addListener(script => { 6 | script.defineGlobals({ 7 | touchbar: script.export({ 8 | changeLayout: layout => { 9 | const changeLayoutMessage = { 10 | type: 'change_layout', 11 | layout, 12 | } 13 | 14 | browser.runtime.sendMessage({ 15 | scope: 'native_bridge', 16 | type: 'send_native_message', 17 | nativeMessage: changeLayoutMessage, 18 | }) 19 | }, 20 | updateItem: (name, values) => { 21 | const updateItemMessage = { 22 | type: 'update_item', 23 | name, 24 | values, 25 | } 26 | 27 | browser.runtime.sendMessage({ 28 | scope: 'native_bridge', 29 | type: 'send_native_message', 30 | nativeMessage: updateItemMessage, 31 | }) 32 | }, 33 | addEventListener: listener => { 34 | browser.runtime.onMessage.addListener(message => { 35 | if (message.scope != 'native_bridge_response') return 36 | listener(script.export(message)) 37 | }) 38 | }, 39 | }), 40 | }) 41 | 42 | console.log('custom userScripts APIs defined') 43 | }) 44 | 45 | console.log( 46 | 'apiScript executed and userScripts.onBeforeScript listener subscribed' 47 | ) 48 | -------------------------------------------------------------------------------- /browser-addon/static/icons/touchbar-icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | touchbar-icon 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /browser-addon/static/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | 3 | "name": "Native Touchbar", 4 | "manifest_version": 2, 5 | "version": "0.1.0", 6 | 7 | "homepage_url": "https://github.com/viktorstrate/native-touchbar-addon", 8 | "description": "Native macOS touchbar controls", 9 | "icons": { 10 | "48": "icons/touchbar-icon.svg" 11 | }, 12 | 13 | "browser_specific_settings": { 14 | "gecko": { 15 | "id": "native_touchbar@viktorstrate.github.com", 16 | "strict_min_version": "68.0" 17 | } 18 | }, 19 | 20 | "background": { 21 | "scripts": ["background.js"] 22 | }, 23 | 24 | "browser_action": { 25 | "browser_style": true, 26 | "default_icon": "icons/touchbar-icon.svg", 27 | "default_title": "Touchbar", 28 | "default_popup": "popup.html" 29 | }, 30 | 31 | "user_scripts": { 32 | "api_script": "touchbarScriptAPI.js" 33 | }, 34 | 35 | "permissions": [ 36 | "https://*/*", 37 | "http://*/*", 38 | "nativeMessaging", 39 | "storage", 40 | "tabs", 41 | "sessions" 42 | ] 43 | 44 | } -------------------------------------------------------------------------------- /browser-addon/touchbar_browser_helper.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "touchbar_browser_helper", 3 | "description": "native touchbar integration helper", 4 | "path": "/Users/YOUR_USERNAME/Library/Application Support/touchbar-browser-helper/touchbar-browser-helper", 5 | "type": "stdio", 6 | "allowed_extensions": [ 7 | "native_touchbar@viktorstrate.github.com" 8 | ] 9 | } -------------------------------------------------------------------------------- /demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/viktorstrate/native-touchbar-addon/2ccd892235750f71339c6921d626e87bd8c51ff8/demo.gif -------------------------------------------------------------------------------- /touchbar-browser-helper.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 52; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 349D4DE02558591F001DD052 /* BrowserCommunication.swift in Sources */ = {isa = PBXBuildFile; fileRef = 349D4DDF2558591F001DD052 /* BrowserCommunication.swift */; }; 11 | 349D4DE425585ADD001DD052 /* TouchBarHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 349D4DE325585ADD001DD052 /* TouchBarHandler.swift */; }; 12 | 349D4DEB25586AEC001DD052 /* touchbar-browser-helper in CopyFiles */ = {isa = PBXBuildFile; fileRef = 34B8E8C6255752A000F0AD2A /* touchbar-browser-helper */; }; 13 | 349D4DF22558744A001DD052 /* MessageHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 349D4DF12558744A001DD052 /* MessageHandler.swift */; }; 14 | 349D4DF6255876C8001DD052 /* SwiftyJSON in Frameworks */ = {isa = PBXBuildFile; productRef = 349D4DF5255876C8001DD052 /* SwiftyJSON */; }; 15 | 349D4DFB25587AB3001DD052 /* TouchBarComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 349D4DFA25587AB3001DD052 /* TouchBarComponent.swift */; }; 16 | 34A485A3255C960500761A2B /* NSColor+webhex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34A485A2255C960500761A2B /* NSColor+webhex.swift */; }; 17 | 34B8E8CA255752A000F0AD2A /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34B8E8C9255752A000F0AD2A /* main.swift */; }; 18 | 34B8E8D2255752C700F0AD2A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34B8E8D1255752C700F0AD2A /* AppDelegate.swift */; }; 19 | 34B8E8DD2557534600F0AD2A /* DFRFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 34B8E8DC2557534600F0AD2A /* DFRFoundation.framework */; }; 20 | /* End PBXBuildFile section */ 21 | 22 | /* Begin PBXCopyFilesBuildPhase section */ 23 | 34B8E8C4255752A000F0AD2A /* CopyFiles */ = { 24 | isa = PBXCopyFilesBuildPhase; 25 | buildActionMask = 12; 26 | dstPath = "$HOME/Library/Application Support/touchbar-browser-helper"; 27 | dstSubfolderSpec = 0; 28 | files = ( 29 | 349D4DEB25586AEC001DD052 /* touchbar-browser-helper in CopyFiles */, 30 | ); 31 | runOnlyForDeploymentPostprocessing = 0; 32 | }; 33 | /* End PBXCopyFilesBuildPhase section */ 34 | 35 | /* Begin PBXFileReference section */ 36 | 349D4DDF2558591F001DD052 /* BrowserCommunication.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrowserCommunication.swift; sourceTree = ""; }; 37 | 349D4DE325585ADD001DD052 /* TouchBarHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TouchBarHandler.swift; sourceTree = ""; }; 38 | 349D4DF12558744A001DD052 /* MessageHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageHandler.swift; sourceTree = ""; }; 39 | 349D4DFA25587AB3001DD052 /* TouchBarComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TouchBarComponent.swift; sourceTree = ""; }; 40 | 34A485A2255C960500761A2B /* NSColor+webhex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSColor+webhex.swift"; sourceTree = ""; }; 41 | 34B8E8C6255752A000F0AD2A /* touchbar-browser-helper */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "touchbar-browser-helper"; sourceTree = BUILT_PRODUCTS_DIR; }; 42 | 34B8E8C9255752A000F0AD2A /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; 43 | 34B8E8D1255752C700F0AD2A /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 44 | 34B8E8D52557531500F0AD2A /* touchbar-browser-helper-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "touchbar-browser-helper-Bridging-Header.h"; sourceTree = ""; }; 45 | 34B8E8DA2557532C00F0AD2A /* TouchBar.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TouchBar.h; sourceTree = ""; }; 46 | 34B8E8DC2557534600F0AD2A /* DFRFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = DFRFoundation.framework; path = ../../../../../System/Library/PrivateFrameworks/DFRFoundation.framework; sourceTree = ""; }; 47 | /* End PBXFileReference section */ 48 | 49 | /* Begin PBXFrameworksBuildPhase section */ 50 | 34B8E8C3255752A000F0AD2A /* Frameworks */ = { 51 | isa = PBXFrameworksBuildPhase; 52 | buildActionMask = 2147483647; 53 | files = ( 54 | 349D4DF6255876C8001DD052 /* SwiftyJSON in Frameworks */, 55 | 34B8E8DD2557534600F0AD2A /* DFRFoundation.framework in Frameworks */, 56 | ); 57 | runOnlyForDeploymentPostprocessing = 0; 58 | }; 59 | /* End PBXFrameworksBuildPhase section */ 60 | 61 | /* Begin PBXGroup section */ 62 | 349D4DF925587AA1001DD052 /* Models */ = { 63 | isa = PBXGroup; 64 | children = ( 65 | 349D4DFA25587AB3001DD052 /* TouchBarComponent.swift */, 66 | ); 67 | path = Models; 68 | sourceTree = ""; 69 | }; 70 | 34A485A1255C95ED00761A2B /* Utils */ = { 71 | isa = PBXGroup; 72 | children = ( 73 | 34A485A2255C960500761A2B /* NSColor+webhex.swift */, 74 | ); 75 | path = Utils; 76 | sourceTree = ""; 77 | }; 78 | 34B8E8BD255752A000F0AD2A = { 79 | isa = PBXGroup; 80 | children = ( 81 | 34B8E8C8255752A000F0AD2A /* touchbar-browser-helper */, 82 | 34B8E8C7255752A000F0AD2A /* Products */, 83 | 34B8E8DB2557534600F0AD2A /* Frameworks */, 84 | ); 85 | sourceTree = ""; 86 | }; 87 | 34B8E8C7255752A000F0AD2A /* Products */ = { 88 | isa = PBXGroup; 89 | children = ( 90 | 34B8E8C6255752A000F0AD2A /* touchbar-browser-helper */, 91 | ); 92 | name = Products; 93 | sourceTree = ""; 94 | }; 95 | 34B8E8C8255752A000F0AD2A /* touchbar-browser-helper */ = { 96 | isa = PBXGroup; 97 | children = ( 98 | 34A485A1255C95ED00761A2B /* Utils */, 99 | 349D4DF925587AA1001DD052 /* Models */, 100 | 34B8E8D4255752FF00F0AD2A /* TouchBar */, 101 | 34B8E8C9255752A000F0AD2A /* main.swift */, 102 | 34B8E8D1255752C700F0AD2A /* AppDelegate.swift */, 103 | 349D4DDF2558591F001DD052 /* BrowserCommunication.swift */, 104 | 349D4DE325585ADD001DD052 /* TouchBarHandler.swift */, 105 | 349D4DF12558744A001DD052 /* MessageHandler.swift */, 106 | ); 107 | path = "touchbar-browser-helper"; 108 | sourceTree = ""; 109 | }; 110 | 34B8E8D4255752FF00F0AD2A /* TouchBar */ = { 111 | isa = PBXGroup; 112 | children = ( 113 | 34B8E8D52557531500F0AD2A /* touchbar-browser-helper-Bridging-Header.h */, 114 | 34B8E8DA2557532C00F0AD2A /* TouchBar.h */, 115 | ); 116 | path = TouchBar; 117 | sourceTree = ""; 118 | }; 119 | 34B8E8DB2557534600F0AD2A /* Frameworks */ = { 120 | isa = PBXGroup; 121 | children = ( 122 | 34B8E8DC2557534600F0AD2A /* DFRFoundation.framework */, 123 | ); 124 | name = Frameworks; 125 | sourceTree = ""; 126 | }; 127 | /* End PBXGroup section */ 128 | 129 | /* Begin PBXNativeTarget section */ 130 | 34B8E8C5255752A000F0AD2A /* touchbar-browser-helper */ = { 131 | isa = PBXNativeTarget; 132 | buildConfigurationList = 34B8E8CD255752A000F0AD2A /* Build configuration list for PBXNativeTarget "touchbar-browser-helper" */; 133 | buildPhases = ( 134 | 34B8E8C2255752A000F0AD2A /* Sources */, 135 | 34B8E8C3255752A000F0AD2A /* Frameworks */, 136 | 34B8E8C4255752A000F0AD2A /* CopyFiles */, 137 | ); 138 | buildRules = ( 139 | ); 140 | dependencies = ( 141 | ); 142 | name = "touchbar-browser-helper"; 143 | packageProductDependencies = ( 144 | 349D4DF5255876C8001DD052 /* SwiftyJSON */, 145 | ); 146 | productName = "touchbar-browser-helper"; 147 | productReference = 34B8E8C6255752A000F0AD2A /* touchbar-browser-helper */; 148 | productType = "com.apple.product-type.tool"; 149 | }; 150 | /* End PBXNativeTarget section */ 151 | 152 | /* Begin PBXProject section */ 153 | 34B8E8BE255752A000F0AD2A /* Project object */ = { 154 | isa = PBXProject; 155 | attributes = { 156 | LastSwiftUpdateCheck = 1210; 157 | LastUpgradeCheck = 1220; 158 | TargetAttributes = { 159 | 34B8E8C5255752A000F0AD2A = { 160 | CreatedOnToolsVersion = 12.1; 161 | LastSwiftMigration = 1210; 162 | }; 163 | }; 164 | }; 165 | buildConfigurationList = 34B8E8C1255752A000F0AD2A /* Build configuration list for PBXProject "touchbar-browser-helper" */; 166 | compatibilityVersion = "Xcode 9.3"; 167 | developmentRegion = en; 168 | hasScannedForEncodings = 0; 169 | knownRegions = ( 170 | en, 171 | Base, 172 | ); 173 | mainGroup = 34B8E8BD255752A000F0AD2A; 174 | packageReferences = ( 175 | 349D4DF4255876C8001DD052 /* XCRemoteSwiftPackageReference "SwiftyJSON" */, 176 | ); 177 | productRefGroup = 34B8E8C7255752A000F0AD2A /* Products */; 178 | projectDirPath = ""; 179 | projectRoot = ""; 180 | targets = ( 181 | 34B8E8C5255752A000F0AD2A /* touchbar-browser-helper */, 182 | ); 183 | }; 184 | /* End PBXProject section */ 185 | 186 | /* Begin PBXSourcesBuildPhase section */ 187 | 34B8E8C2255752A000F0AD2A /* Sources */ = { 188 | isa = PBXSourcesBuildPhase; 189 | buildActionMask = 2147483647; 190 | files = ( 191 | 34B8E8D2255752C700F0AD2A /* AppDelegate.swift in Sources */, 192 | 34B8E8CA255752A000F0AD2A /* main.swift in Sources */, 193 | 349D4DE425585ADD001DD052 /* TouchBarHandler.swift in Sources */, 194 | 349D4DF22558744A001DD052 /* MessageHandler.swift in Sources */, 195 | 349D4DE02558591F001DD052 /* BrowserCommunication.swift in Sources */, 196 | 349D4DFB25587AB3001DD052 /* TouchBarComponent.swift in Sources */, 197 | 34A485A3255C960500761A2B /* NSColor+webhex.swift in Sources */, 198 | ); 199 | runOnlyForDeploymentPostprocessing = 0; 200 | }; 201 | /* End PBXSourcesBuildPhase section */ 202 | 203 | /* Begin XCBuildConfiguration section */ 204 | 34B8E8CB255752A000F0AD2A /* Debug */ = { 205 | isa = XCBuildConfiguration; 206 | buildSettings = { 207 | ALWAYS_SEARCH_USER_PATHS = NO; 208 | CLANG_ANALYZER_NONNULL = YES; 209 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 210 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 211 | CLANG_CXX_LIBRARY = "libc++"; 212 | CLANG_ENABLE_MODULES = YES; 213 | CLANG_ENABLE_OBJC_ARC = YES; 214 | CLANG_ENABLE_OBJC_WEAK = YES; 215 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 216 | CLANG_WARN_BOOL_CONVERSION = YES; 217 | CLANG_WARN_COMMA = YES; 218 | CLANG_WARN_CONSTANT_CONVERSION = YES; 219 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 220 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 221 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 222 | CLANG_WARN_EMPTY_BODY = YES; 223 | CLANG_WARN_ENUM_CONVERSION = YES; 224 | CLANG_WARN_INFINITE_RECURSION = YES; 225 | CLANG_WARN_INT_CONVERSION = YES; 226 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 227 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 228 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 229 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 230 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 231 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 232 | CLANG_WARN_STRICT_PROTOTYPES = YES; 233 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 234 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 235 | CLANG_WARN_UNREACHABLE_CODE = YES; 236 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 237 | COPY_PHASE_STRIP = NO; 238 | DEBUG_INFORMATION_FORMAT = dwarf; 239 | ENABLE_STRICT_OBJC_MSGSEND = YES; 240 | ENABLE_TESTABILITY = YES; 241 | GCC_C_LANGUAGE_STANDARD = gnu11; 242 | GCC_DYNAMIC_NO_PIC = NO; 243 | GCC_NO_COMMON_BLOCKS = YES; 244 | GCC_OPTIMIZATION_LEVEL = 0; 245 | GCC_PREPROCESSOR_DEFINITIONS = ( 246 | "DEBUG=1", 247 | "$(inherited)", 248 | ); 249 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 250 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 251 | GCC_WARN_UNDECLARED_SELECTOR = YES; 252 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 253 | GCC_WARN_UNUSED_FUNCTION = YES; 254 | GCC_WARN_UNUSED_VARIABLE = YES; 255 | MACOSX_DEPLOYMENT_TARGET = 10.15; 256 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 257 | MTL_FAST_MATH = YES; 258 | ONLY_ACTIVE_ARCH = YES; 259 | SDKROOT = macosx; 260 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 261 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 262 | }; 263 | name = Debug; 264 | }; 265 | 34B8E8CC255752A000F0AD2A /* Release */ = { 266 | isa = XCBuildConfiguration; 267 | buildSettings = { 268 | ALWAYS_SEARCH_USER_PATHS = NO; 269 | CLANG_ANALYZER_NONNULL = YES; 270 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 271 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 272 | CLANG_CXX_LIBRARY = "libc++"; 273 | CLANG_ENABLE_MODULES = YES; 274 | CLANG_ENABLE_OBJC_ARC = YES; 275 | CLANG_ENABLE_OBJC_WEAK = YES; 276 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 277 | CLANG_WARN_BOOL_CONVERSION = YES; 278 | CLANG_WARN_COMMA = YES; 279 | CLANG_WARN_CONSTANT_CONVERSION = YES; 280 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 281 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 282 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 283 | CLANG_WARN_EMPTY_BODY = YES; 284 | CLANG_WARN_ENUM_CONVERSION = YES; 285 | CLANG_WARN_INFINITE_RECURSION = YES; 286 | CLANG_WARN_INT_CONVERSION = YES; 287 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 288 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 289 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 290 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 291 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 292 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 293 | CLANG_WARN_STRICT_PROTOTYPES = YES; 294 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 295 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 296 | CLANG_WARN_UNREACHABLE_CODE = YES; 297 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 298 | COPY_PHASE_STRIP = NO; 299 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 300 | ENABLE_NS_ASSERTIONS = NO; 301 | ENABLE_STRICT_OBJC_MSGSEND = YES; 302 | GCC_C_LANGUAGE_STANDARD = gnu11; 303 | GCC_NO_COMMON_BLOCKS = YES; 304 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 305 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 306 | GCC_WARN_UNDECLARED_SELECTOR = YES; 307 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 308 | GCC_WARN_UNUSED_FUNCTION = YES; 309 | GCC_WARN_UNUSED_VARIABLE = YES; 310 | MACOSX_DEPLOYMENT_TARGET = 10.15; 311 | MTL_ENABLE_DEBUG_INFO = NO; 312 | MTL_FAST_MATH = YES; 313 | SDKROOT = macosx; 314 | SWIFT_COMPILATION_MODE = wholemodule; 315 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 316 | }; 317 | name = Release; 318 | }; 319 | 34B8E8CE255752A000F0AD2A /* Debug */ = { 320 | isa = XCBuildConfiguration; 321 | buildSettings = { 322 | CLANG_ENABLE_MODULES = YES; 323 | CODE_SIGN_IDENTITY = "-"; 324 | CODE_SIGN_STYLE = Automatic; 325 | LD_RUNPATH_SEARCH_PATHS = ( 326 | "$(inherited)", 327 | "@executable_path/../Frameworks", 328 | "@loader_path/../Frameworks", 329 | ); 330 | PRODUCT_NAME = "$(TARGET_NAME)"; 331 | SWIFT_OBJC_BRIDGING_HEADER = "touchbar-browser-helper/TouchBar/touchbar-browser-helper-Bridging-Header.h"; 332 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 333 | SWIFT_VERSION = 5.0; 334 | SYSTEM_FRAMEWORK_SEARCH_PATHS = ( 335 | "$(inherited)", 336 | "$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks", 337 | ); 338 | }; 339 | name = Debug; 340 | }; 341 | 34B8E8CF255752A000F0AD2A /* Release */ = { 342 | isa = XCBuildConfiguration; 343 | buildSettings = { 344 | CLANG_ENABLE_MODULES = YES; 345 | CODE_SIGN_IDENTITY = "-"; 346 | CODE_SIGN_STYLE = Automatic; 347 | LD_RUNPATH_SEARCH_PATHS = ( 348 | "$(inherited)", 349 | "@executable_path/../Frameworks", 350 | "@loader_path/../Frameworks", 351 | ); 352 | PRODUCT_NAME = "$(TARGET_NAME)"; 353 | SWIFT_OBJC_BRIDGING_HEADER = "touchbar-browser-helper/TouchBar/touchbar-browser-helper-Bridging-Header.h"; 354 | SWIFT_VERSION = 5.0; 355 | SYSTEM_FRAMEWORK_SEARCH_PATHS = ( 356 | "$(inherited)", 357 | "$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks", 358 | ); 359 | }; 360 | name = Release; 361 | }; 362 | /* End XCBuildConfiguration section */ 363 | 364 | /* Begin XCConfigurationList section */ 365 | 34B8E8C1255752A000F0AD2A /* Build configuration list for PBXProject "touchbar-browser-helper" */ = { 366 | isa = XCConfigurationList; 367 | buildConfigurations = ( 368 | 34B8E8CB255752A000F0AD2A /* Debug */, 369 | 34B8E8CC255752A000F0AD2A /* Release */, 370 | ); 371 | defaultConfigurationIsVisible = 0; 372 | defaultConfigurationName = Release; 373 | }; 374 | 34B8E8CD255752A000F0AD2A /* Build configuration list for PBXNativeTarget "touchbar-browser-helper" */ = { 375 | isa = XCConfigurationList; 376 | buildConfigurations = ( 377 | 34B8E8CE255752A000F0AD2A /* Debug */, 378 | 34B8E8CF255752A000F0AD2A /* Release */, 379 | ); 380 | defaultConfigurationIsVisible = 0; 381 | defaultConfigurationName = Release; 382 | }; 383 | /* End XCConfigurationList section */ 384 | 385 | /* Begin XCRemoteSwiftPackageReference section */ 386 | 349D4DF4255876C8001DD052 /* XCRemoteSwiftPackageReference "SwiftyJSON" */ = { 387 | isa = XCRemoteSwiftPackageReference; 388 | repositoryURL = "https://github.com/SwiftyJSON/SwiftyJSON"; 389 | requirement = { 390 | kind = upToNextMajorVersion; 391 | minimumVersion = 5.0.0; 392 | }; 393 | }; 394 | /* End XCRemoteSwiftPackageReference section */ 395 | 396 | /* Begin XCSwiftPackageProductDependency section */ 397 | 349D4DF5255876C8001DD052 /* SwiftyJSON */ = { 398 | isa = XCSwiftPackageProductDependency; 399 | package = 349D4DF4255876C8001DD052 /* XCRemoteSwiftPackageReference "SwiftyJSON" */; 400 | productName = SwiftyJSON; 401 | }; 402 | /* End XCSwiftPackageProductDependency section */ 403 | }; 404 | rootObject = 34B8E8BE255752A000F0AD2A /* Project object */; 405 | } 406 | -------------------------------------------------------------------------------- /touchbar-browser-helper.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /touchbar-browser-helper.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /touchbar-browser-helper.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved: -------------------------------------------------------------------------------- 1 | { 2 | "object": { 3 | "pins": [ 4 | { 5 | "package": "SwiftyJSON", 6 | "repositoryURL": "https://github.com/SwiftyJSON/SwiftyJSON", 7 | "state": { 8 | "branch": null, 9 | "revision": "2b6054efa051565954e1d2b9da831680026cd768", 10 | "version": "5.0.0" 11 | } 12 | } 13 | ] 14 | }, 15 | "version": 1 16 | } 17 | -------------------------------------------------------------------------------- /touchbar-browser-helper.xcodeproj/xcshareddata/xcschemes/touchbar-browser-helper.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 43 | 45 | 51 | 52 | 53 | 54 | 60 | 62 | 68 | 69 | 70 | 71 | 73 | 74 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /touchbar-browser-helper/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // touchbar-browser-helper 4 | // 5 | // Created by Viktor Strate Kløvedal on 07/11/2020. 6 | // 7 | 8 | import Cocoa 9 | 10 | 11 | class AppDelegate: NSObject, NSApplicationDelegate { 12 | 13 | let touchbarHandler: TouchBarHandler 14 | let browserCommunication: BrowserCommunication 15 | let messageHandler: MessageHandler 16 | 17 | override init() { 18 | self.touchbarHandler = TouchBarHandler() 19 | self.browserCommunication = BrowserCommunication() 20 | self.messageHandler = MessageHandler(touchbarHandler: touchbarHandler) 21 | } 22 | 23 | func applicationDidFinishLaunching(_ aNotification: Notification) { 24 | // Insert code here to initialize your application 25 | 26 | NSWorkspace.shared.notificationCenter.addObserver(self, 27 | selector: #selector(appActivatedEvent), 28 | name: NSWorkspace.didActivateApplicationNotification, 29 | object:nil) 30 | 31 | if let foregroundApp = NSWorkspace.shared.frontmostApplication { 32 | foremostApplicationChanged(to: foregroundApp) 33 | } 34 | 35 | browserCommunication.delegate = messageHandler 36 | browserCommunication.waitForCommands() 37 | 38 | } 39 | 40 | func applicationWillTerminate(_ aNotification: Notification) { 41 | // Insert code here to tear down your application 42 | } 43 | 44 | @objc func appActivatedEvent(notification: Notification) { 45 | 46 | guard let foregroundApp = notification.userInfo?["NSWorkspaceApplicationKey"] as? NSRunningApplication else { 47 | return 48 | } 49 | 50 | foremostApplicationChanged(to: foregroundApp) 51 | } 52 | 53 | func foremostApplicationChanged(to foregroundApp: NSRunningApplication) { 54 | if foregroundApp.bundleIdentifier == "org.mozilla.firefox" { 55 | self.touchbarHandler.showGlobalTouchBarItem() 56 | } else { 57 | self.touchbarHandler.removeGlobalTouchBarItem() 58 | } 59 | } 60 | 61 | } 62 | 63 | -------------------------------------------------------------------------------- /touchbar-browser-helper/BrowserCommunication.swift: -------------------------------------------------------------------------------- 1 | // 2 | // BrowserMessager.swift 3 | // touchbar-browser-helper 4 | // 5 | // Created by Viktor Strate Kløvedal on 08/11/2020. 6 | // 7 | 8 | import Foundation 9 | import SwiftyJSON 10 | 11 | class BrowserCommunication { 12 | 13 | var delegate: BrowserCommunicationDelegate? 14 | 15 | fileprivate let jsonDecoder = JSONDecoder() 16 | fileprivate let jsonEncoder = JSONEncoder() 17 | 18 | fileprivate func processMessage(_ message: String) { 19 | NSLog("Message: %@", message) 20 | 21 | guard let jsonMessage = try? JSON(data: message.data(using: .utf8)!) else { 22 | NSLog("Could not parse message as json") 23 | return 24 | } 25 | 26 | self.delegate?.processMessage(jsonMessage, browserCommunication: self) 27 | } 28 | 29 | func sendMessage(message: JSON) { 30 | NSLog("Sending message") 31 | 32 | guard let messageData = try? message.rawData() else { 33 | NSLog("Failed to format json") 34 | return 35 | } 36 | 37 | let size = UInt32(messageData.count) 38 | var data = withUnsafeBytes(of: size) { 39 | Data($0) 40 | } 41 | 42 | data.append(messageData) 43 | 44 | FileHandle.standardOutput.write(data) 45 | } 46 | 47 | func waitForCommands() { 48 | DispatchQueue.global(qos: .background).async { 49 | let input = FileHandle.standardInput 50 | 51 | var data = Data() 52 | 53 | while true { 54 | // Get at least the message size (4 bytes) 55 | while data.count < 4 { 56 | data.append(input.availableData) 57 | } 58 | 59 | // Parse size 60 | let messageSize: Int = data.withUnsafeBytes { 61 | Int( $0.load(as: UInt32.self) ) 62 | } 63 | 64 | // Remove parsed size bytes from 'data' 65 | if data.count == 4 { 66 | data = Data() 67 | } else { 68 | data = data.advanced(by: 4) 69 | } 70 | 71 | // Read at least the whole message 72 | while data.count < messageSize { 73 | data.append(input.availableData) 74 | } 75 | 76 | // Parse the message at utf8 77 | let message = String(data: data.prefix(messageSize), encoding: .utf8)! 78 | 79 | // Remove parsed message from 'data' 80 | if data.count == messageSize { 81 | data = Data() 82 | } else { 83 | data = data.advanced(by: messageSize) 84 | } 85 | 86 | // Process the parsed message 87 | self.processMessage(message) 88 | } 89 | 90 | } 91 | } 92 | 93 | } 94 | 95 | protocol BrowserCommunicationDelegate { 96 | func processMessage(_ message: JSON, browserCommunication: BrowserCommunication) 97 | } 98 | -------------------------------------------------------------------------------- /touchbar-browser-helper/MessageHandler.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MessageHandler.swift 3 | // touchbar-browser-helper 4 | // 5 | // Created by Viktor Strate Kløvedal on 08/11/2020. 6 | // 7 | 8 | import Foundation 9 | import SwiftyJSON 10 | 11 | class MessageHandler: BrowserCommunicationDelegate { 12 | 13 | fileprivate let jsonDecoder = JSONDecoder() 14 | fileprivate let jsonEncoder = JSONEncoder() 15 | 16 | let touchbarHandler: TouchBarHandler 17 | 18 | init(touchbarHandler: TouchBarHandler) { 19 | self.touchbarHandler = touchbarHandler 20 | } 21 | 22 | func processMessage(_ message: JSON, browserCommunication: BrowserCommunication) { 23 | 24 | guard let messageType = message["type"].string else { 25 | let error = jsonError(type: "null", reason: "Message missing type: \(message["type"].error!)") 26 | browserCommunication.sendMessage(message: error) 27 | return 28 | } 29 | 30 | NSLog("Process message of type '\(messageType)'") 31 | 32 | switch messageType { 33 | case "ping": 34 | handlePingRequest(browserCommunication: browserCommunication) 35 | case "change_layout": 36 | DispatchQueue.main.async { 37 | self.handleChangeLayout(message, browserCommunication: browserCommunication) 38 | } 39 | case "update_item": 40 | DispatchQueue.main.async { 41 | self.handleUpdateItem(message, browserCommunication: browserCommunication) 42 | } 43 | case "dismiss_touchbar": 44 | DispatchQueue.main.async { 45 | self.handleDismissTouchbar() 46 | } 47 | default: 48 | let error = jsonError(type: messageType, reason: "Unknown message type") 49 | browserCommunication.sendMessage(message: error) 50 | } 51 | } 52 | 53 | func handlePingRequest(browserCommunication: BrowserCommunication) { 54 | let pong: [String: Any] = [ 55 | "type": "ping", 56 | "success": true, 57 | "value": "pong", 58 | ] 59 | browserCommunication.sendMessage(message: JSON(pong)) 60 | } 61 | 62 | func handleChangeLayout(_ message: JSON, browserCommunication: BrowserCommunication) { 63 | let layout = message["layout"].arrayValue 64 | 65 | let components: [TouchBarComponent] = layout 66 | .map { generateComponent(componentJson: $0, browserCommunication: browserCommunication) } 67 | .compactMap { $0 } 68 | 69 | touchbarHandler.layoutComponents = components 70 | } 71 | 72 | func handleUpdateItem(_ message: JSON, browserCommunication: BrowserCommunication) { 73 | guard let name = message["name"].string else { 74 | return 75 | } 76 | 77 | guard let component = touchbarHandler.layoutComponents.first(where: { $0.name == name }) else { 78 | return 79 | } 80 | 81 | switch component.component { 82 | case .button: 83 | guard let button = component.touchBarItem as? NSButtonTouchBarItem else { 84 | return 85 | } 86 | 87 | if let newLabel = message["values"]["label"].string { 88 | button.title = newLabel 89 | } 90 | 91 | if let newIcon = message["values"]["icon"].string { 92 | button.image = NSImage(named: newIcon) 93 | } 94 | 95 | case .slider: 96 | guard let slider = component.touchBarItem as? NSSliderTouchBarItem else { 97 | return 98 | } 99 | 100 | if let newValue = message["values"]["value"].double { 101 | slider.doubleValue = newValue 102 | } 103 | 104 | if let newLabel = message["values"]["label"].string { 105 | slider.label = newLabel 106 | } 107 | 108 | if let newColor = message["values"]["color"].string { 109 | slider.slider.trackFillColor = NSColor.from(hex: newColor) 110 | } 111 | 112 | } 113 | 114 | } 115 | 116 | func handleDismissTouchbar() { 117 | self.touchbarHandler.touchbarStripVisible = false 118 | } 119 | 120 | func generateComponent(componentJson: JSON, browserCommunication: BrowserCommunication) -> TouchBarComponent? { 121 | 122 | guard let type = componentJson["type"].string else { return nil} 123 | guard let name = componentJson["name"].string else { return nil } 124 | 125 | let component: TouchBarComponent? 126 | 127 | switch type { 128 | case "button": 129 | 130 | let label = componentJson["label"].stringValue 131 | let icon = componentJson["icon"].string 132 | 133 | component = TouchBarComponent(name: name, component: .button(label: label, icon: icon), browserCommunication: browserCommunication) 134 | 135 | case "slider": 136 | 137 | let label = componentJson["label"].string 138 | let value = componentJson["value"].doubleValue 139 | 140 | let color: NSColor? 141 | if let hex = componentJson["color"].string { 142 | color = NSColor.from(hex: hex) 143 | } else { 144 | color = nil 145 | } 146 | 147 | component = TouchBarComponent(name: name, component: .slider(label: label, value: value, color: color), browserCommunication: browserCommunication) 148 | 149 | default: 150 | component = nil 151 | } 152 | 153 | return component 154 | } 155 | 156 | func jsonError(type: String, reason: String) -> JSON { 157 | NSLog("Message handler error on type \(type): \(reason)") 158 | return JSON([ 159 | "type": type, 160 | "success": false, 161 | "message": reason, 162 | ]) 163 | } 164 | 165 | } 166 | -------------------------------------------------------------------------------- /touchbar-browser-helper/Models/TouchBarComponent.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TouchBarComponent.swift 3 | // touchbar-browser-helper 4 | // 5 | // Created by Viktor Strate Kløvedal on 08/11/2020. 6 | // 7 | 8 | import Cocoa 9 | import SwiftyJSON 10 | 11 | class TouchBarComponent { 12 | enum Component { 13 | case button(label: String, icon: String?) 14 | case slider(label: String?, value: Double, color: NSColor?) 15 | } 16 | 17 | let name: String 18 | 19 | init(name: String, component: Component, browserCommunication: BrowserCommunication) { 20 | self.name = name 21 | self.component = component 22 | self.browserCommunication = browserCommunication 23 | 24 | let alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" 25 | let id = String((0 ..< 8).map{ _ in alphabet.randomElement()! }) 26 | 27 | self.identifier = .init("\(identifierPrefix).layout-component-\(id)") 28 | } 29 | 30 | let identifier: NSTouchBarItem.Identifier 31 | let component: Component 32 | fileprivate let browserCommunication: BrowserCommunication 33 | 34 | lazy var touchBarItem: NSTouchBarItem = { 35 | // var item = NSCustomTouchBarItem(identifier: identifier) 36 | let item: NSTouchBarItem 37 | 38 | switch component { 39 | case .button(let label, let iconName): 40 | 41 | let buttonItem = NSButtonTouchBarItem(identifier: identifier, title: label, target: self, action: #selector(buttonAction(_:))) 42 | 43 | if let iconName = iconName, let image = NSImage(named: iconName) { 44 | buttonItem.image = image 45 | } 46 | 47 | item = buttonItem 48 | 49 | case .slider(let label, let value, let color): 50 | 51 | let sliderItem = NSSliderTouchBarItem(identifier: identifier) 52 | sliderItem.target = self 53 | sliderItem.action = #selector(sliderAction(_:)) 54 | 55 | sliderItem.label = label 56 | 57 | let slider = NSSlider() 58 | slider.isContinuous = false 59 | 60 | slider.doubleValue = value 61 | slider.trackFillColor = color 62 | 63 | sliderItem.slider = slider 64 | 65 | item = sliderItem 66 | 67 | } 68 | 69 | return item 70 | }() 71 | 72 | @objc func buttonAction(_ sender: NSButton) { 73 | 74 | guard case .button(_, _) = self.component else { 75 | return 76 | } 77 | 78 | browserCommunication.sendMessage(message: JSON([ 79 | "type": "action", 80 | "target": "button", 81 | "name": name, 82 | ])) 83 | } 84 | 85 | @objc func sliderAction(_ sender: NSSlider) { 86 | 87 | browserCommunication.sendMessage(message: JSON([ 88 | "type": "action", 89 | "target": "slider", 90 | "name": name, 91 | "value": sender.doubleValue, 92 | ])) 93 | 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /touchbar-browser-helper/TouchBar/TouchBar.h: -------------------------------------------------------------------------------- 1 | // 2 | // TouchBar.h 3 | // touchbar-browser-helper 4 | // 5 | // Created by Alexsander Akers on 2/13/17. 6 | // Modified by Viktor Strate Kløvedal on 07/11/2020. 7 | // 8 | // Copyright © 2017 Alexsander Akers. All rights reserved. 9 | // https://github.com/a2/touch-baer/blob/master/TouchBarTest/TouchBar.h 10 | // 11 | 12 | #import 13 | 14 | extern void DFRElementSetControlStripPresenceForIdentifier(_Nonnull NSTouchBarItemIdentifier, BOOL); 15 | extern void DFRSystemModalShowsCloseBoxWhenFrontMost(BOOL); 16 | 17 | @interface NSTouchBarItem () 18 | + (void)addSystemTrayItem:(nullable NSTouchBarItem *)item; 19 | + (void)removeSystemTrayItem:(nullable NSTouchBarItem *)item; 20 | @end 21 | 22 | @interface NSTouchBar () 23 | 24 | // macOS 10.14 and above 25 | + (void)presentSystemModalTouchBar:(nullable NSTouchBar *)touchBar placement:(long long)placement systemTrayItemIdentifier:(nullable NSTouchBarItemIdentifier)identifier NS_AVAILABLE_MAC(10.14);; 26 | + (void)presentSystemModalTouchBar:(nullable NSTouchBar *)touchBar systemTrayItemIdentifier:(nullable NSTouchBarItemIdentifier)identifier NS_AVAILABLE_MAC(10.14); 27 | + (void)dismissSystemModalTouchBar:(nullable NSTouchBar *)touchBar NS_AVAILABLE_MAC(10.14); 28 | + (void)minimizeSystemModalTouchBar:(nullable NSTouchBar *)touchBar NS_AVAILABLE_MAC(10.14); 29 | 30 | // macOS 10.13 and below 31 | + (void)presentSystemModalFunctionBar:(nullable NSTouchBar *)touchBar placement:(long long)placement systemTrayItemIdentifier:(nullable NSTouchBarItemIdentifier)identifier NS_DEPRECATED_MAC(10.12.2, 10.14); 32 | + (void)presentSystemModalFunctionBar:(nullable NSTouchBar *)touchBar systemTrayItemIdentifier:(nullable NSTouchBarItemIdentifier)identifier NS_DEPRECATED_MAC(10.12.2, 10.14); 33 | + (void)dismissSystemModalFunctionBar:(nullable NSTouchBar *)touchBar NS_DEPRECATED_MAC(10.12.2, 10.14); 34 | + (void)minimizeSystemModalFunctionBar:(nullable NSTouchBar *)touchBar NS_DEPRECATED_MAC(10.12.2, 10.14); 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /touchbar-browser-helper/TouchBar/touchbar-browser-helper-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | // 2 | // Use this file to import your target's public headers that you would like to expose to Swift. 3 | // 4 | 5 | #include "TouchBar.h" 6 | -------------------------------------------------------------------------------- /touchbar-browser-helper/TouchBarHandler.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TouchBarHandler.swift 3 | // touchbar-browser-helper 4 | // 5 | // Created by Viktor Strate Kløvedal on 08/11/2020. 6 | // 7 | 8 | import Cocoa 9 | 10 | let identifierPrefix = "com.github.viktorstrate.touchbar-browser-helper" 11 | 12 | extension NSTouchBarItem.Identifier { 13 | static let touchbarBrowserGlobal = NSTouchBarItem.Identifier("\(identifierPrefix).global") 14 | static let touchbarBrowserClose = NSTouchBarItem.Identifier("\(identifierPrefix).close") 15 | } 16 | 17 | class TouchBarHandler: NSObject, NSTouchBarDelegate { 18 | 19 | var layoutComponents: [TouchBarComponent] = [] { 20 | didSet { 21 | self.updateTouchbarStrip() 22 | self.touchbarStripVisible = true 23 | } 24 | } 25 | 26 | fileprivate lazy var touchbarStrip: NSTouchBar = { 27 | let strip = NSTouchBar() 28 | strip.defaultItemIdentifiers = [] 29 | strip.delegate = self 30 | return strip 31 | }() 32 | 33 | var touchbarStripVisible: Bool { 34 | set { 35 | if newValue { 36 | NSTouchBar.presentSystemModalTouchBar(touchbarStrip, systemTrayItemIdentifier: .touchbarBrowserClose) 37 | } else { 38 | NSTouchBar.dismissSystemModalTouchBar(touchbarStrip) 39 | } 40 | } 41 | 42 | get { 43 | touchbarStrip.isVisible 44 | } 45 | } 46 | 47 | func updateTouchbarStrip() { 48 | touchbarStrip.defaultItemIdentifiers = layoutComponents.map({ $0.identifier }) 49 | } 50 | 51 | lazy var globalTouchBarItem: NSCustomTouchBarItem = { 52 | let item = NSCustomTouchBarItem(identifier: .touchbarBrowserGlobal) 53 | item.view = NSButton(title: "🌍", target: self, action: #selector(actionTouchbarButtonToggle)) 54 | return item 55 | }() 56 | 57 | func touchBar(_ touchBar: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItem.Identifier) -> NSTouchBarItem? { 58 | switch identifier { 59 | case .touchbarBrowserClose: 60 | let globalButton = NSCustomTouchBarItem(identifier: .touchbarBrowserClose) 61 | globalButton.view = NSButton(title: "Close", target: self, action: #selector(actionTouchbarButtonClose)) 62 | return globalButton 63 | default: 64 | // Look in layoutComponents 65 | if let component = layoutComponents.first(where: { $0.identifier == identifier }) { 66 | return component.touchBarItem 67 | } 68 | } 69 | 70 | return nil 71 | } 72 | 73 | @objc func actionTouchbarButtonToggle() { 74 | touchbarStripVisible = !touchbarStripVisible 75 | } 76 | 77 | @objc func actionTouchbarButtonOpen() { 78 | touchbarStripVisible = true 79 | } 80 | 81 | @objc func actionTouchbarButtonClose() { 82 | touchbarStripVisible = false 83 | } 84 | 85 | func showGlobalTouchBarItem() { 86 | NSTouchBarItem.addSystemTrayItem(self.globalTouchBarItem) 87 | DFRElementSetControlStripPresenceForIdentifier(.touchbarBrowserGlobal, true) 88 | } 89 | 90 | func removeGlobalTouchBarItem() { 91 | self.touchbarStripVisible = false 92 | NSTouchBarItem.removeSystemTrayItem(self.globalTouchBarItem) 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /touchbar-browser-helper/Utils/NSColor+webhex.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NSColor+webhex.swift 3 | // touchbar-browser-helper 4 | // 5 | // Created by Viktor Strate Kløvedal on 11/11/2020. 6 | // 7 | 8 | import Cocoa 9 | 10 | extension NSColor { 11 | 12 | static func from(hex: String) -> NSColor? { 13 | var val = hex 14 | if (hex.starts(with: "#")) { 15 | val.removeFirst() 16 | } 17 | 18 | if !val.filter({ !$0.isHexDigit }).isEmpty { 19 | return nil 20 | } 21 | 22 | if (val.count == 3) { 23 | var newVal = "" 24 | for c in val { 25 | newVal += "\(c)\(c)" 26 | } 27 | val = newVal 28 | } 29 | 30 | if (val.count != 6) { 31 | return nil 32 | } 33 | 34 | guard let rgb = Int32(val, radix: 16) else { 35 | return nil 36 | } 37 | 38 | let r = (rgb >> 16) & 0xFF 39 | let g = (rgb >> 8) & 0xFF 40 | let b = rgb & 0xFF 41 | 42 | let rFloat = CGFloat(r) / 256.0 43 | let gFloat = CGFloat(g) / 256.0 44 | let bFloat = CGFloat(b) / 256.0 45 | 46 | let color = NSColor(cgColor: CGColor(red: rFloat, green: gFloat, blue: bFloat, alpha: 1)) 47 | return color 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /touchbar-browser-helper/main.swift: -------------------------------------------------------------------------------- 1 | // 2 | // main.swift 3 | // touchbar-browser-helper 4 | // 5 | // Created by Viktor Strate Kløvedal on 07/11/2020. 6 | // 7 | 8 | import Cocoa 9 | 10 | let app = NSApplication.shared 11 | 12 | let appDelegate = AppDelegate() 13 | app.delegate = appDelegate 14 | 15 | app.run() 16 | --------------------------------------------------------------------------------