@talex-touch/utils 1.0.31 → 1.0.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/animation/window-node.ts +15 -12
  2. package/animation/window.ts +19 -15
  3. package/auth/clerk-types.ts +1 -1
  4. package/auth/index.ts +1 -1
  5. package/auth/useAuthState.ts +6 -5
  6. package/auth/useClerkConfig.ts +4 -4
  7. package/auth/useClerkProvider.ts +3 -2
  8. package/channel/index.ts +23 -22
  9. package/common/file-scan-constants.ts +137 -121
  10. package/common/file-scan-utils.ts +48 -27
  11. package/common/index.ts +3 -3
  12. package/common/search/gather.ts +1 -1
  13. package/common/search/index.ts +5 -6
  14. package/common/storage/constants.ts +3 -2
  15. package/common/storage/entity/app-settings.ts +5 -3
  16. package/common/storage/entity/shortcut-settings.ts +10 -10
  17. package/common/storage/shortcut-storage.ts +6 -4
  18. package/common/utils/file.ts +14 -6
  19. package/common/utils/index.ts +62 -52
  20. package/common/utils/polling.ts +88 -84
  21. package/common/utils/task-queue.ts +11 -10
  22. package/common/utils/time.ts +50 -47
  23. package/common/utils/timing.ts +41 -37
  24. package/core-box/builder/index.ts +1 -1
  25. package/core-box/builder/tuff-builder.ts +254 -229
  26. package/core-box/index.ts +4 -6
  27. package/core-box/preview/index.ts +1 -0
  28. package/core-box/preview/types.ts +43 -0
  29. package/core-box/recommendation.ts +77 -0
  30. package/core-box/tuff/index.ts +1 -1
  31. package/core-box/tuff/tuff-dsl.ts +328 -266
  32. package/electron/download-manager.ts +43 -42
  33. package/electron/env-tool.ts +19 -18
  34. package/electron/file-parsers/index.ts +2 -2
  35. package/electron/file-parsers/parsers/text-parser.ts +15 -14
  36. package/electron/file-parsers/registry.ts +9 -7
  37. package/electron/file-parsers/types.ts +4 -4
  38. package/electron/index.ts +2 -2
  39. package/eventbus/index.ts +11 -11
  40. package/index.ts +5 -4
  41. package/intelligence/client.ts +87 -0
  42. package/intelligence/index.ts +1 -0
  43. package/package.json +14 -14
  44. package/permission/index.ts +8 -8
  45. package/plugin/channel.ts +77 -68
  46. package/plugin/index.ts +96 -82
  47. package/plugin/install.ts +8 -8
  48. package/plugin/log/types.ts +5 -5
  49. package/plugin/node/index.ts +1 -1
  50. package/plugin/node/logger-manager.ts +14 -11
  51. package/plugin/node/logger.ts +8 -8
  52. package/plugin/plugin-source.ts +11 -11
  53. package/plugin/preload.ts +1 -1
  54. package/plugin/providers/registry.ts +8 -7
  55. package/plugin/providers/types.ts +6 -6
  56. package/plugin/sdk/README.md +216 -0
  57. package/plugin/sdk/box-sdk.ts +219 -0
  58. package/plugin/sdk/channel.ts +20 -20
  59. package/plugin/sdk/clipboard.ts +8 -6
  60. package/plugin/sdk/common.ts +10 -6
  61. package/plugin/sdk/core-box.ts +2 -3
  62. package/plugin/sdk/division-box.ts +266 -0
  63. package/plugin/sdk/enum/bridge-event.ts +1 -1
  64. package/plugin/sdk/examples/storage-onDidChange-example.js +1 -1
  65. package/plugin/sdk/feature-sdk.ts +235 -0
  66. package/plugin/sdk/features.ts +34 -26
  67. package/plugin/sdk/hooks/bridge.ts +3 -6
  68. package/plugin/sdk/hooks/index.ts +1 -1
  69. package/plugin/sdk/hooks/life-cycle.ts +4 -10
  70. package/plugin/sdk/index.ts +10 -7
  71. package/plugin/sdk/service/index.ts +3 -3
  72. package/plugin/sdk/storage.ts +4 -4
  73. package/plugin/sdk/system.ts +1 -1
  74. package/plugin/sdk/types.ts +165 -146
  75. package/plugin/sdk/window/index.ts +8 -5
  76. package/preload/loading.ts +6 -6
  77. package/preload/renderer.ts +4 -2
  78. package/renderer/hooks/arg-mapper.ts +1 -2
  79. package/renderer/hooks/index.ts +2 -0
  80. package/renderer/hooks/initialize.ts +10 -8
  81. package/renderer/hooks/performance.ts +4 -4
  82. package/renderer/hooks/use-channel.ts +150 -0
  83. package/renderer/hooks/use-intelligence.ts +236 -0
  84. package/renderer/index.ts +6 -2
  85. package/renderer/ref.ts +32 -36
  86. package/renderer/slots.ts +29 -26
  87. package/renderer/storage/app-settings.ts +16 -6
  88. package/renderer/storage/base-storage.ts +222 -114
  89. package/renderer/storage/index.ts +3 -0
  90. package/renderer/storage/intelligence-storage.ts +218 -0
  91. package/renderer/storage/openers.ts +13 -3
  92. package/renderer/touch-sdk/env.ts +41 -41
  93. package/renderer/touch-sdk/index.ts +1 -1
  94. package/renderer/touch-sdk/terminal.ts +5 -5
  95. package/renderer/touch-sdk/utils.ts +4 -3
  96. package/search/levenshtein-utils.ts +11 -11
  97. package/search/types.ts +102 -102
  98. package/service/index.ts +11 -11
  99. package/service/protocol/index.ts +217 -14
  100. package/types/division-box.ts +248 -0
  101. package/types/download.ts +72 -34
  102. package/types/index.ts +3 -1
  103. package/types/intelligence.ts +607 -0
  104. package/types/modules/base.ts +16 -16
  105. package/types/modules/index.ts +1 -1
  106. package/types/modules/module-lifecycle.ts +21 -21
  107. package/types/modules/module-manager.ts +11 -11
  108. package/types/modules/module.ts +16 -16
  109. package/types/storage.ts +0 -1
  110. package/types/touch-app-core.ts +32 -32
  111. package/types/update.ts +91 -21
  112. package/core-box/README.md +0 -218
  113. package/core-box/builder/tuff-builder.example.ts.bak +0 -258
  114. package/core-box/run-tests.sh +0 -7
  115. package/core-box/search.ts +0 -1
  116. package/electron/clipboard-helper.ts +0 -199
