├── LICENSE ├── README.md ├── docs └── hello.md ├── glanceables.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ ├── IDEWorkspaceChecks.plist │ │ └── WorkspaceSettings.xcsettings │ └── xcuserdata │ │ └── devin.xcuserdatad │ │ ├── IDEFindNavigatorScopes.plist │ │ └── WorkspaceSettings.xcsettings ├── xcshareddata │ └── xcschemes │ │ └── glanceables.xcscheme └── xcuserdata │ └── devin.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ └── xcschememanagement.plist ├── glanceables ├── Assets.xcassets │ ├── AccentColor.colorset │ │ └── Contents.json │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json ├── ContentView.swift ├── Model │ ├── CapturedElement.swift │ ├── LlamaResult.swift │ ├── SchedulerModel.swift │ ├── SnapshotTimelineModel.swift │ └── WebClip.swift ├── Preview Content │ └── Preview Assets.xcassets │ │ └── Contents.json ├── Repository │ ├── WebClipRepositoryProtocol.swift │ └── WebClipUserDefaultsRepository.swift ├── Response.swift ├── Tests │ └── URLModalViewTests.swift ├── UrlModalView.swift ├── Utilities │ ├── ImageLoader.swift │ ├── JavascriptLoader.swift │ ├── LeakAvoider.swift │ ├── LlamaAPIManager.swift │ ├── NotificationManager.swift │ ├── ScreenshotUtils.swift │ ├── URLUtilities.swift │ └── UserDefaults.swift ├── View │ ├── AddURLFormView.swift │ ├── BlackEditMenuBarView.swift │ ├── BlackMenuBarView.swift │ ├── CaptureModeToggleView.swift │ ├── CaptureRectangleView.swift │ ├── ChangeFeedbackFormView.swift │ ├── CreateButtonView.swift │ ├── GridScreenshotView.swift │ ├── NavigationButtonsView.swift │ ├── RedXButton.swift │ ├── SaveButtonView.swift │ ├── WebClipBrowserMenuView.swift │ ├── WebClipCreatorView.swift │ ├── WebClipEditorView.swift │ ├── WebClipGridView.swift │ ├── WebClipRefresherGrid.swift │ ├── WebGridSingleSnapshotView.swift │ └── WebViewSnapshotRefresher.swift ├── ViewModel │ ├── SchedulerManagerViewModel.swift │ ├── WebClipCreatorViewModel.swift │ ├── WebClipManagerViewModel.swift │ ├── WebClipSelectorViewModel.swift │ └── WebClipUpdaterViewModel.swift ├── WebViewScreenshotCapture.swift ├── captureElements.js ├── glanceables.entitlements └── glanceablesApp.swift └── glanceablesTests └── WebViewTests.swift /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 | # Glanceables 2 | 3 | 4 | https://github.com/user-attachments/assets/497c6596-4c36-4baa-b710-b9213e20affd 5 | 6 | 7 | 8 | ## Overview 9 | We're aiming to make the web simpler one widget at a time with our unique approach: "A browser that's not a browser." This means transforming complex websites into easy-to-digest widgets. You get just the essentials—whether that’s watching for price changes, checking if there’s space at the campground, or updating the traffic situation—without the need to keep refreshing pages. 10 | 11 | ## The Problem We're Solving 12 | Ever feel like the internet's a crowded room, shouting at you from every corner? It’s packed with ads and complicated layouts that make finding what you need harder than finding a needle in a haystack. Our project is here to change that by stripping down to the basics and making your digital life as easy as pie. We’re bringing the joy back to browsing—no hassle, just the good stuff. 13 | 14 | ## Precision Capture and Restoration 15 | Our web clip capture & restoring algorithm enhances precise selection and automatic recovery of web content. This is for users who need to monitor specific areas of a webpage with high accuracy. 16 | 17 | Screenshot 2024-07-22 at 11 16 53 AM 18 | 19 | ### How It Works 20 | - **Interactive Selection:** Users can manually select an area on the webpage by dragging a 300px by 300px rectangle. This can be done anywhere on the webpage to focus on content that matters. 21 | - **Element Detection and Selection:** Once an area is selected, our algorithm detects all elements within the center of the rectangle. It then filters these elements to include only those that are fully or partially inside the selected area. 22 | - **Data Capture and Storage:** For each detected element, a unique CSS selector is generated. We record this selector along with the element’s position relative to the scroll position at the time of capture, ensuring detailed and precise information storage. 23 | - **Boundary Restoration:** When accessing the widget again, the system uses the stored CSS selector to locate the element and adjusts the webpage's scroll to the original position, perfectly restoring the view to its previous state. 24 | 25 | 26 | ### Change Detection and Notifications 27 | Glanceables detects changes in your saved web clips and notifies you directly on your desktop. This ensures that you're always aware of the latest updates without needing to manually check back. 28 | 29 | ### Auto-Refresh 30 | To ensure you are viewing the most current information, webpages within Glanceables refresh automatically every 60 seconds. 31 | 32 | ### How to Run 33 | 1. This project requires [Ollama](https://ollama.com/download) for local LLM integration, please download that first. 34 | 2. Go to the [releases page](https://github.com/devin-liu/glanceables/releases) and download the latest version. 35 | 3. Add your first glanceable by following the interactive guide on our application. 36 | 37 | 38 | ## How to Help Out 39 | - **Report Issues:** Stumbled upon a problem or have a suggestion? Pop it into our issues section. 40 | - **Make Improvements:** Have a fix or a new feature? We welcome your pull requests. 41 | - **Share Your Thoughts:** Your feedback drives our improvement, so don’t hesitate to reach out. 42 | -------------------------------------------------------------------------------- /docs/hello.md: -------------------------------------------------------------------------------- 1 | # Glanceables Project Overview 2 | 3 | ## Introduction 4 | 5 | - **Purpose**: Turns parts of websites into Glanceable widgets, helping you keep tabs on what's important. 6 | - **Scope**: Transforming complex websites into widgets that help you find what you need. Watch for price changes, check for open campground spaces, and get updates on the latest traffic situation. 7 | 8 | ## High-Level Architecture 9 | 10 | The Glanceables project is designed to streamline the browsing experience on macOS by allowing users to save and interact with specific portions of webpages. The architecture is composed of several key components that interact through a central ContentView, facilitating a modular and scalable system. 11 | 12 | 1. **ContentView**: 13 | 14 | - Acts as the main interface where users interact with the application. It integrates various views and handles the navigation between different parts of the application. Holds the dashboard, webclip menu, and notifications manager. 15 | 16 | 2. **Web Capture System**: 17 | 18 | - Utilizes WebView to capture screenshots of webpages or specific areas defined by the user. This system is responsible for the real-time rendering and capture of web content. 19 | 20 | 3. **Local Storage**: 21 | 22 | - Saves the captured screenshots and webpage data locally. This allows users to access and manage their saved content offline and enhances the application's performance by reducing load times. 23 | 24 | 4. **Notification System**: 25 | 26 | - Integrates with macOS desktop notifications to alert users about updates or changes in their saved web content. This system helps in keeping the user informed without needing to actively check the app. 27 | 28 | 5. **Ollama Integration**: 29 | - Connects to Ollama for secure, private integration with an open-source LLM (large language model). This feature allows users to perform enhanced text analysis and other AI-driven tasks directly within the application. 30 | 31 | ## Directory Structure 32 | 33 | - **Root Folders**: 34 | - `/View`: Contains all UI components. 35 | - `/ViewModel`: Handles the business logic associated with views. 36 | - `/Model`: Defines the data structure and business models. 37 | - `/Utilities`: Includes helper classes and utilities functions. 38 | 39 | ## Key Components 40 | 41 | ### Views 42 | 43 | - **AddURLFormView**: Responsible for handling URL input forms. 44 | - **WebClipBrowserMenuView**: Manages the browser menu for web clips, facilitating user interaction with web content. 45 | - **WebViewSnapshotRefresher**: Refreshes web view snapshots to ensure up-to-date content display. 46 | - **CaptureRectangleView**: Manages the functionality to capture specific areas of the webpage. 47 | 48 | ### Repository 49 | 50 | - **WebClipRepositoryProtocol.swift**: Defines the protocol for web clip data handling. 51 | - **WebClipUserDefaultsRepository.swift**: Implementation of the WebClip repository using User Defaults for storage. 52 | 53 | ### ViewModels 54 | 55 | - **DashboardViewModel**: Manages data and state for the dashboard. 56 | - **WebClipManagerViewModel.swift**: Manages the lifecycle and operations of web clips. 57 | - **WebViewCoordinator.swift**: Coordinates web views and their interactions within the app. 58 | - **SchedulerManagerViewModel**: Manages scheduling tasks for refreshing and updating web clips. 59 | - **WebClipSelectorViewModel**: Manages the selection and management of different web clips. 60 | 61 | 62 | ### Models 63 | 64 | - **WebClip**: Represents the data model for a web clip. 65 | - **SnapshotTimelineModel.swift**: Manages the timeline of captured web snapshots for historical views. 66 | - **UserDefaults**: Manages user preferences stored across sessions. 67 | - **SnapshotTimelineModel.swift**: Manages the timeline of captured web snapshots for historical views. 68 | 69 | ### Utilities 70 | 71 | - **JavascriptLoader.swift**: Loads and manages JavaScript for dynamic interaction within webviews. 72 | - **NotificationManager.swift**: Manages all notifications to alert users about changes or updates. 73 | - **URLUtilities.swift**: Helper functions for URL validation and manipulation. 74 | - **UserDefaults.swift**: Manages the storage of user settings and preferences. 75 | -------------------------------------------------------------------------------- /glanceables.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 56; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 030062992C0A833200B0242D /* CreateButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 030062982C0A833200B0242D /* CreateButtonView.swift */; }; 11 | 0300629B2C0D209400B0242D /* UserDefaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0300629A2C0D209400B0242D /* UserDefaults.swift */; }; 12 | 0300629D2C0D229800B0242D /* BlackMenuBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0300629C2C0D229800B0242D /* BlackMenuBarView.swift */; }; 13 | 030062A72C0FE8A100B0242D /* WebClipBrowserMenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 030062A62C0FE8A100B0242D /* WebClipBrowserMenuView.swift */; }; 14 | 030062B42C112BD100B0242D /* WebClip.swift in Sources */ = {isa = PBXBuildFile; fileRef = 030062B32C112BD100B0242D /* WebClip.swift */; }; 15 | 03553FE32C41F6A800FCB4CC /* WebClipSelectorViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03553FE22C41F6A800FCB4CC /* WebClipSelectorViewModel.swift */; }; 16 | 036D58E52C3C99300042D491 /* WebClipManagerViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 036D58E42C3C99300042D491 /* WebClipManagerViewModel.swift */; }; 17 | 036F46562C5AE066005E1377 /* NotificationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 036F46552C5AE066005E1377 /* NotificationManager.swift */; }; 18 | 036F465C2C5AE85F005E1377 /* SnapshotTimelineModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 036F465B2C5AE85F005E1377 /* SnapshotTimelineModel.swift */; }; 19 | 03778E402C35E740009CB9A1 /* captureElements.js in Resources */ = {isa = PBXBuildFile; fileRef = 03778E3E2C35E6FC009CB9A1 /* captureElements.js */; }; 20 | 03778E422C36028F009CB9A1 /* CapturedElement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03778E412C36028F009CB9A1 /* CapturedElement.swift */; }; 21 | 0378B8672C096D850005BAE5 /* glanceablesApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0378B8662C096D850005BAE5 /* glanceablesApp.swift */; }; 22 | 0378B8692C096D850005BAE5 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0378B8682C096D850005BAE5 /* ContentView.swift */; }; 23 | 0378B86D2C096D860005BAE5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0378B86C2C096D860005BAE5 /* Assets.xcassets */; }; 24 | 0378B8702C096D860005BAE5 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0378B86F2C096D860005BAE5 /* Preview Assets.xcassets */; }; 25 | 0378B8772C096DB00005BAE5 /* WebGridSingleSnapshotView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0378B8762C096DB00005BAE5 /* WebGridSingleSnapshotView.swift */; }; 26 | 038208DA2C18CAFB00606536 /* WebViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 038208D92C18CAFB00606536 /* WebViewTests.swift */; }; 27 | 038208E02C1BB3F400606536 /* WebViewScreenshotCapture.swift in Sources */ = {isa = PBXBuildFile; fileRef = 038208DF2C1BB3F400606536 /* WebViewScreenshotCapture.swift */; }; 28 | 038208E22C1BB40400606536 /* WebViewSnapshotRefresher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 038208E12C1BB40400606536 /* WebViewSnapshotRefresher.swift */; }; 29 | 038DAC262C617A3F0000EA6A /* WebClipCreatorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 038DAC252C617A3F0000EA6A /* WebClipCreatorView.swift */; }; 30 | 038DAC282C6182140000EA6A /* BlackEditMenuBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 038DAC272C6182140000EA6A /* BlackEditMenuBarView.swift */; }; 31 | 038DAC2A2C618AE20000EA6A /* WebClipEditorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 038DAC292C618AE20000EA6A /* WebClipEditorView.swift */; }; 32 | 038DAC2C2C61A0950000EA6A /* ChangeFeedbackFormView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 038DAC2B2C61A0950000EA6A /* ChangeFeedbackFormView.swift */; }; 33 | 038DAC2F2C61C9710000EA6A /* WebClipRepositoryProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 038DAC2E2C61C9710000EA6A /* WebClipRepositoryProtocol.swift */; }; 34 | 038DAC312C61C97D0000EA6A /* WebClipUserDefaultsRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 038DAC302C61C97D0000EA6A /* WebClipUserDefaultsRepository.swift */; }; 35 | 03A868512C4865C900CCB79D /* CaptureRectangleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03A868502C4865C900CCB79D /* CaptureRectangleView.swift */; }; 36 | 03A868532C48692A00CCB79D /* SaveButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03A868522C48692A00CCB79D /* SaveButtonView.swift */; }; 37 | 03A868552C48871000CCB79D /* LlamaAPIManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03A868542C48871000CCB79D /* LlamaAPIManager.swift */; }; 38 | 03A868572C48880600CCB79D /* Response.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03A868562C48880600CCB79D /* Response.swift */; }; 39 | 03A868592C489B3100CCB79D /* JavascriptLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03A868582C489B3100CCB79D /* JavascriptLoader.swift */; }; 40 | 03A8685B2C4B312E00CCB79D /* LlamaResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03A8685A2C4B312E00CCB79D /* LlamaResult.swift */; }; 41 | 03A868632C51FF0800CCB79D /* NavigationButtonsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03A868622C51FF0800CCB79D /* NavigationButtonsView.swift */; }; 42 | 03B557922C753488001466BB /* LeakAvoider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03B557912C753488001466BB /* LeakAvoider.swift */; }; 43 | 03B557942C755446001466BB /* WebClipUpdaterViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03B557932C755446001466BB /* WebClipUpdaterViewModel.swift */; }; 44 | 03B798572C62E9A400E431E4 /* SchedulerManagerViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03B798562C62E9A400E431E4 /* SchedulerManagerViewModel.swift */; }; 45 | 03B798592C62EA5600E431E4 /* SchedulerModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03B798582C62EA5600E431E4 /* SchedulerModel.swift */; }; 46 | 03B7985B2C62F0BA00E431E4 /* WebClipCreatorViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03B7985A2C62F0BA00E431E4 /* WebClipCreatorViewModel.swift */; }; 47 | 03BEC9AF2C6AD34E00372E6E /* WebClipGridView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03BEC9AE2C6AD34E00372E6E /* WebClipGridView.swift */; }; 48 | 03BEC9B12C6B1CC200372E6E /* GridScreenshotView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03BEC9B02C6B1CC200372E6E /* GridScreenshotView.swift */; }; 49 | 03BEC9B32C6EAA2500372E6E /* ImageLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03BEC9B22C6EAA2500372E6E /* ImageLoader.swift */; }; 50 | 03BEC9B92C72720A00372E6E /* WebClipRefresherGrid.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03BEC9B82C72720A00372E6E /* WebClipRefresherGrid.swift */; }; 51 | 03C5DAD12C23A76B0061FA25 /* ScreenshotUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03C5DAD02C23A76B0061FA25 /* ScreenshotUtils.swift */; }; 52 | 03C5DAD32C24F0CF0061FA25 /* URLUtilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03C5DAD22C24F0CF0061FA25 /* URLUtilities.swift */; }; 53 | 03C5DAD52C2647E20061FA25 /* CaptureModeToggleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03C5DAD42C2647E20061FA25 /* CaptureModeToggleView.swift */; }; 54 | 03C5DAD72C264BE00061FA25 /* RedXButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03C5DAD62C264BE00061FA25 /* RedXButton.swift */; }; 55 | 03C5DAD92C2A4DB20061FA25 /* AddURLFormView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03C5DAD82C2A4DB20061FA25 /* AddURLFormView.swift */; }; 56 | /* End PBXBuildFile section */ 57 | 58 | /* Begin PBXContainerItemProxy section */ 59 | 0355A0722C17DA8B005BBAF3 /* PBXContainerItemProxy */ = { 60 | isa = PBXContainerItemProxy; 61 | containerPortal = 0378B85B2C096D850005BAE5 /* Project object */; 62 | proxyType = 1; 63 | remoteGlobalIDString = 0378B8622C096D850005BAE5; 64 | remoteInfo = glanceables; 65 | }; 66 | /* End PBXContainerItemProxy section */ 67 | 68 | /* Begin PBXFileReference section */ 69 | 030062982C0A833200B0242D /* CreateButtonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateButtonView.swift; sourceTree = ""; }; 70 | 0300629A2C0D209400B0242D /* UserDefaults.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDefaults.swift; sourceTree = ""; }; 71 | 0300629C2C0D229800B0242D /* BlackMenuBarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlackMenuBarView.swift; sourceTree = ""; }; 72 | 030062A62C0FE8A100B0242D /* WebClipBrowserMenuView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebClipBrowserMenuView.swift; sourceTree = ""; }; 73 | 030062B32C112BD100B0242D /* WebClip.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = WebClip.swift; path = glanceables/Model/WebClip.swift; sourceTree = SOURCE_ROOT; }; 74 | 03553FE22C41F6A800FCB4CC /* WebClipSelectorViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebClipSelectorViewModel.swift; sourceTree = ""; }; 75 | 0355A0672C17D741005BBAF3 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Platforms/iPhoneOS.platform/Developer/Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; 76 | 0355A06E2C17DA8B005BBAF3 /* glanceablesTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = glanceablesTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 77 | 036D58E42C3C99300042D491 /* WebClipManagerViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebClipManagerViewModel.swift; sourceTree = ""; }; 78 | 036F46552C5AE066005E1377 /* NotificationManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationManager.swift; sourceTree = ""; }; 79 | 036F465B2C5AE85F005E1377 /* SnapshotTimelineModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnapshotTimelineModel.swift; sourceTree = ""; }; 80 | 03778E3E2C35E6FC009CB9A1 /* captureElements.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = captureElements.js; sourceTree = ""; }; 81 | 03778E412C36028F009CB9A1 /* CapturedElement.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CapturedElement.swift; sourceTree = ""; }; 82 | 0378B8632C096D850005BAE5 /* glanceables.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = glanceables.app; sourceTree = BUILT_PRODUCTS_DIR; }; 83 | 0378B8662C096D850005BAE5 /* glanceablesApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = glanceablesApp.swift; sourceTree = ""; }; 84 | 0378B8682C096D850005BAE5 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 85 | 0378B86C2C096D860005BAE5 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 86 | 0378B86F2C096D860005BAE5 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 87 | 0378B8762C096DB00005BAE5 /* WebGridSingleSnapshotView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebGridSingleSnapshotView.swift; sourceTree = ""; }; 88 | 038208D92C18CAFB00606536 /* WebViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebViewTests.swift; sourceTree = ""; }; 89 | 038208DF2C1BB3F400606536 /* WebViewScreenshotCapture.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebViewScreenshotCapture.swift; sourceTree = ""; }; 90 | 038208E12C1BB40400606536 /* WebViewSnapshotRefresher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebViewSnapshotRefresher.swift; sourceTree = ""; }; 91 | 038DAC252C617A3F0000EA6A /* WebClipCreatorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebClipCreatorView.swift; sourceTree = ""; }; 92 | 038DAC272C6182140000EA6A /* BlackEditMenuBarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlackEditMenuBarView.swift; sourceTree = ""; }; 93 | 038DAC292C618AE20000EA6A /* WebClipEditorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebClipEditorView.swift; sourceTree = ""; }; 94 | 038DAC2B2C61A0950000EA6A /* ChangeFeedbackFormView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChangeFeedbackFormView.swift; sourceTree = ""; }; 95 | 038DAC2E2C61C9710000EA6A /* WebClipRepositoryProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebClipRepositoryProtocol.swift; sourceTree = ""; }; 96 | 038DAC302C61C97D0000EA6A /* WebClipUserDefaultsRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebClipUserDefaultsRepository.swift; sourceTree = ""; }; 97 | 03A868502C4865C900CCB79D /* CaptureRectangleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CaptureRectangleView.swift; sourceTree = ""; }; 98 | 03A868522C48692A00CCB79D /* SaveButtonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SaveButtonView.swift; sourceTree = ""; }; 99 | 03A868542C48871000CCB79D /* LlamaAPIManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LlamaAPIManager.swift; sourceTree = ""; }; 100 | 03A868562C48880600CCB79D /* Response.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Response.swift; sourceTree = ""; }; 101 | 03A868582C489B3100CCB79D /* JavascriptLoader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JavascriptLoader.swift; sourceTree = ""; }; 102 | 03A8685A2C4B312E00CCB79D /* LlamaResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LlamaResult.swift; sourceTree = ""; }; 103 | 03A868622C51FF0800CCB79D /* NavigationButtonsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationButtonsView.swift; sourceTree = ""; }; 104 | 03B557912C753488001466BB /* LeakAvoider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LeakAvoider.swift; sourceTree = ""; }; 105 | 03B557932C755446001466BB /* WebClipUpdaterViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebClipUpdaterViewModel.swift; sourceTree = ""; }; 106 | 03B798562C62E9A400E431E4 /* SchedulerManagerViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SchedulerManagerViewModel.swift; sourceTree = ""; }; 107 | 03B798582C62EA5600E431E4 /* SchedulerModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SchedulerModel.swift; sourceTree = ""; }; 108 | 03B7985A2C62F0BA00E431E4 /* WebClipCreatorViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebClipCreatorViewModel.swift; sourceTree = ""; }; 109 | 03BEC9AE2C6AD34E00372E6E /* WebClipGridView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebClipGridView.swift; sourceTree = ""; }; 110 | 03BEC9B02C6B1CC200372E6E /* GridScreenshotView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GridScreenshotView.swift; sourceTree = ""; }; 111 | 03BEC9B22C6EAA2500372E6E /* ImageLoader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageLoader.swift; sourceTree = ""; }; 112 | 03BEC9B82C72720A00372E6E /* WebClipRefresherGrid.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebClipRefresherGrid.swift; sourceTree = ""; }; 113 | 03C5DAD02C23A76B0061FA25 /* ScreenshotUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = ScreenshotUtils.swift; path = glanceables/Utilities/ScreenshotUtils.swift; sourceTree = SOURCE_ROOT; }; 114 | 03C5DAD22C24F0CF0061FA25 /* URLUtilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLUtilities.swift; sourceTree = ""; }; 115 | 03C5DAD42C2647E20061FA25 /* CaptureModeToggleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CaptureModeToggleView.swift; sourceTree = ""; }; 116 | 03C5DAD62C264BE00061FA25 /* RedXButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RedXButton.swift; sourceTree = ""; }; 117 | 03C5DAD82C2A4DB20061FA25 /* AddURLFormView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AddURLFormView.swift; path = glanceables/View/AddURLFormView.swift; sourceTree = SOURCE_ROOT; }; 118 | 03DF92F42C40B98A00625AEB /* glanceables.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = glanceables.entitlements; sourceTree = ""; }; 119 | /* End PBXFileReference section */ 120 | 121 | /* Begin PBXFrameworksBuildPhase section */ 122 | 0355A06B2C17DA8B005BBAF3 /* Frameworks */ = { 123 | isa = PBXFrameworksBuildPhase; 124 | buildActionMask = 2147483647; 125 | files = ( 126 | ); 127 | runOnlyForDeploymentPostprocessing = 0; 128 | }; 129 | 0378B8602C096D850005BAE5 /* Frameworks */ = { 130 | isa = PBXFrameworksBuildPhase; 131 | buildActionMask = 2147483647; 132 | files = ( 133 | ); 134 | runOnlyForDeploymentPostprocessing = 0; 135 | }; 136 | /* End PBXFrameworksBuildPhase section */ 137 | 138 | /* Begin PBXGroup section */ 139 | 0355A0662C17D741005BBAF3 /* Frameworks */ = { 140 | isa = PBXGroup; 141 | children = ( 142 | 0355A0672C17D741005BBAF3 /* XCTest.framework */, 143 | ); 144 | name = Frameworks; 145 | sourceTree = ""; 146 | }; 147 | 0355A06F2C17DA8B005BBAF3 /* glanceablesTests */ = { 148 | isa = PBXGroup; 149 | children = ( 150 | 038208D92C18CAFB00606536 /* WebViewTests.swift */, 151 | ); 152 | path = glanceablesTests; 153 | sourceTree = ""; 154 | }; 155 | 0378B85A2C096D850005BAE5 = { 156 | isa = PBXGroup; 157 | children = ( 158 | 0378B8652C096D850005BAE5 /* glanceables */, 159 | 0355A06F2C17DA8B005BBAF3 /* glanceablesTests */, 160 | 0378B8642C096D850005BAE5 /* Products */, 161 | 0355A0662C17D741005BBAF3 /* Frameworks */, 162 | ); 163 | sourceTree = ""; 164 | }; 165 | 0378B8642C096D850005BAE5 /* Products */ = { 166 | isa = PBXGroup; 167 | children = ( 168 | 0378B8632C096D850005BAE5 /* glanceables.app */, 169 | 0355A06E2C17DA8B005BBAF3 /* glanceablesTests.xctest */, 170 | ); 171 | name = Products; 172 | sourceTree = ""; 173 | }; 174 | 0378B8652C096D850005BAE5 /* glanceables */ = { 175 | isa = PBXGroup; 176 | children = ( 177 | 03DF92F42C40B98A00625AEB /* glanceables.entitlements */, 178 | 038DAC2D2C61C9600000EA6A /* Repository */, 179 | 03A8685D2C4EE54200CCB79D /* View */, 180 | 03A8685F2C4EE63500CCB79D /* Utilities */, 181 | 03A868562C48880600CCB79D /* Response.swift */, 182 | 038208DF2C1BB3F400606536 /* WebViewScreenshotCapture.swift */, 183 | 03A8685E2C4EE5B300CCB79D /* ViewModel */, 184 | 03A8685C2C4EE50600CCB79D /* Model */, 185 | 03778E3E2C35E6FC009CB9A1 /* captureElements.js */, 186 | 0378B8662C096D850005BAE5 /* glanceablesApp.swift */, 187 | 0378B8682C096D850005BAE5 /* ContentView.swift */, 188 | 0378B86C2C096D860005BAE5 /* Assets.xcassets */, 189 | 0378B86E2C096D860005BAE5 /* Preview Content */, 190 | ); 191 | path = glanceables; 192 | sourceTree = ""; 193 | }; 194 | 0378B86E2C096D860005BAE5 /* Preview Content */ = { 195 | isa = PBXGroup; 196 | children = ( 197 | 0378B86F2C096D860005BAE5 /* Preview Assets.xcassets */, 198 | ); 199 | path = "Preview Content"; 200 | sourceTree = ""; 201 | }; 202 | 038DAC2D2C61C9600000EA6A /* Repository */ = { 203 | isa = PBXGroup; 204 | children = ( 205 | 038DAC2E2C61C9710000EA6A /* WebClipRepositoryProtocol.swift */, 206 | 038DAC302C61C97D0000EA6A /* WebClipUserDefaultsRepository.swift */, 207 | ); 208 | path = Repository; 209 | sourceTree = ""; 210 | }; 211 | 03A8685C2C4EE50600CCB79D /* Model */ = { 212 | isa = PBXGroup; 213 | children = ( 214 | 03778E412C36028F009CB9A1 /* CapturedElement.swift */, 215 | 03A8685A2C4B312E00CCB79D /* LlamaResult.swift */, 216 | 030062B32C112BD100B0242D /* WebClip.swift */, 217 | 036F465B2C5AE85F005E1377 /* SnapshotTimelineModel.swift */, 218 | 03B798582C62EA5600E431E4 /* SchedulerModel.swift */, 219 | ); 220 | path = Model; 221 | sourceTree = ""; 222 | }; 223 | 03A8685D2C4EE54200CCB79D /* View */ = { 224 | isa = PBXGroup; 225 | children = ( 226 | 03C5DAD82C2A4DB20061FA25 /* AddURLFormView.swift */, 227 | 03A868622C51FF0800CCB79D /* NavigationButtonsView.swift */, 228 | 0300629C2C0D229800B0242D /* BlackMenuBarView.swift */, 229 | 038DAC272C6182140000EA6A /* BlackEditMenuBarView.swift */, 230 | 03C5DAD42C2647E20061FA25 /* CaptureModeToggleView.swift */, 231 | 03A868502C4865C900CCB79D /* CaptureRectangleView.swift */, 232 | 030062A62C0FE8A100B0242D /* WebClipBrowserMenuView.swift */, 233 | 0378B8762C096DB00005BAE5 /* WebGridSingleSnapshotView.swift */, 234 | 030062982C0A833200B0242D /* CreateButtonView.swift */, 235 | 03A868522C48692A00CCB79D /* SaveButtonView.swift */, 236 | 038208E12C1BB40400606536 /* WebViewSnapshotRefresher.swift */, 237 | 03C5DAD62C264BE00061FA25 /* RedXButton.swift */, 238 | 038DAC252C617A3F0000EA6A /* WebClipCreatorView.swift */, 239 | 038DAC292C618AE20000EA6A /* WebClipEditorView.swift */, 240 | 038DAC2B2C61A0950000EA6A /* ChangeFeedbackFormView.swift */, 241 | 03BEC9AE2C6AD34E00372E6E /* WebClipGridView.swift */, 242 | 03BEC9B02C6B1CC200372E6E /* GridScreenshotView.swift */, 243 | 03BEC9B82C72720A00372E6E /* WebClipRefresherGrid.swift */, 244 | ); 245 | path = View; 246 | sourceTree = ""; 247 | }; 248 | 03A8685E2C4EE5B300CCB79D /* ViewModel */ = { 249 | isa = PBXGroup; 250 | children = ( 251 | 036D58E42C3C99300042D491 /* WebClipManagerViewModel.swift */, 252 | 03553FE22C41F6A800FCB4CC /* WebClipSelectorViewModel.swift */, 253 | 03B798562C62E9A400E431E4 /* SchedulerManagerViewModel.swift */, 254 | 03B7985A2C62F0BA00E431E4 /* WebClipCreatorViewModel.swift */, 255 | 03B557932C755446001466BB /* WebClipUpdaterViewModel.swift */, 256 | ); 257 | path = ViewModel; 258 | sourceTree = ""; 259 | }; 260 | 03A8685F2C4EE63500CCB79D /* Utilities */ = { 261 | isa = PBXGroup; 262 | children = ( 263 | 03A868542C48871000CCB79D /* LlamaAPIManager.swift */, 264 | 0300629A2C0D209400B0242D /* UserDefaults.swift */, 265 | 036F46552C5AE066005E1377 /* NotificationManager.swift */, 266 | 03C5DAD02C23A76B0061FA25 /* ScreenshotUtils.swift */, 267 | 03A868582C489B3100CCB79D /* JavascriptLoader.swift */, 268 | 03C5DAD22C24F0CF0061FA25 /* URLUtilities.swift */, 269 | 03BEC9B22C6EAA2500372E6E /* ImageLoader.swift */, 270 | 03B557912C753488001466BB /* LeakAvoider.swift */, 271 | ); 272 | path = Utilities; 273 | sourceTree = ""; 274 | }; 275 | /* End PBXGroup section */ 276 | 277 | /* Begin PBXNativeTarget section */ 278 | 0355A06D2C17DA8B005BBAF3 /* glanceablesTests */ = { 279 | isa = PBXNativeTarget; 280 | buildConfigurationList = 0355A0742C17DA8B005BBAF3 /* Build configuration list for PBXNativeTarget "glanceablesTests" */; 281 | buildPhases = ( 282 | 0355A06A2C17DA8B005BBAF3 /* Sources */, 283 | 0355A06B2C17DA8B005BBAF3 /* Frameworks */, 284 | 0355A06C2C17DA8B005BBAF3 /* Resources */, 285 | ); 286 | buildRules = ( 287 | ); 288 | dependencies = ( 289 | 0355A0732C17DA8B005BBAF3 /* PBXTargetDependency */, 290 | ); 291 | name = glanceablesTests; 292 | productName = glanceablesTests; 293 | productReference = 0355A06E2C17DA8B005BBAF3 /* glanceablesTests.xctest */; 294 | productType = "com.apple.product-type.bundle.unit-test"; 295 | }; 296 | 0378B8622C096D850005BAE5 /* glanceables */ = { 297 | isa = PBXNativeTarget; 298 | buildConfigurationList = 0378B8732C096D860005BAE5 /* Build configuration list for PBXNativeTarget "glanceables" */; 299 | buildPhases = ( 300 | 0378B85F2C096D850005BAE5 /* Sources */, 301 | 0378B8602C096D850005BAE5 /* Frameworks */, 302 | 0378B8612C096D850005BAE5 /* Resources */, 303 | ); 304 | buildRules = ( 305 | ); 306 | dependencies = ( 307 | ); 308 | name = glanceables; 309 | productName = glanceables; 310 | productReference = 0378B8632C096D850005BAE5 /* glanceables.app */; 311 | productType = "com.apple.product-type.application"; 312 | }; 313 | /* End PBXNativeTarget section */ 314 | 315 | /* Begin PBXProject section */ 316 | 0378B85B2C096D850005BAE5 /* Project object */ = { 317 | isa = PBXProject; 318 | attributes = { 319 | BuildIndependentTargetsInParallel = 1; 320 | LastSwiftUpdateCheck = 1540; 321 | LastUpgradeCheck = 1540; 322 | TargetAttributes = { 323 | 0355A06D2C17DA8B005BBAF3 = { 324 | CreatedOnToolsVersion = 15.4; 325 | TestTargetID = 0378B8622C096D850005BAE5; 326 | }; 327 | 0378B8622C096D850005BAE5 = { 328 | CreatedOnToolsVersion = 15.4; 329 | }; 330 | }; 331 | }; 332 | buildConfigurationList = 0378B85E2C096D850005BAE5 /* Build configuration list for PBXProject "glanceables" */; 333 | compatibilityVersion = "Xcode 14.0"; 334 | developmentRegion = en; 335 | hasScannedForEncodings = 0; 336 | knownRegions = ( 337 | en, 338 | Base, 339 | ); 340 | mainGroup = 0378B85A2C096D850005BAE5; 341 | productRefGroup = 0378B8642C096D850005BAE5 /* Products */; 342 | projectDirPath = ""; 343 | projectRoot = ""; 344 | targets = ( 345 | 0378B8622C096D850005BAE5 /* glanceables */, 346 | 0355A06D2C17DA8B005BBAF3 /* glanceablesTests */, 347 | ); 348 | }; 349 | /* End PBXProject section */ 350 | 351 | /* Begin PBXResourcesBuildPhase section */ 352 | 0355A06C2C17DA8B005BBAF3 /* Resources */ = { 353 | isa = PBXResourcesBuildPhase; 354 | buildActionMask = 2147483647; 355 | files = ( 356 | ); 357 | runOnlyForDeploymentPostprocessing = 0; 358 | }; 359 | 0378B8612C096D850005BAE5 /* Resources */ = { 360 | isa = PBXResourcesBuildPhase; 361 | buildActionMask = 2147483647; 362 | files = ( 363 | 03778E402C35E740009CB9A1 /* captureElements.js in Resources */, 364 | 0378B8702C096D860005BAE5 /* Preview Assets.xcassets in Resources */, 365 | 0378B86D2C096D860005BAE5 /* Assets.xcassets in Resources */, 366 | ); 367 | runOnlyForDeploymentPostprocessing = 0; 368 | }; 369 | /* End PBXResourcesBuildPhase section */ 370 | 371 | /* Begin PBXSourcesBuildPhase section */ 372 | 0355A06A2C17DA8B005BBAF3 /* Sources */ = { 373 | isa = PBXSourcesBuildPhase; 374 | buildActionMask = 2147483647; 375 | files = ( 376 | 038208DA2C18CAFB00606536 /* WebViewTests.swift in Sources */, 377 | ); 378 | runOnlyForDeploymentPostprocessing = 0; 379 | }; 380 | 0378B85F2C096D850005BAE5 /* Sources */ = { 381 | isa = PBXSourcesBuildPhase; 382 | buildActionMask = 2147483647; 383 | files = ( 384 | 03553FE32C41F6A800FCB4CC /* WebClipSelectorViewModel.swift in Sources */, 385 | 03A8685B2C4B312E00CCB79D /* LlamaResult.swift in Sources */, 386 | 03A868512C4865C900CCB79D /* CaptureRectangleView.swift in Sources */, 387 | 03B557942C755446001466BB /* WebClipUpdaterViewModel.swift in Sources */, 388 | 03778E422C36028F009CB9A1 /* CapturedElement.swift in Sources */, 389 | 0378B8772C096DB00005BAE5 /* WebGridSingleSnapshotView.swift in Sources */, 390 | 03BEC9B32C6EAA2500372E6E /* ImageLoader.swift in Sources */, 391 | 038DAC262C617A3F0000EA6A /* WebClipCreatorView.swift in Sources */, 392 | 0378B8692C096D850005BAE5 /* ContentView.swift in Sources */, 393 | 038208E02C1BB3F400606536 /* WebViewScreenshotCapture.swift in Sources */, 394 | 03C5DAD32C24F0CF0061FA25 /* URLUtilities.swift in Sources */, 395 | 03BEC9B12C6B1CC200372E6E /* GridScreenshotView.swift in Sources */, 396 | 038DAC2F2C61C9710000EA6A /* WebClipRepositoryProtocol.swift in Sources */, 397 | 03A868552C48871000CCB79D /* LlamaAPIManager.swift in Sources */, 398 | 03C5DAD52C2647E20061FA25 /* CaptureModeToggleView.swift in Sources */, 399 | 03B7985B2C62F0BA00E431E4 /* WebClipCreatorViewModel.swift in Sources */, 400 | 0300629D2C0D229800B0242D /* BlackMenuBarView.swift in Sources */, 401 | 038DAC282C6182140000EA6A /* BlackEditMenuBarView.swift in Sources */, 402 | 036D58E52C3C99300042D491 /* WebClipManagerViewModel.swift in Sources */, 403 | 030062992C0A833200B0242D /* CreateButtonView.swift in Sources */, 404 | 0300629B2C0D209400B0242D /* UserDefaults.swift in Sources */, 405 | 03C5DAD72C264BE00061FA25 /* RedXButton.swift in Sources */, 406 | 03A868572C48880600CCB79D /* Response.swift in Sources */, 407 | 03A868592C489B3100CCB79D /* JavascriptLoader.swift in Sources */, 408 | 038208E22C1BB40400606536 /* WebViewSnapshotRefresher.swift in Sources */, 409 | 03A868632C51FF0800CCB79D /* NavigationButtonsView.swift in Sources */, 410 | 036F46562C5AE066005E1377 /* NotificationManager.swift in Sources */, 411 | 03BEC9B92C72720A00372E6E /* WebClipRefresherGrid.swift in Sources */, 412 | 038DAC2C2C61A0950000EA6A /* ChangeFeedbackFormView.swift in Sources */, 413 | 03C5DAD92C2A4DB20061FA25 /* AddURLFormView.swift in Sources */, 414 | 036F465C2C5AE85F005E1377 /* SnapshotTimelineModel.swift in Sources */, 415 | 030062A72C0FE8A100B0242D /* WebClipBrowserMenuView.swift in Sources */, 416 | 038DAC2A2C618AE20000EA6A /* WebClipEditorView.swift in Sources */, 417 | 03C5DAD12C23A76B0061FA25 /* ScreenshotUtils.swift in Sources */, 418 | 038DAC312C61C97D0000EA6A /* WebClipUserDefaultsRepository.swift in Sources */, 419 | 03BEC9AF2C6AD34E00372E6E /* WebClipGridView.swift in Sources */, 420 | 0378B8672C096D850005BAE5 /* glanceablesApp.swift in Sources */, 421 | 03B557922C753488001466BB /* LeakAvoider.swift in Sources */, 422 | 030062B42C112BD100B0242D /* WebClip.swift in Sources */, 423 | 03A868532C48692A00CCB79D /* SaveButtonView.swift in Sources */, 424 | 03B798572C62E9A400E431E4 /* SchedulerManagerViewModel.swift in Sources */, 425 | 03B798592C62EA5600E431E4 /* SchedulerModel.swift in Sources */, 426 | ); 427 | runOnlyForDeploymentPostprocessing = 0; 428 | }; 429 | /* End PBXSourcesBuildPhase section */ 430 | 431 | /* Begin PBXTargetDependency section */ 432 | 0355A0732C17DA8B005BBAF3 /* PBXTargetDependency */ = { 433 | isa = PBXTargetDependency; 434 | target = 0378B8622C096D850005BAE5 /* glanceables */; 435 | targetProxy = 0355A0722C17DA8B005BBAF3 /* PBXContainerItemProxy */; 436 | }; 437 | /* End PBXTargetDependency section */ 438 | 439 | /* Begin XCBuildConfiguration section */ 440 | 0355A0752C17DA8B005BBAF3 /* Debug */ = { 441 | isa = XCBuildConfiguration; 442 | buildSettings = { 443 | BUNDLE_LOADER = "$(TEST_HOST)"; 444 | CODE_SIGN_STYLE = Automatic; 445 | CURRENT_PROJECT_VERSION = 1; 446 | DEVELOPMENT_TEAM = F6425Y8M3J; 447 | GENERATE_INFOPLIST_FILE = YES; 448 | MARKETING_VERSION = 1.0; 449 | PRODUCT_BUNDLE_IDENTIFIER = glanceables.glanceablesTests; 450 | PRODUCT_NAME = "$(TARGET_NAME)"; 451 | SWIFT_EMIT_LOC_STRINGS = NO; 452 | SWIFT_VERSION = 5.0; 453 | TARGETED_DEVICE_FAMILY = "1,2"; 454 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/glanceables.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/glanceables"; 455 | }; 456 | name = Debug; 457 | }; 458 | 0355A0762C17DA8B005BBAF3 /* Release */ = { 459 | isa = XCBuildConfiguration; 460 | buildSettings = { 461 | BUNDLE_LOADER = "$(TEST_HOST)"; 462 | "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; 463 | CODE_SIGN_STYLE = Manual; 464 | CURRENT_PROJECT_VERSION = 1; 465 | DEVELOPMENT_TEAM = ""; 466 | "DEVELOPMENT_TEAM[sdk=macosx*]" = F6425Y8M3J; 467 | GENERATE_INFOPLIST_FILE = YES; 468 | MARKETING_VERSION = 1.0; 469 | PRODUCT_BUNDLE_IDENTIFIER = glanceables.glanceablesTests; 470 | PRODUCT_NAME = "$(TARGET_NAME)"; 471 | PROVISIONING_PROFILE_SPECIFIER = ""; 472 | "PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = ""; 473 | SWIFT_EMIT_LOC_STRINGS = NO; 474 | SWIFT_VERSION = 5.0; 475 | TARGETED_DEVICE_FAMILY = "1,2"; 476 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/glanceables.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/glanceables"; 477 | }; 478 | name = Release; 479 | }; 480 | 0378B8712C096D860005BAE5 /* Debug */ = { 481 | isa = XCBuildConfiguration; 482 | buildSettings = { 483 | ALWAYS_SEARCH_USER_PATHS = NO; 484 | ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; 485 | CLANG_ANALYZER_NONNULL = YES; 486 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 487 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; 488 | CLANG_ENABLE_MODULES = YES; 489 | CLANG_ENABLE_OBJC_ARC = YES; 490 | CLANG_ENABLE_OBJC_WEAK = YES; 491 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 492 | CLANG_WARN_BOOL_CONVERSION = YES; 493 | CLANG_WARN_COMMA = YES; 494 | CLANG_WARN_CONSTANT_CONVERSION = YES; 495 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 496 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 497 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 498 | CLANG_WARN_EMPTY_BODY = YES; 499 | CLANG_WARN_ENUM_CONVERSION = YES; 500 | CLANG_WARN_INFINITE_RECURSION = YES; 501 | CLANG_WARN_INT_CONVERSION = YES; 502 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 503 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 504 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 505 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 506 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 507 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 508 | CLANG_WARN_STRICT_PROTOTYPES = YES; 509 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 510 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 511 | CLANG_WARN_UNREACHABLE_CODE = YES; 512 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 513 | COPY_PHASE_STRIP = NO; 514 | DEBUG_INFORMATION_FORMAT = dwarf; 515 | ENABLE_STRICT_OBJC_MSGSEND = YES; 516 | ENABLE_TESTABILITY = YES; 517 | ENABLE_USER_SCRIPT_SANDBOXING = YES; 518 | GCC_C_LANGUAGE_STANDARD = gnu17; 519 | GCC_DYNAMIC_NO_PIC = NO; 520 | GCC_NO_COMMON_BLOCKS = YES; 521 | GCC_OPTIMIZATION_LEVEL = 0; 522 | GCC_PREPROCESSOR_DEFINITIONS = ( 523 | "DEBUG=1", 524 | "$(inherited)", 525 | ); 526 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 527 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 528 | GCC_WARN_UNDECLARED_SELECTOR = YES; 529 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 530 | GCC_WARN_UNUSED_FUNCTION = YES; 531 | GCC_WARN_UNUSED_VARIABLE = YES; 532 | IPHONEOS_DEPLOYMENT_TARGET = 17.5; 533 | LOCALIZATION_PREFERS_STRING_CATALOGS = YES; 534 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 535 | MTL_FAST_MATH = YES; 536 | ONLY_ACTIVE_ARCH = YES; 537 | SDKROOT = iphoneos; 538 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)"; 539 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 540 | }; 541 | name = Debug; 542 | }; 543 | 0378B8722C096D860005BAE5 /* Release */ = { 544 | isa = XCBuildConfiguration; 545 | buildSettings = { 546 | ALWAYS_SEARCH_USER_PATHS = NO; 547 | ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; 548 | CLANG_ANALYZER_NONNULL = YES; 549 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 550 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; 551 | CLANG_ENABLE_MODULES = YES; 552 | CLANG_ENABLE_OBJC_ARC = YES; 553 | CLANG_ENABLE_OBJC_WEAK = YES; 554 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 555 | CLANG_WARN_BOOL_CONVERSION = YES; 556 | CLANG_WARN_COMMA = YES; 557 | CLANG_WARN_CONSTANT_CONVERSION = YES; 558 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 559 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 560 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 561 | CLANG_WARN_EMPTY_BODY = YES; 562 | CLANG_WARN_ENUM_CONVERSION = YES; 563 | CLANG_WARN_INFINITE_RECURSION = YES; 564 | CLANG_WARN_INT_CONVERSION = YES; 565 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 566 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 567 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 568 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 569 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 570 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 571 | CLANG_WARN_STRICT_PROTOTYPES = YES; 572 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 573 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 574 | CLANG_WARN_UNREACHABLE_CODE = YES; 575 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 576 | COPY_PHASE_STRIP = NO; 577 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 578 | ENABLE_NS_ASSERTIONS = NO; 579 | ENABLE_STRICT_OBJC_MSGSEND = YES; 580 | ENABLE_USER_SCRIPT_SANDBOXING = YES; 581 | GCC_C_LANGUAGE_STANDARD = gnu17; 582 | GCC_NO_COMMON_BLOCKS = YES; 583 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 584 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 585 | GCC_WARN_UNDECLARED_SELECTOR = YES; 586 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 587 | GCC_WARN_UNUSED_FUNCTION = YES; 588 | GCC_WARN_UNUSED_VARIABLE = YES; 589 | IPHONEOS_DEPLOYMENT_TARGET = 17.5; 590 | LOCALIZATION_PREFERS_STRING_CATALOGS = YES; 591 | MTL_ENABLE_DEBUG_INFO = NO; 592 | MTL_FAST_MATH = YES; 593 | SDKROOT = iphoneos; 594 | SWIFT_COMPILATION_MODE = wholemodule; 595 | VALIDATE_PRODUCT = YES; 596 | }; 597 | name = Release; 598 | }; 599 | 0378B8742C096D860005BAE5 /* Debug */ = { 600 | isa = XCBuildConfiguration; 601 | buildSettings = { 602 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 603 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 604 | CODE_SIGN_ENTITLEMENTS = glanceables/glanceables.entitlements; 605 | CODE_SIGN_STYLE = Automatic; 606 | CURRENT_PROJECT_VERSION = 1; 607 | DEVELOPMENT_ASSET_PATHS = "\"glanceables/Preview Content\""; 608 | DEVELOPMENT_TEAM = F6425Y8M3J; 609 | ENABLE_PREVIEWS = YES; 610 | GENERATE_INFOPLIST_FILE = YES; 611 | INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; 612 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 613 | INFOPLIST_KEY_UILaunchScreen_Generation = YES; 614 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 615 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 616 | LD_RUNPATH_SEARCH_PATHS = ( 617 | "$(inherited)", 618 | "@executable_path/Frameworks", 619 | ); 620 | MARKETING_VERSION = 1.2; 621 | PRODUCT_BUNDLE_IDENTIFIER = glanceables.glanceables; 622 | PRODUCT_NAME = "$(TARGET_NAME)"; 623 | SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; 624 | SUPPORTS_MACCATALYST = NO; 625 | SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES; 626 | SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO; 627 | SWIFT_EMIT_LOC_STRINGS = YES; 628 | SWIFT_VERSION = 5.0; 629 | TARGETED_DEVICE_FAMILY = 2; 630 | }; 631 | name = Debug; 632 | }; 633 | 0378B8752C096D860005BAE5 /* Release */ = { 634 | isa = XCBuildConfiguration; 635 | buildSettings = { 636 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 637 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 638 | CODE_SIGN_ENTITLEMENTS = glanceables/glanceables.entitlements; 639 | CODE_SIGN_IDENTITY = "Apple Development"; 640 | CODE_SIGN_STYLE = Automatic; 641 | CURRENT_PROJECT_VERSION = 1; 642 | DEVELOPMENT_ASSET_PATHS = "\"glanceables/Preview Content\""; 643 | DEVELOPMENT_TEAM = F6425Y8M3J; 644 | ENABLE_PREVIEWS = YES; 645 | GENERATE_INFOPLIST_FILE = YES; 646 | INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; 647 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 648 | INFOPLIST_KEY_UILaunchScreen_Generation = YES; 649 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 650 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 651 | LD_RUNPATH_SEARCH_PATHS = ( 652 | "$(inherited)", 653 | "@executable_path/Frameworks", 654 | ); 655 | MARKETING_VERSION = 1.2; 656 | PRODUCT_BUNDLE_IDENTIFIER = glanceables.glanceables; 657 | PRODUCT_NAME = "$(TARGET_NAME)"; 658 | PROVISIONING_PROFILE_SPECIFIER = ""; 659 | SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; 660 | SUPPORTS_MACCATALYST = NO; 661 | SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES; 662 | SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO; 663 | SWIFT_EMIT_LOC_STRINGS = YES; 664 | SWIFT_VERSION = 5.0; 665 | TARGETED_DEVICE_FAMILY = 2; 666 | }; 667 | name = Release; 668 | }; 669 | /* End XCBuildConfiguration section */ 670 | 671 | /* Begin XCConfigurationList section */ 672 | 0355A0742C17DA8B005BBAF3 /* Build configuration list for PBXNativeTarget "glanceablesTests" */ = { 673 | isa = XCConfigurationList; 674 | buildConfigurations = ( 675 | 0355A0752C17DA8B005BBAF3 /* Debug */, 676 | 0355A0762C17DA8B005BBAF3 /* Release */, 677 | ); 678 | defaultConfigurationIsVisible = 0; 679 | defaultConfigurationName = Release; 680 | }; 681 | 0378B85E2C096D850005BAE5 /* Build configuration list for PBXProject "glanceables" */ = { 682 | isa = XCConfigurationList; 683 | buildConfigurations = ( 684 | 0378B8712C096D860005BAE5 /* Debug */, 685 | 0378B8722C096D860005BAE5 /* Release */, 686 | ); 687 | defaultConfigurationIsVisible = 0; 688 | defaultConfigurationName = Release; 689 | }; 690 | 0378B8732C096D860005BAE5 /* Build configuration list for PBXNativeTarget "glanceables" */ = { 691 | isa = XCConfigurationList; 692 | buildConfigurations = ( 693 | 0378B8742C096D860005BAE5 /* Debug */, 694 | 0378B8752C096D860005BAE5 /* Release */, 695 | ); 696 | defaultConfigurationIsVisible = 0; 697 | defaultConfigurationName = Release; 698 | }; 699 | /* End XCConfigurationList section */ 700 | }; 701 | rootObject = 0378B85B2C096D850005BAE5 /* Project object */; 702 | } 703 | -------------------------------------------------------------------------------- /glanceables.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /glanceables.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /glanceables.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /glanceables.xcodeproj/project.xcworkspace/xcuserdata/devin.xcuserdatad/IDEFindNavigatorScopes.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /glanceables.xcodeproj/project.xcworkspace/xcuserdata/devin.xcuserdatad/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BuildLocationStyle 6 | UseAppPreferences 7 | CustomBuildLocationType 8 | RelativeToDerivedData 9 | DerivedDataLocationStyle 10 | Default 11 | ShowSharedSchemesAutomaticallyEnabled 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /glanceables.xcodeproj/xcshareddata/xcschemes/glanceables.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 9 | 10 | 16 | 22 | 23 | 24 | 25 | 26 | 32 | 33 | 36 | 42 | 43 | 44 | 45 | 46 | 56 | 58 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /glanceables.xcodeproj/xcuserdata/devin.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /glanceables.xcodeproj/xcuserdata/devin.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | glanceables.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /glanceables/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /glanceables/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "platform" : "ios", 6 | "size" : "1024x1024" 7 | } 8 | ], 9 | "info" : { 10 | "author" : "xcode", 11 | "version" : 1 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /glanceables/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /glanceables/ContentView.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | import UniformTypeIdentifiers 3 | 4 | struct ContentView: View { 5 | @Environment(WebClipManagerViewModel.self) private var webClipManager 6 | var body: some View { 7 | NavigationStack{ 8 | VStack { 9 | BlackMenuBarView() 10 | ScrollView { 11 | Text("Glanceables") 12 | .font(.system(.largeTitle, design: .rounded)) 13 | .fontWeight(.medium) 14 | .foregroundColor(Color.black) 15 | if webClipManager.isEmpty() { 16 | emptyStateView 17 | } else { 18 | WebClipGridView() 19 | } 20 | } 21 | .padding() 22 | .background(Color(.systemGray6).opacity(0.85)) 23 | } 24 | } 25 | } 26 | 27 | var emptyStateView: some View { 28 | VStack { 29 | Spacer() 30 | CreateButtonView() 31 | .padding() 32 | Spacer() 33 | } 34 | .frame(maxWidth: .infinity, maxHeight: .infinity) 35 | } 36 | } 37 | 38 | struct ContentView_Previews: PreviewProvider { 39 | static var previews: some View { 40 | ContentView() 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /glanceables/Model/CapturedElement.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | struct CapturedElement: Codable { 4 | let relativeTop: Double 5 | let relativeLeft: Double 6 | let selector: String 7 | } 8 | 9 | struct HTMLElement: Codable { 10 | let outerHTML: String 11 | let innerText: String 12 | 13 | } 14 | -------------------------------------------------------------------------------- /glanceables/Model/LlamaResult.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | struct LlamaResult { 4 | let innerText: String? 5 | let conciseText: String? 6 | 7 | init(innerText: String, conciseText: String?) { 8 | self.innerText = innerText 9 | self.conciseText = conciseText 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /glanceables/Model/SchedulerModel.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import Combine 3 | 4 | class SchedulerModel { 5 | private var timer: Timer? 6 | private let interval: TimeInterval 7 | private let actions: [() -> Void] 8 | 9 | init(interval: TimeInterval = 60.0, actions: [() -> Void]) { 10 | self.interval = interval 11 | self.actions = actions 12 | } 13 | 14 | func start() { 15 | timer = Timer.scheduledTimer(withTimeInterval: interval, repeats: true) { _ in 16 | self.actions.forEach { $0() } 17 | } 18 | } 19 | 20 | func stop() { 21 | timer?.invalidate() 22 | timer = nil 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /glanceables/Model/SnapshotTimelineModel.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | struct SnapshotTimelineModel: Identifiable, Codable { 4 | let id: UUID 5 | let timestamp: Date 6 | let innerText: String 7 | let outerHTML: String? 8 | let snapshotImagePath: String 9 | let snapshotImage: UIImage? 10 | let conciseText: String? 11 | 12 | enum CodingKeys: String, CodingKey { 13 | case id, timestamp, innerText, outerHTML, snapshotImagePath, conciseText 14 | } 15 | 16 | init(id: UUID = UUID(), timestamp: Date, innerText: String, outerHTML: String? = nil, snapshotImagePath: String, conciseText: String? = nil) { 17 | self.id = id 18 | self.timestamp = timestamp 19 | self.innerText = innerText 20 | self.outerHTML = outerHTML 21 | self.snapshotImagePath = snapshotImagePath 22 | self.snapshotImage = UIImage(contentsOfFile: snapshotImagePath) // Initialize UIImage from local path 23 | self.conciseText = conciseText 24 | } 25 | 26 | init(from decoder: Decoder) throws { 27 | let container = try decoder.container(keyedBy: CodingKeys.self) 28 | id = try container.decode(UUID.self, forKey: .id) 29 | timestamp = try container.decode(Date.self, forKey: .timestamp) 30 | innerText = try container.decode(String.self, forKey: .innerText) 31 | outerHTML = try container.decodeIfPresent(String.self, forKey: .outerHTML) 32 | snapshotImagePath = try container.decode(String.self, forKey: .snapshotImagePath) 33 | snapshotImage = UIImage(contentsOfFile: snapshotImagePath) // Initialize UIImage from local path during decoding 34 | conciseText = try container.decodeIfPresent(String.self, forKey: .conciseText) 35 | } 36 | 37 | func encode(to encoder: Encoder) throws { 38 | var container = encoder.container(keyedBy: CodingKeys.self) 39 | try container.encode(id, forKey: .id) 40 | try container.encode(timestamp, forKey: .timestamp) 41 | try container.encode(innerText, forKey: .innerText) 42 | try container.encodeIfPresent(outerHTML, forKey: .outerHTML) 43 | try container.encode(snapshotImagePath, forKey: .snapshotImagePath) 44 | try container.encodeIfPresent(conciseText, forKey: .conciseText) 45 | } 46 | } 47 | 48 | 49 | struct SnapshotUpdate { 50 | let newSnapshot: String? 51 | let innerText: String? 52 | let conciseText: String? 53 | } 54 | -------------------------------------------------------------------------------- /glanceables/Model/WebClip.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | class WebClip: ObservableObject, Identifiable, Equatable { 4 | let id: UUID 5 | @Published var url: URL 6 | var clipRect: CGRect? 7 | var originalSize: CGSize? 8 | @Published var screenshotPath: String? // Observable property 9 | @Published var screenshot: UIImage? // Observable property 10 | var scrollY: Double? 11 | @Published var pageTitle: String? 12 | var capturedElements: [CapturedElement]? 13 | var htmlElements: [HTMLElement]? 14 | @Published var snapshots: [SnapshotTimelineModel] = [] 15 | // private var pendingUpdates: [SnapshotUpdate] = [] { 16 | // didSet { 17 | // print("pendingUpdates \(id) \(pendingUpdates.count)", pendingUpdates) 18 | // } 19 | // } 20 | 21 | init(id: UUID, url: URL, clipRect: CGRect? = nil, originalSize: CGSize? = nil, screenshotPath: String? = nil, screenshot: UIImage? = nil, scrollY: Double? = nil, pageTitle: String? = nil, capturedElements: [CapturedElement]? = nil, htmlElements: [HTMLElement]? = nil, snapshots: [SnapshotTimelineModel]? = nil) { 22 | self.id = id 23 | self.url = url 24 | self.clipRect = clipRect 25 | self.originalSize = originalSize 26 | self._screenshotPath = Published(initialValue: screenshotPath) 27 | self._screenshot = Published(initialValue: screenshot) 28 | self.scrollY = scrollY 29 | self.pageTitle = pageTitle 30 | self.capturedElements = capturedElements 31 | self.htmlElements = htmlElements 32 | self.snapshots = snapshots ?? [] 33 | } 34 | 35 | static func ==(lhs: WebClip, rhs: WebClip) -> Bool { 36 | return lhs.id == rhs.id && lhs.url == rhs.url 37 | } 38 | 39 | func addSnapshotIfNeeded(screenshotPath: String, innerText: String, conciseText: String? = nil) { 40 | if snapshots.isEmpty { 41 | appendSnapshot(screenshotPath: screenshotPath, innerText: innerText, conciseText: conciseText) 42 | return 43 | } 44 | 45 | // Add snapshot if innerText is changed 46 | if let lastSnapshot = snapshots.last, lastSnapshot.innerText != innerText { 47 | appendSnapshot(screenshotPath: screenshotPath, innerText: innerText, conciseText: conciseText) 48 | } 49 | } 50 | 51 | private func appendSnapshot(screenshotPath: String, innerText: String, conciseText: String?) { 52 | let newSnapshotModel = SnapshotTimelineModel(timestamp: Date(), innerText: innerText, snapshotImagePath: screenshotPath, conciseText: conciseText) 53 | snapshots.append(newSnapshotModel) 54 | 55 | persistSnapshots() 56 | 57 | // Check if the appended snapshot is not the first one and then send a notification 58 | if snapshots.count > 1, let title = pageTitle { 59 | NotificationManager.sendNotification(title: title, body: innerText) 60 | } 61 | } 62 | 63 | func reset() { 64 | // Reset URL and path-related properties 65 | url = URL(string: "about:blank")! // Assigning a default blank URL 66 | clipRect = nil 67 | originalSize = nil 68 | screenshotPath = nil 69 | screenshot = nil 70 | scrollY = nil 71 | pageTitle = nil 72 | 73 | // Clear collections 74 | capturedElements = [] 75 | htmlElements = [] 76 | snapshots = [] 77 | } 78 | } 79 | 80 | 81 | extension WebClip { 82 | func persistSnapshots() { 83 | WebClipUserDefaultsRepository.updateWebClip(self) 84 | } 85 | } 86 | 87 | struct PendingWebClip { 88 | var id: UUID = UUID() 89 | var url: URL? // Changed to optional 90 | var clipRect: CGRect? 91 | var originalSize: CGSize? 92 | var screenshotPath: String? 93 | var scrollY: Double? 94 | var pageTitle: String? 95 | var capturedElements: [CapturedElement]? // Assumed to be defined elsewhere 96 | var htmlElements: [HTMLElement]? // Assumed to be defined elsewhere 97 | } 98 | 99 | 100 | extension WebClip: Hashable { 101 | func hash(into hasher: inout Hasher) { 102 | hasher.combine(id) 103 | hasher.combine(url) 104 | } 105 | 106 | func toPendingWebClip() -> PendingWebClip { 107 | var pendingClip = PendingWebClip() 108 | pendingClip.id = self.id // Retain the same UUID for continuity 109 | pendingClip.url = self.url 110 | pendingClip.clipRect = self.clipRect 111 | pendingClip.originalSize = self.originalSize 112 | pendingClip.screenshotPath = self.screenshotPath 113 | pendingClip.scrollY = self.scrollY 114 | pendingClip.pageTitle = self.pageTitle 115 | pendingClip.capturedElements = self.capturedElements 116 | pendingClip.htmlElements = self.htmlElements 117 | 118 | return pendingClip 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /glanceables/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /glanceables/Repository/WebClipRepositoryProtocol.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | protocol WebClipRepositoryProtocol { 4 | static func loadWebClips() -> [WebClip] 5 | static func saveWebClips(_ webClips: [WebClip]) 6 | static func deleteWebClip(_ webClip: WebClip) 7 | static func deleteWebClipById(_ id: UUID) 8 | } 9 | -------------------------------------------------------------------------------- /glanceables/Repository/WebClipUserDefaultsRepository.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import UIKit // Needed for CGSize and CGRect 3 | 4 | class WebClipUserDefaultsRepository: WebClipRepositoryProtocol { 5 | private static let userDefaults = UserDefaults.standard 6 | private static let webClipKey = "savedURLs" 7 | 8 | // Load all WebClips from UserDefaults. 9 | static func loadWebClips() -> [WebClip] { 10 | let itemsData = UserDefaults.standard.array(forKey: webClipKey) as? [[String: Any]] ?? [] 11 | return itemsData.compactMap { decodeWebViewItem(dict: $0) } 12 | } 13 | 14 | // Save an array of WebClips to UserDefaults. 15 | static func saveWebClips(_ webClips: [WebClip]) { 16 | let itemsData = webClips.map { encodeWebViewItem($0) } 17 | UserDefaults.standard.set(itemsData, forKey: webClipKey) 18 | } 19 | 20 | // Delete a specific WebClip from UserDefaults. 21 | static func deleteWebClip(_ webClip: WebClip) { 22 | var webClips = loadWebClips() 23 | print("before delete ", webClips.count) 24 | if let index = webClips.firstIndex(where: { $0.id == webClip.id }) { 25 | webClips.remove(at: index) 26 | print("after delete ", webClips.count) 27 | saveWebClips(webClips) 28 | } 29 | } 30 | 31 | // Delete a specific WebClip from UserDefaults. 32 | static func deleteWebClipById(_ id: UUID) { 33 | print("Deleting item with ID: \(id)") 34 | var webClips = loadWebClips() 35 | if let index = webClips.firstIndex(where: { $0.id == id }) { 36 | let webClip = webClips[index] 37 | webClip.reset() 38 | webClips.remove(at: index) 39 | } 40 | print("Remaining clips: \(webClips.count)") 41 | saveWebClips(webClips) 42 | } 43 | 44 | // Update a specific WebClip in UserDefaults. 45 | static func updateWebClip(_ webClip: WebClip) { 46 | var webClips = loadWebClips() 47 | if let index = webClips.firstIndex(where: { $0.id == webClip.id }) { 48 | webClips[index] = webClip 49 | saveWebClips(webClips) 50 | } 51 | } 52 | 53 | static private func encodeWebViewItem(_ item: WebClip) -> [String: Any] { 54 | var dict = [String: Any]() 55 | dict["id"] = item.id.uuidString 56 | dict["url"] = item.url.absoluteString 57 | dict["pageTitle"] = item.pageTitle ?? "" 58 | dict["screenshotPath"] = item.screenshotPath ?? "" 59 | dict["scrollY"] = item.scrollY ?? 0 60 | 61 | // Encode screenshot as Base64 string 62 | if let screenshot = item.screenshot, let imageData = screenshot.pngData() { 63 | dict["screenshot"] = imageData.base64EncodedString() 64 | } 65 | 66 | // Encode CGRect and CGSize 67 | if let clipRect = item.clipRect { 68 | dict["clipRect"] = [ 69 | "x": clipRect.origin.x, 70 | "y": clipRect.origin.y, 71 | "width": clipRect.width, 72 | "height": clipRect.height 73 | ] 74 | } 75 | 76 | if let originalSize = item.originalSize { 77 | dict["originalSize"] = [ 78 | "width": originalSize.width, 79 | "height": originalSize.height 80 | ] 81 | } 82 | 83 | // Encode CapturedElement and HTMLElement using JSON serialization 84 | if let capturedElements = item.capturedElements { 85 | dict["capturedElements"] = try? JSONEncoder().encode(capturedElements).base64EncodedString() 86 | } 87 | 88 | if let htmlElements = item.htmlElements { 89 | dict["htmlElements"] = try? JSONEncoder().encode(htmlElements).base64EncodedString() 90 | } 91 | 92 | // Encode Snapshots 93 | dict["snapshots"] = try? JSONEncoder().encode(item.snapshots).base64EncodedString() 94 | 95 | return dict 96 | } 97 | 98 | static private func decodeWebViewItem(dict: [String: Any]) -> WebClip? { 99 | guard let idString = dict["id"] as? String, 100 | let id = UUID(uuidString: idString), 101 | let urlString = dict["url"] as? String, 102 | let url = URL(string: urlString) else { 103 | return nil 104 | } 105 | 106 | let pageTitle = dict["pageTitle"] as? String 107 | let screenshotPath = dict["screenshotPath"] as? String 108 | let scrollY = dict["scrollY"] as? Double 109 | let clipRect = decodeRect(dict: dict["clipRect"] as? [String: Any]) 110 | let originalSize = decodeSize(dict: dict["originalSize"] as? [String: Any]) 111 | 112 | var screenshot: UIImage? 113 | if let screenshotString = dict["screenshot"] as? String, let imageData = Data(base64Encoded: screenshotString) { 114 | screenshot = UIImage(data: imageData) 115 | } 116 | 117 | var capturedElements: [CapturedElement]? 118 | if let elementsString = dict["capturedElements"] as? String, let elementsData = Data(base64Encoded: elementsString) { 119 | capturedElements = try? JSONDecoder().decode([CapturedElement].self, from: elementsData) 120 | } 121 | 122 | var htmlElements: [HTMLElement]? 123 | if let elementsString = dict["htmlElements"] as? String, let elementsData = Data(base64Encoded: elementsString) { 124 | htmlElements = try? JSONDecoder().decode([HTMLElement].self, from: elementsData) 125 | } 126 | 127 | var snapshots: [SnapshotTimelineModel]? 128 | if let snapshotsString = dict["snapshots"] as? String, let snapshotsData = Data(base64Encoded: snapshotsString) { 129 | snapshots = try? JSONDecoder().decode([SnapshotTimelineModel].self, from: snapshotsData) 130 | } 131 | return WebClip(id: id, url: url, clipRect: clipRect, originalSize: originalSize, screenshotPath: screenshotPath, screenshot: screenshot, scrollY: scrollY, pageTitle: pageTitle, capturedElements: capturedElements, htmlElements: htmlElements, snapshots: snapshots) 132 | } 133 | 134 | static private func decodeRect(dict: [String: Any]?) -> CGRect? { 135 | guard let dict = dict, 136 | let x = dict["x"] as? CGFloat, 137 | let y = dict["y"] as? CGFloat, 138 | let width = dict["width"] as? CGFloat, 139 | let height = dict["height"] as? CGFloat else { 140 | return nil 141 | } 142 | return CGRect(x: x, y: y, width: width, height: height) 143 | } 144 | 145 | static private func decodeSize(dict: [String: Any]?) -> CGSize? { 146 | guard let dict = dict, 147 | let width = dict["width"] as? CGFloat, 148 | let height = dict["height"] as? CGFloat else { 149 | return nil 150 | } 151 | return CGSize(width: width, height: height) 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /glanceables/Response.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | // Struct to decode the JSON response 4 | struct Response: Codable { 5 | let model: String 6 | let response: String 7 | } 8 | -------------------------------------------------------------------------------- /glanceables/Tests/URLModalViewTests.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | 3 | // Create a testable instance of the view model to manage the view logic 4 | class URLModalViewTests: XCTestCase { 5 | 6 | // Setup your test environment variables 7 | var showingURLModal: Bool = false 8 | var urlString: String = "" 9 | var isURLValid: Bool = false 10 | var urls: [WebViewItem] = [] 11 | var selectedURLIndex: Int? = nil 12 | var isEditing: Bool = false 13 | var validURL: URL? = nil 14 | 15 | override func setUp() { 16 | super.setUp() 17 | // Reset the environment before each test 18 | showingURLModal = false 19 | urlString = "" 20 | isURLValid = false 21 | urls = [] 22 | selectedURLIndex = nil 23 | isEditing = false 24 | validURL = nil 25 | } 26 | 27 | func testValidURL() { 28 | urlString = "https://www.example.com" 29 | validateURL() 30 | XCTAssertTrue(isURLValid) 31 | XCTAssertNotNil(validURL) 32 | } 33 | 34 | func testInvalidURL() { 35 | urlString = "htt:/example" 36 | validateURL() 37 | XCTAssertFalse(isURLValid) 38 | XCTAssertNil(validURL) 39 | } 40 | 41 | func testHandleSaveURL_ValidData() { 42 | urlString = "https://www.example.com" 43 | validateURL() 44 | handleSaveURL() 45 | XCTAssertFalse(showingURLModal) // Modal should be closed 46 | XCTAssertEqual(urls.count, 1) // New URL should be added 47 | } 48 | 49 | func testResetModalState() { 50 | resetModalState() 51 | XCTAssertFalse(showingURLModal) 52 | XCTAssertTrue(urlString.isEmpty) 53 | XCTAssertTrue(isURLValid) 54 | XCTAssertNil(selectedURLIndex) 55 | XCTAssertNil(validURL) 56 | } 57 | 58 | // Implementation of actual methods under test 59 | private func validateURL() { 60 | if !urlString.hasPrefix("http://") && !urlString.hasPrefix("https://") { 61 | urlString = "https://" + urlString 62 | } 63 | if let url = URL(string: urlString), canOpenURL(urlString) && isValidURLFormat(urlString) { 64 | isURLValid = true 65 | validURL = url 66 | } else { 67 | isURLValid = false 68 | validURL = nil 69 | } 70 | } 71 | 72 | private func canOpenURL(_ string: String?) -> Bool { 73 | guard let urlString = string, let url = URL(string: urlString) else { 74 | return false 75 | } 76 | return UIApplication.shared.canOpenURL(url) 77 | } 78 | 79 | private func isValidURLFormat(_ string: String) -> Bool { 80 | let regex = "^(https?://)?([\\w\\d-]+\\.)+[\\w\\d-]+/?([\\w\\d-._\\?,'+/&%$#=~]*)*[^.]$" 81 | return NSPredicate(format: "SELF MATCHES %@", regex).evaluate(with: string) 82 | } 83 | 84 | private func handleSaveURL() { 85 | if isURLValid && !urlString.isEmpty { 86 | let newUrlItem = WebViewItem(id: UUID(), url: URL(string: urlString)!, clipRect: nil) 87 | if isEditing, let index = selectedURLIndex { 88 | urls[index] = newUrlItem 89 | } else { 90 | urls.append(newUrlItem) 91 | } 92 | resetModalState() // Reset modal only on successful save 93 | } 94 | } 95 | 96 | private func resetModalState() { 97 | showingURLModal = false 98 | urlString = "" 99 | isEditing = false 100 | selectedURLIndex = nil 101 | isURLValid = true // Reset to true so the error message won't persist across different uses of the modal 102 | validURL = nil 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /glanceables/UrlModalView.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | var urlModal: some View { 4 | NavigationView { 5 | Form { 6 | Section(header: Text(isEditing ? "Edit URL" : "Add a new URL")) { 7 | TextField("Enter URL here", text: $urlString) 8 | } 9 | Section { 10 | Button("Save") { 11 | if !urlString.isEmpty { 12 | if isEditing, let index = selectedURLIndex { 13 | urls[index] = urlString 14 | } else { 15 | urls.append(urlString) 16 | } 17 | resetModalState() 18 | } 19 | } 20 | } 21 | } 22 | .navigationBarTitle(isEditing ? "Edit URL" : "New URL", displayMode: .inline) 23 | .navigationBarItems(trailing: Button("Cancel") { 24 | resetModalState() 25 | }) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /glanceables/Utilities/ImageLoader.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | class ImageLoader: ObservableObject { 4 | @Published var image: UIImage? 5 | private let imagePath: String 6 | 7 | init(imagePath: String) { 8 | self.imagePath = imagePath 9 | } 10 | 11 | func load() { 12 | let imagePath = imagePath 13 | DispatchQueue.global(qos: .background).async { [weak self] in 14 | guard let self = self else { return } 15 | if let data = FileManager.default.contents(atPath: imagePath), 16 | let image = UIImage(data: data) { 17 | DispatchQueue.main.async { 18 | self.image = image 19 | } 20 | } else { 21 | print("Failed to load image from path: \(imagePath)") 22 | } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /glanceables/Utilities/JavascriptLoader.swift: -------------------------------------------------------------------------------- 1 | import WebKit 2 | 3 | struct JavaScriptLoader { 4 | static func loadJavaScript(userContentController: WKUserContentController, resourceName: String, extensionType: String) { 5 | guard let scriptURL = Bundle.main.url(forResource: resourceName, withExtension: extensionType), 6 | let scriptContent = try? String(contentsOf: scriptURL) else { 7 | print("Failed to load JavaScript file: \(resourceName).\(extensionType)") 8 | return 9 | } 10 | 11 | let userScript = WKUserScript(source: scriptContent, injectionTime: .atDocumentStart, forMainFrameOnly: false) 12 | userContentController.addUserScript(userScript) 13 | } 14 | 15 | static func injectGetElementsFromSelectorsScript(userContentController: WKUserContentController, elementSelector: String) { 16 | let jsCode = """ 17 | (function() { 18 | function restoreElement() { 19 | try { 20 | const elementSelector = "\(elementSelector)"; 21 | const element = document.querySelector(elementSelector); 22 | const selectors = 23 | [{selector: elementSelector, innerText: element.innerText, outerHTML: element.outerHTML}] 24 | window.webkit.messageHandlers.elementsFromSelectorsHandler.postMessage(JSON.stringify(selectors)); 25 | } catch (error) { 26 | console.error('Error in script:', error); 27 | window.webkit.messageHandlers.elementsFromSelectorsHandler.postMessage('Error: ' + error.message); 28 | } 29 | } 30 | 31 | function watchForElement() { 32 | const elementSelector = "\(elementSelector)"; 33 | const observer = new MutationObserver((mutationsList, observer) => { 34 | const element = document.querySelector(elementSelector); 35 | if (element) { 36 | restoreElement(); 37 | observer.disconnect(); // Stop observing once elements are found 38 | } 39 | }); 40 | 41 | observer.observe(document.body, { childList: true, subtree: true }); 42 | 43 | // Check if the elements are already present 44 | const element = document.querySelector(elementSelector); 45 | if (element) { 46 | restoreElement(); 47 | observer.disconnect(); 48 | } 49 | } 50 | 51 | watchForElement(); 52 | })(); 53 | """ 54 | 55 | userContentController.addUserScript(WKUserScript(source: jsCode, injectionTime: .atDocumentEnd, forMainFrameOnly: false)) 56 | } 57 | 58 | static func injectIsolateElementFromSelectorScript(webView: WKWebView, elementSelector: String) { 59 | let jsCode = """ 60 | (function() { 61 | function watchForElement() { 62 | const elementSelector = "\(elementSelector)"; 63 | const observer = new MutationObserver((mutationsList, observer) => { 64 | const element = document.querySelector(elementSelector); 65 | if (element) { 66 | isolateElement("\(elementSelector)"); 67 | observer.disconnect(); // Stop observing once elements are found 68 | } 69 | }); 70 | 71 | observer.observe(document.body, { childList: true, subtree: true }); 72 | 73 | // Check if the elements are already present 74 | const element = document.querySelector(elementSelector); 75 | if (element) { 76 | isolateElement("\(elementSelector)"); 77 | observer.disconnect(); 78 | } 79 | } 80 | 81 | watchForElement(); 82 | })(); 83 | """ 84 | 85 | webView.configuration.userContentController.addUserScript(WKUserScript(source: jsCode, injectionTime: .atDocumentEnd, forMainFrameOnly: false)) 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /glanceables/Utilities/LeakAvoider.swift: -------------------------------------------------------------------------------- 1 | import WebKit 2 | 3 | // stackoverflow.com/a/26383032 4 | class LeakAvoider : NSObject, WKScriptMessageHandler { 5 | weak var delegate : WKScriptMessageHandler? 6 | init(delegate:WKScriptMessageHandler) { 7 | self.delegate = delegate 8 | super.init() 9 | } 10 | func userContentController(_ userContentController: WKUserContentController, 11 | didReceive message: WKScriptMessage) { 12 | self.delegate?.userContentController( 13 | userContentController, didReceive: message) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /glanceables/Utilities/LlamaAPIManager.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | // Class for managing interaction with the Llama API 4 | @Observable class LlamaAPIManager { 5 | 6 | var isSending: Bool = false 7 | var response: String? = nil 8 | var conciseText: String? = nil 9 | 10 | // Modular function to perform the API request 11 | private func performRequest(prompt: String, innerText: String, completion: @escaping (Result) -> Void) { 12 | guard !isSending else { 13 | completion(.failure(NSError(domain: "LlamaAPIManager", code: 2, userInfo: [NSLocalizedDescriptionKey: "Request is already in progress."]))) 14 | return 15 | } 16 | 17 | isSending = true 18 | 19 | let urlString = "http://127.0.0.1:11434/api/generate" 20 | guard let url = URL(string: urlString) else { 21 | isSending = false 22 | completion(.failure(NSError(domain: "LlamaAPIManager", code: 3, userInfo: [NSLocalizedDescriptionKey: "Invalid URL."]))) 23 | return 24 | } 25 | 26 | var request = URLRequest(url: url) 27 | request.httpMethod = "POST" 28 | request.addValue("application/json", forHTTPHeaderField: "Content-Type") 29 | 30 | let body: [String: Any] = [ 31 | "model": "llama3", 32 | "prompt": prompt, 33 | "options": ["num_ctx": 200], 34 | "format": "json", 35 | "stream": false, 36 | ] 37 | 38 | do { 39 | request.httpBody = try JSONSerialization.data(withJSONObject: body) 40 | } catch { 41 | isSending = false 42 | completion(.failure(error)) 43 | return 44 | } 45 | 46 | URLSession.shared.dataTask(with: request) { data, response, error in 47 | defer { DispatchQueue.main.async { self.isSending = false } } 48 | 49 | if let error = error { 50 | DispatchQueue.main.async { self.response = "Error: \(error.localizedDescription)" } 51 | return 52 | } 53 | 54 | guard let data = data else { 55 | DispatchQueue.main.async { self.response = "No data received" } 56 | return 57 | } 58 | 59 | let decoder = JSONDecoder() 60 | let lines = data.split(separator: 10) 61 | var responses = [String]() 62 | 63 | for line in lines { 64 | if let jsonLine = try? decoder.decode(Response.self, from: Data(line)) { 65 | responses.append(jsonLine.response) 66 | } 67 | } 68 | 69 | DispatchQueue.main.async { 70 | self.response = responses.joined(separator: "") 71 | if let responseString = self.response, 72 | let data = responseString.data(using: .utf8), 73 | let jsonObject = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any], 74 | let conciseText = jsonObject["concise_text"] as? String { 75 | self.conciseText = conciseText 76 | completion(.success(LlamaResult(innerText: innerText, conciseText: conciseText))) 77 | } else { 78 | completion(.failure(NSError(domain: "LlamaAPIManager", code: 5, userInfo: [NSLocalizedDescriptionKey: "Failed to parse JSON data or 'concise_text' key missing."]))) 79 | } 80 | } 81 | }.resume() 82 | } 83 | 84 | func analyzeInnerText(innerText: String, completion: @escaping (Result) -> Void) { 85 | guard !innerText.isEmpty else { 86 | completion(.failure(NSError(domain: "LlamaAPIManager", code: 6, userInfo: [NSLocalizedDescriptionKey: "Empty innerText."]))) 87 | return 88 | } 89 | 90 | 91 | 92 | let innerTextPrompt = """ 93 | Instructions: 94 | - Extract key information such as headlines, prices, and times. 95 | - Simplify the text to produce readable content for humans. 96 | 97 | Input Text: 98 | \(innerText) 99 | 100 | Expected Output JSON Format: 101 | { 102 | "concise_text": "" 103 | } 104 | 105 | Objective: 106 | Transform and extract essential data from the provided text. 107 | """ 108 | 109 | 110 | performRequest(prompt: innerTextPrompt, innerText: innerText, completion: completion) 111 | } 112 | // func analyzeHTML(htmlElements: [HTMLElement], completion: @escaping (Result) -> Void) { 113 | // print("Started analyzing HTML elements") 114 | // guard !htmlElements.isEmpty else { 115 | // completion(.failure(NSError(domain: "LlamaAPIManager", code: 1, userInfo: [NSLocalizedDescriptionKey: "No HTML elements to analyze."]))) 116 | // return 117 | // } 118 | // 119 | // let htmlAnalysisPrompt = """ 120 | // HTML Input: 121 | // \( 122 | // htmlElements.map { "
\($0.outerHTML)
" }.joined(separator: "\n") 123 | // ) 124 | // 125 | // Output JSON: 126 | // { 127 | // "concise_text": Analyze HTML to produce readable text for humans. 128 | // } 129 | // """ 130 | // 131 | // performRequest(prompt: htmlAnalysisPrompt, innerText: , completion: completion) 132 | // } 133 | } 134 | -------------------------------------------------------------------------------- /glanceables/Utilities/NotificationManager.swift: -------------------------------------------------------------------------------- 1 | import UserNotifications 2 | 3 | class NotificationManager { 4 | static func requestAuthorization() { 5 | UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { granted, error in 6 | if granted { 7 | print("Notification permission granted.") 8 | } else if let error = error { 9 | print("Notification permission denied with error: \(error.localizedDescription)") 10 | } 11 | } 12 | } 13 | 14 | static func sendNotification(title: String, body: String) { 15 | let content = UNMutableNotificationContent() 16 | content.title = title 17 | content.body = body 18 | content.sound = .default 19 | 20 | let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: nil) 21 | UNUserNotificationCenter.current().add(request) { error in 22 | if let error = error { 23 | print("Error scheduling notification: \(error)") 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /glanceables/Utilities/ScreenshotUtils.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | struct ScreenshotUtils { 4 | static func saveScreenshotToLocalDirectory(screenshot: UIImage) -> String? { 5 | guard let data = screenshot.jpegData(compressionQuality: 1.0) else { return nil } 6 | let filename = UUID().uuidString + ".jpg" 7 | let url = getDocumentsDirectory().appendingPathComponent(filename) 8 | 9 | do { 10 | try data.write(to: url) 11 | return url.path 12 | } catch { 13 | print("Error saving screenshot: \(error)") 14 | return nil 15 | } 16 | } 17 | 18 | static func saveScreenshotToFile(screenshotPath: String, from screenshot: UIImage) -> String? { 19 | guard let data = screenshot.jpegData(compressionQuality: 1.0) else { return nil } 20 | let url = URL(fileURLWithPath: screenshotPath) 21 | 22 | do { 23 | try data.write(to: url) 24 | return url.path 25 | } catch { 26 | print("Error refreshing screenshot: \(error)") 27 | return nil 28 | } 29 | } 30 | 31 | static func getDocumentsDirectory() -> URL { 32 | return FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0] 33 | } 34 | 35 | static func loadImage(from path: String?) -> UIImage? { 36 | guard let path = path else { return nil } 37 | let url = URL(fileURLWithPath: path) 38 | guard let data = try? Data(contentsOf: url) else { return nil } 39 | return UIImage(data: data) 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /glanceables/Utilities/URLUtilities.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import UIKit 3 | 4 | struct URLUtilities { 5 | static func validateURL(from urlString: String) -> (isValid: Bool, url: URL?) { 6 | if !urlString.hasPrefix("http://") && !urlString.hasPrefix("https://") { 7 | let modifiedURLString = "https://" + urlString 8 | return checkURL(modifiedURLString) 9 | } 10 | return checkURL(urlString) 11 | } 12 | 13 | private static func checkURL(_ urlString: String) -> (isValid: Bool, url: URL?) { 14 | if let url = URL(string: urlString), canOpenURL(url) && isValidURLFormat(urlString) { 15 | return (true, url) 16 | } else { 17 | return (false, nil) 18 | } 19 | } 20 | 21 | static func canOpenURL(_ url: URL) -> Bool { 22 | return UIApplication.shared.canOpenURL(url) 23 | } 24 | 25 | static func isValidURLFormat(_ urlString: String) -> Bool { 26 | let regex = "^(https?://)?([\\w\\d-]+\\.)+[\\w\\d-]+/?([\\w\\d-._\\?,'+/&%$#=~]*)*[^.]$" 27 | return NSPredicate(format: "SELF MATCHES %@", regex).evaluate(with: urlString) 28 | } 29 | 30 | static func simplifyPageTitle(_ title: String) -> String { 31 | // Define allowed characters as alphanumerics and whitespaces 32 | let allowedCharacters = CharacterSet.alphanumerics.union(CharacterSet.whitespaces) 33 | 34 | // Find the range of the first character that is not allowed 35 | if let range = title.rangeOfCharacter(from: allowedCharacters.inverted) { 36 | let firstPart = title[.. String? { 46 | let components = host.components(separatedBy: ".") 47 | guard components.count >= 2 else { return nil } 48 | return components.suffix(2).joined(separator: ".") 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /glanceables/Utilities/UserDefaults.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import UIKit 3 | 4 | import Foundation 5 | 6 | class UserDefaultsManager { 7 | static let urlsKey = "savedURLs" 8 | 9 | static func saveWebClips(_ itemsData: [[String: Any]]) { 10 | UserDefaults.standard.set(itemsData, forKey: urlsKey) 11 | } 12 | 13 | static func loadWebClips() -> [[String: Any]] { 14 | return UserDefaults.standard.array(forKey: urlsKey) as? [[String: Any]] ?? [] 15 | } 16 | 17 | static func deleteWebClip(at index: Int) { 18 | var items = loadWebClips() 19 | items.remove(at: index) 20 | saveWebClips(items) 21 | } 22 | 23 | static func updateWebClip(_ itemData: [String: Any], at index: Int) { 24 | var items = loadWebClips() 25 | items[index] = itemData 26 | saveWebClips(items) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /glanceables/View/AddURLFormView.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | struct AddURLFormView: View { 4 | @Bindable var viewModel: WebClipCreatorViewModel 5 | 6 | var body: some View { 7 | HStack { 8 | urlTextField 9 | 10 | if viewModel.urlString != "" { 11 | Button(action: viewModel.clearTextField) { 12 | Image(systemName: "xmark.circle.fill") 13 | .foregroundColor(.gray) 14 | } 15 | .padding(.trailing, 10) 16 | } else { 17 | Image(systemName: "magnifyingglass") 18 | .foregroundColor(.gray) 19 | } 20 | if !viewModel.isURLValid && viewModel.showValidationError && !viewModel.urlString.isEmpty { 21 | Text("Invalid URL") 22 | .foregroundColor(.red) 23 | } 24 | } 25 | .multilineTextAlignment(.center) 26 | .frame(width: UIScreen.main.bounds.width * 0.7) 27 | .padding(.vertical, 5) 28 | .padding(.horizontal, 20) 29 | .background(Color(.systemGray5)) 30 | .cornerRadius(10) 31 | .overlay( 32 | RoundedRectangle(cornerRadius: 10) 33 | .stroke(Color(.systemGray3), lineWidth: 1) 34 | ) 35 | } 36 | 37 | private var urlTextField: some View { 38 | TextField("Search or enter website name", text: $viewModel.urlString) 39 | .autocapitalization(.none) 40 | .disableAutocorrection(true) 41 | .textInputAutocapitalization(.never) 42 | .multilineTextAlignment(.center) 43 | } 44 | } 45 | 46 | struct AddURLFormView_Previews: PreviewProvider { 47 | static var previews: some View { 48 | VStack { 49 | AddURLFormView(viewModel: WebClipCreatorViewModel()) 50 | .previewLayout(.sizeThatFits) 51 | .padding() 52 | 53 | Spacer() 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /glanceables/View/BlackEditMenuBarView.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | struct BlackEditMenuBarView: View { 4 | var webClipSelector: WebClipSelectorViewModel 5 | 6 | var body: some View { 7 | HStack { 8 | Spacer() 9 | CaptureModeToggleView(viewModel: webClipSelector) 10 | .padding(.trailing, 24) 11 | 12 | } 13 | .padding() 14 | .background(Color.black) // Black background for the menu bar 15 | } 16 | } 17 | 18 | struct BlackEditMenubarView_Previews: PreviewProvider { 19 | static var previews: some View { 20 | let webClipSelector = WebClipSelectorViewModel() 21 | BlackEditMenuBarView(webClipSelector: webClipSelector) 22 | .frame(maxHeight: .infinity, alignment: .top) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /glanceables/View/BlackMenuBarView.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | struct BlackMenuBarView: View { 4 | var body: some View { 5 | HStack { 6 | Spacer() 7 | NavigationLink(destination: WebClipCreatorView()) { 8 | Image(systemName: "plus") 9 | .font(.system(size: 40)) 10 | .foregroundColor(.white) 11 | } 12 | } 13 | .padding() 14 | .background(Color.black) // Black background for the menu bar 15 | } 16 | } 17 | 18 | struct SearchBar: View { 19 | @Binding var text: String 20 | 21 | var body: some View { 22 | HStack { 23 | Image(systemName: "magnifyingglass") 24 | .foregroundColor(.gray) 25 | 26 | TextField("Search", text: $text) 27 | .foregroundColor(.white) 28 | .textFieldStyle(PlainTextFieldStyle()) 29 | } 30 | .padding(EdgeInsets(top: 8, leading: 6, bottom: 8, trailing: 6)) 31 | .background(Color.white.opacity(0.2)) 32 | .cornerRadius(10) 33 | } 34 | } 35 | 36 | struct ParentView: View { 37 | var body: some View { 38 | BlackMenuBarView() 39 | .frame(maxHeight: .infinity, alignment: .top) 40 | } 41 | } 42 | 43 | struct ParentView_Previews: PreviewProvider { 44 | static var previews: some View { 45 | ParentView() 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /glanceables/View/CaptureModeToggleView.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | struct CaptureModeToggleView: View { 4 | @Bindable var viewModel: WebClipSelectorViewModel 5 | 6 | 7 | var body: some View { 8 | HStack(spacing: 10) { // Reduced spacing between elements 9 | VStack { // Use VStack for vertical stacking of text 10 | Text("CAPTURE") 11 | .font(.system(size: 12, weight: .semibold)) 12 | .foregroundColor(.white) 13 | Text("MODE") 14 | .font(.system(size: 12, weight: .semibold)) 15 | .foregroundColor(.white) 16 | } 17 | 18 | Toggle("", isOn: $viewModel.captureModeOn) 19 | .toggleStyle(SwitchToggleStyle(tint: .blue)) 20 | .frame(width: 51, height: 31) // Specific sizing for the toggle 21 | } 22 | .padding(.horizontal, 10) // Horizontal padding 23 | .padding(.vertical, 5) // Vertical padding 24 | .cornerRadius(10) // Optional: Rounded corners for the background 25 | } 26 | } 27 | 28 | // SwiftUI Preview 29 | struct CaptureModeToggleView_Previews: PreviewProvider { 30 | static var previews: some View { 31 | let webClipSelector = WebClipSelectorViewModel() 32 | CaptureModeToggleView(viewModel: webClipSelector) 33 | .previewLayout(.sizeThatFits) // Uses minimal size that fits the content 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /glanceables/View/CaptureRectangleView.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | struct CaptureRectangleView: View { 4 | @Environment(WebClipManagerViewModel.self) private var webClipManager 5 | var dismiss: DismissAction? 6 | var captureMenuViewModel: WebClipSelectorViewModel 7 | var pendingClip: WebClipCreatorViewModel 8 | 9 | var body: some View { 10 | ZStack { 11 | if captureMenuViewModel.dragEnded { 12 | // Gray overlay 13 | GeometryReader { geometry in 14 | if captureMenuViewModel.captureModeOn { 15 | Path { path in 16 | // Full screen rectangle 17 | path.addRect(CGRect(origin: .zero, size: geometry.size)) 18 | 19 | // Subtract the clip rectangle if it exists 20 | if let clipRect = pendingClip.currentClipRect { 21 | path.addRect(clipRect) 22 | } 23 | } 24 | .fill(Color.gray.opacity(0.5), style: FillStyle(eoFill: true)) 25 | .edgesIgnoringSafeArea(.all) 26 | } 27 | } 28 | } 29 | if captureMenuViewModel.captureModeOn { 30 | captureModeContent 31 | } 32 | } 33 | } 34 | 35 | 36 | @ViewBuilder 37 | private var captureModeContent: some View { 38 | if let clipRect = pendingClip.currentClipRect { 39 | Rectangle() 40 | .stroke(style: StrokeStyle(lineWidth: 2, lineCap: .round, lineJoin: .round, dash: [10, 5])) 41 | .frame(width: clipRect.width, height: clipRect.height) 42 | .overlay(saveButtonOverlay, alignment: .topTrailing) 43 | .position(x: clipRect.midX, y: clipRect.midY) 44 | } 45 | } 46 | 47 | @ViewBuilder 48 | private var saveButtonOverlay: some View { 49 | if captureMenuViewModel.dragEnded { 50 | SaveButtonView { 51 | if let dismiss { 52 | dismiss() 53 | } 54 | // Check if a web clip is selected and if it's in editing mode 55 | if let webClip = webClipManager.selectedWebClip(), webClipManager.isEditing { 56 | // Call updateWebClip function with correct parameters 57 | webClipManager.updateWebClip(withId: webClip.id, 58 | newURL: pendingClip.validURL, 59 | newClipRect: pendingClip.currentClipRect, 60 | newScreenshotPath: pendingClip.screenShot.flatMap(ScreenshotUtils.saveScreenshotToLocalDirectory), 61 | newPageTitle: pendingClip.pageTitle, 62 | newCapturedElements: captureMenuViewModel.capturedElements) 63 | } else { 64 | // Add a new web clip if no web clip is selected or not in editing mode 65 | webClipManager.createWebClip(newClip: pendingClip.getNewClip()) 66 | } 67 | 68 | 69 | 70 | } 71 | .offset(x: -10, y: -65) 72 | .onAppear { 73 | pendingClip.finalizeClip() 74 | print("save button overlay appear") 75 | } 76 | } else { 77 | EmptyView() 78 | } 79 | } 80 | } 81 | 82 | 83 | 84 | struct CaptureRectangleView_Previews: PreviewProvider { 85 | @Environment(\.dismiss) private var dismiss 86 | static var previews: some View { 87 | let creatorModel = WebClipCreatorViewModel() 88 | 89 | GeometryReader { geometry in 90 | let captureMenuViewModel = WebClipSelectorViewModel() 91 | let screenWidth = geometry.size.width 92 | let screenHeight = geometry.size.height 93 | 94 | CaptureRectangleView( 95 | dismiss:nil, captureMenuViewModel: captureMenuViewModel, 96 | pendingClip: creatorModel 97 | ) 98 | .frame(width: screenWidth, height: screenHeight) 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /glanceables/View/ChangeFeedbackFormView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ChangeFeedbackFormView.swift 3 | // glanceables 4 | // 5 | // Created by Devin Liu on 8/5/24. 6 | // 7 | 8 | import Foundation 9 | -------------------------------------------------------------------------------- /glanceables/View/CreateButtonView.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | struct CreateButtonView: View { 4 | 5 | var body: some View { 6 | NavigationLink(destination: WebClipCreatorView()) { 7 | VStack { 8 | ZStack { 9 | Rectangle() 10 | .frame(width: 60, height: 60) 11 | .foregroundColor(Color.white) 12 | .cornerRadius(10) 13 | 14 | Image(systemName: "plus") 15 | .resizable() 16 | .scaledToFit() 17 | .frame(width: 30, height: 24) 18 | .foregroundColor(Color.gray) 19 | } 20 | .frame(width: 144, height: 170) 21 | .background(Color.black.opacity(0.3)) 22 | .cornerRadius(24) 23 | .shadow(radius: 6) 24 | 25 | Text("Create Your First Glanceable") 26 | .font(.system(.footnote, design: .rounded)) // Use dynamic type with style 27 | .fontWeight(.medium) 28 | .foregroundColor(Color.black) 29 | } 30 | } 31 | } 32 | } 33 | 34 | struct CreateButtonView_Previews: PreviewProvider { 35 | static var previews: some View { 36 | CreateButtonView() 37 | .previewLayout(.sizeThatFits) // Adjust this to match the context you want to preview in 38 | .padding() 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /glanceables/View/GridScreenshotView.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | struct GridScreenshotView: View { 4 | @Environment(WebClipManagerViewModel.self) private var webClipManager 5 | var webClipId: UUID 6 | 7 | var body: some View { 8 | ZStack(alignment: .top) { 9 | if let screenshotPath = webClipManager.webClip(webClipId)?.screenshotPath { 10 | AsyncImageView(imagePath: screenshotPath) 11 | } 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /glanceables/View/NavigationButtonsView.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | import WebKit 3 | 4 | struct NavigationButtonsView: View { 5 | var webView: WKWebView 6 | 7 | var body: some View { 8 | HStack { 9 | Button(action: { 10 | webView.goBack() 11 | }) { 12 | Image(systemName: "chevron.left") 13 | .resizable() 14 | .aspectRatio(contentMode: .fit) 15 | .frame(width: 20, height: 20) 16 | } 17 | .buttonStyle(PlainButtonStyle()) 18 | .disabled(!webView.canGoBack) 19 | 20 | Button(action: { 21 | webView.goForward() 22 | }) { 23 | Image(systemName: "chevron.right") 24 | .resizable() 25 | .aspectRatio(contentMode: .fit) 26 | .frame(width: 20, height: 20) 27 | } 28 | .buttonStyle(PlainButtonStyle()) 29 | .disabled(!webView.canGoForward) 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /glanceables/View/RedXButton.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | struct RedXButton: View { 4 | var action: () -> Void 5 | 6 | var body: some View { 7 | Button(action: action) { 8 | ZStack { 9 | Circle() 10 | .foregroundColor(.red) 11 | .frame(width: 40, height: 40) // Adjust size as needed 12 | Text("X") 13 | .font(.system(size: 20, weight: .bold)) 14 | .foregroundColor(.white) 15 | } 16 | } 17 | .shadow(radius: 3) // Optional: adds shadow for 3D effect 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /glanceables/View/SaveButtonView.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | struct SaveButtonView: View { 4 | var action: () -> Void 5 | 6 | var body: some View { 7 | Button(action: action) { 8 | Text("SAVE") 9 | .font(.headline) 10 | .foregroundColor(.white) 11 | .padding() 12 | .frame(width: 100, height: 50) 13 | .background(Color.blue) 14 | .cornerRadius(10) 15 | } 16 | } 17 | } 18 | 19 | struct SaveButtonView_Previews: PreviewProvider { 20 | static var previews: some View { 21 | SaveButtonView { 22 | print("Save button tapped") 23 | } 24 | .previewLayout(.sizeThatFits) 25 | .padding() 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /glanceables/View/WebClipBrowserMenuView.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | import WebKit 3 | 4 | struct WebClipBrowserMenuView: View { 5 | var webClipSelector: WebClipSelectorViewModel 6 | var dismiss: DismissAction 7 | var pendingClip:WebClipCreatorViewModel 8 | 9 | 10 | var body: some View { 11 | ZStack { 12 | VStack { 13 | HStack { 14 | // if let webView = webView { 15 | // NavigationButtonsView(webView: webView) 16 | // .padding(10) 17 | // } 18 | AddURLFormView(viewModel: pendingClip) // Create a new instance or pass as needed 19 | .padding(10) 20 | } 21 | 22 | if let screenshot = pendingClip.screenShot, webClipSelector.showPreview { 23 | Image(uiImage: screenshot) 24 | .frame(width: 300, height: 300) 25 | .padding() 26 | } 27 | 28 | if pendingClip.isURLValid && !webClipSelector.showPreview { 29 | GeometryReader { geometry in 30 | ZStack { 31 | if let validURL = pendingClip.validURLs.last { 32 | WebViewScreenshotCapture(viewModel: pendingClip, captureMenuViewModel: webClipSelector, validURL: validURL) 33 | .frame(maxHeight: .infinity) 34 | .frame(width: geometry.size.width) 35 | .gesture( 36 | DragGesture(minimumDistance: 0) 37 | .onChanged { [weak webClipSelector, weak pendingClip] value in 38 | webClipSelector!.setStartLocation(webClipSelector?.startLocation ?? value.location) 39 | webClipSelector!.setEndLocation(value.location) 40 | // Note: We don't need to set dragging and dragEnded explicitly here, 41 | // as they're handled in the setStartLocation and setEndLocation methods 42 | webClipSelector!.updateClipRect(endLocation: value.location, bounds: geometry.size) 43 | pendingClip!.currentClipRect = webClipSelector?.currentClipRect 44 | } 45 | .onEnded { [weak webClipSelector] _ in 46 | webClipSelector!.setDragging(false) 47 | webClipSelector!.setDragEnded(true) 48 | 49 | } 50 | ) 51 | .overlay(CaptureRectangleView(dismiss: dismiss, captureMenuViewModel: webClipSelector, pendingClip: pendingClip)) 52 | } 53 | } 54 | } 55 | } 56 | Spacer() 57 | } 58 | .background(Color(UIColor.secondarySystemBackground)) 59 | .cornerRadius(10) 60 | VStack { 61 | HStack { 62 | Spacer() 63 | RedXButton(action: { 64 | dismiss() 65 | }) 66 | .padding(.top, -20) 67 | .padding(.trailing, -20) 68 | } 69 | Spacer() 70 | } 71 | } 72 | } 73 | } 74 | 75 | //struct WebPreviewCaptureMenuView_Previews: PreviewProvider { 76 | // static var previewViewModel: WebClipCreatorViewModel = { 77 | // let model = WebClipCreatorViewModel() 78 | // model.urlString = "https://news.ycombinator.com/" 79 | // return model 80 | // }() 81 | // 82 | // static var previews: some View { 83 | // let pendingClip = WebClipCreatorViewModel() 84 | // WebClipBrowserMenuView(webClipSelector: WebClipSelectorViewModel(), pendingClip: pendingClip 85 | // ) 86 | // } 87 | //} 88 | -------------------------------------------------------------------------------- /glanceables/View/WebClipCreatorView.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | struct WebClipCreatorView: View { 4 | @Environment(WebClipManagerViewModel.self) private var webClipManager 5 | @Environment(\.dismiss) private var dismiss 6 | @State private var webClipSelector = WebClipSelectorViewModel() 7 | @State var pendingClip = WebClipCreatorViewModel() 8 | private var webClip: WebClip? 9 | 10 | init(webClip: WebClip? = nil) { 11 | self.webClip = webClip 12 | if let webClip { 13 | pendingClip.updatePendingWebClip(newPendingClip: webClip.toPendingWebClip()) 14 | } 15 | } 16 | 17 | var body: some View { 18 | VStack{ 19 | BlackEditMenuBarView(webClipSelector: webClipSelector) 20 | VStack{ 21 | WebClipBrowserMenuView(webClipSelector: webClipSelector, dismiss: dismiss, pendingClip: pendingClip) 22 | }.padding(20) 23 | } 24 | .background(Color(.systemGray5).opacity(0.25)) 25 | .navigationBarHidden(true) 26 | .onDisappear { 27 | // Perform any clean up tasks here 28 | pendingClip.reset() 29 | print("WebClipCreatorView is disappearing") 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /glanceables/View/WebClipEditorView.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | struct WebClipEditorView: View { 4 | @Environment(WebClipManagerViewModel.self) private var webClipManager 5 | var webClipId: UUID 6 | 7 | 8 | var body: some View { 9 | WebClipCreatorView(webClip: webClipManager.webClip(webClipId)) 10 | .onAppear { 11 | print("WebClipEditorView init") 12 | }.onDisappear { 13 | webClipManager.reset() 14 | } 15 | } 16 | } 17 | 18 | struct WebClipEditorView_Previews: PreviewProvider { 19 | static var previews: some View { 20 | let captureModel = WebClipSelectorViewModel() 21 | // Provide a sample WebClip instance 22 | let sampleWebClip = WebClip( 23 | id: UUID(), 24 | url: URL(string: "https://news.ycombinator.com/")!, 25 | clipRect: CGRect(x: 0, y: 0, width: 300, height: 200), 26 | originalSize: CGSize(width: 800, height: 600), 27 | scrollY: 100, 28 | pageTitle: "Hacker News", 29 | capturedElements: [], 30 | htmlElements: [], 31 | snapshots: [] 32 | ) 33 | WebClipEditorView(webClipId: sampleWebClip.id) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /glanceables/View/WebClipGridView.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | import UniformTypeIdentifiers 3 | 4 | struct WebClipGridView: View { 5 | @Environment(WebClipManagerViewModel.self) private var webClipManager 6 | 7 | var body: some View { 8 | WebClipGridItems(webClips: webClipManager.getClips()) 9 | .animation(.easeInOut, value: webClipManager.getClips()) 10 | WebClipRefresherGrid() 11 | } 12 | } 13 | 14 | struct WebClipGridItems: View { 15 | @Environment(WebClipManagerViewModel.self) private var webClipManager 16 | var webClips: [WebClip] 17 | 18 | let columns = [GridItem(.adaptive(minimum: 300))] 19 | 20 | var body: some View { 21 | LazyVGrid(columns: columns) { 22 | ForEach(webClips, id: \.self) { item in 23 | VStack { 24 | GridScreenshotView(webClipId: item.id) 25 | .padding(10) 26 | WebGridSingleSnapshotView(item: item) 27 | } .contextMenu { 28 | NavigationLink(destination: WebClipEditorView(webClipId: item.id)) { 29 | Text("Edit") 30 | }.onSubmit { 31 | webClipManager.openEditForItem(item.id) 32 | } 33 | Button("Delete") { 34 | webClipManager.deleteItemById(item.id) 35 | } 36 | } 37 | } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /glanceables/View/WebClipRefresherGrid.swift: -------------------------------------------------------------------------------- 1 | // 2 | // WebClipRefresherGrid.swift 3 | // glanceables 4 | // 5 | // Created by Devin Liu on 8/18/24. 6 | // 7 | 8 | import Foundation 9 | import SwiftUI 10 | 11 | struct WebClipRefresherGrid: View { 12 | @Environment(WebClipManagerViewModel.self) private var webClipManager 13 | 14 | let columns = [GridItem(.adaptive(minimum: 300))] 15 | 16 | 17 | var body: some View { 18 | LazyVGrid(columns: columns) { 19 | ForEach(webClipManager.webClips, id: \.self) { item in 20 | let updaterViewModel = WebClipUpdaterViewModel(webClip: item) 21 | WebViewSnapshotRefresher(webClipId: item.id, updaterViewModel: updaterViewModel) 22 | .edgesIgnoringSafeArea(.all) 23 | .opacity(0) // Make the ScrollView invisible 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /glanceables/View/WebGridSingleSnapshotView.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | import WebKit 3 | import Combine 4 | 5 | struct WebGridSingleSnapshotView: View { 6 | @State private var lastRefreshDate: Date = Date() 7 | @State private var timer: Timer? 8 | @State private var rotationAngle: Double = 0 // State variable for rotation angle 9 | @State private var reloadTrigger = PassthroughSubject() // Local reload trigger 10 | @ObservedObject var item: WebClip 11 | 12 | var body: some View { 13 | VStack { 14 | PageTitleView(title: item.pageTitle ?? "Loading...") 15 | .padding() 16 | 17 | ConciseTextView(text: item.snapshots.last?.conciseText ?? item.snapshots.last?.innerText ?? " ") 18 | .padding() 19 | 20 | RefreshIconView(rotationAngle: $rotationAngle, lastRefreshDate: $lastRefreshDate, reloadTrigger: reloadTrigger) 21 | .padding() 22 | .contentShape(Rectangle()) 23 | .onTapGesture { 24 | withAnimation { 25 | rotationAngle += 360 // Rotate by 360 degrees 26 | } 27 | reloadWebView() 28 | } 29 | } 30 | .cornerRadius(8) 31 | .padding() 32 | .onAppear { 33 | startTimer() 34 | } 35 | .onDisappear { 36 | stopTimer() 37 | } 38 | } 39 | 40 | private func startTimer() { 41 | timer = Timer.scheduledTimer(withTimeInterval: 60, repeats: true) { _ in 42 | reloadWebView() 43 | } 44 | } 45 | 46 | private func stopTimer() { 47 | timer?.invalidate() 48 | timer = nil 49 | } 50 | 51 | private func reloadWebView() { 52 | lastRefreshDate = Date() 53 | reloadTrigger.send() // Trigger the reload for this instance 54 | } 55 | } 56 | 57 | struct ScreenshotView: View { 58 | @ObservedObject var item: WebClip 59 | 60 | var body: some View { 61 | ZStack(alignment: .top) { 62 | if let screenshotPath = item.screenshotPath { 63 | AsyncImageView(imagePath: screenshotPath) 64 | } 65 | } 66 | } 67 | } 68 | 69 | 70 | struct PageTitleView: View { 71 | let title: String 72 | 73 | var body: some View { 74 | Text(title) 75 | .font(.headline) 76 | .lineLimit(1) 77 | .truncationMode(.tail) 78 | } 79 | } 80 | 81 | struct ConciseTextView: View { 82 | let text: String 83 | 84 | var body: some View { 85 | Text(text) 86 | .font(.caption) 87 | } 88 | } 89 | 90 | struct RefreshIconView: View { 91 | @Binding var rotationAngle: Double 92 | @Binding var lastRefreshDate: Date 93 | let reloadTrigger: PassthroughSubject 94 | 95 | var body: some View { 96 | HStack { 97 | Image(systemName: "arrow.clockwise.circle.fill") 98 | .foregroundColor(.gray) 99 | .rotationEffect(.degrees(rotationAngle)) // Apply rotation effect 100 | .animation(Animation.easeInOut(duration: 0.5), value: rotationAngle) 101 | 102 | Text(timeAgoSinceDate(lastRefreshDate)) 103 | .font(.subheadline) 104 | .foregroundColor(.gray) 105 | } 106 | } 107 | 108 | private func timeAgoSinceDate(_ date: Date) -> String { 109 | let interval = Date().timeIntervalSince(date) 110 | if interval < 60 { 111 | return "Just now" 112 | } 113 | let formatter = DateComponentsFormatter() 114 | formatter.allowedUnits = [.minute, .hour, .day] 115 | formatter.maximumUnitCount = 1 116 | formatter.unitsStyle = .full 117 | return formatter.string(from: interval) ?? "Just now" 118 | } 119 | } 120 | 121 | 122 | struct AsyncImageView: View { 123 | @StateObject private var imageLoader: ImageLoader 124 | let placeholder: Image 125 | 126 | // Updated to accept a file path as a String instead of a URL 127 | init(imagePath: String, placeholder: Image = Image(systemName: "photo")) { 128 | _imageLoader = StateObject(wrappedValue: ImageLoader(imagePath: imagePath)) 129 | self.placeholder = placeholder 130 | } 131 | 132 | var body: some View { 133 | ZStack { 134 | if let image = imageLoader.image { 135 | Image(uiImage: image) 136 | .resizable() 137 | .scaledToFit() 138 | .frame(height: 300) 139 | .cornerRadius(24) 140 | } else { 141 | placeholder 142 | .resizable() 143 | .scaledToFit() 144 | } 145 | } 146 | .onAppear { 147 | imageLoader.load() 148 | } 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /glanceables/View/WebViewSnapshotRefresher.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | import WebKit 3 | import Combine 4 | 5 | struct WebViewSnapshotRefresher: UIViewRepresentable { 6 | @Environment(WebClipManagerViewModel.self) private var webClipManager 7 | var webClipId: UUID 8 | var llamaAPIManager = LlamaAPIManager() 9 | @State private var schedulerViewModel = SchedulerViewModel() 10 | var updaterViewModel: WebClipUpdaterViewModel 11 | 12 | init(webClipId: UUID, updaterViewModel: WebClipUpdaterViewModel) { 13 | self.webClipId = webClipId 14 | self.updaterViewModel = updaterViewModel 15 | } 16 | 17 | func makeUIView(context: Context) -> WKWebView { 18 | let webView = WKWebView() 19 | 20 | let coordinator = context.coordinator 21 | webView.navigationDelegate = coordinator 22 | webView.uiDelegate = coordinator 23 | webView.scrollView.delegate = coordinator 24 | 25 | 26 | let leakAvoider = LeakAvoider(delegate: context.coordinator) 27 | 28 | context.coordinator.webView = webView 29 | 30 | configureMessageHandler(webView: webView, contentController: webView.configuration.userContentController, leakAvoider: leakAvoider) 31 | 32 | 33 | JavaScriptLoader.loadJavaScript(userContentController: webView.configuration.userContentController, resourceName: "captureElements", extensionType: "js") 34 | injectGetElementsFromSelectorsScript(userContentController: webView.configuration.userContentController) 35 | 36 | 37 | let request = URLRequest(url: webClipManager.webClip(webClipId)!.url) 38 | webView.load(request) 39 | 40 | schedulerViewModel.configure( 41 | interval: 60.0, // Reload every minute 42 | actions: { [] schedulerViewModel in 43 | return ( 44 | { captureScreenshot(webView: webView) }, 45 | { webView.reload() } 46 | ) 47 | } 48 | ) 49 | 50 | schedulerViewModel.startScheduler() 51 | 52 | return webView 53 | } 54 | 55 | private func configureMessageHandler(webView: WKWebView, contentController: WKUserContentController, leakAvoider: LeakAvoider) { 56 | contentController.removeAllScriptMessageHandlers() 57 | contentController.add(leakAvoider, name: "capturedElementsHandler") 58 | contentController.add(leakAvoider, name: "elementsFromSelectorsHandler") 59 | } 60 | 61 | func updateUIView(_ webView: WKWebView, context: Context) { 62 | print("updateUIView") 63 | } 64 | 65 | func makeCoordinator() -> Coordinator { 66 | return Coordinator(self) 67 | } 68 | 69 | func dismantleUIView(_ uiView: WKWebView, coordinator: Coordinator) { 70 | print("dismantleUIView WebViewSnapshotRefresher") 71 | schedulerViewModel.stopScheduler() 72 | 73 | } 74 | func viewWillDisappear(){ 75 | print("viewWillDisappear WebViewSnapshotRefresher") 76 | schedulerViewModel.stopScheduler() 77 | } 78 | 79 | func handleDidFinishNavigation(webView: WKWebView?){ 80 | guard let webView else { return } 81 | if let capturedElements = webClipManager.webClip(webClipId)?.capturedElements { 82 | restoreScrollPosition(capturedElements, in: webView) 83 | } 84 | } 85 | 86 | // Method to restore the scroll position for captured elements 87 | func restoreScrollPosition(_ elements: [CapturedElement], in webView: WKWebView) { 88 | // Assuming 'CapturedElement' has properties like 'relativeTop' that can be used for scrolling 89 | guard let firstElement = elements.first else { return } 90 | 91 | print("firstelement \(firstElement.selector) | top \(firstElement.relativeTop)") 92 | 93 | let scrollScript = """ 94 | scrollToElementWithRelativeTop("\(firstElement.selector)", \(firstElement.relativeTop)); 95 | """ 96 | 97 | webView.evaluateJavaScript(scrollScript, completionHandler: { result, error in 98 | if let error = error { 99 | print("Error while trying to scroll: \(error.localizedDescription)") 100 | } 101 | }) 102 | } 103 | 104 | func processElementsInnerText(_ innerText: String) { 105 | updaterViewModel.queueSnapshotUpdate(innerText: innerText, conciseText: innerText) 106 | llamaAPIManager.analyzeInnerText(innerText: innerText) { [self] result in 107 | switch result { 108 | case .success(let result): 109 | webClipManager.updateWebClip(withId: webClipId, newLlamaResult: result) 110 | print("Generated result: \(result)") 111 | updaterViewModel.queueSnapshotUpdate(innerText: innerText, conciseText: result.conciseText) 112 | case .failure(let error): 113 | print("Error interpreting changes: \(error.localizedDescription)") 114 | } 115 | } 116 | } 117 | 118 | func injectGetElementsFromSelectorsScript(userContentController: WKUserContentController) { 119 | guard let capturedElement = webClipManager.webClip(webClipId)?.capturedElements?.first else { return } 120 | let elementSelector = capturedElement.selector 121 | JavaScriptLoader.injectGetElementsFromSelectorsScript(userContentController: userContentController, elementSelector: elementSelector) 122 | } 123 | 124 | func injectIsolateElementFromSelectorScript(webView: WKWebView) { 125 | guard let capturedElement = webClipManager.webClip(webClipId)?.capturedElements?.last else { return } 126 | let elementSelector = capturedElement.selector 127 | JavaScriptLoader.injectIsolateElementFromSelectorScript(webView: webView, elementSelector: elementSelector) 128 | } 129 | 130 | func captureScreenshot(webView: WKWebView?) { 131 | guard let webView else { return } 132 | let webClipId = webClipId 133 | 134 | let configuration = WKSnapshotConfiguration() 135 | 136 | if let clipRect = webClipManager.webClip(webClipId)?.clipRect { 137 | // Adjust clipRect based on the current zoom scale and content offset 138 | let zoomScale = webView.scrollView.zoomScale 139 | let offsetX = webView.scrollView.contentOffset.x 140 | let y = clipRect.origin.y 141 | 142 | let adjustedClipRect = CGRect( 143 | x: (clipRect.origin.x + offsetX) / zoomScale, 144 | y: y / zoomScale, 145 | width: clipRect.size.width / zoomScale, 146 | height: clipRect.size.height / zoomScale 147 | ) 148 | 149 | configuration.rect = adjustedClipRect 150 | } 151 | 152 | webView.takeSnapshot(with: configuration) { image, error in 153 | if let image = image { 154 | let newSnapshot = webClipManager.updateScreenshot(image, toClipId: webClipId) 155 | if newSnapshot != nil { 156 | updaterViewModel.queueSnapshotUpdate(newSnapshot: newSnapshot) 157 | } 158 | } 159 | } 160 | } 161 | 162 | 163 | class Coordinator: NSObject, WKNavigationDelegate, WKUIDelegate, UIScrollViewDelegate, WKScriptMessageHandler { 164 | var parent: WebViewSnapshotRefresher 165 | weak var webView: WKWebView? 166 | 167 | private var cancellables = Set() 168 | 169 | init(_ parent: WebViewSnapshotRefresher) { 170 | self.parent = parent 171 | } 172 | 173 | deinit { 174 | // Print to console that the coordinator is being deinitialized 175 | print("Snapshot WebViewCoordinator deinitialized") 176 | 177 | // Remove any script message handlers 178 | webView?.configuration.userContentController.removeScriptMessageHandler(forName: "elementsFromSelectorsHandler") 179 | 180 | // Cancel all active Combine subscriptions 181 | cancellables.forEach { $0.cancel() } 182 | cancellables.removeAll() 183 | 184 | // Clear the webView's delegate to avoid retain cycles 185 | webView?.navigationDelegate = nil 186 | webView?.uiDelegate = nil 187 | } 188 | 189 | func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation! 190 | ) { 191 | 192 | } 193 | 194 | func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { 195 | parent.handleDidFinishNavigation(webView: webView) 196 | } 197 | 198 | func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) { 199 | guard let webView = webView else { return } 200 | if message.name == "elementsFromSelectorsHandler", let messageBody = message.body as? String { 201 | parseElementsFromSelectors(messageBody) 202 | parent.captureScreenshot(webView: webView) 203 | } 204 | } 205 | 206 | func parseElementsFromSelectors(_ jsonString: String) { 207 | guard let data = jsonString.data(using: .utf8) else { 208 | print("Error: Cannot create data from jsonString") 209 | return 210 | } 211 | 212 | do { 213 | let elements = try JSONDecoder().decode([HTMLElement].self, from: data) 214 | if let innerText = elements.first?.innerText { 215 | print("InnerText result: ", innerText) 216 | parent.processElementsInnerText(innerText) 217 | } 218 | 219 | } catch { 220 | print("Error: \(error)") 221 | } 222 | } 223 | 224 | } 225 | } 226 | -------------------------------------------------------------------------------- /glanceables/ViewModel/SchedulerManagerViewModel.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import Combine 3 | 4 | class SchedulerViewModel: ObservableObject { 5 | private var schedulerModel: SchedulerModel? 6 | private var cancellables = Set() 7 | @Published private(set) var screenshotTrigger = PassthroughSubject() 8 | @Published private(set) var reloadTrigger = PassthroughSubject() 9 | 10 | private var screenshotAction: () -> Void = {} 11 | private var reloadAction: () -> Void = {} 12 | private var interval: TimeInterval = 60.0 13 | 14 | var pendingUpdates: [SnapshotUpdate] = [] 15 | 16 | init() {} 17 | 18 | func configure(interval: TimeInterval, actions: @escaping (SchedulerViewModel) -> (() -> Void, () -> Void)) { 19 | self.interval = interval 20 | 21 | let (screenshotAction, reloadAction) = actions(self) 22 | self.screenshotAction = screenshotAction 23 | self.reloadAction = reloadAction 24 | 25 | // Configure the throttle for screenshotTrigger 26 | screenshotTrigger 27 | .throttle(for: .seconds(interval), scheduler: RunLoop.main, latest: true) 28 | .sink { self.screenshotAction() } 29 | .store(in: &cancellables) 30 | 31 | // Configure the throttle for reloadTrigger 32 | reloadTrigger 33 | .throttle(for: .seconds(interval), scheduler: RunLoop.main, latest: true) 34 | .sink { self.reloadAction() } 35 | .store(in: &cancellables) 36 | 37 | schedulerModel = SchedulerModel(interval: interval, actions: [ 38 | { self.screenshotTrigger.send(()) }, 39 | { self.reloadTrigger.send(()) } 40 | ]) 41 | } 42 | 43 | func startScheduler() { 44 | schedulerModel?.start() 45 | } 46 | 47 | func stopScheduler() { 48 | schedulerModel?.stop() 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /glanceables/ViewModel/WebClipCreatorViewModel.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import SwiftUI 3 | import Combine 4 | import WebKit 5 | 6 | @Observable class WebClipCreatorViewModel { 7 | var urlString = "" { 8 | didSet { 9 | debouncer.debounce { 10 | self.validateURL(self.urlString) 11 | } 12 | } 13 | } 14 | 15 | private var debouncer: Debouncer = Debouncer(seconds: 0.3) 16 | private var urlStringCancellable: AnyCancellable? // To hold the subscription 17 | private var cancellables: Set = [] 18 | 19 | var validURLs: [URL] = [] 20 | var currentClipRect: CGRect? 21 | var isURLValid = true 22 | var showValidationError = false 23 | var originalSize: CGSize? 24 | var pageTitle: String? 25 | var screenShot: UIImage? 26 | var screenshotPath: String? 27 | var capturedElements: [CapturedElement]? 28 | var snapshots: [SnapshotTimelineModel] = [] 29 | weak var webView: WKWebView? 30 | 31 | private var webClip: PendingWebClip = PendingWebClip() 32 | 33 | init() {} 34 | 35 | var validURL: URL? { 36 | return validURLs.last 37 | } 38 | 39 | func updateWebView(newWebView: WKWebView){ 40 | webView = newWebView 41 | } 42 | 43 | func updateUrlString(_ newText: String){ 44 | urlString = newText 45 | } 46 | 47 | func updatePendingWebClip(newPendingClip: PendingWebClip){ 48 | webClip = newPendingClip 49 | updateUrlString(newPendingClip.url!.absoluteString) 50 | } 51 | 52 | func clearTextField() { 53 | urlString = "" 54 | } 55 | 56 | func updateClipRect(newRect: CGRect){ 57 | currentClipRect = newRect 58 | } 59 | 60 | func updatePageTitle(_ newTitle: String?){ 61 | let simpleTitle = URLUtilities.simplifyPageTitle(newTitle ?? "No Title") 62 | pageTitle = simpleTitle 63 | } 64 | 65 | 66 | func getNewClip() -> WebClip{ 67 | return WebClip( 68 | id: UUID(), 69 | url: validURL!, 70 | clipRect: currentClipRect, 71 | originalSize: originalSize, 72 | screenshotPath: screenShot.flatMap(ScreenshotUtils.saveScreenshotToLocalDirectory) ?? "", 73 | pageTitle: pageTitle, 74 | capturedElements: capturedElements, 75 | snapshots:snapshots 76 | ) 77 | } 78 | 79 | func saveSnapshots(newSnapshots: [SnapshotTimelineModel]){ 80 | snapshots = newSnapshots 81 | } 82 | 83 | func saveCapturedElements(newElements: [CapturedElement]){ 84 | capturedElements = newElements 85 | } 86 | 87 | func saveScreenShot(_ newScreenShot: UIImage, toClip:WebClip?=nil) -> String? { 88 | screenShot = newScreenShot 89 | if let newScreenshotPath = ScreenshotUtils.saveScreenshotToLocalDirectory(screenshot: newScreenShot) { 90 | screenshotPath = newScreenshotPath 91 | } 92 | return nil 93 | } 94 | 95 | func saveOriginalSize(newOriginalSize: CGSize) { 96 | originalSize = newOriginalSize 97 | } 98 | 99 | func finalizeClip(){ 100 | if let webView = webView { 101 | webView.evaluateJavaScript("window.webkit.messageHandlers.userStoppedInteracting.postMessage(null);") 102 | updatePageTitle(webView.title) 103 | if let newURL = webView.url { 104 | validURLs.append(newURL) 105 | } 106 | 107 | } 108 | } 109 | 110 | func reset() { 111 | // Reset basic string and URL properties 112 | urlString = "" 113 | validURLs.removeAll() 114 | 115 | // Reset state flags 116 | isURLValid = true 117 | showValidationError = false 118 | 119 | // Reset geometry and image properties 120 | currentClipRect = nil 121 | originalSize = nil 122 | pageTitle = nil 123 | screenShot = nil 124 | screenshotPath = nil 125 | 126 | // Reset collections 127 | capturedElements = [] 128 | snapshots.removeAll() 129 | 130 | // Reset web view 131 | webView = nil 132 | 133 | // Clear any held subscriptions if any 134 | cancellables.forEach { $0.cancel() } 135 | cancellables.removeAll() 136 | 137 | // Reset the internal web clip model 138 | webClip = PendingWebClip() 139 | 140 | // Clear any pending operations in debouncer 141 | debouncer.cancel() 142 | } 143 | 144 | 145 | private func validateURL(_ urlString: String) { 146 | debouncer.cancel() 147 | let (isValid, url) = URLUtilities.validateURL(from: urlString) 148 | isURLValid = isValid 149 | if isValid, let url = url { 150 | validURLs.append(url) 151 | } 152 | 153 | } 154 | } 155 | 156 | class Debouncer { 157 | private var workItem: DispatchWorkItem? 158 | private let interval: TimeInterval 159 | 160 | init(seconds: TimeInterval) { 161 | self.interval = seconds 162 | } 163 | 164 | func debounce(action: @escaping () -> Void) { 165 | workItem?.cancel() 166 | workItem = DispatchWorkItem(block: action) 167 | DispatchQueue.main.asyncAfter(deadline: .now() + interval, execute: workItem!) 168 | } 169 | 170 | // Ensure this method is properly defined 171 | func cancel() { 172 | workItem?.cancel() 173 | workItem = nil 174 | } 175 | } 176 | -------------------------------------------------------------------------------- /glanceables/ViewModel/WebClipManagerViewModel.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import SwiftUI 3 | 4 | @Observable class WebClipManagerViewModel { 5 | var webClips: [WebClip] = [] 6 | 7 | init() { 8 | loadWebClips() 9 | } 10 | 11 | public func isEmpty() -> Bool { 12 | return webClips.count == 0 13 | } 14 | 15 | public func getClips() -> [WebClip] { 16 | return webClips 17 | } 18 | 19 | var isEditing = false 20 | var selectedWebClipIndex: Int? = nil 21 | 22 | // Add a computed property to access a specific WebClip by ID 23 | func webClip(_ id: UUID) -> WebClip? { 24 | return webClips.first(where: { $0.id == id }) 25 | } 26 | 27 | func selectedWebClip() -> WebClip? { 28 | guard let index = selectedWebClipIndex, webClips.indices.contains(index) else { 29 | return nil 30 | } 31 | return webClips[index] 32 | } 33 | 34 | func imageForWebClip(withId id: UUID) -> UIImage? { 35 | guard let webClip = webClip(id) else { return nil } 36 | return ScreenshotUtils.loadImage(from: webClip.screenshotPath) 37 | } 38 | 39 | func updateScreenshot(_ newScreenShot: UIImage, toClipId:UUID) -> String? { 40 | if let toClip = webClip(toClipId){ 41 | if let screenshotPath = toClip.screenshotPath{ 42 | if let newScreenshotPath = ScreenshotUtils.saveScreenshotToFile(screenshotPath: screenshotPath, from: newScreenShot) { 43 | updateWebClip(withId: toClip.id, newScreenshotPath: newScreenshotPath) 44 | return newScreenshotPath 45 | } 46 | } 47 | } 48 | return nil 49 | } 50 | 51 | func loadWebClips() { 52 | webClips = WebClipUserDefaultsRepository.loadWebClips() 53 | } 54 | 55 | func saveWebClips() { 56 | WebClipUserDefaultsRepository.saveWebClips(webClips) 57 | } 58 | 59 | func createWebClip(newClip: WebClip){ 60 | webClips.append(newClip) 61 | saveWebClips() 62 | // loadWebClips() 63 | } 64 | 65 | func updateWebClip(withId id: UUID, newURL: URL? = nil, newClipRect: CGRect? = nil, newScreenshotPath: String? = nil, newPageTitle: String? = nil, newCapturedElements: [CapturedElement]? = nil, newLlamaResult: LlamaResult? = nil, newInnerText: String? = nil) { 66 | guard let index = webClips.firstIndex(where: { $0.id == id }) else { 67 | return 68 | } 69 | let updatedWebClip = webClips[index] 70 | 71 | if let newURL = newURL { 72 | updatedWebClip.url = newURL 73 | } 74 | if let newClipRect = newClipRect { 75 | updatedWebClip.clipRect = newClipRect 76 | } 77 | if let newScreenshotPath = newScreenshotPath { 78 | updatedWebClip.screenshotPath = newScreenshotPath 79 | } 80 | if let newPageTitle = newPageTitle { 81 | updatedWebClip.pageTitle = newPageTitle 82 | } 83 | if let newCapturedElements = newCapturedElements { 84 | updatedWebClip.capturedElements = newCapturedElements 85 | } 86 | 87 | WebClipUserDefaultsRepository.updateWebClip(updatedWebClip) 88 | loadWebClips() 89 | } 90 | 91 | func openEditForItem(_ id: UUID) { 92 | guard let index = webClips.firstIndex(where: { $0.id == id }) else { return } 93 | selectedWebClipIndex = index 94 | } 95 | 96 | func deleteItemById(_ id: UUID) { 97 | WebClipUserDefaultsRepository.deleteWebClipById(id) 98 | loadWebClips() 99 | } 100 | 101 | func moveItem(fromOffsets: IndexSet, toOffset: Int) { 102 | webClips.move(fromOffsets: fromOffsets, toOffset: toOffset) 103 | saveWebClips() // Persist the new order in the repository 104 | } 105 | 106 | func reset() { 107 | isEditing = false 108 | selectedWebClipIndex = nil 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /glanceables/ViewModel/WebClipSelectorViewModel.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | @Observable class WebClipSelectorViewModel { 4 | private(set) var currentClipRect: CGRect? 5 | private(set) var userInteracting: Bool = false 6 | private(set) var scrollY: Double = 0 7 | private(set) var capturedElements: [CapturedElement]? 8 | private(set) var startLocation: CGPoint? = nil 9 | private(set) var endLocation: CGPoint? = nil 10 | private(set) var dragging: Bool = false 11 | private(set) var dragEnded: Bool = false 12 | private(set) var showPreview: Bool = false 13 | 14 | private var _captureModeOn: Bool = true 15 | var captureModeOn: Bool { 16 | get { _captureModeOn } 17 | set { 18 | _captureModeOn = newValue 19 | if !newValue { 20 | // Reset related properties when capture mode is turned off 21 | currentClipRect = nil 22 | capturedElements = nil 23 | } 24 | } 25 | } 26 | 27 | func setUserInteracting(_ value: Bool) { 28 | userInteracting = value 29 | } 30 | 31 | func setScrollY(_ value: Double) { 32 | scrollY = max(0, value) // Ensure scrollY is never negative 33 | } 34 | 35 | func setStartLocation(_ point: CGPoint?) { 36 | startLocation = point 37 | if point != nil { 38 | dragging = true 39 | dragEnded = false 40 | } 41 | } 42 | 43 | func setEndLocation(_ point: CGPoint?) { 44 | endLocation = point 45 | if point == nil { 46 | dragging = false 47 | dragEnded = true 48 | } 49 | } 50 | 51 | func setShowPreview(_ value: Bool) { 52 | showPreview = value 53 | } 54 | 55 | func setCapturedElements(_ elements: [CapturedElement]?) { 56 | capturedElements = elements 57 | } 58 | 59 | func setDragging(_ value: Bool){ 60 | dragging = value 61 | } 62 | 63 | func setDragEnded(_ value: Bool){ 64 | dragEnded = value 65 | } 66 | 67 | func updateClipRect(endLocation: CGPoint, bounds: CGSize) { 68 | let width = 300.0 69 | let height = 300.0 70 | 71 | let centerX = endLocation.x 72 | let centerY = endLocation.y 73 | 74 | let minX = max(0, min(centerX - width / 2, bounds.width - width)) 75 | let minY = max(0, min(centerY - height / 2, bounds.height - height)) 76 | 77 | currentClipRect = CGRect(x: minX, y: minY, width: width, height: height) 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /glanceables/ViewModel/WebClipUpdaterViewModel.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import SwiftUI 3 | 4 | class WebClipUpdaterViewModel: ObservableObject { 5 | @Published var pendingUpdates: [SnapshotUpdate] = [] 6 | var webClip: WebClip 7 | 8 | init(webClip: WebClip) { 9 | self.webClip = webClip 10 | } 11 | 12 | 13 | func queueSnapshotUpdate(newSnapshot: String? = nil, innerText: String? = nil, conciseText: String? = nil) { 14 | let update = SnapshotUpdate(newSnapshot: newSnapshot, innerText: innerText, conciseText: conciseText) 15 | pendingUpdates.append(update) 16 | processPendingUpdates() 17 | } 18 | 19 | private func processPendingUpdates() { 20 | // Initialize a dictionary to keep track of the first occurrence of each update component 21 | var fieldsDictionary: [String: String] = [:] 22 | 23 | // Iterate over all pending updates to merge them 24 | for update in pendingUpdates { 25 | // Collect only the first non-nil occurrence of each field 26 | if let innerText = update.innerText, fieldsDictionary["innerText"] == nil { 27 | fieldsDictionary["innerText"] = innerText 28 | } 29 | if let conciseText = update.conciseText, fieldsDictionary["conciseText"] == nil { 30 | fieldsDictionary["conciseText"] = conciseText 31 | } 32 | if let newSnapshot = update.newSnapshot, fieldsDictionary["newSnapshot"] == nil { 33 | fieldsDictionary["newSnapshot"] = newSnapshot 34 | } 35 | } 36 | 37 | // Check if we have collected all necessary fields 38 | if let innerText = fieldsDictionary["innerText"], 39 | let conciseText = fieldsDictionary["conciseText"], 40 | let newSnapshot = fieldsDictionary["newSnapshot"] { 41 | // If all required fields are present, process the update 42 | webClip.addSnapshotIfNeeded(screenshotPath: newSnapshot, innerText: innerText, conciseText: conciseText) 43 | pendingUpdates.removeAll() 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /glanceables/WebViewScreenshotCapture.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | import WebKit 3 | 4 | struct WebViewScreenshotCapture: UIViewRepresentable { 5 | var viewModel: WebClipCreatorViewModel 6 | var captureMenuViewModel: WebClipSelectorViewModel 7 | var validURL: URL 8 | 9 | func makeUIView(context: Context) -> WKWebView { 10 | print("makeUIView", validURL) 11 | let web = WKWebView() 12 | configureWebView(webView: web, context: context) 13 | viewModel.updateWebView(newWebView: web) 14 | return web 15 | } 16 | 17 | func updateUIView(_ uiView: WKWebView, context: Context) { 18 | // Perform any dynamic updates to your view's content. 19 | } 20 | 21 | func makeCoordinator() -> Coordinator { 22 | print("makeCoordinator") 23 | return Coordinator(self) 24 | } 25 | 26 | private func configureWebView(webView: WKWebView, context: Context) { 27 | 28 | let coordinator = context.coordinator 29 | webView.navigationDelegate = coordinator 30 | webView.uiDelegate = coordinator 31 | webView.scrollView.delegate = coordinator 32 | 33 | let leakAvoider = LeakAvoider(delegate: context.coordinator) 34 | 35 | context.coordinator.webView = webView 36 | 37 | // Observers Setup 38 | // webView.addObserver(coordinator, forKeyPath: #keyPath(WKWebView.title), options: .new, context: nil) 39 | // webView.addObserver(coordinator, forKeyPath: #keyPath(WKWebView.canGoBack), options: .new, context: nil) 40 | // webView.addObserver(coordinator, forKeyPath: #keyPath(WKWebView.canGoForward), options: .new, context: nil) 41 | // 42 | configureMessageHandler(webView: webView, contentController: webView.configuration.userContentController, leakAvoider: leakAvoider) 43 | JavaScriptLoader.loadJavaScript(userContentController: webView.configuration.userContentController, resourceName: "captureElements", extensionType: "js") 44 | injectSelectionScript(webView: webView) 45 | injectCaptureElementsScript(webView: webView) 46 | 47 | let request = URLRequest(url: validURL) 48 | webView.load(request) 49 | } 50 | 51 | 52 | private func configureMessageHandler(webView: WKWebView, contentController: WKUserContentController, leakAvoider: LeakAvoider) { 53 | contentController.removeAllScriptMessageHandlers() 54 | contentController.add(leakAvoider, name: "selectionHandler") 55 | contentController.add(leakAvoider, name: "capturedElementsHandler") 56 | contentController.add(leakAvoider, name: "userStoppedInteracting") 57 | } 58 | 59 | private func injectCaptureElementsScript(webView: WKWebView){ 60 | let jsCode = """ 61 | document.addEventListener('mouseup', function(e) { 62 | const elements = getElementsWithinBoundary(e.clientX, e.clientY); 63 | const selectors = elements.map(element => ({ 64 | ...getElementPosition(element), 65 | selector: getUniqueSelector(element) 66 | })); 67 | window.webkit.messageHandlers.capturedElementsHandler.postMessage(JSON.stringify(selectors)); 68 | }); 69 | """ 70 | 71 | webView.configuration.userContentController.addUserScript(WKUserScript(source: jsCode, injectionTime: .atDocumentStart, forMainFrameOnly: false)) 72 | } 73 | 74 | private func injectSelectionScript(webView: WKWebView) { 75 | let jsString = """ 76 | function getCSSSelector(element) { 77 | let selector = element.tagName.toLowerCase(); 78 | if (element.id) { 79 | selector += '#' + element.id; 80 | } else if (element.className) { 81 | const classes = element.className.split(' ').filter(c => c !== '').join('.'); 82 | if (classes) { 83 | selector += '.' + classes; 84 | } 85 | } 86 | return selector; 87 | } 88 | 89 | document.addEventListener('mousedown', function(e) { 90 | const rect = e.target.getBoundingClientRect(); 91 | const scrollY = window.pageYOffset || document.documentElement.scrollTop; 92 | const selector = getCSSSelector(e.target); 93 | const data = { 94 | viewportX: e.clientX, // X coordinate relative to the viewport 95 | viewportY: e.clientY, // Y coordinate relative to the viewport 96 | documentX: e.clientX + window.pageXOffset, // X coordinate relative to the document 97 | documentY: e.clientY + window.pageYOffset, // Y coordinate relative to the document 98 | width: rect.width, 99 | height: rect.height, 100 | scrollY: scrollY, 101 | selector: selector 102 | }; 103 | window.webkit.messageHandlers.selectionHandler.postMessage(JSON.stringify(data)); 104 | }); 105 | 106 | document.addEventListener('mouseup', function(e) { 107 | const rect = e.target.getBoundingClientRect(); 108 | const scrollY = window.pageYOffset || document.documentElement.scrollTop; 109 | const selector = getCSSSelector(e.target); 110 | const data = { 111 | viewportX: e.clientX, // X coordinate relative to the viewport 112 | viewportY: e.clientY, // Y coordinate relative to the viewport 113 | documentX: e.clientX + window.pageXOffset, // X coordinate relative to the document 114 | documentY: e.clientY + window.pageYOffset, // Y coordinate relative to the document 115 | width: rect.width, 116 | height: rect.height, 117 | scrollY: scrollY, 118 | mouseup: true, 119 | selector: selector 120 | }; 121 | window.webkit.messageHandlers.selectionHandler.postMessage(JSON.stringify(data)); 122 | window.webkit.messageHandlers.userStoppedInteracting.postMessage(null); 123 | }); 124 | """ 125 | webView.configuration.userContentController.addUserScript(WKUserScript(source: jsString, injectionTime: .atDocumentStart, forMainFrameOnly: false)) 126 | } 127 | 128 | class Coordinator: NSObject, WKNavigationDelegate, WKUIDelegate, UIScrollViewDelegate, WKScriptMessageHandler { 129 | var parent: WebViewScreenshotCapture 130 | weak var webView: WKWebView? 131 | private var screenshotCaptureWorkItem: DispatchWorkItem? 132 | 133 | 134 | init(_ parent: WebViewScreenshotCapture) { 135 | self.parent = parent 136 | } 137 | 138 | override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { 139 | guard let webView = object as? WKWebView else { return } 140 | if keyPath == #keyPath(WKWebView.title) { 141 | initializeClipRect() 142 | 143 | } 144 | } 145 | 146 | deinit { 147 | webView?.navigationDelegate = nil 148 | webView?.uiDelegate = nil 149 | webView?.scrollView.delegate = nil 150 | 151 | // Clean up message handlers to ensure they are not retaining this Coordinator 152 | webView?.configuration.userContentController.removeScriptMessageHandler(forName: "selectionHandler") 153 | webView?.configuration.userContentController.removeScriptMessageHandler(forName: "capturedElementsHandler") 154 | webView?.configuration.userContentController.removeScriptMessageHandler(forName: "userStoppedInteracting") 155 | print("Coordinator is being deinitialized") 156 | } 157 | 158 | func initializeClipRect(){ 159 | if parent.viewModel.currentClipRect == nil, let frame = webView?.frame { 160 | print("webView ClipRect 2") 161 | let rectWidth: CGFloat = 300 // Example width 162 | let rectHeight: CGFloat = 300 // Example height 163 | let centerX = frame.width / 2 - rectWidth / 2 164 | let centerY = frame.height / 2 - rectHeight / 2 165 | parent.viewModel.updateClipRect(newRect: CGRect(x: centerX, y: centerY, width: rectWidth, height: rectHeight)) 166 | } 167 | } 168 | 169 | func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation! 170 | ) { 171 | // Initialize clipRect in the center of the WebView frame 172 | if parent.viewModel.currentClipRect == nil { 173 | let rectWidth: CGFloat = 300 // Example width 174 | let rectHeight: CGFloat = 300 // Example height 175 | let centerX = webView.frame.width / 2 - rectWidth / 2 176 | let centerY = webView.frame.height / 2 - rectHeight / 2 177 | parent.viewModel.updateClipRect(newRect: (CGRect(x: centerX, y: centerY, width: rectWidth, height: rectHeight))) 178 | } 179 | } 180 | 181 | 182 | func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { 183 | DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [weak self] in 184 | guard let self = self else { return } 185 | parent.viewModel.updatePageTitle(webView.title) 186 | parent.viewModel.saveOriginalSize(newOriginalSize: webView.scrollView.contentSize) 187 | 188 | // Initialize clipRect in the center of the WebView frame 189 | if parent.viewModel.currentClipRect == nil { 190 | let rectWidth: CGFloat = 300 // Example width 191 | let rectHeight: CGFloat = 300 // Example height 192 | let centerX = webView.frame.width / 2 - rectWidth / 2 193 | let centerY = webView.frame.height / 2 - rectHeight / 2 194 | parent.viewModel.updateClipRect(newRect: (CGRect(x: centerX, y: centerY, width: rectWidth, height: rectHeight))) 195 | } 196 | } 197 | } 198 | 199 | func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) { 200 | if message.name == "selectionHandler", let messageBody = message.body as? String { 201 | let scrollY = parseScrollY(messageBody) 202 | if scrollY != 0 { 203 | parent.captureMenuViewModel.setScrollY(scrollY) 204 | } 205 | userDidStopInteracting() 206 | } 207 | 208 | if message.name == "capturedElementsHandler", let messageBody = message.body as? String { 209 | parseCapturedElements(messageBody) 210 | } 211 | 212 | if message.name == "userStoppedInteracting" { 213 | // Handle user stop interaction here 214 | print("userStoppedInteracting", parent.validURL) 215 | userDidStopInteracting() 216 | } 217 | 218 | } 219 | 220 | func userDidStopInteracting() { 221 | captureScreenshot() 222 | parent.viewModel.updatePageTitle(webView?.title) 223 | } 224 | 225 | func parseCapturedElements(_ jsonString: String) { 226 | guard let data = jsonString.data(using: .utf8) else { 227 | print("Error: Cannot create data from jsonString") 228 | return 229 | } 230 | 231 | do { 232 | let elements = try JSONDecoder().decode([CapturedElement].self, from: data) 233 | processCapturedElements(elements) 234 | } catch { 235 | print("Error: \(error)") 236 | } 237 | } 238 | 239 | func processCapturedElements(_ elements: [CapturedElement]) { 240 | // parent.captureMenuViewModel.setCapturedElements(elements) 241 | parent.viewModel.saveCapturedElements(newElements: elements) 242 | } 243 | 244 | private func parseScrollY(_ message: String) -> Double { 245 | let data = Data(message.utf8) 246 | 247 | if let json = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: CGFloat], 248 | let scrollY = json["scrollY"] { 249 | return scrollY 250 | } 251 | return 0.0 252 | } 253 | 254 | private func parseMessage(_ message: String) -> CGRect { 255 | let data = Data(message.utf8) 256 | 257 | if let json = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: CGFloat], 258 | let x = json["x"], let y = json["y"], let width = json["width"], let height = json["height"] { 259 | return CGRect(x: x, y: y, width: width, height: height) 260 | } 261 | return .zero 262 | } 263 | 264 | 265 | 266 | func scrollViewDidScroll(_ scrollView: UIScrollView) { 267 | parent.captureMenuViewModel.setScrollY(Double(scrollView.contentOffset.y)) 268 | } 269 | 270 | func scrollViewWillBeginDragging(_ scrollView: UIScrollView) { 271 | parent.captureMenuViewModel.setUserInteracting(true) 272 | } 273 | 274 | func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) { 275 | if !decelerate { 276 | parent.captureMenuViewModel.setUserInteracting(false) 277 | } 278 | } 279 | 280 | func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) { 281 | parent.captureMenuViewModel.setUserInteracting(false) 282 | } 283 | 284 | private func captureScreenshot() { 285 | guard let webView = webView else { return } 286 | let viewModel = parent.viewModel 287 | let configuration = WKSnapshotConfiguration() 288 | if let clipRect = parent.viewModel.currentClipRect { 289 | // Capture the current screenshot that the user sees 290 | let adjustedClipRect = CGRect( 291 | x: clipRect.origin.x, 292 | y: clipRect.origin.y, 293 | width: clipRect.size.width, 294 | height: clipRect.size.height 295 | ) 296 | configuration.rect = adjustedClipRect 297 | } 298 | 299 | webView.takeSnapshot(with: configuration) { image, error in 300 | if let image = image { 301 | viewModel.saveScreenShot(image) 302 | } else if let error = error { 303 | print("Screenshot error: \(error.localizedDescription)") 304 | } 305 | } 306 | 307 | } 308 | } 309 | } 310 | -------------------------------------------------------------------------------- /glanceables/captureElements.js: -------------------------------------------------------------------------------- 1 | function scrollToElementWithRelativeTop(selector, desiredRelativeTop) { 2 | const element = document.querySelector(selector); 3 | if (element) { 4 | const currentPosition = getElementPosition(element).relativeTop; 5 | const offset = desiredRelativeTop - currentPosition; 6 | const newScrollPosition = window.scrollY + offset; 7 | 8 | window.scrollTo({ 9 | top: newScrollPosition, 10 | behavior: 'instant' // Optional: for smooth scrolling 11 | }); 12 | } else { 13 | console.error("Element not found with selector: " + selector); 14 | } 15 | } 16 | 17 | function getElementPosition(element) { 18 | const rect = element.getBoundingClientRect(); 19 | return { 20 | relativeTop: rect.top - window.scrollY, 21 | relativeLeft: rect.left - window.scrollX 22 | }; 23 | } 24 | 25 | function getUniqueSelector(element) { 26 | if (!element) return null; 27 | 28 | let path = "", current = element; 29 | while (current && current !== document.body && current.nodeType === Node.ELEMENT_NODE) { // Stop at body element 30 | let selector = current.nodeName.toLowerCase(); 31 | 32 | // Use attribute selector for ID 33 | if (current.id) { 34 | selector += `[id='${current.id}']`; // Updated line 35 | path = selector + (path ? " > " + path : ""); 36 | break; // ID is unique enough for a selector 37 | } 38 | 39 | const classList = Array.from(current.classList); 40 | if (classList.length > 0) { 41 | selector += '.' + classList.join('.'); 42 | } 43 | 44 | let sibling = current; 45 | let nth = 1; 46 | while (sibling = sibling.previousElementSibling) { 47 | if (sibling.nodeName.toLowerCase() === current.nodeName.toLowerCase()) { 48 | nth++; 49 | } 50 | } 51 | if (nth > 1) { 52 | selector += `:nth-of-type(${nth})`; 53 | } 54 | 55 | path = selector + (path ? " > " + path : ""); 56 | current = current.parentElement; 57 | } 58 | return path; 59 | } 60 | 61 | function getElementsWithinBoundary(x, y) { 62 | const elements = document.elementsFromPoint(x, y); 63 | const boundarySize = 150; 64 | const yMin = y - boundarySize; 65 | const yMax = y + boundarySize; 66 | const xMin = x - boundarySize; 67 | const xMax = x + boundarySize; 68 | 69 | return elements.filter(element => { 70 | const rect = element.getBoundingClientRect(); 71 | 72 | // Check if the vertical position of the element is within the boundary 73 | const isTopWithinBoundary = rect.top >= yMin && rect.top <= yMax; 74 | const isBottomWithinBoundary = rect.bottom >= yMin && rect.bottom <= yMax; 75 | 76 | // Check if the horizontal position of the element is within the boundary 77 | const isLeftWithinBoundary = rect.left >= xMin && rect.left <= xMax; 78 | const isRightWithinBoundary = rect.right >= xMin && rect.right <= xMax; 79 | 80 | // Allow elements where either the top or bottom is within the vertical boundary 81 | // and either the left or right is within the horizontal boundary 82 | return (isTopWithinBoundary || isBottomWithinBoundary) && (isLeftWithinBoundary || isRightWithinBoundary); 83 | }); 84 | } 85 | 86 | function getElementsFromSelectors(selectors) { 87 | let elements = []; 88 | selectors.forEach(selector => { 89 | const element = document.querySelector(selector); 90 | if (element) { 91 | elements.push(element); 92 | } else { 93 | console.log(`No element found for selector: ${selector}`); 94 | } 95 | }); 96 | return elements; 97 | } 98 | 99 | 100 | function isolateElement(selector) { 101 | // Select the target element 102 | const target = document.querySelector(selector); 103 | 104 | // Hide all siblings of the target 105 | let sibling = target.parentNode.firstChild; 106 | while (sibling) { 107 | if (sibling !== target && sibling.nodeType === Node.ELEMENT_NODE) { 108 | sibling.style.display = 'none'; 109 | } 110 | sibling = sibling.nextSibling; 111 | } 112 | 113 | // Traverse up the DOM tree and hide other branches not containing the target 114 | let ancestor = target.parentNode; 115 | while (ancestor && ancestor !== document.body) { 116 | // Hide all children of the ancestor, except the direct child that is an ancestor of the target 117 | Array.from(ancestor.children).forEach(child => { 118 | if (!child.contains(target)) { 119 | child.style.visibility = 'hidden'; 120 | } 121 | }); 122 | ancestor = ancestor.parentNode; 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /glanceables/glanceables.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | com.apple.security.network.client 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /glanceables/glanceablesApp.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | @main 4 | struct glanceablesApp: App { 5 | @State private var webClipManager = WebClipManagerViewModel() 6 | 7 | init() { 8 | NotificationManager.requestAuthorization() 9 | } 10 | 11 | var body: some Scene { 12 | WindowGroup { 13 | ContentView() 14 | .environment(webClipManager) 15 | 16 | } 17 | } 18 | } 19 | 20 | private struct webClipManagerKey: EnvironmentKey { 21 | static var defaultValue: WebClipManagerViewModel = WebClipManagerViewModel() 22 | 23 | typealias Value = WebClipManagerViewModel 24 | 25 | static let webClipManager: WebClipManagerViewModel = WebClipManagerViewModel() 26 | } 27 | 28 | extension EnvironmentValues { 29 | var webClipManager: WebClipManagerViewModel { 30 | get { self[webClipManagerKey.self] } 31 | set { self[webClipManagerKey.self] = newValue } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /glanceablesTests/WebViewTests.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | 3 | class WebViewUITests: XCTestCase { 4 | var app: XCUIApplication! 5 | 6 | override func setUp() { 7 | super.setUp() 8 | continueAfterFailure = false 9 | app = XCUIApplication() 10 | app.launch() 11 | } 12 | 13 | func testWebViewLoading() { 14 | let webView = app.webViews.firstMatch // Ensure your WebView is accessible 15 | 16 | // Test loading URL 17 | XCTAssertTrue(webView.exists, "WebView does not exist.") 18 | 19 | // Wait for the page to load by checking for an element on the page 20 | let pageTitle = webView.staticTexts["Your Expected Page Title"].firstMatch 21 | let exists = NSPredicate(format: "exists == true") 22 | expectation(for: exists, evaluatedWith: pageTitle, handler: nil) 23 | waitForExpectations(timeout: 5, handler: nil) 24 | XCTAssertEqual(pageTitle.label, "Your Expected Page Title", "Page title did not match.") 25 | } 26 | 27 | func testClipRectAdjustment() { 28 | let webView = app.webViews.firstMatch 29 | let startCoordinate = webView.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)) 30 | let endCoordinate = startCoordinate.withOffset(CGVector(dx: 150, dy: 150)) // Simulate drag to select a 300x300 area 31 | 32 | // Start the drag operation 33 | startCoordinate.press(forDuration: 0.5, thenDragTo: endCoordinate) 34 | 35 | // Since the end result of this action depends on the JavaScript executing properly, 36 | // and possibly updating an element with the resulting dimensions, 37 | // we need to wait for that to be visible 38 | let expectedLabel = "300x300" // Adjust this based on actual test setup and expectations 39 | let clipDimensionsLabel = webView.staticTexts[expectedLabel].firstMatch 40 | let clipExists = NSPredicate(format: "exists == true") 41 | expectation(for: clipExists, evaluatedWith: clipDimensionsLabel, handler: nil) 42 | waitForExpectations(timeout: 5, handler: nil) 43 | 44 | XCTAssertEqual(clipDimensionsLabel.label, expectedLabel, "Clip dimensions did not match expected values.") 45 | } 46 | } 47 | --------------------------------------------------------------------------------