@talex-touch/utils 1.0.30 → 1.0.32

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 (113) hide show
  1. package/animation/window-node.ts +205 -0
  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 +6 -6
  7. package/auth/useClerkProvider.ts +3 -2
  8. package/channel/index.ts +28 -21
  9. package/common/file-scan-constants.ts +137 -121
  10. package/common/file-scan-utils.ts +49 -25
  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 +19 -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 +15 -4
  19. package/common/utils/index.ts +62 -52
  20. package/common/utils/polling.ts +114 -63
  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 +255 -230
  26. package/core-box/index.ts +3 -6
  27. package/core-box/preview/index.ts +1 -0
  28. package/core-box/preview/types.ts +43 -0
  29. package/core-box/tuff/index.ts +1 -1
  30. package/core-box/tuff/tuff-dsl.ts +419 -253
  31. package/electron/clipboard-helper.ts +20 -12
  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 +1 -1
  39. package/eventbus/index.ts +11 -11
  40. package/index.ts +6 -5
  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 +113 -84
  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 +6 -3
  54. package/plugin/providers/registry.ts +8 -7
  55. package/plugin/providers/types.ts +6 -6
  56. package/plugin/sdk/channel.ts +20 -20
  57. package/plugin/sdk/clipboard.ts +8 -6
  58. package/plugin/sdk/common.ts +10 -6
  59. package/plugin/sdk/core-box.ts +2 -3
  60. package/plugin/sdk/division-box.ts +266 -0
  61. package/plugin/sdk/enum/bridge-event.ts +1 -1
  62. package/plugin/sdk/examples/storage-onDidChange-example.js +1 -1
  63. package/plugin/sdk/features.ts +34 -26
  64. package/plugin/sdk/hooks/bridge.ts +3 -6
  65. package/plugin/sdk/hooks/index.ts +1 -1
  66. package/plugin/sdk/hooks/life-cycle.ts +4 -10
  67. package/plugin/sdk/index.ts +9 -13
  68. package/plugin/sdk/service/index.ts +3 -3
  69. package/plugin/sdk/storage.ts +4 -4
  70. package/plugin/sdk/system.ts +1 -1
  71. package/plugin/sdk/types.ts +169 -143
  72. package/plugin/sdk/window/index.ts +8 -5
  73. package/preload/loading.ts +6 -6
  74. package/preload/renderer.ts +4 -2
  75. package/renderer/hooks/arg-mapper.ts +1 -2
  76. package/renderer/hooks/index.ts +2 -0
  77. package/renderer/hooks/initialize.ts +10 -8
  78. package/renderer/hooks/performance.ts +4 -4
  79. package/renderer/hooks/use-channel.ts +150 -0
  80. package/renderer/hooks/use-intelligence.ts +236 -0
  81. package/renderer/index.ts +6 -1
  82. package/renderer/ref.ts +32 -36
  83. package/renderer/slots.ts +29 -26
  84. package/renderer/storage/app-settings.ts +16 -6
  85. package/renderer/storage/base-storage.ts +236 -88
  86. package/renderer/storage/index.ts +3 -0
  87. package/renderer/storage/intelligence-storage.ts +215 -0
  88. package/renderer/storage/openers.ts +13 -3
  89. package/renderer/touch-sdk/env.ts +41 -41
  90. package/renderer/touch-sdk/index.ts +1 -1
  91. package/renderer/touch-sdk/terminal.ts +5 -5
  92. package/renderer/touch-sdk/utils.ts +4 -3
  93. package/search/levenshtein-utils.ts +11 -11
  94. package/search/types.ts +102 -103
  95. package/service/index.ts +11 -11
  96. package/service/protocol/index.ts +217 -14
  97. package/types/division-box.ts +248 -0
  98. package/types/download.ts +72 -34
  99. package/types/icon.ts +2 -1
  100. package/types/index.ts +3 -1
  101. package/types/intelligence.ts +413 -0
  102. package/types/modules/base.ts +16 -16
  103. package/types/modules/index.ts +1 -1
  104. package/types/modules/module-lifecycle.ts +21 -21
  105. package/types/modules/module-manager.ts +11 -11
  106. package/types/modules/module.ts +16 -16
  107. package/types/storage.ts +0 -1
  108. package/types/touch-app-core.ts +32 -32
  109. package/types/update.ts +79 -21
  110. package/core-box/README.md +0 -218
  111. package/core-box/builder/tuff-builder.example.ts.bak +0 -258
  112. package/core-box/run-tests.sh +0 -7
  113. package/core-box/search.ts +0 -1
@@ -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,19 +7,32 @@
7
7
  * @version 1.0.0
8
8
  */
9
9
 
10
- import path from 'path'
10
+ import type { FileScanOptions } from './file-scan-constants'
11
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
11
12
  import {
12
- type FileScanOptions,
13
- DEFAULT_SCAN_OPTIONS,
14
13
  BASE_BLACKLISTED_DIRS,
15
14
  BLACKLISTED_EXTENSIONS,
16
15
  BLACKLISTED_FILE_PREFIXES,
17
16
  BLACKLISTED_FILE_SUFFIXES,
18
- PHOTOS_LIBRARY_CONFIG,
17
+ DEFAULT_SCAN_OPTIONS,
18
+
19
19
  PATH_PATTERNS,
20
- PLATFORM
20
+ PHOTOS_LIBRARY_CONFIG,
21
+ PLATFORM,
21
22
  } from './file-scan-constants'
22
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
+
23
36
  // 重新导出类型
24
37
  export type { FileScanOptions }
25
38
 