@@ -13,7 +13,7 @@ export const PLATFORM = {
13
13
  IS_WINDOWS: process.platform === 'win32',
14
14
  IS_MACOS: process.platform === 'darwin',
15
15
  IS_LINUX: process.platform === 'linux',
16
- IS_UNIX: process.platform !== 'win32'
16
+ IS_UNIX: process.platform !== 'win32',
17
17
  } as const
18
18
 
19
19
  // ==================== 基础黑名单 ====================
@@ -45,7 +45,7 @@ export const DEV_BLACKLISTED_DIRS = new Set([
45
45
  '.next',
46
46
  '.nuxt',
47
47
  '.vuepress',
48
- '.docusaurus'
48
+ '.docusaurus',
49
49
  ])
50
50
 
51
51
  /** Windows 系统目录黑名单 */
@@ -62,7 +62,7 @@ export const WINDOWS_SYSTEM_DIRS = new Set([
62
62
  'Boot',
63
63
  'EFI',
64
64
  'System Volume Information',
65
- '$Recycle.Bin'
65
+ '$Recycle.Bin',
66
66
  ])
67
67
 
68
68
  /** macOS 系统目录黑名单 */
@@ -79,7 +79,7 @@ export const MACOS_SYSTEM_DIRS = new Set([
79
79
  'tmp',
80
80
  'opt',
81
81
  'etc',
82
- 'dev'
82
+ 'dev',
83
83
  ])
84
84
 
85
85
  /** Linux 系统目录黑名单 */
@@ -99,14 +99,14 @@ export const LINUX_SYSTEM_DIRS = new Set([
99
99
  'lib64',
100
100
  'mnt',
101
101
  'media',
102
- 'srv'
102
+ 'srv',
103
103
  ])
104
104
 
105
105
  /** 跨平台系统目录黑名单 */
106
106
  export const SYSTEM_BLACKLISTED_DIRS = new Set([
107
107
  ...(PLATFORM.IS_WINDOWS ? WINDOWS_SYSTEM_DIRS : []),
108
108
  ...(PLATFORM.IS_MACOS ? MACOS_SYSTEM_DIRS : []),
109
- ...(PLATFORM.IS_LINUX ? LINUX_SYSTEM_DIRS : [])
109
+ ...(PLATFORM.IS_LINUX ? LINUX_SYSTEM_DIRS : []),
110
110
  ])
111
111
 
112
112
  /** 临时文件目录黑名单(跨平台) */
@@ -121,14 +121,14 @@ export const TEMP_BLACKLISTED_DIRS = new Set([
121
121
  // Windows 临时目录
122
122
  ...(PLATFORM.IS_WINDOWS ? ['%TEMP%', '%TMP%'] : []),
123
123
  // Unix 临时目录
124
- ...(PLATFORM.IS_UNIX ? ['/tmp', '/var/tmp'] : [])
124
+ ...(PLATFORM.IS_UNIX ? ['/tmp', '/var/tmp'] : []),
125
125
  ])
