├── .gitignore ├── .prettierrc ├── LICENSE ├── README.md ├── index.html ├── package.json ├── pnpm-lock.yaml ├── postcss.config.js ├── public ├── disk.png ├── exec.png ├── file.png ├── folder.png ├── logo.png ├── plugin.json └── quicklook.html ├── screenshots ├── list-mode-detail.png ├── list-mode.png └── preview-mode.png ├── src ├── App.vue ├── assets │ └── empty_inbox.svg ├── components │ ├── common │ │ ├── Checkbox.vue │ │ ├── FormItem.vue │ │ ├── Header.vue │ │ ├── Hover.vue │ │ ├── OverlayProgress.vue │ │ ├── SelectBox.vue │ │ ├── ShowBox.vue │ │ └── Subheader.vue │ ├── home │ │ ├── DisplayMode.vue │ │ ├── FileList.vue │ │ ├── FileThumbnail.vue │ │ ├── FolderSubItem.vue │ │ ├── FolderViewer.vue │ │ ├── Preview.vue │ │ ├── SearchInput.vue │ │ ├── SideNumOverlay.vue │ │ ├── SortOrder.vue │ │ └── TextViewer.vue │ └── setting │ │ ├── table │ │ ├── BodyRow.vue │ │ ├── FlexTable.vue │ │ └── HeadRow.vue │ │ └── tabs │ │ ├── AboutTab.vue │ │ ├── FilterTab.vue │ │ ├── GeneralTab.vue │ │ └── PreviewTab.vue ├── constant │ ├── enums.ts │ └── index.ts ├── directives │ └── index.ts ├── hooks │ ├── useActivated.ts │ ├── useContextMenu.ts │ ├── useDark.ts │ ├── useEventListener.ts │ ├── useHotkeys.ts │ ├── useKeyLongPress.ts │ ├── useLastState.ts │ └── useMouse.ts ├── main.ts ├── models │ ├── KindFilterModel.ts │ ├── SearchScopeModel.ts │ ├── SettingModel.ts │ └── index.ts ├── plugins │ ├── context-menu.ts │ ├── toastification.ts │ └── vuetify.ts ├── preload.ts ├── router │ └── index.ts ├── store │ └── index.ts ├── style.css ├── styles │ └── context-menu.scss ├── typings │ ├── global.d.ts │ └── preload.d.ts ├── utils │ ├── collections.ts │ ├── common.ts │ ├── handler.ts │ ├── icons.ts │ ├── mdfinds.ts │ ├── plist.ts │ ├── query.ts │ └── strings.ts ├── views │ ├── Home.vue │ └── Setting.vue └── vite-env.d.ts ├── tailwind.config.js ├── tsconfig.json ├── tsconfig.node.json └── vite.config.ts /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | test 16 | 17 | # Editor directories and files 18 | .vscode 19 | .idea 20 | .DS_Store 21 | *.suo 22 | *.ntvs* 23 | *.njsproj 24 | *.sln 25 | *.sw? 26 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 110, 3 | "semi": false, 4 | "singleQuote": true, 5 | "trailingComma": "none", 6 | "bracketSameLine": false, 7 | "plugins": [ 8 | "prettier-plugin-tailwindcss" 9 | ], 10 | "tailwindConfig": "./tailwind.config.js" 11 | } -------------------------------------------------------------------------------- /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 | # 文件搜索 2 | 3 | 文件搜索,快速查找 Mac 上的文件,原 Mverything Plus,基于 `mdfind` 命令构建。 4 | 5 | ## 背景 6 | 7 | 在 uTools 的 Mac 端上的文件搜索工具,只有 [Mverything](https://github.com/lanyuanxiaoyao/Mverything) 这一个插件可供选择,但其搜索体验略显繁琐,且很久没有维护了,一直缺少一款好用的文件搜索插件,于是就打算自己写一个。本项目的初始版本在 [Mverything](https://github.com/lanyuanxiaoyao/Mverything) 的基础上开发,感谢 [lanyuanxiaoyao](https://github.com/lanyuanxiaoyao) 的开源项目。 8 | 9 | ## 特性 10 | 11 | 1. 主搜索框快速搜索,空格或单引号触发 12 | 2. 查看最近使用的文件 13 | 3. 自定义类型筛选 14 | 4. 搜索结果高亮 15 | 5. 深色模式 16 | 6. 支持多选、拖拽文件 17 | 7. 多种显示模式:列表、预览模式 18 | 8. 支持文件夹、文件预览 19 | 9. 方便切换搜索范围,目录或磁盘 20 | 10. 多种排序规则 21 | 11. 易用的快捷键 22 | 23 | ## 安装 24 | 25 | 直接在 uTools 插件应用市场搜索“文件搜索”安装 26 | 27 | ## 开发 28 | 29 | ```shell 30 | # 安装依赖 31 | pnpm install 32 | 33 | # 运行项目 34 | pnpm dev 35 | 36 | # 构建项目 37 | pnpm build 38 | ``` 39 | 40 | ## 帮助 41 | 42 | ### 搜索 43 | 44 | 在搜索框输入文本即可搜索,默认模糊搜索文件和文件夹。除此之外,还可以: 45 | 46 | 1. 使用 `*` 手动进行模糊搜索; 47 | 48 | 2. 加上引号完全匹配名称,支持中英文引号; 49 | 50 | 3. 在搜索文本前添加:一个空格只搜索文件夹,两个空格只搜索文件; 51 | 52 | 4. 多个搜索词可用空格分开; 53 | 54 | 5. 使用 `-` 排除匹配搜索词。 55 | 56 | 示例: 57 | 58 | 1. `*txt`,搜索所有名称以“txt”结尾的文件或文件夹 59 | 60 | 2. `“图片”`,搜索名称为“图片”的文件或文件夹 61 | 62 | 3.  附件,搜索名称包含“附件”的文件夹 63 | 64 | 4. `学习 语言`,搜索名称同时包含“学习”和“语言”的文件或文件夹 65 | 66 | 5. `java -javascript`,搜索名称包含“java”而不包含”javascript“的文件或文件夹 67 | 68 | ### 筛选 69 | 70 | #### 类型筛选 71 | 72 | 根据文件类型直接进行搜索。 73 | 74 | 添加规则:多个类型用 `|` 分隔,排除用 `!`,详细类型见预览框中的类型树项,可参考默认提供的编写。 75 | 76 | #### 正则筛选 77 | 78 | 对搜索结果的每个文件路径,使用正则表达式进行过滤筛选。使用方法:在搜索文本前加上关键字,具体格式 `关键字:搜索文本`。 79 | 80 | 示例: 81 | 82 | `notlibrary:xml`,搜索名称包含“xml”的结果,并使用关键字 `notlibrary` 对应的正则表达式进行筛选 83 | 84 | ### 预览 85 | 86 | 直接预览文件、文件夹内容。支持文件夹、文本、图片、音频和视频文件的预览,可根据需要配置文件名后缀,使用逗号 `,` 分隔开。(注:图片、音频和视频文件的预览,有些格式可能无法显示) 87 | 88 | ### 问题 89 | 90 | - 搜索不到已存在的文件? 91 | 92 | 请尝试重建索引,见 https://support.apple.com/zh-cn/HT201716 93 | 94 | - 主搜索框搜索结果与插件内搜索结果不一致? 95 | 96 | 设计上就是如此,考虑到在主搜索框搜索的效率问题,搜索结果不包含系统文件,而插件内的搜索结果则是包含系统文件的。 97 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Mverything Plus 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mverything-plus", 3 | "private": true, 4 | "type": "commonjs", 5 | "scripts": { 6 | "dev": "vite", 7 | "build": "vue-tsc && vite build", 8 | "preview": "vite preview" 9 | }, 10 | "dependencies": { 11 | "@imengyu/vue3-context-menu": "^1.2.10", 12 | "@mdi/js": "^7.2.96", 13 | "@vueuse/core": "^10.1.2", 14 | "chardet": "^1.5.1", 15 | "dayjs": "^1.11.7", 16 | "fast-xml-parser": "^4.3.3", 17 | "hotkeys-js": "^3.10.2", 18 | "iconv-lite": "^0.6.3", 19 | "lodash": "^4.17.21", 20 | "mdfind": "^1.0.0", 21 | "nanoid": "^4.0.2", 22 | "pinia": "^2.1.3", 23 | "pinia-persistence": "^1.0.0", 24 | "pinyin-pro": "^3.18.4", 25 | "utools-utils": "^1.1.15", 26 | "vue": "^3.4.21", 27 | "vue-draggable-next": "^2.1.1", 28 | "vue-router": "^4.2.1", 29 | "vue-toastification": "2.0.0-rc.5", 30 | "vuetify": "^3.3.1" 31 | }, 32 | "devDependencies": { 33 | "@types/lodash": "^4.14.195", 34 | "@types/node": "^16.18.0", 35 | "@vitejs/plugin-vue": "^4.2.3", 36 | "autoprefixer": "^10.4.14", 37 | "electron": "^24.1.2", 38 | "postcss": "^8.4.23", 39 | "prettier": "^2.8.8", 40 | "prettier-plugin-tailwindcss": "^0.2.8", 41 | "sass": "^1.62.1", 42 | "tailwindcss": "^3.3.2", 43 | "typescript": "^5.0.4", 44 | "utools-api-types": "^5.0.0", 45 | "vite": "^4.3.5", 46 | "vite-plugin-utools": "^0.5.4", 47 | "vue-tsc": "^1.6.5" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /public/disk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trentlee0/mverything-plus/311efa99d62f0d23869b5d325bec8a34de54a291/public/disk.png -------------------------------------------------------------------------------- /public/exec.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trentlee0/mverything-plus/311efa99d62f0d23869b5d325bec8a34de54a291/public/exec.png -------------------------------------------------------------------------------- /public/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trentlee0/mverything-plus/311efa99d62f0d23869b5d325bec8a34de54a291/public/file.png -------------------------------------------------------------------------------- /public/folder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trentlee0/mverything-plus/311efa99d62f0d23869b5d325bec8a34de54a291/public/folder.png -------------------------------------------------------------------------------- /public/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trentlee0/mverything-plus/311efa99d62f0d23869b5d325bec8a34de54a291/public/logo.png -------------------------------------------------------------------------------- /public/plugin.json: -------------------------------------------------------------------------------- 1 | { 2 | "pluginName": "文件搜索", 3 | "author": "Trent0", 4 | "homepage": "https://github.com/trentlee0/mverything-plus", 5 | "description": "快速查找 Mac 上的文件,原 Mverything Plus", 6 | "version": "2.3.0", 7 | "logo": "logo.png", 8 | "main": "index.html", 9 | "preload": "preload.js", 10 | "platform": [ 11 | "darwin" 12 | ], 13 | "development": { 14 | "main": "http://localhost:5173" 15 | }, 16 | "pluginSetting": { 17 | "height": 545, 18 | "single": true 19 | }, 20 | "features": [ 21 | { 22 | "code": "find", 23 | "explain": "查找 Mac 上的文件", 24 | "cmds": [ 25 | "find", 26 | "查找", 27 | "文件搜索", 28 | { 29 | "type": "window", 30 | "label": "在当前文件夹中搜索", 31 | "match": { 32 | "app": [ 33 | "Finder.app" 34 | ] 35 | } 36 | }, 37 | { 38 | "type": "files", 39 | "label": "此文件夹中搜索", 40 | "fileType": "directory", 41 | "minNum": 1, 42 | "maxNum": 1 43 | }, 44 | { 45 | "type": "regex", 46 | "label": "此文件夹中搜索", 47 | "match": "/^(\\/[^/\\n\\r\\f\\v]+)+\\/?$/", 48 | "minLength": 1, 49 | "maxLength": 300 50 | }, 51 | { 52 | "type": "over", 53 | "label": "搜索", 54 | "exclude": "/[\\\\\\/\\t\\n]/", 55 | "minLength": 1, 56 | "maxLength": 100 57 | } 58 | ] 59 | }, 60 | { 61 | "code": "find-push", 62 | "mainPush": true, 63 | "explain": "快速搜索文件", 64 | "cmds": [ 65 | { 66 | "type": "regex", 67 | "label": "文件搜索", 68 | "match": "/^[ '\u2018\u2019](.*)$/", 69 | "minLength": 1, 70 | "maxLength": 100 71 | } 72 | ] 73 | } 74 | ] 75 | } -------------------------------------------------------------------------------- /public/quicklook.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Mverything Plus QuickLook 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /screenshots/list-mode-detail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trentlee0/mverything-plus/311efa99d62f0d23869b5d325bec8a34de54a291/screenshots/list-mode-detail.png -------------------------------------------------------------------------------- /screenshots/list-mode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trentlee0/mverything-plus/311efa99d62f0d23869b5d325bec8a34de54a291/screenshots/list-mode.png -------------------------------------------------------------------------------- /screenshots/preview-mode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trentlee0/mverything-plus/311efa99d62f0d23869b5d325bec8a34de54a291/screenshots/preview-mode.png -------------------------------------------------------------------------------- /src/App.vue: -------------------------------------------------------------------------------- 1 | 10 | 11 | 24 | 25 | 37 | -------------------------------------------------------------------------------- /src/assets/empty_inbox.svg: -------------------------------------------------------------------------------- 1 | Inbox Empty 2 | -------------------------------------------------------------------------------- /src/components/common/Checkbox.vue: -------------------------------------------------------------------------------- 1 | 15 | 16 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/components/common/FormItem.vue: -------------------------------------------------------------------------------- 1 | 34 | 35 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /src/components/common/Header.vue: -------------------------------------------------------------------------------- 1 | 9 | 10 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/components/common/Hover.vue: -------------------------------------------------------------------------------- 1 | 9 | 10 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/components/common/OverlayProgress.vue: -------------------------------------------------------------------------------- 1 | 15 | 16 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/components/common/SelectBox.vue: -------------------------------------------------------------------------------- 1 | 17 | 18 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /src/components/common/ShowBox.vue: -------------------------------------------------------------------------------- 1 | 12 | 13 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/components/common/Subheader.vue: -------------------------------------------------------------------------------- 1 | 9 | 10 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/components/home/DisplayMode.vue: -------------------------------------------------------------------------------- 1 | 22 | 23 | 28 | 29 | 40 | -------------------------------------------------------------------------------- /src/components/home/FileList.vue: -------------------------------------------------------------------------------- 1 | 54 | 55 | 372 | 373 | 378 | -------------------------------------------------------------------------------- /src/components/home/FileThumbnail.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/components/home/FolderSubItem.vue: -------------------------------------------------------------------------------- 1 | 20 | 21 | 52 | 53 | 62 | -------------------------------------------------------------------------------- /src/components/home/FolderViewer.vue: -------------------------------------------------------------------------------- 1 | 31 | 32 | 144 | 145 | 146 | -------------------------------------------------------------------------------- /src/components/home/Preview.vue: -------------------------------------------------------------------------------- 1 | 140 | 141 | 217 | 218 | 219 | -------------------------------------------------------------------------------- /src/components/home/SearchInput.vue: -------------------------------------------------------------------------------- 1 | 27 | 28 | 91 | 92 | 101 | -------------------------------------------------------------------------------- /src/components/home/SideNumOverlay.vue: -------------------------------------------------------------------------------- 1 | 19 | 20 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/components/home/SortOrder.vue: -------------------------------------------------------------------------------- 1 | 13 | 14 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/components/home/TextViewer.vue: -------------------------------------------------------------------------------- 1 | 43 | 44 | 113 | 114 | 124 | -------------------------------------------------------------------------------- /src/components/setting/table/BodyRow.vue: -------------------------------------------------------------------------------- 1 | 11 | 12 | 17 | 18 | 23 | -------------------------------------------------------------------------------- /src/components/setting/table/FlexTable.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/components/setting/table/HeadRow.vue: -------------------------------------------------------------------------------- 1 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/components/setting/tabs/AboutTab.vue: -------------------------------------------------------------------------------- 1 | 61 | 62 | 143 | 144 | 149 | -------------------------------------------------------------------------------- /src/components/setting/tabs/FilterTab.vue: -------------------------------------------------------------------------------- 1 | 186 | 187 | 335 | 336 | 345 | -------------------------------------------------------------------------------- /src/components/setting/tabs/GeneralTab.vue: -------------------------------------------------------------------------------- 1 | 176 | 177 | 246 | 247 | 248 | -------------------------------------------------------------------------------- /src/components/setting/tabs/PreviewTab.vue: -------------------------------------------------------------------------------- 1 | 68 | 69 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /src/constant/enums.ts: -------------------------------------------------------------------------------- 1 | export enum DisplayModeEnum { 2 | LIST = 0, 3 | PREVIEW = 1 4 | } 5 | 6 | export enum SortOrderEnum { 7 | ASC = 1, 8 | DESC = -1 9 | } 10 | 11 | export enum FilePreviewType { 12 | NONE, 13 | FOLDER, 14 | TEXT, 15 | PICTURE, 16 | AUDIO, 17 | VIDEO 18 | } 19 | 20 | export enum SimpleFilterEnum { 21 | NONE, 22 | FILE, 23 | FOLDER 24 | } 25 | 26 | export enum FindEndingStatus { 27 | NORMAL, 28 | INTERRUPTED 29 | } 30 | 31 | // 可通过命令 `mdimport -X` 查看 32 | export enum kMDItem { 33 | ContentCreationDate = 'kMDItemContentCreationDate', 34 | ContentModificationDate = 'kMDItemContentModificationDate', 35 | ContentType = 'kMDItemContentType', 36 | ContentTypeTree = 'kMDItemContentTypeTree', 37 | DateAdded = 'kMDItemDateAdded', 38 | DisplayName = 'kMDItemDisplayName', 39 | FSContentChangeDate = 'kMDItemFSContentChangeDate', 40 | FSCreationDate = 'kMDItemFSCreationDate', 41 | FSCreatorCode = 'kMDItemFSCreatorCode', 42 | FSFinderFlags = 'kMDItemFSFinderFlags', 43 | FSHasCustomIcon = 'kMDItemFSHasCustomIcon', 44 | FSInvisible = 'kMDItemFSInvisible', 45 | FSIsExtensionHidden = 'kMDItemFSIsExtensionHidden', 46 | FSIsStationery = 'kMDItemFSIsStationery', 47 | FSLabel = 'kMDItemFSLabel', 48 | FSName = 'kMDItemFSName', 49 | FSNodeCount = 'kMDItemFSNodeCount', 50 | FSOwnerGroupID = 'kMDItemFSOwnerGroupID', 51 | FSOwnerUserID = 'kMDItemFSOwnerUserID', 52 | FSSize = 'kMDItemFSSize', 53 | FSTypeCode = 'kMDItemFSTypeCode', 54 | Kind = 'kMDItemKind', 55 | LogicalSize = 'kMDItemLogicalSize', 56 | PhysicalSize = 'kMDItemPhysicalSize', 57 | LastUsedDate = 'kMDItemLastUsedDate', 58 | TextContent = 'kMDItemTextContent', 59 | TextContentLanguage = 'kMDItemTextContentLanguage', 60 | Version = 'kMDItemVersion', 61 | WhereFroms = 'kMDItemWhereFroms', 62 | UserTags = 'kMDItemUserTags', 63 | SupportFileType = 'kMDItemSupportFileType' 64 | } 65 | -------------------------------------------------------------------------------- /src/constant/index.ts: -------------------------------------------------------------------------------- 1 | export * from './enums' 2 | 3 | export namespace StoreKey { 4 | export const SETTING = 'setting' 5 | export const DISPLAY_MODE = 'displayItemIndex' 6 | export const IS_PREVIEW_CONTENT = 'enablePreviewContent' 7 | export const IS_SHOW_RECENT = 'enableShowRecent' 8 | } 9 | 10 | export namespace FileConstant { 11 | export const KB = 1000 12 | export const MB = KB * 1000 13 | export const GB = MB * 1000 14 | 15 | export const KiB = 1 << 10 16 | export const MiB = 1 << 20 17 | export const GiB = 1 << 30 18 | } 19 | 20 | export namespace ContentType { 21 | export const FOLDER = 'public.folder' 22 | 23 | export const IMAGE = 'public.image' 24 | export const AUDIO = 'public.audio' 25 | 26 | export const MOVIE = 'public.movie' 27 | export const MPEG2_TS = 'public.mpeg-2-transport-stream' 28 | 29 | export const PDF = 'com.adobe.pdf' 30 | export const PRESENTATION = 'public.presentation' 31 | 32 | export const PAGES = 'com.apple.iwork.pages.sfftemplate' 33 | export const DOC = 'com.microsoft.word.doc' 34 | export const DOCX = 'org.openxmlformats.wordprocessingml.document' 35 | 36 | export const SPREADSHEET = 'public.spreadsheet' 37 | export const XLS = 'com.microsoft.excel.xls' 38 | export const XLSX = 'org.openxmlformats.spreadsheetml.sheet' 39 | 40 | export const TEXT = 'public.text' 41 | export const PLAIN_TEXT = 'public.plain-text' 42 | export const MARKDOWN = 'net.daringfireball.markdown' 43 | export const SOURCE_CODE = 'public.source-code' 44 | 45 | export const ARCHIVE = 'public.archive' 46 | 47 | export const APPLICATION = 'com.apple.application' 48 | 49 | export const EXECUTABLE = 'public.unix-executable' 50 | 51 | export const VOLUME = 'public.volume' 52 | 53 | export const DIRECTORY = 'public.directory' 54 | 55 | export const ITEM = 'public.item' 56 | } 57 | 58 | export namespace ScopeName { 59 | export const HOME = 'home' 60 | export const SETTING = 'setting' 61 | } 62 | -------------------------------------------------------------------------------- /src/directives/index.ts: -------------------------------------------------------------------------------- 1 | import { App, nextTick, DirectiveBinding } from 'vue' 2 | 3 | function vTitle(el: HTMLElement, binding: DirectiveBinding) { 4 | nextTick(() => { 5 | const { clientWidth, scrollWidth } = el 6 | if (clientWidth < scrollWidth) { 7 | el.title = binding.value ?? el.innerText 8 | } 9 | }) 10 | } 11 | 12 | export default { 13 | install: (app: App) => { 14 | app.directive('title', { 15 | mounted: vTitle, 16 | updated: vTitle 17 | }) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/hooks/useActivated.ts: -------------------------------------------------------------------------------- 1 | import { onActivated } from 'vue' 2 | 3 | export function onNonFirstActivated(hook: Function) { 4 | let isFirst = true 5 | onActivated(() => { 6 | if (isFirst) { 7 | isFirst = false 8 | } else { 9 | hook() 10 | } 11 | }) 12 | } 13 | -------------------------------------------------------------------------------- /src/hooks/useContextMenu.ts: -------------------------------------------------------------------------------- 1 | import ContextMenu, { MenuItem } from '@imengyu/vue3-context-menu' 2 | import { useDark } from './useDark' 3 | 4 | export interface RightMenuItem { 5 | type?: 'normal' | 'separator' | 'submenu' 6 | label?: string 7 | click?: () => void 8 | submenu?: RightMenuItem[] 9 | } 10 | 11 | function toMenuItems(items?: RightMenuItem[]): MenuItem[] | undefined { 12 | return items 13 | ?.map((item, index) => ({ 14 | label: item.label, 15 | onClick: item.click, 16 | divided: index + 1 < items.length && items[index + 1].type === 'separator', 17 | children: toMenuItems(item.submenu) 18 | })) 19 | .filter((item) => item.label !== undefined) 20 | } 21 | 22 | export function closeContextMenu() { 23 | ContextMenu.closeContextMenu() 24 | } 25 | 26 | export function useContextMenu(menuItems?: RightMenuItem[]) { 27 | const { isDark } = useDark() 28 | 29 | return { 30 | showMenu(pos: { x: number; y: number }, items?: RightMenuItem[]) { 31 | ContextMenu.showContextMenu({ 32 | zIndex: 11, 33 | x: pos.x, 34 | y: pos.y, 35 | theme: isDark.value ? 'macos-dark' : 'macos-light', 36 | items: toMenuItems(items || menuItems) 37 | }) 38 | }, 39 | closeMenu() { 40 | ContextMenu.closeContextMenu() 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/hooks/useDark.ts: -------------------------------------------------------------------------------- 1 | import { computed } from 'vue' 2 | import { onBeforeUnmount } from 'vue' 3 | import { onBeforeMount } from 'vue' 4 | import { useTheme } from 'vuetify' 5 | 6 | export function useDark() { 7 | const theme = useTheme() 8 | 9 | function setThemeName(dark: boolean) { 10 | theme.global.name.value = dark ? 'dark' : 'light' 11 | } 12 | 13 | return { 14 | isDark: computed(() => theme.global.current.value.dark), 15 | setDark(dark: boolean = true) { 16 | setThemeName(dark) 17 | }, 18 | autoDark() { 19 | const matchMedia = window.matchMedia('(prefers-color-scheme: dark)') 20 | const handler = (e: MediaQueryListEvent) => setThemeName(e.matches) 21 | 22 | onBeforeMount(() => { 23 | setThemeName(matchMedia.matches) 24 | matchMedia.addEventListener('change', handler) 25 | }) 26 | 27 | onBeforeUnmount(() => { 28 | matchMedia.removeEventListener('change', handler) 29 | }) 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/hooks/useEventListener.ts: -------------------------------------------------------------------------------- 1 | import { onBeforeUnmount, onMounted } from 'vue' 2 | 3 | export function useEventListener( 4 | type: K, 5 | listener: (this: Window, ev: WindowEventMap[K]) => any 6 | ): void { 7 | onMounted(() => { 8 | window.addEventListener(type, listener) 9 | }) 10 | 11 | onBeforeUnmount(() => { 12 | window.removeEventListener(type, listener) 13 | }) 14 | } 15 | -------------------------------------------------------------------------------- /src/hooks/useHotkeys.ts: -------------------------------------------------------------------------------- 1 | import hotkeys, { KeyHandler } from 'hotkeys-js' 2 | import { computed, onBeforeMount, onBeforeUnmount, ref } from 'vue' 3 | 4 | type Options = { 5 | scope?: string 6 | element?: HTMLElement | null 7 | keyup?: boolean | null 8 | keydown?: boolean | null 9 | capture?: boolean 10 | splitKey?: string 11 | } 12 | 13 | // 关闭过滤 14 | hotkeys.filter = (e) => true 15 | 16 | export function useHotkeys(key: string, method: KeyHandler, options?: Options) { 17 | if (options) { 18 | onBeforeMount(() => hotkeys(key, options, method)) 19 | } else { 20 | onBeforeMount(() => hotkeys(key, method)) 21 | } 22 | onBeforeUnmount(() => hotkeys.unbind(key)) 23 | } 24 | 25 | const currentScope = ref('all') 26 | 27 | export function useHotkeysScope(scopeName: string) { 28 | onBeforeUnmount(() => hotkeys.deleteScope(scopeName)) 29 | const isCurrentScope = computed( 30 | () => currentScope.value === 'all' || currentScope.value === scopeName 31 | ) 32 | 33 | return { 34 | setScope() { 35 | hotkeys.setScope(scopeName) 36 | currentScope.value = scopeName 37 | }, 38 | currentScope, 39 | isCurrentScope 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/hooks/useKeyLongPress.ts: -------------------------------------------------------------------------------- 1 | import { onBeforeUnmount, onMounted } from 'vue' 2 | 3 | export function useKeyLongPress( 4 | key: string, 5 | handler: (event: KeyboardEvent) => void, 6 | cancelHandler: (event: KeyboardEvent, isKeyUp: boolean) => void, 7 | timeout: number 8 | ) { 9 | const checkKey = (e: KeyboardEvent) => e.key === key 10 | 11 | let timer: number 12 | const handleDown = (e: KeyboardEvent) => { 13 | if (checkKey(e)) { 14 | window.clearTimeout(timer) 15 | timer = window.setTimeout(() => { 16 | handler(e) 17 | }, timeout) 18 | } else { 19 | window.clearTimeout(timer) 20 | cancelHandler(e, false) 21 | } 22 | } 23 | const handleUp = (e: KeyboardEvent) => { 24 | if (checkKey(e)) { 25 | window.clearTimeout(timer) 26 | cancelHandler(e, true) 27 | } else { 28 | window.clearTimeout(timer) 29 | } 30 | } 31 | onMounted(() => { 32 | window.addEventListener('keydown', handleDown) 33 | window.addEventListener('keyup', handleUp) 34 | }) 35 | 36 | onBeforeUnmount(() => { 37 | window.removeEventListener('keydown', handleDown) 38 | window.removeEventListener('keyup', handleUp) 39 | }) 40 | } 41 | -------------------------------------------------------------------------------- /src/hooks/useLastState.ts: -------------------------------------------------------------------------------- 1 | export function useLastState(compareFn: (a: T, b: T) => boolean = (a: T, b: T) => a === b) { 2 | const lastState = { value: >null } 3 | return { 4 | lastState, 5 | isEqualLast(newValue: T) { 6 | const ret = lastState.value === null ? false : compareFn(newValue, lastState.value) 7 | lastState.value = newValue 8 | return ret 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/hooks/useMouse.ts: -------------------------------------------------------------------------------- 1 | import { onBeforeMount } from 'vue' 2 | import { onBeforeUnmount } from 'vue' 3 | import { ref } from 'vue' 4 | 5 | interface MouseOptions { 6 | delay?: number 7 | } 8 | 9 | export function useMouse(options?: MouseOptions) { 10 | const isMouseMove = ref(false) 11 | const position = ref<{ x: number; y: number }>({ x: 0, y: 0 }) 12 | 13 | let mouseMoveTimer: number 14 | 15 | const handler = (e: MouseEvent) => { 16 | position.value.x = e.clientX 17 | position.value.y = e.clientY 18 | 19 | isMouseMove.value = true 20 | window.clearTimeout(mouseMoveTimer) 21 | mouseMoveTimer = window.setTimeout( 22 | () => (isMouseMove.value = false), 23 | options?.delay ?? 200 24 | ) 25 | } 26 | 27 | onBeforeMount(() => { 28 | window.addEventListener('mousemove', handler) 29 | }) 30 | 31 | onBeforeUnmount(() => { 32 | window.clearTimeout(mouseMoveTimer) 33 | window.removeEventListener('mousemove', handler) 34 | }) 35 | 36 | return { 37 | isMouseMove, 38 | position 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import { createApp } from 'vue' 2 | import './style.css' 3 | import App from './App.vue' 4 | import pinia from './store' 5 | import router from './router' 6 | import directives from './directives' 7 | import vuetify from './plugins/vuetify' 8 | import toastification from './plugins/toastification' 9 | import contextMenu from './plugins/context-menu' 10 | 11 | createApp(App) 12 | .use(pinia) 13 | .use(router) 14 | .use(directives) 15 | .use(vuetify) 16 | .use(toastification) 17 | .use(contextMenu) 18 | .mount('#app') 19 | -------------------------------------------------------------------------------- /src/models/KindFilterModel.ts: -------------------------------------------------------------------------------- 1 | import { ContentType } from '@/constant' 2 | 3 | /** 4 | * 文件类型筛选 5 | */ 6 | export class KindFilterModel { 7 | id: string 8 | label: string 9 | // 规则:多个文件类型用 `|` 分隔开,排除用 `!` 10 | value: string 11 | enabled: boolean 12 | 13 | constructor( 14 | id: string | number, 15 | label: string, 16 | value: string, 17 | enabled: boolean = true 18 | ) { 19 | this.id = typeof id === 'number' ? id.toString() : id 20 | this.label = label 21 | this.value = value 22 | this.enabled = enabled 23 | } 24 | 25 | public static readonly ANY = new KindFilterModel(0, '不筛选', '') 26 | 27 | public static DEFAULT_KINDS = this.defaultKindFilters() 28 | 29 | public static defaultKindFilters() { 30 | let id = 0 31 | const movieFilter = `${ContentType.MOVIE}!${ContentType.MPEG2_TS}` 32 | const wordFilter = [ 33 | ContentType.PAGES, 34 | ContentType.DOC, 35 | ContentType.DOCX 36 | ].join('|') 37 | return [ 38 | new KindFilterModel(id++, '不筛选', ''), 39 | new KindFilterModel(id++, '图片', ContentType.IMAGE), 40 | new KindFilterModel(id++, '音频', ContentType.AUDIO), 41 | new KindFilterModel(id++, '视频', movieFilter), 42 | new KindFilterModel(id++, 'PDF', ContentType.PDF), 43 | new KindFilterModel(id++, 'WORD', wordFilter), 44 | new KindFilterModel(id++, 'EXCEL', ContentType.SPREADSHEET), 45 | new KindFilterModel(id++, 'PPT', ContentType.PRESENTATION), 46 | new KindFilterModel(id++, '应用程序', ContentType.APPLICATION, false), 47 | new KindFilterModel(id++, '文件夹', ContentType.FOLDER, false), 48 | new KindFilterModel(id++, '压缩包', ContentType.ARCHIVE, false), 49 | new KindFilterModel(id++, 'MD', ContentType.MARKDOWN, false) 50 | ] 51 | } 52 | } 53 | 54 | export default KindFilterModel 55 | -------------------------------------------------------------------------------- /src/models/SearchScopeModel.ts: -------------------------------------------------------------------------------- 1 | import { getOsUserInfo, getVolumes } from '@/preload' 2 | 3 | export class SearchScopeModel { 4 | public static readonly ROOT_ID = 'root' 5 | public static readonly USER_ID = 'user' 6 | public static readonly COMMON_ID = 'common' 7 | 8 | id: string 9 | label: string 10 | paths: string[] 11 | 12 | constructor(id: string, label: string, paths: string[]) { 13 | this.id = id 14 | this.label = label 15 | this.paths = paths 16 | } 17 | 18 | public static readonly ROOT = new SearchScopeModel(SearchScopeModel.ROOT_ID, '这台 Mac', ['/']) 19 | 20 | public static readonly USER = new SearchScopeModel(SearchScopeModel.USER_ID, '', []) 21 | 22 | public static readonly COMMON = new SearchScopeModel(SearchScopeModel.COMMON_ID, '常用', []) 23 | 24 | static { 25 | const info = getOsUserInfo() 26 | SearchScopeModel.USER.label = info.username 27 | SearchScopeModel.USER.paths = [info.homedir] 28 | 29 | SearchScopeModel.COMMON.paths = [ 30 | '/Applications', 31 | '/System/Applications', 32 | '/System/Library/CoreServices', 33 | '/Library/Developer', 34 | info.homedir 35 | ] 36 | } 37 | 38 | private static DEFAULT_SCOPES: SearchScopeModel[] = [ 39 | SearchScopeModel.ROOT, 40 | SearchScopeModel.USER, 41 | SearchScopeModel.COMMON 42 | ] 43 | 44 | public static defaultSearchScopes() { 45 | return SearchScopeModel.DEFAULT_SCOPES 46 | } 47 | 48 | public static async refreshDefaultSearchScopes() { 49 | const scopes = [SearchScopeModel.ROOT] 50 | const volumes = await getVolumes() 51 | volumes.forEach((v, index) => { 52 | scopes.push(new SearchScopeModel(index + v.name, v.name, [v.path])) 53 | }) 54 | SearchScopeModel.ROOT.paths = ['/', ...volumes.map((v) => v.path)] 55 | scopes.push(SearchScopeModel.USER) 56 | scopes.push(SearchScopeModel.COMMON) 57 | SearchScopeModel.DEFAULT_SCOPES = scopes 58 | return SearchScopeModel.DEFAULT_SCOPES 59 | } 60 | } 61 | 62 | export default SearchScopeModel 63 | -------------------------------------------------------------------------------- /src/models/SettingModel.ts: -------------------------------------------------------------------------------- 1 | import KindFilterModel from './KindFilterModel' 2 | import SearchScopeModel from './SearchScopeModel' 3 | 4 | export interface KeyRegexItem { 5 | key: string 6 | regex: string 7 | } 8 | 9 | export interface HighlightConfig { 10 | enabled: boolean 11 | style: string 12 | } 13 | 14 | export class SettingModel { 15 | databaseVersion: number 16 | isFindFileContent: boolean 17 | searchRoot: string 18 | searchScopes: Array 19 | searchKey: ':' 20 | keyList: Array 21 | fileExtension: string 22 | pictureExtension: string 23 | audioExtension: string 24 | videoExtension: string 25 | isAutoSearch: boolean 26 | isShowFilesInTempDir: boolean 27 | isUseSystemFileIcon: boolean 28 | isShowFilesInKind: boolean 29 | nameHighlight: HighlightConfig 30 | kindFilters: Array 31 | isOpenAsShortcutting: boolean 32 | isUseSubInput: boolean 33 | 34 | constructor() { 35 | // default setting 36 | this.databaseVersion = 6 37 | this.isFindFileContent = false 38 | this.searchRoot = SearchScopeModel.COMMON_ID 39 | this.searchScopes = [] 40 | this.searchKey = ':' 41 | this.keyList = [ 42 | { 43 | key: 'notlibrary', 44 | regex: '^((?!Library).)*$' 45 | } 46 | ] 47 | this.fileExtension = 'vue,ts,jsx,dart,ps1' 48 | this.pictureExtension = 'png,jpg,jpeg,webp,gif,svg,ico,bmp' 49 | this.audioExtension = 'mp3,ogg,wav,m4a' 50 | this.videoExtension = 'mp4,flv,mov,webm' 51 | this.isAutoSearch = true 52 | this.isShowFilesInTempDir = true 53 | this.isUseSystemFileIcon = false 54 | this.isShowFilesInKind = true 55 | this.nameHighlight = { 56 | enabled: false, 57 | style: 'color: red;' 58 | } 59 | this.kindFilters = KindFilterModel.defaultKindFilters() 60 | this.isOpenAsShortcutting = false 61 | this.isUseSubInput = true 62 | } 63 | 64 | public static migrateDatabase(setting: SettingModel): boolean { 65 | let needed = false 66 | const check = (version: number) => { 67 | if (!setting.databaseVersion || setting.databaseVersion < version) { 68 | setting.databaseVersion = version 69 | needed = true 70 | return true 71 | } 72 | return false 73 | } 74 | 75 | const defaultSetting = new SettingModel() 76 | if (check(1)) { 77 | setting.fileExtension = defaultSetting.fileExtension 78 | setting.pictureExtension = defaultSetting.pictureExtension 79 | } 80 | if (check(3)) { 81 | setting.videoExtension = defaultSetting.videoExtension 82 | setting.audioExtension = defaultSetting.audioExtension 83 | } 84 | if (check(4)) { 85 | setting.isAutoSearch = defaultSetting.isAutoSearch 86 | setting.isShowFilesInTempDir = defaultSetting.isShowFilesInTempDir 87 | setting.isUseSystemFileIcon = defaultSetting.isUseSystemFileIcon 88 | } 89 | if (check(5)) { 90 | setting.searchScopes = defaultSetting.searchScopes 91 | setting.isShowFilesInKind = defaultSetting.isShowFilesInKind 92 | setting.nameHighlight = defaultSetting.nameHighlight 93 | setting.kindFilters = defaultSetting.kindFilters 94 | setting.isOpenAsShortcutting = defaultSetting.isOpenAsShortcutting 95 | } 96 | if (check(6)) { 97 | setting.isUseSubInput = defaultSetting.isUseSubInput 98 | } 99 | return needed 100 | } 101 | } 102 | 103 | export default SettingModel 104 | -------------------------------------------------------------------------------- /src/models/index.ts: -------------------------------------------------------------------------------- 1 | import { FilePreviewType } from '@/constant' 2 | 3 | export * from './KindFilterModel' 4 | export * from './SearchScopeModel' 5 | export * from './SettingModel' 6 | 7 | // ========================= Raw File Metadata ========================= 8 | 9 | export interface PrimaryFileMetadata { 10 | kMDItemContentType: string 11 | kMDItemKind: string 12 | kMDItemDisplayName: string 13 | kMDItemFSSize: string | null 14 | kMDItemContentCreationDate: string | null 15 | kMDItemContentModificationDate: string | null 16 | kMDItemFSCreationDate: string | null 17 | kMDItemFSContentChangeDate: string | null 18 | kMDItemLastUsedDate: string | null 19 | kMDItemUserTags: string[] 20 | } 21 | 22 | export interface FindFileMetadata extends PrimaryFileMetadata { 23 | kMDItemPath: string 24 | } 25 | 26 | export interface ExtraFileMetadata { 27 | kMDItemContentCreationDate?: Date 28 | kMDItemContentModificationDate?: Date 29 | kMDItemContentType?: string 30 | kMDItemContentTypeTree?: string[] 31 | kMDItemCopyright?: string 32 | kMDItemExecutableArchitectures?: string[] 33 | kMDItemFSName?: string 34 | kMDItemFSNodeCount?: number 35 | kMDItemFSSize?: number 36 | kMDItemKind?: string 37 | kMDItemLastUsedDate?: Date 38 | kMDItemPixelHeight?: number 39 | kMDItemPixelWidth?: number 40 | kMDItemUserTags?: string[] 41 | kMDItemVersion?: string 42 | } 43 | 44 | // ========================= File Info ========================= 45 | 46 | export interface BaseFileInfo { 47 | name: string 48 | displayName: string 49 | path: string 50 | displayPath: string 51 | icon: string 52 | size: number | null 53 | type: string 54 | kind: string 55 | createDate?: string | Date | null 56 | updateDate?: string | Date | null 57 | usedDate?: string | Date | null 58 | } 59 | 60 | export interface PreviewFileInfo extends BaseFileInfo { 61 | thumbnail?: string 62 | typeTree: string[] 63 | previewType: FilePreviewType 64 | isCloudFile: boolean 65 | itemCount?: number 66 | pixelWidth?: number 67 | pixelHeight?: number 68 | fileText?: string 69 | readTextSize?: number 70 | textEncoding?: string 71 | files?: Array 72 | tags?: string[] 73 | version?: string 74 | architectures?: string[] 75 | copyright?: string 76 | } 77 | 78 | export interface SimpleFileInfo { 79 | name: string 80 | isDirectory: boolean 81 | } 82 | -------------------------------------------------------------------------------- /src/plugins/context-menu.ts: -------------------------------------------------------------------------------- 1 | import '@imengyu/vue3-context-menu/lib/vue3-context-menu.css' 2 | import '@/styles/context-menu.scss' 3 | import ContextMenu from '@imengyu/vue3-context-menu' 4 | 5 | export default ContextMenu 6 | -------------------------------------------------------------------------------- /src/plugins/toastification.ts: -------------------------------------------------------------------------------- 1 | import { App } from 'vue' 2 | import Toast, { PluginOptions } from 'vue-toastification' 3 | import 'vue-toastification/dist/index.css' 4 | 5 | const options: PluginOptions = { 6 | timeout: 2000, 7 | bodyClassName: 'custom-toast-body-class' 8 | } 9 | 10 | export default { 11 | install: (app: App) => { 12 | app.use(Toast, options) 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/plugins/vuetify.ts: -------------------------------------------------------------------------------- 1 | import 'vuetify/styles' 2 | import { createVuetify } from 'vuetify' 3 | import * as components from 'vuetify/components' 4 | import * as directives from 'vuetify/directives' 5 | import { aliases, mdi } from 'vuetify/iconsets/mdi-svg' 6 | 7 | const vuetify = createVuetify({ 8 | defaults: { 9 | global: { 10 | } 11 | }, 12 | components: { 13 | ...components 14 | }, 15 | directives, 16 | icons: { 17 | defaultSet: 'mdi', 18 | aliases, 19 | sets: { 20 | mdi 21 | } 22 | } 23 | }) 24 | 25 | export default vuetify 26 | -------------------------------------------------------------------------------- /src/preload.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | import { ExtraFileMetadata, FindFileMetadata, PrimaryFileMetadata, SimpleFileInfo } from '@/models' 5 | 6 | import { 7 | createReadStream, 8 | existsSync, 9 | lstatSync, 10 | mkdirSync, 11 | readlinkSync, 12 | stat, 13 | statSync, 14 | writeFileSync 15 | } from 'fs' 16 | import path, { basename, dirname, extname, isAbsolute, join, resolve } from 'path' 17 | import os, { UserInfo } from 'os' 18 | import { Buffer } from 'buffer' 19 | import mdfind from 'mdfind' 20 | import chardet from 'chardet' 21 | import iconv from 'iconv-lite' 22 | import { ContentType, FileConstant, FindEndingStatus } from '@/constant' 23 | import { execAppleScript } from 'utools-utils/preload' 24 | import { MainPushItem, getFileIcon, getPath } from 'utools-api' 25 | import { MdfindProcessManager } from '@/utils/mdfinds' 26 | import { readdir } from 'fs/promises' 27 | import { decodeUnicode, escapeQuote } from './utils/strings' 28 | import { execFile, execFileSync } from 'child_process' 29 | import { parsePlist } from './utils/plist' 30 | 31 | const mdfindManager = new MdfindProcessManager() 32 | 33 | function spotlight( 34 | query: string, 35 | directories: string[], 36 | attributes: Array, 37 | limit?: number 38 | ): Promise> { 39 | mdfindManager.killCurrent() 40 | return new Promise((resolve, reject) => { 41 | const res = mdfind({ 42 | query, 43 | attributes, 44 | names: [], 45 | directories, 46 | limit 47 | }) 48 | const currentTask = mdfindManager.add(res) 49 | if (res.output) { 50 | const data: Array = [] 51 | res.output.on('data', (chunk) => data.push(chunk)) 52 | res.output.on('end', () => { 53 | // 防止已终止的 mdfind 子进程还返回数据 54 | if (!mdfindManager.isInterruptLastTask()) { 55 | resolve(data) 56 | } 57 | mdfindManager.markTaskAsEnd(currentTask) 58 | }) 59 | res.output.on('error', (err) => reject(err)) 60 | } else { 61 | resolve([]) 62 | } 63 | }) 64 | } 65 | 66 | function getFindAttributes(): Array { 67 | return [ 68 | 'kMDItemContentType', 69 | 'kMDItemKind', 70 | 'kMDItemDisplayName', 71 | 'kMDItemFSSize', 72 | 'kMDItemContentCreationDate', 73 | 'kMDItemContentModificationDate', 74 | 'kMDItemFSCreationDate', 75 | 'kMDItemFSContentChangeDate', 76 | 'kMDItemLastUsedDate' 77 | ] 78 | } 79 | 80 | export function findCallback( 81 | query: string, 82 | directories: string[], 83 | callback: (data: FindFileMetadata | null, index: number, endingStatus?: FindEndingStatus) => void, 84 | filter: RegExp | null, 85 | limit?: number 86 | ) { 87 | mdfindManager.killCurrent() 88 | const res = mdfind({ 89 | query, 90 | directories, 91 | attributes: getFindAttributes(), 92 | names: [], 93 | limit 94 | }) 95 | if (!res.output) return 96 | 97 | const currentTask = mdfindManager.add(res) 98 | let length = 0 99 | if (filter) { 100 | res.output.on('data', (chunk: FindFileMetadata) => { 101 | if (!filter.test(chunk.kMDItemPath)) return 102 | callback(chunk, ++length) 103 | }) 104 | } else { 105 | res.output.on('data', (chunk) => callback(chunk, ++length)) 106 | } 107 | res.output.on('end', () => { 108 | if (mdfindManager.isLastTask(currentTask)) { 109 | callback( 110 | null, 111 | length, 112 | mdfindManager.isInterruptLastTask() ? FindEndingStatus.INTERRUPTED : FindEndingStatus.NORMAL 113 | ) 114 | } 115 | mdfindManager.markTaskAsEnd(currentTask) 116 | }) 117 | } 118 | 119 | export async function findPush( 120 | query: string, 121 | directories: string[], 122 | limit: number 123 | ): Promise> { 124 | const attributes: Array = [ 125 | 'kMDItemDisplayName', 126 | 'kMDItemContentType', 127 | 'kMDItemUserTags' 128 | ] 129 | return (await spotlight(query, directories, attributes, limit)).map((v) => ({ 130 | text: v.kMDItemDisplayName, 131 | title: v.kMDItemPath, 132 | icon: getFileIconPath(v.kMDItemPath, v.kMDItemContentType), 133 | tags: v.kMDItemUserTags?.map(decodeUnicode) 134 | })) 135 | } 136 | 137 | function getEmbeddedIcon(contentType: string) { 138 | if (contentType === ContentType.FOLDER) return 'folder.png' 139 | if (contentType === ContentType.EXECUTABLE) return 'exec.png' 140 | if (contentType === ContentType.VOLUME) return 'disk.png' 141 | return null 142 | } 143 | 144 | function saveFileIcon(base64Icon: string, key: string) { 145 | const data = Buffer.from(base64Icon.replace(/^data:image\/\w+;base64,/, ''), 'base64') 146 | const basePath = resolve(getPath('temp'), 'utools-mverything-plus') 147 | if (!existsSync(basePath)) { 148 | mkdirSync(basePath) 149 | } 150 | const imgPath = `${basePath}/file-icon-${key}.png` 151 | if (!existsSync(imgPath)) { 152 | writeFileSync(imgPath, data) 153 | } 154 | return imgPath 155 | } 156 | 157 | function getAppIcon(appPath: string) { 158 | if (lstatSync(appPath).isSymbolicLink()) { 159 | const realPath = readlinkSync(appPath) 160 | if (isAbsolute(realPath)) { 161 | appPath = realPath 162 | } else { 163 | appPath = resolve(dirname(appPath), realPath) 164 | } 165 | } 166 | return getFileIcon(appPath) 167 | } 168 | 169 | function getFileIconPath(filePath: string, contentType: string) { 170 | const embeddedIcon = getEmbeddedIcon(contentType) 171 | if (embeddedIcon) return embeddedIcon 172 | 173 | const ext = extname(filePath) 174 | if (ext) { 175 | return ( 176 | 'file://' + 177 | (filePath.endsWith('.app') 178 | ? saveFileIcon(getAppIcon(filePath), basename(filePath)) 179 | : saveFileIcon(getFileIcon(ext), ext)) 180 | ) 181 | } 182 | return 'file.png' 183 | } 184 | 185 | export function getFileIconBase64(filePath: string, contentType: string) { 186 | const embeddedIcon = getEmbeddedIcon(contentType) 187 | if (embeddedIcon) return embeddedIcon 188 | 189 | if (filePath.endsWith('.app')) return getAppIcon(filePath) 190 | 191 | const ext = extname(filePath) 192 | if (ext && contentType !== ContentType.DIRECTORY) return getFileIcon(ext) 193 | if (dirname(filePath) === '/Volumes') return 'disk.png' 194 | if (contentType === ContentType.DIRECTORY) return 'folder.png' 195 | return 'file.png' 196 | } 197 | 198 | export async function find(query: string, directories: string[], filter: RegExp | null, limit?: number) { 199 | const res = await spotlight(query, directories, getFindAttributes(), limit) 200 | return filter ? res.filter((item) => filter.test(item.kMDItemPath)) : res 201 | } 202 | 203 | export function killFind() { 204 | return mdfindManager.killCurrent() 205 | } 206 | 207 | export function getFileMetadata(filePath: string) { 208 | return new Promise((resolve, reject) => { 209 | execFile('mdls', ['-plist', '-', filePath], (error, stdout) => { 210 | if (error) return reject(error) 211 | resolve(parsePlist(stdout)) 212 | }) 213 | }) 214 | } 215 | 216 | export function trashFile(filePath: string | string[]) { 217 | if (typeof filePath === 'string') filePath = [filePath] 218 | const script = ` 219 | tell application "Finder" 220 | set moveList to {${filePath.map(p => `"${escapeQuote(p)}" as POSIX file`).join(',')}} 221 | move moveList to trash 222 | end tell` 223 | execFileSync('osascript', ['-e', script]) 224 | } 225 | 226 | export function readFilePartText(filePath: string): Promise<{ 227 | text: string 228 | encoding: string 229 | partialSize: number 230 | size: number 231 | }> { 232 | return new Promise((resolve, reject) => { 233 | const st = lstatSync(filePath) 234 | const stream = createReadStream(filePath, { 235 | flags: 'r', 236 | highWaterMark: 128 * FileConstant.KB, 237 | start: 0 238 | }) 239 | .on('data', (data) => { 240 | stream.close() 241 | const res = data as Buffer 242 | const encoding = chardet.detect(res) 243 | if (encoding !== null) { 244 | resolve({ 245 | text: iconv.decode(res, encoding), 246 | encoding, 247 | partialSize: res.byteLength, 248 | size: st.size 249 | }) 250 | } else { 251 | throw new Error('The encoding of the detected file is null! File: ' + filePath) 252 | } 253 | }) 254 | .on('error', reject) 255 | }) 256 | } 257 | 258 | export async function readFileList(dirPath: string) { 259 | const st = lstatSync(dirPath) 260 | if (!st.isDirectory()) return null 261 | // 获取并过滤隐藏文件 262 | const files = await readdir(dirPath) 263 | const excludedFiles = ['Icon\r', '$RECYCLE.BIN', 'desktop.ini'] 264 | return files 265 | .filter((item) => !item.startsWith('.') && !excludedFiles.includes(item)) 266 | .map((name) => { 267 | const st = lstatSync(path.join(dirPath, name)) 268 | return { 269 | name, 270 | isDirectory: st.isDirectory() 271 | } 272 | }) 273 | } 274 | 275 | export function existsDir(dirPath: string): Promise { 276 | return new Promise((resolve) => { 277 | stat(dirPath, (err, stat) => { 278 | resolve(err ? false : stat.isDirectory()) 279 | }) 280 | }) 281 | } 282 | 283 | export function existsFile(path: string) { 284 | return existsSync(path) 285 | } 286 | 287 | export function getOsUserInfo(): UserInfo { 288 | return os.userInfo() 289 | } 290 | 291 | export function getBasename(path: string) { 292 | return basename(path) 293 | } 294 | 295 | export function getDirname(path: string) { 296 | return dirname(path) 297 | } 298 | 299 | export function joinPath(...paths: string[]) { 300 | return join(...paths) 301 | } 302 | 303 | export interface VolumeInfo { 304 | name: string 305 | path: string 306 | } 307 | 308 | interface DiskInfo { 309 | AllDisks: string[] 310 | AllDisksAndPartitions: AllDisksAndPartition[] 311 | VolumesFromDisks: string[] 312 | WholeDisks: string[] 313 | } 314 | 315 | interface AllDisksAndPartition { 316 | Content: string 317 | DeviceIdentifier: string 318 | OSInternal: boolean 319 | Partitions: Partition[] 320 | Size: number 321 | } 322 | 323 | interface Partition { 324 | Content: string 325 | DeviceIdentifier: string 326 | MountPoint?: string 327 | Size: number 328 | VolumeName?: string 329 | VolumeUUID?: string 330 | } 331 | 332 | export async function getVolumes() { 333 | return new Promise>((resolve, reject) => { 334 | execFile('diskutil', ['list', '-plist', 'external'], (error, stdout) => { 335 | if (error) return reject(error) 336 | resolve( 337 | parsePlist(stdout).AllDisksAndPartitions.flatMap((item) => { 338 | return item.Partitions.filter((p) => !!p.MountPoint).map((p) => { 339 | const name = p.VolumeName as string 340 | const path = p.MountPoint as string 341 | return { name, path } 342 | }) 343 | }) 344 | ) 345 | }) 346 | }) 347 | } 348 | 349 | export function openInfoWindow(paths: string | string[]) { 350 | if (typeof paths === 'string') paths = [paths] 351 | const openScript = (p: string) => { 352 | p = escapeQuote(p) 353 | if (!p.startsWith('/System')) return `open information window of ((POSIX file "${p}") as alias)` 354 | return ` 355 | activate reveal (POSIX file "${p}") as alias 356 | tell application "System Events" 357 | click menu item "显示简介" of menu "文件" of menu bar item "文件" of menu bar 1 of process "Finder" 358 | end tell` 359 | } 360 | const script = ` 361 | tell application "Finder" 362 | ${paths.map(openScript).join('\n')} 363 | activate information window 364 | end tell` 365 | execFileSync('osascript', ['-e', script]) 366 | } 367 | 368 | export function openFile(path: string) { 369 | execFileSync('open', [path]) 370 | } 371 | 372 | export function isLocalFile(path: string) { 373 | try { 374 | const st = statSync(path) 375 | if (st.isDirectory()) return true 376 | return !(st.size !== 0 && st.blocks === 0) 377 | } catch (err) { 378 | return false 379 | } 380 | } 381 | -------------------------------------------------------------------------------- /src/router/index.ts: -------------------------------------------------------------------------------- 1 | import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router' 2 | import Home from '@/views/Home.vue' 3 | 4 | const routes: Array = [ 5 | { 6 | path: '/', 7 | name: 'Home', 8 | component: Home 9 | }, 10 | { 11 | path: '/setting', 12 | name: 'Setting', 13 | component: () => import('@/views/Setting.vue') 14 | } 15 | ] 16 | 17 | const router = createRouter({ 18 | history: createWebHashHistory(), 19 | routes 20 | }) 21 | 22 | export default router 23 | -------------------------------------------------------------------------------- /src/store/index.ts: -------------------------------------------------------------------------------- 1 | import { defineStore, createPinia, Store } from 'pinia' 2 | import persistencePiniaPlugin from 'pinia-persistence' 3 | import { sync } from 'utools-utils' 4 | import { StoreKey } from '@/constant' 5 | import { DisplayModeEnum } from '@/constant' 6 | import { toRaw } from 'vue' 7 | import { db } from 'utools-api' 8 | import { isIllegalIndex } from '@/utils/collections' 9 | import { KindFilterModel, SearchScopeModel, SettingModel } from '@/models' 10 | 11 | export const useCommonStore = defineStore('common', { 12 | state: () => ({ 13 | isPreviewContent: sync.get(StoreKey.IS_PREVIEW_CONTENT, true), 14 | displayMode: sync.get(StoreKey.DISPLAY_MODE, DisplayModeEnum.PREVIEW), 15 | isShowRecent: sync.get(StoreKey.IS_SHOW_RECENT, true), 16 | defaultSearchScopes: SearchScopeModel.defaultSearchScopes() 17 | }), 18 | actions: { 19 | setIsPreviewContent(isPreview: boolean) { 20 | sync.set(StoreKey.IS_PREVIEW_CONTENT, isPreview) 21 | this.isPreviewContent = isPreview 22 | }, 23 | setDisplayMode(displayMode: DisplayModeEnum) { 24 | sync.set(StoreKey.DISPLAY_MODE, displayMode) 25 | this.displayMode = displayMode 26 | }, 27 | setIsShowRecent(showRecent: boolean) { 28 | sync.set(StoreKey.IS_SHOW_RECENT, showRecent) 29 | this.isShowRecent = showRecent 30 | }, 31 | async refreshDefaultSearchScopes() { 32 | this.defaultSearchScopes = await SearchScopeModel.refreshDefaultSearchScopes() 33 | } 34 | } 35 | }) 36 | 37 | const dbRevMap = new Map() 38 | export const useSettingStore = defineStore(StoreKey.SETTING, { 39 | state: (): SettingModel => ({ ...new SettingModel() }), 40 | persist: { 41 | enable: true, 42 | storage: { 43 | get(key: string): T | null { 44 | const doc = db.get(key) 45 | dbRevMap.set(key, doc?._rev) 46 | return doc?.data ?? null 47 | }, 48 | set(key: string, value: any) { 49 | const res = db.put({ _id: key, _rev: dbRevMap.get(key), data: value }) 50 | dbRevMap.set(key, res.rev) 51 | } 52 | }, 53 | map: toRaw, 54 | restored(store: Store) { 55 | const setting = toRaw(store.$state as SettingModel) 56 | if (SettingModel.migrateDatabase(setting)) { 57 | store.$patch(setting) 58 | store.$persist() 59 | console.log('database migrated:', setting) 60 | } 61 | }, 62 | persisted(store: Store) { 63 | if (import.meta.env.DEV) { 64 | console.log('persisted', store.$id, toRaw(store.$state)) 65 | } 66 | } 67 | }, 68 | getters: { 69 | allSearchScopes(): Array { 70 | const commonStore = useCommonStore() 71 | return [...commonStore.defaultSearchScopes, ...this.searchScopes] 72 | }, 73 | enabledKindFilters(): Array { 74 | return this.kindFilters.filter((kind) => kind.enabled) 75 | } 76 | }, 77 | actions: { 78 | removeSearchScope(indexInAll: number) { 79 | const commonStore = useCommonStore() 80 | const index = indexInAll - commonStore.defaultSearchScopes.length 81 | if (isIllegalIndex(this.searchScopes, index)) return 82 | this.searchScopes.splice(index, 1) 83 | }, 84 | getSearchScope(searchScopeId: string) { 85 | const scope = this.allSearchScopes.find((s) => s.id === searchScopeId) 86 | if (scope) return scope 87 | 88 | // fallback 89 | this.searchRoot = SearchScopeModel.USER_ID 90 | return SearchScopeModel.USER 91 | } 92 | } 93 | }) 94 | 95 | const pinia = createPinia() 96 | pinia.use(persistencePiniaPlugin) 97 | export default pinia 98 | -------------------------------------------------------------------------------- /src/style.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | -------------------------------------------------------------------------------- /src/styles/context-menu.scss: -------------------------------------------------------------------------------- 1 | @mixin macos-common-context-menu { 2 | & { 3 | --mx-menu-active-backgroud: var(--mx-menu-hover-backgroud); 4 | --mx-menu-open-backgroud: var(--mx-menu-hover-backgroud); 5 | 6 | --mx-menu-active-text: var(--mx-menu-hover-text); 7 | --mx-menu-open-text: var(--mx-menu-hover-text); 8 | 9 | --mx-menu-placeholder-width: 0; 10 | } 11 | 12 | min-width: 180px; 13 | padding: 4px; 14 | font-weight: 500; 15 | border: 1px solid var(--mx-menu-border-color); 16 | border-radius: 5px; 17 | @apply tw-backdrop-blur-xl; 18 | 19 | $menu-item-padding-x: 10px; 20 | 21 | .mx-context-menu-item { 22 | border-radius: 5px; 23 | padding: 2px $menu-item-padding-x; 24 | } 25 | 26 | .mx-context-menu-item-sperator { 27 | margin-left: $menu-item-padding-x; 28 | margin-right: $menu-item-padding-x; 29 | @apply tw-bg-transparent; 30 | } 31 | } 32 | 33 | .mx-context-menu.macos-dark { 34 | & { 35 | --mx-menu-backgroud: rgba(46, 50, 43, 0.7); 36 | --mx-menu-hover-backgroud: #1857ba; 37 | --mx-menu-border-color: #535553; 38 | 39 | --mx-menu-text: #dfdfdf; 40 | --mx-menu-divider: #414547; 41 | --mx-menu-hover-text: #ffffff; 42 | } 43 | 44 | @include macos-common-context-menu(); 45 | } 46 | 47 | .mx-context-menu.macos-light { 48 | & { 49 | --mx-menu-backgroud: rgba(221, 224, 215, 0.7); 50 | --mx-menu-hover-backgroud: #4f8bf1; 51 | --mx-menu-border-color: #c7c7c6; 52 | 53 | --mx-menu-text: #232323; 54 | --mx-menu-divider: #d0d0cd; 55 | --mx-menu-hover-text: #ffffff; 56 | } 57 | 58 | @include macos-common-context-menu(); 59 | } 60 | -------------------------------------------------------------------------------- /src/typings/global.d.ts: -------------------------------------------------------------------------------- 1 | type Nullable = T | null 2 | 3 | type ComponentRef = InstanceType | null 4 | 5 | type ElementRef = T | null 6 | 7 | interface DisplayModeItem { 8 | value: string | number 9 | title: string 10 | icon: string 11 | } 12 | 13 | interface MenuItem { 14 | type?: 'normal' | 'separator' | 'submenu' 15 | label?: string 16 | click?: () => void 17 | submenu?: MenuItem[] 18 | } 19 | -------------------------------------------------------------------------------- /src/typings/preload.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'mdfind' { 2 | import { Readable } from 'stream' 3 | 4 | type MdfindOptions = { 5 | query: string 6 | attributes?: string[] 7 | limit?: number 8 | directories?: string[] 9 | names?: string[] 10 | interpret?: boolean 11 | } 12 | 13 | type MdfindResult = { 14 | output: Readable | null 15 | terminate: () => boolean 16 | } 17 | 18 | export function mdfind(options: MdfindOptions): MdfindResult 19 | export default mdfind 20 | } 21 | 22 | declare module 'file-metadata' { 23 | import { ExtraFileMetadata } from '@/models' 24 | 25 | export function fileMetadata(filePath: string): Promise 26 | export function fileMetadataSync(filePath: string): ExtraFileMetadata 27 | } 28 | -------------------------------------------------------------------------------- /src/utils/collections.ts: -------------------------------------------------------------------------------- 1 | type KeyFn = (item: T, index: number) => K 2 | type ValFn = (item: T, index: number) => V 3 | 4 | export function toMap(arr: V[], keyFn: KeyFn): Map 5 | export function toMap(arr: T[], keyFn: KeyFn, valFn: ValFn): Map 6 | 7 | export function toMap(arr: T[], keyFn: KeyFn, valFn?: ValFn): Map | Map { 8 | if (valFn) { 9 | const map = new Map() 10 | arr.forEach((item, index) => map.set(keyFn(item, index), valFn(item, index))) 11 | return map 12 | } 13 | const map = new Map() 14 | arr.forEach((item, index) => map.set(keyFn(item, index), item)) 15 | return map 16 | } 17 | 18 | export function isIllegalIndex(arr: any[], index: number) { 19 | return index < 0 || index >= arr.length 20 | } 21 | 22 | export function isLegalIndex(arr: any[], index: number) { 23 | return !isIllegalIndex(arr, index) 24 | } 25 | 26 | export function limitArray(arr: T[], limit?: number) { 27 | return limit !== undefined && arr.length > limit ? arr.slice(0, limit) : arr 28 | } 29 | 30 | export function getFinalIndex(arr: T[], index: number) { 31 | return arr.length ? Math.min(index, arr.length - 1) : undefined 32 | } 33 | 34 | export class SortedSet { 35 | private list: Array 36 | private map: Map 37 | 38 | constructor() { 39 | this.list = new Array() 40 | this.map = new Map() 41 | } 42 | 43 | add(value: T) { 44 | this.list.push(value) 45 | this.map.set(value, this.list.length - 1) 46 | } 47 | 48 | remove(value: T) { 49 | const index = this.map.get(value) 50 | if (index !== undefined) { 51 | this.list.splice(index, 1) 52 | for (let i = index; i < this.list.length; i++) { 53 | this.map.set(this.list[i], i) 54 | } 55 | return this.map.delete(value) 56 | } 57 | return false 58 | } 59 | 60 | clear() { 61 | this.list = new Array() 62 | this.map.clear() 63 | } 64 | 65 | has(value: T) { 66 | return this.map.has(value) 67 | } 68 | 69 | first() { 70 | return this.list[0] 71 | } 72 | 73 | last() { 74 | return this.list[this.list.length - 1] 75 | } 76 | 77 | getList() { 78 | return this.list 79 | } 80 | 81 | size() { 82 | return this.list.length 83 | } 84 | 85 | isEmpty() { 86 | return this.list.length === 0 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/utils/common.ts: -------------------------------------------------------------------------------- 1 | import { copyImage, copyFile } from 'utools-api' 2 | 3 | export function copyFromPath(path: string, isImage: boolean = false) { 4 | if (isImage) { 5 | copyImage(path) 6 | } else { 7 | copyFile(path) 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/utils/handler.ts: -------------------------------------------------------------------------------- 1 | import { ContentType, SortOrderEnum } from '@/constant' 2 | import * as icons from './icons' 3 | import isNull from 'lodash/isNull' 4 | import { BaseFileInfo, FindFileMetadata, SearchScopeModel } from '@/models' 5 | import { match } from 'pinyin-pro' 6 | import { SearchTextPattern } from './query' 7 | import { escapeRegExp } from 'lodash' 8 | import { getBasename, getDirname, joinPath } from '@/preload' 9 | 10 | /** 11 | * 根据自定义关键字,获取过滤正则表达式 12 | */ 13 | export function getCustomKeywordRegExp(customKeyword: string, keyMap: Map) { 14 | if (customKeyword) { 15 | const pattern = keyMap.get(customKeyword) 16 | if (pattern) return new RegExp(pattern, 'i') 17 | } 18 | return null 19 | } 20 | 21 | function homedir(...names: string[]) { 22 | return joinPath(SearchScopeModel.USER.paths[0], ...names) 23 | } 24 | 25 | function getDisplayName(item: FindFileMetadata) { 26 | return item.kMDItemDisplayName || getBasename(item.kMDItemPath) 27 | } 28 | 29 | export function getDisplayPath(path: string) { 30 | const replacements = [ 31 | { prefix: homedir('Library', 'CloudStorage') + '/', replace: '' }, 32 | { prefix: homedir('Library', 'Mobile Documents'), replace: 'iCloud Drive' }, 33 | { prefix: homedir(), replace: '~' } 34 | ] 35 | for (const { prefix, replace } of replacements) { 36 | if (path.startsWith(prefix)) return replace + path.substring(prefix.length) 37 | } 38 | return path 39 | } 40 | 41 | /** 42 | * 映射到文件 Model 对象 43 | */ 44 | export function mapToFileInfo(item: FindFileMetadata) { 45 | const name = getDisplayName(item) 46 | const mappedItem: BaseFileInfo = { 47 | name, 48 | displayName: name, 49 | path: item.kMDItemPath, 50 | displayPath: getDisplayPath(item.kMDItemPath), 51 | icon: icons.getIcon(item), 52 | size: isNull(item.kMDItemFSSize) ? null : parseInt(item.kMDItemFSSize), 53 | kind: item.kMDItemKind, 54 | type: item.kMDItemKind === '文件夹' ? ContentType.FOLDER : item.kMDItemContentType, 55 | createDate: item.kMDItemFSCreationDate ?? item.kMDItemContentCreationDate, 56 | updateDate: item.kMDItemFSContentChangeDate ?? item.kMDItemContentModificationDate, 57 | usedDate: item.kMDItemLastUsedDate 58 | } 59 | return mappedItem 60 | } 61 | 62 | type CompareFn = (a: T, b: T) => number 63 | export interface SortRule { 64 | propName: keyof T 65 | sortOrder: SortOrderEnum 66 | } 67 | 68 | function compareFn(obj1: T, obj2: T, propName: keyof T): number { 69 | const a = obj1[propName] ?? null 70 | const b = obj2[propName] ?? null 71 | let compare = 0 72 | if (a === null && b === null) compare = 0 73 | // a < b 74 | else if (a === null) compare = -1 75 | // a > b 76 | else if (b === null) compare = 1 77 | else if (a < b) compare = -1 78 | else if (a > b) compare = 1 79 | return compare 80 | } 81 | 82 | function createCompareFn(...sortRules: Array>): CompareFn { 83 | if (sortRules.length === 0) return () => 0 84 | return (a: T, b: T) => { 85 | for (const { propName, sortOrder } of sortRules) { 86 | const compare = compareFn(a, b, propName) 87 | if (compare !== 0) return compare * sortOrder 88 | } 89 | return 0 90 | } 91 | } 92 | 93 | /** 94 | * 排序文件 Model 数组 95 | */ 96 | export function sortFileInfos( 97 | data: Array, 98 | fieldName: keyof BaseFileInfo, 99 | sortOrder: SortOrderEnum 100 | ) { 101 | return data.sort( 102 | createCompareFn({ sortOrder, propName: fieldName }, { sortOrder: SortOrderEnum.ASC, propName: 'name' }) 103 | ) 104 | } 105 | 106 | /** 107 | * 获取拼音匹配的子串 108 | */ 109 | function getPinyinMatches(s: string, pinyins: string[]) { 110 | const mats: string[] = [] 111 | for (const pinyin of pinyins) { 112 | let arr = match(s, pinyin, { continuous: true }) 113 | if (!arr?.length) continue 114 | 115 | let lastPos = arr[0] 116 | for (let i = 1; i < arr.length - 1; i++) { 117 | if (arr[i] - arr[i - 1] === 1) continue 118 | mats.push(s.substring(lastPos, arr[i] + 1)) 119 | lastPos = arr[i] 120 | } 121 | mats.push(s.substring(lastPos, arr[arr.length - 1] + 1)) 122 | } 123 | return mats 124 | } 125 | 126 | function highlightString( 127 | pattern: SearchTextPattern, 128 | source: string, 129 | style: string, 130 | recordMatched: boolean = false 131 | ) { 132 | const preTag = `` 133 | const matchStrings = getPinyinMatches(source, pattern.words) 134 | const p = pattern.expression + (matchStrings.length ? '|' + matchStrings.map(escapeRegExp).join('|') : '') 135 | const matched: boolean[] = recordMatched ? new Array(pattern.words.length).fill(false) : [] 136 | const highlight = source.replaceAll(new RegExp(p, 'ig'), (s, ...args) => { 137 | if (recordMatched) { 138 | const index = args.findIndex((value) => !!value) 139 | matched[index % matched.length] = true 140 | } 141 | return preTag + s + `` 142 | }) 143 | const allMatched: boolean | undefined = recordMatched ? matched.reduce((p, c) => p && c, true) : undefined 144 | return { highlight, allMatched } 145 | } 146 | 147 | /** 148 | * 高亮文件 Model 数组中的文件名 149 | */ 150 | export function highlightFileInfo(item: BaseFileInfo, pattern: SearchTextPattern, highlightStyle: string) { 151 | const { highlight, allMatched } = highlightString(pattern, item.name, highlightStyle, true) 152 | item.displayName = highlight 153 | if (!allMatched) { 154 | const { highlight } = highlightString(pattern, getBasename(item.path), highlightStyle) 155 | item.displayPath = joinPath(getDirname(item.displayPath), highlight) 156 | } 157 | return item 158 | } 159 | 160 | export function highlightFileInfos( 161 | data: Array, 162 | pattern: SearchTextPattern, 163 | highlightStyle: string 164 | ) { 165 | return data.map((item) => highlightFileInfo(item, pattern, highlightStyle)) 166 | } 167 | -------------------------------------------------------------------------------- /src/utils/mdfinds.ts: -------------------------------------------------------------------------------- 1 | class CQueue { 2 | private data: Array 3 | private front = 0 4 | private rear = 0 5 | 6 | constructor(capacity: number) { 7 | this.data = new Array(capacity + 1) 8 | } 9 | 10 | isEmpty() { 11 | return this.front === this.rear 12 | } 13 | 14 | isFull() { 15 | return (this.rear + 1) % this.data.length === this.front 16 | } 17 | 18 | peekLast() { 19 | return this.isEmpty() 20 | ? null 21 | : this.data[(this.rear - 1 + this.data.length) % this.data.length] 22 | } 23 | 24 | peekFirst() { 25 | return this.isEmpty() ? null : this.data[this.front] 26 | } 27 | 28 | add(el: T) { 29 | if (this.isFull()) { 30 | this.front = (this.front + 1) % this.data.length 31 | } 32 | this.data[this.rear] = el 33 | this.rear = (this.rear + 1) % this.data.length 34 | } 35 | } 36 | 37 | export class FindTask { 38 | id: number 39 | interrupted: boolean 40 | end: boolean 41 | 42 | constructor() { 43 | this.id = Date.now() 44 | this.interrupted = false 45 | this.end = false 46 | } 47 | } 48 | 49 | export class MdfindProcessManager { 50 | private terminateFunc: Nullable<() => boolean> = null 51 | private window = new CQueue(10) 52 | 53 | add(mdfindReturn: { terminate: () => boolean }) { 54 | this.terminateFunc = mdfindReturn.terminate 55 | const task = new FindTask() 56 | this.window.add(task) 57 | return task 58 | } 59 | 60 | /** 61 | * 终止当前正在执行的任务 62 | * @returns 如果有任务正在执行,返回 `boolean`,否则返回 `null` 63 | */ 64 | killCurrent() { 65 | if (this.window.isEmpty()) return null 66 | const res = this.kill() 67 | const last = this.window.peekLast()! 68 | if (!last.end) { 69 | last.interrupted = true 70 | } 71 | return res 72 | } 73 | 74 | private kill() { 75 | if (this.terminateFunc) { 76 | const res = this.terminateFunc() 77 | if (import.meta.env.DEV) { 78 | console.log('terminate mdfind') 79 | } 80 | this.terminateFunc = null 81 | return res 82 | } 83 | // 没有任务在执行,返回 null 84 | return null 85 | } 86 | 87 | markTaskAsEnd(task: FindTask) { 88 | task.end = true 89 | } 90 | 91 | isLastTask(task: FindTask) { 92 | return task.id === this.window.peekLast()?.id 93 | } 94 | 95 | isInterruptLastTask() { 96 | return this.terminateFunc === null 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/utils/plist.ts: -------------------------------------------------------------------------------- 1 | import { XMLParser } from 'fast-xml-parser' 2 | 3 | interface TextTag { 4 | [prop: string]: Array<{ '#text': string }> 5 | } 6 | 7 | interface ArrayTag { 8 | array: Array 9 | } 10 | 11 | interface DictTag { 12 | [prop: string]: any 13 | } 14 | 15 | type TagObject = TextTag | ArrayTag | DictTag 16 | 17 | function tagText(tagObject: T, key: string) { 18 | const arr = tagObject[key] 19 | return arr.length >= 1 ? arr[0]['#text'] : '' 20 | } 21 | 22 | export type TagValue = string | number | Date | boolean | object | { type: string } 23 | 24 | function parseTagValue(tagObject: TagObject): TagValue | TagValue[] { 25 | const key = Object.keys(tagObject)[0] 26 | if (key === 'array') { 27 | return (tagObject as ArrayTag).array.map(parseTagValue) as TagValue[] 28 | } 29 | 30 | if (key === 'dict') { 31 | const obj: any = {} 32 | const dict = (tagObject as DictTag)[key] 33 | for (let i = 0; i < dict?.length; i += 2) { 34 | const key = tagText(dict[i], 'key') 35 | const value = parseTagValue(dict[i + 1]) 36 | obj[key] = value 37 | } 38 | return obj 39 | } 40 | 41 | if (key === 'true') return true 42 | if (key === 'false') return false 43 | 44 | const text = tagText(tagObject as TextTag, key) 45 | if (key === 'string') return text 46 | if (key === 'integer') return parseInt(text) 47 | if (key === 'date') return new Date(text) 48 | return { type: key } 49 | } 50 | 51 | export function parsePlist(data: string): T { 52 | const parser = new XMLParser({ 53 | parseTagValue: false, 54 | ignoreDeclaration: true, 55 | preserveOrder: true 56 | }) 57 | const obj = parser.parse(data) 58 | return parseTagValue(obj[0]?.['plist'][0]) as T 59 | } 60 | -------------------------------------------------------------------------------- /src/utils/query.ts: -------------------------------------------------------------------------------- 1 | import { ContentType, kMDItem } from '@/constant' 2 | import { SimpleFilterEnum } from '@/constant' 3 | import { KindFilterModel } from '@/models' 4 | import escapeRegExp from 'lodash/escapeRegExp' 5 | 6 | type BuildQueryFn = (builder: QueryBuilder) => QueryBuilder 7 | 8 | enum Logic { 9 | AND = '&&', 10 | OR = '||' 11 | } 12 | 13 | enum Comparison { 14 | EQ = '==', 15 | NE = '!=', 16 | GT = '>', 17 | GE = '>=', 18 | LT = '<', 19 | LE = '<=' 20 | } 21 | 22 | class QueryHelper { 23 | static readonly QUOTE = '"' 24 | 25 | // ================= Comparison ================= 26 | 27 | static expression(attr: string, comparison: string, val: string) { 28 | return `${attr} ${comparison} ${val}` 29 | } 30 | 31 | static mark(val: string, ignoreCase?: boolean) { 32 | // 转义引号 33 | val = val.replaceAll(this.QUOTE, '\\' + this.QUOTE) 34 | return this.QUOTE + val + this.QUOTE + (ignoreCase ? 'cd' : '') 35 | } 36 | 37 | static enclose(exp: string) { 38 | return `(${exp})` 39 | } 40 | 41 | static inRange(attr: string, min: number, max: number) { 42 | return `InRange(${attr},${min},${max})` 43 | } 44 | 45 | static like(val: string) { 46 | return `*${val}*` 47 | } 48 | 49 | static likeStart(val: string) { 50 | return `*${val}` 51 | } 52 | 53 | static likeEnd(val: string) { 54 | return `${val}*` 55 | } 56 | 57 | // ================= Time and Date ================= 58 | 59 | private static offset(offset?: number) { 60 | return offset ? `(${offset})` : '' 61 | } 62 | 63 | static now(offset?: number) { 64 | return '$time.now' + this.offset(offset) 65 | } 66 | 67 | static today(offset?: number) { 68 | return '$time.today' + this.offset(offset) 69 | } 70 | 71 | static thisWeek(offset?: number) { 72 | return '$time.this_week' + this.offset(offset) 73 | } 74 | 75 | static thisMonth(offset?: number) { 76 | return '$time.this_month' + this.offset(offset) 77 | } 78 | 79 | static thisYear(offset?: number) { 80 | return '$time.this_year' + this.offset(offset) 81 | } 82 | 83 | static datetime(date: Date) { 84 | return `$time.iso(${date.toISOString()})` 85 | } 86 | } 87 | 88 | export class QueryBuilder { 89 | protected exp = '' 90 | 91 | private endsWithLogic() { 92 | const trim = this.exp.trimEnd() 93 | return trim.endsWith(Logic.OR) || trim.endsWith(Logic.AND) 94 | } 95 | 96 | private append(logic: Logic, s: string) { 97 | if (this.exp && !this.endsWithLogic()) { 98 | this.exp = QueryHelper.expression(this.exp, logic, '') 99 | } 100 | this.exp += s 101 | return this 102 | } 103 | 104 | // ================= Comparison ================= 105 | 106 | private comparison(attr: kMDItem, comparison: Comparison, val: string, ignoreCase?: boolean) { 107 | val = QueryHelper.mark(val, ignoreCase) 108 | return this.append(Logic.AND, QueryHelper.expression(attr, comparison, val)) 109 | } 110 | 111 | eq(cond: boolean, attr: kMDItem, val: string, ignoreCase?: boolean) { 112 | return cond ? this.comparison(attr, Comparison.EQ, val, ignoreCase) : this 113 | } 114 | 115 | ne(cond: boolean, attr: kMDItem, val: string, ignoreCase?: boolean) { 116 | return cond ? this.comparison(attr, Comparison.NE, val, ignoreCase) : this 117 | } 118 | 119 | gt(attr: kMDItem, val: string) { 120 | return this.comparison(attr, Comparison.GT, val) 121 | } 122 | 123 | ge(attr: kMDItem, val: string) { 124 | return this.comparison(attr, Comparison.GE, val) 125 | } 126 | 127 | lt(attr: kMDItem, val: string) { 128 | return this.comparison(attr, Comparison.LT, val) 129 | } 130 | 131 | le(attr: kMDItem, val: string) { 132 | return this.comparison(attr, Comparison.LE, val) 133 | } 134 | 135 | // ================= Like ================= 136 | 137 | like(cond: boolean, attr: kMDItem, val: string, ignoreCase: boolean = true) { 138 | return this.eq(cond, attr, QueryHelper.like(val), ignoreCase) 139 | } 140 | 141 | notLike(cond: boolean, attr: kMDItem, val: string, ignoreCase: boolean = true) { 142 | return this.ne(cond, attr, QueryHelper.like(val), ignoreCase) 143 | } 144 | 145 | likeStart(cond: boolean, attr: kMDItem, val: string, ignoreCase: boolean = true) { 146 | return this.eq(cond, attr, QueryHelper.likeStart(val), ignoreCase) 147 | } 148 | 149 | likeEnd(cond: boolean, attr: kMDItem, val: string, ignoreCase: boolean = true) { 150 | return this.eq(cond, attr, QueryHelper.likeEnd(val), ignoreCase) 151 | } 152 | 153 | // ================= Logical ================= 154 | 155 | private nested(logic: Logic, builder?: BuildQueryFn | QueryBuilder) { 156 | let exp: string | undefined 157 | exp = typeof builder === 'function' ? builder?.(new QueryBuilder()).exp : builder?.exp 158 | if (exp) this.append(logic, QueryHelper.enclose(exp)) 159 | return this 160 | } 161 | 162 | and(builder: BuildQueryFn | QueryBuilder) { 163 | return this.nested(Logic.AND, builder) 164 | } 165 | 166 | or(builder: BuildQueryFn | QueryBuilder) { 167 | return this.nested(Logic.OR, builder) 168 | } 169 | 170 | // ================= Build ================= 171 | 172 | build() { 173 | return this.exp 174 | } 175 | } 176 | 177 | /** 178 | * 处理条件自定义关键字 179 | */ 180 | export function splitKeyword(str: string, separator: string) { 181 | let keyIndex = str.indexOf(separator) 182 | if (keyIndex === -1) return { keyword: '', statement: str } 183 | 184 | const keyword = str.substring(0, keyIndex) 185 | return { keyword, statement: str.substring(keyIndex + 1) } 186 | } 187 | 188 | /** 189 | * 判断是文件、文件夹还是无筛选 190 | */ 191 | export function getSimpleFilter(searchText: string) { 192 | if (searchText.startsWith(' ')) return SimpleFilterEnum.FILE 193 | if (searchText.startsWith(' ')) return SimpleFilterEnum.FOLDER 194 | return SimpleFilterEnum.NONE 195 | } 196 | 197 | function parseKindExpression(kindExp: string) { 198 | const includes: string[] = [] 199 | const excludes: string[] = [] 200 | // include 0, exclude 1 201 | let symbol: 0 | 1 = 0 202 | let kind = '' 203 | const addKind = () => { 204 | if (!kind) return 205 | if (symbol === 1) excludes.push(kind) 206 | else includes.push(kind) 207 | kind = '' 208 | } 209 | for (const ch of kindExp) { 210 | if (ch === '!' || ch === '|') { 211 | addKind() 212 | symbol = ch === '!' ? 1 : 0 213 | } else { 214 | kind += ch 215 | } 216 | } 217 | addKind() 218 | return { includes, excludes } 219 | } 220 | 221 | function unescapeQueryWord(word: string) { 222 | // 反转义开头的 \- 为 - 223 | if (word.startsWith('\\-')) return word.substring(1) 224 | return word 225 | } 226 | 227 | function escapeMdfindQuery(q: string) { 228 | // 只转义 \ 和 * 229 | return q.replaceAll(/[\\*]/g, (s) => '\\' + s) 230 | } 231 | 232 | function getQuoteContent(s: string, leftQuote: string, rightQuote: string) { 233 | if (s.length > leftQuote.length + rightQuote.length && s.startsWith(leftQuote) && s.endsWith(rightQuote)) { 234 | return s.substring(leftQuote.length, s.length - rightQuote.length) 235 | } 236 | return '' 237 | } 238 | 239 | function parseQuoteContent(s: string) { 240 | const quoteContent = 241 | getQuoteContent(s, `"`, `"`) || 242 | getQuoteContent(s, `'`, `'`) || 243 | getQuoteContent(s, `“`, `”`) || 244 | getQuoteContent(s, `‘`, `’`) 245 | const hasQuote = !!quoteContent 246 | let escapedContent = '' 247 | if (hasQuote) { 248 | escapedContent = escapeMdfindQuery(quoteContent) 249 | } 250 | return { hasQuote, escapedContent } 251 | } 252 | 253 | enum QueryTermType { 254 | EXACT, 255 | PARTLY_FUZZY, 256 | FULLY_FUZZY, 257 | EXCLUDED 258 | } 259 | 260 | interface QueryTerm { 261 | type: QueryTermType 262 | word: string 263 | } 264 | 265 | function parseQueryByWord(word: string): QueryTerm { 266 | const { hasQuote, escapedContent } = parseQuoteContent(word) 267 | // 精确匹配 268 | if (hasQuote) { 269 | return { word: escapedContent, type: QueryTermType.EXACT } 270 | } 271 | 272 | // 判断是否是部分模糊匹配 273 | if (word.startsWith('*') || word.endsWith('*')) { 274 | return { word, type: QueryTermType.PARTLY_FUZZY } 275 | } 276 | 277 | // 判断是否是排除匹配 278 | if (word.startsWith('-')) { 279 | let excludeWord = escapeMdfindQuery(word.replace('-', '')) 280 | const { hasQuote, escapedContent } = parseQuoteContent(excludeWord) 281 | if (hasQuote) { 282 | excludeWord = escapedContent 283 | } 284 | return { word: excludeWord, type: QueryTermType.EXCLUDED } 285 | } 286 | 287 | // 默认为模糊匹配 288 | const queryWord = unescapeQueryWord(word) 289 | return { word: queryWord, type: QueryTermType.FULLY_FUZZY } 290 | } 291 | 292 | function splitSearchText(searchText: string) { 293 | // 以空格分割,由引号括起来的内容不分割 294 | const words: string[] = [] 295 | const n = searchText.length 296 | const quoteMap = new Map([ 297 | [`"`, `"`], 298 | [`'`, `'`], 299 | [`“`, `”`], 300 | [`‘`, `’`] 301 | ]) 302 | let p = -1 303 | const getRightQuoteIndex = (i: number, leftQuote: string) => { 304 | let j = i + 1 305 | const rightQuote = quoteMap.get(leftQuote) 306 | while (j < n && searchText[j] !== rightQuote) j++ 307 | if (j === n) return i 308 | return j 309 | } 310 | for (let i = 0; i < n; i++) { 311 | if (searchText[i] === `"`) { 312 | i = getRightQuoteIndex(i, `"`) 313 | } else if (searchText[i] === `'`) { 314 | i = getRightQuoteIndex(i, `'`) 315 | } else if (searchText[i] === `“`) { 316 | i = getRightQuoteIndex(i, `“`) 317 | } else if (searchText[i] === `‘`) { 318 | i = getRightQuoteIndex(i, `‘`) 319 | } else { 320 | if (searchText[i] === ' ') { 321 | words.push(searchText.substring(p + 1, i)) 322 | p = i 323 | } 324 | } 325 | } 326 | if (p + 1 < n) { 327 | words.push(searchText.substring(p + 1)) 328 | } 329 | 330 | return words.map((text) => { 331 | // 奇数个 \ 就移除最后一个 332 | let n = text.length 333 | let i = n - 1 334 | while (i >= 0 && text[i] === '\\') i-- 335 | return (n - 1 - i) % 2 === 0 ? text : text.substring(0, n - 1) 336 | }) 337 | } 338 | 339 | export interface SearchTextPattern { 340 | expression: string 341 | // 使用空格隔开的搜索词 342 | words: string[] 343 | } 344 | 345 | /** 346 | * 获取搜索匹配正则 347 | */ 348 | export function getSearchTextPattern(searchText: string): SearchTextPattern { 349 | searchText = searchText.trim() 350 | const { hasQuote, escapedContent } = parseQuoteContent(searchText) 351 | if (hasQuote) { 352 | searchText = escapedContent 353 | } 354 | let n = searchText.length 355 | let l = 0 356 | let r = n - 1 357 | 358 | const words = splitSearchText(searchText.substring(l, r + 1)).filter((word) => !word.startsWith('-')) 359 | const locales = [ 360 | [`“`, `”`, '"'], 361 | [`‘`, `’`, `'`, '`'], 362 | [`?`, '?'], 363 | [`:`, ':'], 364 | [`!`, '!'], 365 | [`(`, '('], 366 | [`)`, ')'], 367 | [`,`, ','], 368 | [`;`, ';'], 369 | [`|`, '|'], 370 | [`+`, '+'] 371 | ] 372 | 373 | const expression = words 374 | .map((word) => { 375 | let ans = '' 376 | let locale: string[] | undefined = undefined 377 | let isEscape = false 378 | for (let i = 0; i < word.length; i++) { 379 | const ch = word[i] 380 | 381 | if (ch === '\\') { 382 | if (isEscape) { 383 | ans += '\\\\' 384 | isEscape = false 385 | } else { 386 | isEscape = true 387 | } 388 | continue 389 | } 390 | 391 | if (ch === '-') { 392 | ans += `[-]?` 393 | } else if (ch === '*') { 394 | ans += isEscape ? '\\*' : '' 395 | ans += i !== word.length - 1 && i !== 0 ? '|' : '' 396 | } else if ((locale = locales.find((item) => item.includes(ch)))) { 397 | ans += `[${locale.join('')}]` 398 | } else if ((i === word.length - 1 || i === 0 || isEscape) && (ch === '.' || ch === '?')) { 399 | ans += escapeRegExp(ch) 400 | } else { 401 | ans += `[${ch}][.-]?` 402 | } 403 | isEscape = false 404 | } 405 | return ans ? `(${ans})` : '' 406 | }) 407 | .filter((item) => !!item) 408 | .join('|') 409 | return { expression, words } 410 | } 411 | 412 | export function buildRecentUsedQuery(recentMonth: number) { 413 | return new QueryBuilder() 414 | .ne(true, kMDItem.SupportFileType, 'MDSystemFile') 415 | .ge(kMDItem.LastUsedDate, QueryHelper.thisMonth(recentMonth)) 416 | .build() 417 | } 418 | 419 | /** 420 | * 构建 mdfind 查询表达式 421 | * 422 | * 参考文档: 423 | * - https://ss64.com/osx/mdfind.html 424 | * - https://developer.apple.com/library/archive/documentation/Carbon/Conceptual/SpotlightQuery/Concepts/QueryFormat.html 425 | */ 426 | export function buildQuery( 427 | searchText: string, 428 | kindModel: KindFilterModel, 429 | isFindContent: boolean, 430 | isFindSystemFile: boolean 431 | ) { 432 | const simpleFilter = getSimpleFilter(searchText) 433 | searchText = searchText.trim() 434 | 435 | let builder = new QueryBuilder() 436 | if (kindModel.id !== KindFilterModel.ANY.id) { 437 | const { includes, excludes } = parseKindExpression(kindModel.value) 438 | excludes.forEach((kind) => builder.ne(true, kMDItem.ContentTypeTree, kind)) 439 | builder.and((b) => { 440 | includes.forEach((kind) => b.or((b2) => b2.eq(true, kMDItem.ContentTypeTree, kind))) 441 | return b 442 | }) 443 | } 444 | 445 | switch (simpleFilter) { 446 | case SimpleFilterEnum.FOLDER: 447 | builder.eq(true, kMDItem.ContentType, ContentType.FOLDER) 448 | break 449 | case SimpleFilterEnum.FILE: 450 | builder.ne(true, kMDItem.ContentType, ContentType.FOLDER) 451 | break 452 | } 453 | return builder 454 | .ne(!isFindSystemFile, kMDItem.SupportFileType, 'MDSystemFile') 455 | .and((b) => { 456 | const words = splitSearchText(searchText) 457 | const contentQuery = new QueryBuilder() 458 | 459 | for (const word of words) { 460 | const queryTerm = parseQueryByWord(word) 461 | b.and((b2) => { 462 | switch (queryTerm.type) { 463 | case QueryTermType.EXACT: 464 | return b2 465 | .eq(true, kMDItem.FSName, queryTerm.word, true) 466 | .or((b3) => b3.eq(true, kMDItem.DisplayName, queryTerm.word, true)) 467 | case QueryTermType.PARTLY_FUZZY: 468 | return b2 469 | .eq(true, kMDItem.FSName, queryTerm.word, true) 470 | .or((b3) => b3.eq(true, kMDItem.DisplayName, queryTerm.word, true)) 471 | case QueryTermType.EXCLUDED: 472 | const hasExclude = !!queryTerm.word 473 | return b2 474 | .notLike(hasExclude, kMDItem.FSName, queryTerm.word) 475 | .notLike(hasExclude, kMDItem.DisplayName, queryTerm.word) 476 | case QueryTermType.FULLY_FUZZY: 477 | return b2 478 | .like(true, kMDItem.FSName, queryTerm.word) 479 | .or((b3) => b3.like(true, kMDItem.DisplayName, queryTerm.word)) 480 | } 481 | }) 482 | 483 | if (isFindContent) { 484 | switch (queryTerm.type) { 485 | case QueryTermType.EXCLUDED: 486 | contentQuery.notLike(true, kMDItem.TextContent, queryTerm.word) 487 | break 488 | default: 489 | contentQuery.like(true, kMDItem.TextContent, queryTerm.word) 490 | break 491 | } 492 | } 493 | } 494 | return b.or(contentQuery) 495 | }) 496 | .build() 497 | } 498 | -------------------------------------------------------------------------------- /src/utils/strings.ts: -------------------------------------------------------------------------------- 1 | import { FileConstant } from '@/constant' 2 | import dayjs from 'dayjs' 3 | 4 | export function formatDatetime(datetime?: Nullable) { 5 | if (!datetime) return '' 6 | return dayjs(datetime).format('YYYY-MM-DD HH:mm:ss') 7 | } 8 | 9 | export function formatDecimal(num: number) { 10 | const fraction = num % 1 11 | if (fraction < 0.1) return Math.floor(num).toString() 12 | if (fraction > 0.9) return Math.ceil(num).toString() 13 | return num.toFixed(1) 14 | } 15 | 16 | export function formatBytesToHuman(bytes: number) { 17 | if (bytes > FileConstant.GB) return formatDecimal(bytes / FileConstant.GB) + ' GB' 18 | if (bytes > FileConstant.MB) return formatDecimal(bytes / FileConstant.MB) + ' MB' 19 | if (bytes > FileConstant.KB) return formatDecimal(Math.round(bytes / FileConstant.KB)) + ' KB' 20 | if (bytes >= 0) return bytes + ' B' 21 | return '' 22 | } 23 | 24 | export function formatNumberToThousands(num: number, separator = ',') { 25 | const s = num.toString() 26 | const n = s.length 27 | let res = '' 28 | let i = n - 3 29 | while (i >= 0) { 30 | res = s.slice(i, i + 3) + (i !== n - 3 ? separator : '') + res 31 | i -= 3 32 | } 33 | i += 3 34 | return s.slice(0, i) + (i > 0 && n - i > 0 ? separator : '') + res 35 | } 36 | 37 | export function formatBytesToThousands(bytes: number) { 38 | return formatNumberToThousands(bytes) + ' 字节' 39 | } 40 | 41 | export function formatArchitectures(architectures?: string[]) { 42 | if (!architectures?.length) return '' 43 | if (architectures.length === 1) { 44 | switch (architectures[0]) { 45 | case 'x86_64': 46 | return 'Intel' 47 | case 'arm64': 48 | return 'Apple 芯片' 49 | } 50 | } 51 | return '通用' 52 | } 53 | 54 | export function getFileExtension(filename: string) { 55 | if (!filename) return '' 56 | let index = filename.lastIndexOf('.') || 0 57 | if (index > 0) { 58 | return filename.substring(index + 1, filename.length).toLowerCase() 59 | } 60 | return '' 61 | } 62 | 63 | export function decodeUnicode(s: string) { 64 | return String.fromCharCode( 65 | ...s 66 | .split(/\\[uU]/) 67 | .slice(1) 68 | .map((code) => parseInt(code, 16)) 69 | ) 70 | } 71 | 72 | export function escapeQuote(s: string) { 73 | return s.replace(/"/g, '\\"') 74 | } 75 | -------------------------------------------------------------------------------- /src/views/Setting.vue: -------------------------------------------------------------------------------- 1 | 37 | 38 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /src/vite-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | declare module '*.vue' { 4 | import type { DefineComponent } from 'vue' 5 | const component: DefineComponent<{}, {}, any> 6 | export default component 7 | } 8 | 9 | declare module 'utools-api' { 10 | import utools from 'utools-api-types' 11 | export = utools 12 | } 13 | 14 | declare module 'utools-api' { 15 | import type { BrowserWindow, BrowserWindowConstructorOptions } from 'electron' 16 | import { Action } from 'utools-utils/type' 17 | 18 | export type * from 'utools-utils/type' 19 | 20 | export interface MainPushItem { 21 | icon?: string 22 | text: string 23 | title?: string 24 | tags?: string[] 25 | 26 | [prop: string]: any 27 | } 28 | 29 | export function createBrowserWindow( 30 | url: string, 31 | options: BrowserWindowConstructorOptions, 32 | callback?: () => void 33 | ): Omit< 34 | BrowserWindow, 35 | | 'on' 36 | | 'once' 37 | | 'addListener' 38 | | 'removeListener' 39 | | 'listenerCount' 40 | | 'listeners' 41 | | 'rawListeners' 42 | | 'getMaxListeners' 43 | | 'setMaxListeners' 44 | | 'removeAllListeners' 45 | | 'prependListener' 46 | | 'prependOnceListener' 47 | > 48 | 49 | export function onPluginEnter(callback: (action: Action) => void): void 50 | 51 | export function onMainPush( 52 | callback: (action: Action) => MainPushItem[] | Promise, 53 | selectCallback: (action: Action & { option: MainPushItem }) => void 54 | ): void 55 | } 56 | -------------------------------------------------------------------------------- /tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | module.exports = { 3 | prefix: 'tw-', 4 | content: ['./index.html', './src/**/*.{vue,js,ts,jsx,tsx}'], 5 | theme: { 6 | extend: { 7 | colors: { 8 | 'utools-dark': '#303133' 9 | } 10 | } 11 | }, 12 | plugins: [] 13 | } 14 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ESNext", 4 | "useDefineForClassFields": true, 5 | "module": "ESNext", 6 | "moduleResolution": "Node", 7 | "strict": true, 8 | "jsx": "preserve", 9 | "resolveJsonModule": true, 10 | "isolatedModules": true, 11 | "esModuleInterop": true, 12 | "lib": ["ESNext", "DOM"], 13 | "skipLibCheck": true, 14 | "removeComments": true, 15 | "noEmit": true, 16 | "baseUrl": ".", 17 | "paths": { 18 | "@/*": ["src/*"] 19 | }, 20 | "types": ["lodash"] 21 | }, 22 | "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"], 23 | "references": [{ "path": "./tsconfig.node.json" }] 24 | } 25 | -------------------------------------------------------------------------------- /tsconfig.node.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true, 4 | "skipLibCheck": true, 5 | "module": "ESNext", 6 | "moduleResolution": "Node", 7 | "allowSyntheticDefaultImports": true, 8 | "types": ["node"] 9 | }, 10 | "include": ["vite.config.ts"] 11 | } 12 | -------------------------------------------------------------------------------- /vite.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite' 2 | import vue from '@vitejs/plugin-vue' 3 | import utools from 'vite-plugin-utools' 4 | import path from 'path' 5 | 6 | // https://vitejs.dev/config/ 7 | export default defineConfig({ 8 | base: './', 9 | build: { 10 | outDir: 'dist/', 11 | rollupOptions: { 12 | external: ['electron'] 13 | } 14 | }, 15 | define: { 16 | __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: 'true' 17 | }, 18 | plugins: [ 19 | vue({ 20 | script: { 21 | propsDestructure: true 22 | } 23 | }), 24 | utools({ 25 | external: 'utools-api', 26 | preload: { 27 | path: './src/preload.ts', 28 | watch: false, 29 | name: 'window.preload' 30 | }, 31 | buildUpx: false 32 | }) 33 | ], 34 | resolve: { 35 | alias: [ 36 | { 37 | find: '@', 38 | replacement: path.resolve(__dirname, './src') 39 | } 40 | ] 41 | } 42 | }) 43 | --------------------------------------------------------------------------------