@@ -74,29 +87,33 @@ export function isIndexableFile(
74
87
  fullPath: string,
75
88
  extension: string,
76
89
  fileName: string,
77
- options: FileScanOptions = DEFAULT_SCAN_OPTIONS
90
+ options: FileScanOptions = DEFAULT_SCAN_OPTIONS,
78
91
  ): boolean {
79
92
  // 合并选项
80
93
  const opts = { ...DEFAULT_SCAN_OPTIONS, ...options }
81
94
 
82
95
  // 基础检查
83
- if (!extension) return false
96
+ if (!extension)
97
+ return false
84
98
 
85
99
  // 检查扩展名黑名单
86
100
  const blacklistedExtensions = new Set([
87
101
  ...BLACKLISTED_EXTENSIONS,
88
- ...(opts.customBlacklistedExtensions || [])
102
+ ...(opts.customBlacklistedExtensions || []),
89
103
  ])
90
104
 
91
- if (blacklistedExtensions.has(extension)) return false
105
+ if (blacklistedExtensions.has(extension))
106
+ return false
92
107
 
93
108
  // 检查文件名前缀和后缀
94
109
  if (fileName) {
95
110
  const firstChar = fileName[0]
96
111
  const lastChar = fileName[fileName.length - 1]
97
112
 
98
- if (BLACKLISTED_FILE_PREFIXES.has(firstChar)) return false
99
- 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
100
117
  }
101
118
 
102
119
  // Photos Library 智能过滤(仅 macOS)
@@ -124,15 +141,18 @@ export function isIndexableFile(
124
141
  // 目录黑名单检查
125
142
  const blacklistedDirs = new Set([
126
143
  ...BASE_BLACKLISTED_DIRS,
127
- ...(opts.customBlacklistedDirs || [])
144
+ ...(opts.customBlacklistedDirs || []),
128
145
  ])
129
146
 
130
147
  const segments = fullPath.split(path.sep)
131
148
  for (let i = 0; i < segments.length - 1; i++) {
132
149
  const segment = segments[i]
133
- if (!segment) continue
134
- if (segment.startsWith('.')) return false
135
- 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
136
156
  }
137
157
 
138
158
  // 自定义排除路径检查
@@ -249,7 +269,7 @@ function isCachePath(fullPath: string): boolean {
249
269
  export async function scanDirectory(
250
270
  dirPath: string,
251
271
  options: FileScanOptions = DEFAULT_SCAN_OPTIONS,
252
- excludePaths?: Set<string>
272
+ excludePaths?: Set<string>,
253
273
  ): Promise<ScannedFileInfo[]> {
254
274
  const opts = { ...DEFAULT_SCAN_OPTIONS, ...options }
255
275
 
@@ -262,7 +282,7 @@ export async function scanDirectory(
262
282
  const dirName = path.basename(dirPath)
263
283
  const blacklistedDirs = new Set([
264
284
  ...BASE_BLACKLISTED_DIRS,
265
- ...(opts.customBlacklistedDirs || [])
285
+ ...(opts.customBlacklistedDirs || []),
266
286
  ])
267
287
 
268
288
  if (blacklistedDirs.has(dirName) || dirName.startsWith('.')) {
@@ -285,9 +305,10 @@ export async function scanDirectory(
285
305
  // 读取目录
286
306
  let entries: any[] = []
287
307
  try {
288
- const fs = await import('fs/promises')
308
+ const fs = await import('node:fs/promises')
289
309
  entries = await fs.readdir(dirPath, { withFileTypes: true })
290
- } catch {
310
+ }
311
+ catch {
291
312
  // 忽略权限错误等
292
313
  return []
293
314
  }
@@ -305,7 +326,8 @@ export async function scanDirectory(
305
326
  // 递归扫描子目录
306
327
  const subFiles = await scanDirectory(fullPath, opts, excludePaths)
307
328
  files.push(...subFiles)
308
- } else if (entry.isFile()) {
329
+ }
330
+ else if (entry.isFile()) {
309
331
  const fileName = entry.name
310
332
  const fileExtension = path.extname(fileName).toLowerCase()
311
333
 
@@ -315,7 +337,7 @@ export async function scanDirectory(
315
337
  }
316
338
 
317
339
  try {
318
- const fs = await import('fs/promises')
340
+ const fs = await import('node:fs/promises')
319
341
  const stats = await fs.stat(fullPath)
320
342
  files.push({
321
343
  path: fullPath,
@@ -323,9 +345,10 @@ export async function scanDirectory(
323
345
  extension: fileExtension,
324
346
  size: stats.size,
325
347
  ctime: stats.birthtime ?? stats.ctime,
326
- mtime: stats.mtime
348
+ mtime: stats.mtime,
327
349
  })
328
- } catch (error) {
350
+ }
351
+ catch (error) {
329
352
  console.error(`[FileScanUtils] Could not stat file ${fullPath}:`, error)
330
353
  }
331
354
  }
@@ -363,7 +386,7 @@ export async function scanDirectory(
363
386
  export async function scanDirectories(
364
387
  dirPaths: string[],
365
388
  options: FileScanOptions = DEFAULT_SCAN_OPTIONS,
366
- excludePaths?: Set<string>
389
+ excludePaths?: Set<string>,
367
390
  ): Promise<ScannedFileInfo[]> {
368
391
  const allFiles: ScannedFileInfo[] = []
369
392
 
@@ -371,7 +394,8 @@ export async function scanDirectories(
371
394
  try {
372
395
  const files = await scanDirectory(dirPath, options, excludePaths)
373
396
  allFiles.push(...files)
374
- } catch (error) {
397
+ }
398
+ catch (error) {
375
399
  console.error(`[FileScanUtils] Error scanning directory ${dirPath}:`, error)
376
400
  }
377
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