126
126
 
127
127
  /** 合并的基础目录黑名单 */
128
128
  export const BASE_BLACKLISTED_DIRS = new Set([
129
129
  ...DEV_BLACKLISTED_DIRS,
130
130
  ...SYSTEM_BLACKLISTED_DIRS,
131
- ...TEMP_BLACKLISTED_DIRS
131
+ ...TEMP_BLACKLISTED_DIRS,
132
132
  ])
133
133
 
134
134
  // ==================== 应用特定黑名单 ====================
@@ -140,7 +140,7 @@ export const PHOTOS_LIBRARY_CONFIG = {
140
140
  'Masters',
141
141
  'Originals',
142
142
  'Resources',
143
- 'Thumbnails'
143
+ 'Thumbnails',
144
144
  ]),
145
145
 
146
146
  /** 禁止扫描的 Photos Library 子目录 */
@@ -152,7 +152,7 @@ export const PHOTOS_LIBRARY_CONFIG = {
152
152
  'index.spotlightV3',
153
153
  'NSFileProtectionCompleteUnti',
154
154
  'com.apple.photoanalysisd',
155
- 'com.apple.photolibraryd'
155
+ 'com.apple.photolibraryd',
156
156
  ]),
157
157
 
158
158
  /** Photos Library 路径模式(使用路径分隔符) */
@@ -161,16 +161,16 @@ export const PHOTOS_LIBRARY_CONFIG = {
161
161
  `${PLATFORM.IS_WINDOWS ? '\\' : '/'}Masters${PLATFORM.IS_WINDOWS ? '\\' : '/'}`,
162
162
  `${PLATFORM.IS_WINDOWS ? '\\' : '/'}Originals${PLATFORM.IS_WINDOWS ? '\\' : '/'}`,
163
163
  `${PLATFORM.IS_WINDOWS ? '\\' : '/'}Resources${PLATFORM.IS_WINDOWS ? '\\' : '/'}`,
164
- `${PLATFORM.IS_WINDOWS ? '\\' : '/'}Thumbnails${PLATFORM.IS_WINDOWS ? '\\' : '/'}`
164
+ `${PLATFORM.IS_WINDOWS ? '\\' : '/'}Thumbnails${PLATFORM.IS_WINDOWS ? '\\' : '/'}`,
165
165
  ],
166
166
  BLOCKED: [
167
167
  `${PLATFORM.IS_WINDOWS ? '\\' : '/'}database${PLATFORM.IS_WINDOWS ? '\\' : '/'}`,
168
168
  `${PLATFORM.IS_WINDOWS ? '\\' : '/'}search${PLATFORM.IS_WINDOWS ? '\\' : '/'}`,
169
169
  `${PLATFORM.IS_WINDOWS ? '\\' : '/'}Spotlight${PLATFORM.IS_WINDOWS ? '\\' : '/'}`,
170
170
  `${PLATFORM.IS_WINDOWS ? '\\' : '/'}Cache${PLATFORM.IS_WINDOWS ? '\\' : '/'}`,
171
- `${PLATFORM.IS_WINDOWS ? '\\' : '/'}index.spotlightV3${PLATFORM.IS_WINDOWS ? '\\' : '/'}`
172
- ]
173
- }
171
+ `${PLATFORM.IS_WINDOWS ? '\\' : '/'}index.spotlightV3${PLATFORM.IS_WINDOWS ? '\\' : '/'}`,
172
+ ],
173
+ },
174
174
  }
175
175
 
176
176
  /** 其他应用特定目录配置(跨平台) */
@@ -179,12 +179,12 @@ export const APP_SPECIFIC_CONFIG = {
179
179
  ICLOUD: {
180
180
  BLOCKED_PATHS: [
181
181
  `${PLATFORM.IS_WINDOWS ? '\\' : '/'}iCloud Drive${PLATFORM.IS_WINDOWS ? '\\' : '/'}`,
182
- `${PLATFORM.IS_WINDOWS ? '\\' : '/'}Mobile Documents${PLATFORM.IS_WINDOWS ? '\\' : '/'}`
182
+ `${PLATFORM.IS_WINDOWS ? '\\' : '/'}Mobile Documents${PLATFORM.IS_WINDOWS ? '\\' : '/'}`,
183
183
  ],
184
184
  ALLOWED_PATHS: [
185
185
  `${PLATFORM.IS_WINDOWS ? '\\' : '/'}iCloud Drive${PLATFORM.IS_WINDOWS ? '\\' : '/'}Desktop${PLATFORM.IS_WINDOWS ? '\\' : '/'}`,
186
- `${PLATFORM.IS_WINDOWS ? '\\' : '/'}iCloud Drive${PLATFORM.IS_WINDOWS ? '\\' : '/'}Documents${PLATFORM.IS_WINDOWS ? '\\' : '/'}`
187
- ]
186
+ `${PLATFORM.IS_WINDOWS ? '\\' : '/'}iCloud Drive${PLATFORM.IS_WINDOWS ? '\\' : '/'}Documents${PLATFORM.IS_WINDOWS ? '\\' : '/'}`,
187
+ ],
188
188
  },
189
189
 
190
190
  /** 浏览器缓存目录(跨平台) */
@@ -197,7 +197,7 @@ export const APP_SPECIFIC_CONFIG = {
197
197
  'Opera',
198
198
  'Brave',
199
199
  'Vivaldi',
200
- 'Tor Browser'
200
+ 'Tor Browser',
201
201
  ]),
202
202
  BLOCKED_PATHS: [
203
203
  `${PLATFORM.IS_WINDOWS ? '\\' : '/'}Cache${PLATFORM.IS_WINDOWS ? '\\' : '/'}`,
@@ -205,8 +205,8 @@ export const APP_SPECIFIC_CONFIG = {
205
205
  `${PLATFORM.IS_WINDOWS ? '\\' : '/'}Local Storage${PLATFORM.IS_WINDOWS ? '\\' : '/'}`,
206
206
  `${PLATFORM.IS_WINDOWS ? '\\' : '/'}Session Storage${PLATFORM.IS_WINDOWS ? '\\' : '/'}`,
207
207
  `${PLATFORM.IS_WINDOWS ? '\\' : '/'}IndexedDB${PLATFORM.IS_WINDOWS ? '\\' : '/'}`,
208
- `${PLATFORM.IS_WINDOWS ? '\\' : '/'}WebStorage${PLATFORM.IS_WINDOWS ? '\\' : '/'}`
209
- ]
208
+ `${PLATFORM.IS_WINDOWS ? '\\' : '/'}WebStorage${PLATFORM.IS_WINDOWS ? '\\' : '/'}`,
209
+ ],
210
210
  },
211
211
 
212
212
  /** 开发工具目录(跨平台) */
@@ -227,34 +227,38 @@ export const APP_SPECIFIC_CONFIG = {
227
227
  '.vuepress',
228
228
  '.docusaurus',
229
229
  'coverage',
230
- '.nyc_output'
231
- ])
230
+ '.nyc_output',
231
+ ]),
232
232
  },
233
233
 
234
234
  /** Windows 特定应用目录 */
235
- WINDOWS_APPS: PLATFORM.IS_WINDOWS ? {
236
- BLOCKED_DIRS: new Set([
237
- 'WindowsApps',
238
- 'Microsoft',
239
- 'Windows Defender',
240
- 'Windows Security',
241
- 'Windows Update',
242
- 'Windows.old'
243
- ])
244
- } : undefined,
235
+ WINDOWS_APPS: PLATFORM.IS_WINDOWS
236
+ ? {
237
+ BLOCKED_DIRS: new Set([
238
+ 'WindowsApps',
239
+ 'Microsoft',
240
+ 'Windows Defender',
241
+ 'Windows Security',
242
+ 'Windows Update',
243
+ 'Windows.old',
244
+ ]),
245
+ }
246
+ : undefined,
245
247
 
246
248
  /** Linux 特定应用目录 */
247
- LINUX_APPS: PLATFORM.IS_LINUX ? {
248
- BLOCKED_DIRS: new Set([
249
- '.local',
250
- '.config',
251
- '.cache',
252
- '.snap',
253
- '.flatpak',
254
- 'snap',
255
- 'flatpak'
256
- ])
257
- } : undefined
249
+ LINUX_APPS: PLATFORM.IS_LINUX
250
+ ? {
251
+ BLOCKED_DIRS: new Set([
252
+ '.local',
253
+ '.config',
254
+ '.cache',
255
+ '.snap',
256
+ '.flatpak',
257
+ 'snap',
258
+ 'flatpak',
259
+ ]),
260
+ }
261
+ : undefined,
258
262
  }
259
263
 
260
264
  // ==================== 文件扩展名配置 ====================
@@ -271,7 +275,7 @@ export const TEMP_FILE_EXTENSIONS = new Set([
271
275
  '.swo',
272
276
  '.~',
273
277
  '.DS_Store',
274
- '.Thumbs.db'
278
+ '.Thumbs.db',
275
279
  ])
276
280
 
277
281
  /** 系统文件扩展名黑名单 */
@@ -287,7 +291,7 @@ export const SYSTEM_FILE_EXTENSIONS = new Set([
287
291
  '.pkg',
288
292
  '.dmg',
289
293
  '.iso',
290
- '.img'
294
+ '.img',
291
295
  ])
292
296
 
293
297
  /** 数据库文件扩展名黑名单 */
@@ -299,35 +303,35 @@ export const DATABASE_FILE_EXTENSIONS = new Set([
299
303
  '.sqlite',
300
304
  '.sqlite3',
301
305
  '.sqlite-wal',
302
- '.sqlite-shm'
306
+ '.sqlite-shm',
303
307
  ])
304
308
 
305
309
  /** 合并的文件扩展名黑名单 */
306
310
  export const BLACKLISTED_EXTENSIONS = new Set([
307
311
  ...TEMP_FILE_EXTENSIONS,
308
312
  ...SYSTEM_FILE_EXTENSIONS,
309
- ...DATABASE_FILE_EXTENSIONS
313
+ ...DATABASE_FILE_EXTENSIONS,
310
314
  ])
311
315
 
312
316
  // ==================== 文件名模式配置 ====================
313
317
 
314
318
  /** 文件名前缀黑名单 */
315
319
  export const BLACKLISTED_FILE_PREFIXES = new Set([
316
- '.', // 隐藏文件
317
- '~', // 临时文件
318
- '#', // 临时文件
319
- '$' // 系统文件
320
+ '.', // 隐藏文件
321
+ '~', // 临时文件
322
+ '#', // 临时文件
323
+ '$', // 系统文件
320
324
  ])
321
325
 
322
326
  /** 文件名后缀黑名单 */
323
327
  export const BLACKLISTED_FILE_SUFFIXES = new Set([
324
- '~', // 备份文件
325
- '.tmp', // 临时文件
326
- '.bak', // 备份文件
327
- '.old', // 旧文件
328
- '.orig', // 原始文件
329
- '.swp', // Vim 交换文件
330
- '.swo' // Vim 交换文件
328
+ '~', // 备份文件
329
+ '.tmp', // 临时文件
330
+ '.bak', // 备份文件
331
+ '.old', // 旧文件
332
+ '.orig', // 原始文件
333
+ '.swp', // Vim 交换文件
334
+ '.swo', // Vim 交换文件
331
335
  ])
332
336
 
333
337
  // ==================== 路径模式配置 ====================
@@ -337,52 +341,58 @@ export const PATH_PATTERNS = {
337
341
  /** 系统路径模式(跨平台) */
338
342
  SYSTEM_PATHS: [
339
343
  // macOS 系统路径
340
- ...(PLATFORM.IS_MACOS ? [
341
- /^\/System\//,
342
- /^\/Library\//,
343
- /^\/Applications\//,
344
- /^\/usr\//,
345
- /^\/bin\//,
346
- /^\/sbin\//,
347
- /^\/var\//,
348
- /^\/tmp\//,
349
- /^\/private\//,
350
- /^\/opt\//,
351
- /^\/Users\/[^\/]+\/Library\//,
352
- /^\/Users\/[^\/]+\/\./
353
- ] : []),
344
+ ...(PLATFORM.IS_MACOS
345
+ ? [
346
+ /^\/System\//,
347
+ /^\/Library\//,
348
+ /^\/Applications\//,
349
+ /^\/usr\//,
350
+ /^\/bin\//,
351
+ /^\/sbin\//,
352
+ /^\/var\//,
353
+ /^\/tmp\//,
354
+ /^\/private\//,
355
+ /^\/opt\//,
356
+ /^\/Users\/[^/]+\/Library\//,
357
+ /^\/Users\/[^/]+\/\./,
358
+ ]
359
+ : []),
354
360
 
355
361
  // Windows 系统路径
356
- ...(PLATFORM.IS_WINDOWS ? [
357
- /^[A-Za-z]:\\Windows\\/i,
358
- /^[A-Za-z]:\\Program Files\\/i,
359
- /^[A-Za-z]:\\Program Files \(x86\)\\/i,
360
- /^[A-Za-z]:\\ProgramData\\/i,
361
- /^[A-Za-z]:\\System32\\/i,
362
- /^[A-Za-z]:\\Users\\[^\\]+\\./i,
363
- /^[A-Za-z]:\\Users\\[^\\]+\\AppData\\/i
364
- ] : []),
362
+ ...(PLATFORM.IS_WINDOWS
363
+ ? [
364
+ /^[A-Z]:\\Windows\\/i,
365
+ /^[A-Z]:\\Program Files\\/i,
366
+ /^[A-Z]:\\Program Files \(x86\)\\/i,
367
+ /^[A-Z]:\\ProgramData\\/i,
368
+ /^[A-Z]:\\System32\\/i,
369
+ /^[A-Z]:\\Users\\[^\\]+\\./i,
370
+ /^[A-Z]:\\Users\\[^\\]+\\AppData\\/i,
371
+ ]
372
+ : []),
365
373
 
366
374
  // Linux 系统路径
367
- ...(PLATFORM.IS_LINUX ? [
368
- /^\/bin\//,
369
- /^\/sbin\//,
370
- /^\/usr\//,
371
- /^\/var\//,
372
- /^\/tmp\//,
373
- /^\/opt\//,
374
- /^\/etc\//,
375
- /^\/dev\//,
376
- /^\/proc\//,
377
- /^\/sys\//,
378
- /^\/boot\//,
379
- /^\/lib\//,
380
- /^\/lib64\//,
381
- /^\/mnt\//,
382
- /^\/media\//,
383
- /^\/srv\//,
384
- /^\/home\/[^\/]+\/\./
385
- ] : [])
375
+ ...(PLATFORM.IS_LINUX
376
+ ? [
377
+ /^\/bin\//,
378
+ /^\/sbin\//,
379
+ /^\/usr\//,
380
+ /^\/var\//,
381
+ /^\/tmp\//,
382
+ /^\/opt\//,
383
+ /^\/etc\//,
384
+ /^\/dev\//,
385
+ /^\/proc\//,
386
+ /^\/sys\//,
387
+ /^\/boot\//,
388
+ /^\/lib\//,
389
+ /^\/lib64\//,
390
+ /^\/mnt\//,
391
+ /^\/media\//,
392
+ /^\/srv\//,
393
+ /^\/home\/[^/]+\/\./,
394
+ ]
395
+ : []),
386
396
  ],
387
397
 
388
398
  /** 开发路径模式(跨平台) */
@@ -402,7 +412,7 @@ export const PATH_PATTERNS = {
402
412
  /\.vuepress\//,
403
413
  /\.docusaurus\//,
404
414
  /coverage\//,
405
- /\.nyc_output\//
415
+ /\.nyc_output\//,
406
416
  ],
407
417
 
408
418
  /** 缓存路径模式(跨平台) */
@@ -416,28 +426,34 @@ export const PATH_PATTERNS = {
416
426
  /\/logs\//,
417
427
  /\/\.logs\//,
418
428
  // Windows 特定缓存路径
419
- ...(PLATFORM.IS_WINDOWS ? [
420
- /\\AppData\\Local\\Temp\\/i,
421
- /\\AppData\\Local\\Microsoft\\Windows\\INetCache\\/i,
422
- /\\AppData\\Roaming\\Microsoft\\Windows\\Recent\\/i
423
- ] : []),
429
+ ...(PLATFORM.IS_WINDOWS
430
+ ? [
431
+ /\\AppData\\Local\\Temp\\/i,
432
+ /\\AppData\\Local\\Microsoft\\Windows\\INetCache\\/i,
433
+ /\\AppData\\Roaming\\Microsoft\\Windows\\Recent\\/i,
434
+ ]
435
+ : []),
424
436
  // Unix 特定缓存路径
425
- ...(PLATFORM.IS_UNIX ? [
426
- /\/var\/cache\//,
427
- /\/var\/tmp\//,
428
- /\/home\/[^\/]+\/\.cache\//,
429
- /\/home\/[^\/]+\/\.local\/share\//
430
- ] : [])
437
+ ...(PLATFORM.IS_UNIX
438
+ ? [
439
+ /\/var\/cache\//,
440
+ /\/var\/tmp\//,
441
+ /\/home\/[^/]+\/\.cache\//,
442
+ /\/home\/[^/]+\/\.local\/share\//,
443
+ ]
444
+ : []),
431
445
  ],
432
446
 
433
447
  /** Photos Library 路径模式(仅 macOS) */
434
- PHOTOS_LIBRARY_PATHS: PLATFORM.IS_MACOS ? [
435
- /Photos Library\.photoslibrary\/database\//,
436
- /Photos Library\.photoslibrary\/search\//,
437
- /Photos Library\.photoslibrary\/Spotlight\//,
438
- /Photos Library\.photoslibrary\/Cache\//,
439
- /Photos Library\.photoslibrary\/index\.spotlightV3\//
440
- ] : []
448
+ PHOTOS_LIBRARY_PATHS: PLATFORM.IS_MACOS
449
+ ? [
450
+ /Photos Library\.photoslibrary\/database\//,
451
+ /Photos Library\.photoslibrary\/search\//,
452
+ /Photos Library\.photoslibrary\/Spotlight\//,
453
+ /Photos Library\.photoslibrary\/Cache\//,
454
+ /Photos Library\.photoslibrary\/index\.spotlightV3\//,
455
+ ]
456
+ : [],
441
457
  }
442
458
 
443
459
  // ==================== 导出配置 ====================
@@ -521,7 +537,7 @@ export const DEFAULT_SCAN_OPTIONS: FileScanOptions = {
521
537
  enableSystemPathFilter: true,
522
538
  enableDevPathFilter: true,
523
539
  enableCachePathFilter: true,
524
- strictMode: false
540
+ strictMode: false,
525
541
  }
526
542
 
527
543
  /**
@@ -539,5 +555,5 @@ export const STRICT_SCAN_OPTIONS: FileScanOptions = {
539
555
  enableSystemPathFilter: true,
540
556
  enableDevPathFilter: true,
541
557
  enableCachePathFilter: true,
542
- strictMode: true
558
+ strictMode: true,
543
559
  }
@@ -7,22 +7,32 @@
7
7
  * @version 1.0.0
8
8
  */
9
9
 
10
+ import type { FileScanOptions } from './file-scan-constants'
10
11
  // eslint-disable-next-line @typescript-eslint/no-var-requires
11
- const path = typeof window === 'undefined'
12
- ? require('path')
13
- : require('path-browserify')
14
12
  import {
15
- type FileScanOptions,
16
- DEFAULT_SCAN_OPTIONS,
17
13
  BASE_BLACKLISTED_DIRS,
18
14
  BLACKLISTED_EXTENSIONS,
19
15
  BLACKLISTED_FILE_PREFIXES,
20
16
  BLACKLISTED_FILE_SUFFIXES,
21
- PHOTOS_LIBRARY_CONFIG,
17
+ DEFAULT_SCAN_OPTIONS,
18
+
22
19
  PATH_PATTERNS,
23
- PLATFORM
20
+ PHOTOS_LIBRARY_CONFIG,
21
+ PLATFORM,
24
22
  } from './file-scan-constants'
25
23
 
24
+ const path = (() => {
25
+ if (typeof window === 'undefined') {
26
+ return require('node:path')
27
+ }
28
+ try {
29
+ return require('path-browserify')
30
+ }
31
+ catch {
32
+ return require('node:path')
33
+ }
34
+ })()
35
+
26
36
  // 重新导出类型
27
37
  export type { FileScanOptions }
28
38
 
@@ -77,29 +87,33 @@ export function isIndexableFile(
77
87
  fullPath: string,
78
88
  extension: string,
79
89
  fileName: string,
80
- options: FileScanOptions = DEFAULT_SCAN_OPTIONS
90
+ options: FileScanOptions = DEFAULT_SCAN_OPTIONS,
81
91
  ): boolean {
82
92
  // 合并选项
83
93
  const opts = { ...DEFAULT_SCAN_OPTIONS, ...options }
84
94
 
85
95
  // 基础检查
86
- if (!extension) return false
96
+ if (!extension)
97
+ return false
87
98
 
88
99
  // 检查扩展名黑名单
89
100
  const blacklistedExtensions = new Set([
90
101
  ...BLACKLISTED_EXTENSIONS,
91
- ...(opts.customBlacklistedExtensions || [])
102
+ ...(opts.customBlacklistedExtensions || []),
92
103
  ])
93
104
 
94
- if (blacklistedExtensions.has(extension)) return false
105
+ if (blacklistedExtensions.has(extension))
106
+ return false
95
107
 
96
108
  // 检查文件名前缀和后缀
97
109
  if (fileName) {
98
110
  const firstChar = fileName[0]
99
111
  const lastChar = fileName[fileName.length - 1]
100
112
 
101
- if (BLACKLISTED_FILE_PREFIXES.has(firstChar)) return false
102
- if (BLACKLISTED_FILE_SUFFIXES.has(lastChar)) return false
113
+ if (BLACKLISTED_FILE_PREFIXES.has(firstChar))
114
+ return false
115
+ if (BLACKLISTED_FILE_SUFFIXES.has(lastChar))
116
+ return false
103
117
  }
104
118
 
105
119
  // Photos Library 智能过滤(仅 macOS)
@@ -127,15 +141,18 @@ export function isIndexableFile(
127
141
  // 目录黑名单检查
128
142
  const blacklistedDirs = new Set([
129
143
  ...BASE_BLACKLISTED_DIRS,
130
- ...(opts.customBlacklistedDirs || [])
144
+ ...(opts.customBlacklistedDirs || []),
131
145
  ])
132
146
 
133
147
  const segments = fullPath.split(path.sep)
134
148
  for (let i = 0; i < segments.length - 1; i++) {
135
149
  const segment = segments[i]
136
- if (!segment) continue
137
- if (segment.startsWith('.')) return false
138
- if (blacklistedDirs.has(segment)) return false
150
+ if (!segment)
151
+ continue
152
+ if (segment.startsWith('.'))
153
+ return false
154
+ if (blacklistedDirs.has(segment))
155
+ return false
139
156
  }
140
157
 
141
158
  // 自定义排除路径检查
@@ -252,7 +269,7 @@ function isCachePath(fullPath: string): boolean {
252
269
  export async function scanDirectory(
253
270
  dirPath: string,
254
271
  options: FileScanOptions = DEFAULT_SCAN_OPTIONS,
255
- excludePaths?: Set<string>
272
+ excludePaths?: Set<string>,
256
273
  ): Promise<ScannedFileInfo[]> {
257
274
  const opts = { ...DEFAULT_SCAN_OPTIONS, ...options }
258
275
 
@@ -265,7 +282,7 @@ export async function scanDirectory(
265
282
  const dirName = path.basename(dirPath)
266
283
  const blacklistedDirs = new Set([
267
284
  ...BASE_BLACKLISTED_DIRS,
268
- ...(opts.customBlacklistedDirs || [])
285
+ ...(opts.customBlacklistedDirs || []),
269
286
  ])
270
287
 
271
288
  if (blacklistedDirs.has(dirName) || dirName.startsWith('.')) {
@@ -288,9 +305,10 @@ export async function scanDirectory(
288
305
  // 读取目录
289
306
  let entries: any[] = []
290
307
  try {
291
- const fs = await import('fs/promises')
308
+ const fs = await import('node:fs/promises')
292
309
  entries = await fs.readdir(dirPath, { withFileTypes: true })
293
- } catch {
310
+ }
311
+ catch {
294
312
  // 忽略权限错误等
295
313
  return []
296
314
  }
@@ -308,7 +326,8 @@ export async function scanDirectory(
308
326
  // 递归扫描子目录
309
327
  const subFiles = await scanDirectory(fullPath, opts, excludePaths)
310
328
  files.push(...subFiles)
311
- } else if (entry.isFile()) {
329
+ }
330
+ else if (entry.isFile()) {
312
331
  const fileName = entry.name
313
332
  const fileExtension = path.extname(fileName).toLowerCase()
314
333
 
@@ -318,7 +337,7 @@ export async function scanDirectory(
318
337
  }
319
338
 
320
339
  try {
321
- const fs = await import('fs/promises')
340
+ const fs = await import('node:fs/promises')
322
341
  const stats = await fs.stat(fullPath)
323
342
  files.push({
324
343
  path: fullPath,
@@ -326,9 +345,10 @@ export async function scanDirectory(
326
345
  extension: fileExtension,
327
346
  size: stats.size,
328
347
  ctime: stats.birthtime ?? stats.ctime,
329
- mtime: stats.mtime
348
+ mtime: stats.mtime,
330
349
  })
331
- } catch (error) {
350
+ }
351
+ catch (error) {
332
352
  console.error(`[FileScanUtils] Could not stat file ${fullPath}:`, error)
333
353
  }
334
354
  }
@@ -366,7 +386,7 @@ export async function scanDirectory(
366
386
  export async function scanDirectories(
367
387
  dirPaths: string[],
368
388
  options: FileScanOptions = DEFAULT_SCAN_OPTIONS,
369
- excludePaths?: Set<string>
389
+ excludePaths?: Set<string>,
370
390
  ): Promise<ScannedFileInfo[]> {
371
391
  const allFiles: ScannedFileInfo[] = []
372
392
 
@@ -374,7 +394,8 @@ export async function scanDirectories(
374
394
  try {
375
395
  const files = await scanDirectory(dirPath, options, excludePaths)
376
396
  allFiles.push(...files)
377
- } catch (error) {
397
+ }
398
+ catch (error) {
378
399
  console.error(`[FileScanUtils] Error scanning directory ${dirPath}:`, error)
379
400
  }
380
401
  }
package/common/index.ts CHANGED
@@ -1,6 +1,6 @@
1
- export * from './storage/index'
2
- export * from './utils'
3
- export * from './search'
4
1
  export * from '../electron/file-parsers'
5
2
  export * from './file-scan-constants'
6
3
  export * from './file-scan-utils'
4
+ export * from './search'
5
+ export * from './storage/index'
6
+ export * from './utils'
@@ -1,4 +1,4 @@
1
- import { TuffUpdate } from "."
1
+ import type { TuffUpdate } from '.'
2
2
 
3
3
  /**
4
4
  * @interface ITuffGatherOptions