@talex-touch/utils 1.0.31 → 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 (112) 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 +87 -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 +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 +328 -266
  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 +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/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 +8 -7
  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 +147 -141
  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 -2
  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 +222 -114
  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 -102
  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/index.ts +3 -1
  100. package/types/intelligence.ts +413 -0
  101. package/types/modules/base.ts +16 -16
  102. package/types/modules/index.ts +1 -1
  103. package/types/modules/module-lifecycle.ts +21 -21
  104. package/types/modules/module-manager.ts +11 -11
  105. package/types/modules/module.ts +16 -16
  106. package/types/storage.ts +0 -1
  107. package/types/touch-app-core.ts +32 -32
  108. package/types/update.ts +79 -21
  109. package/core-box/README.md +0 -218
  110. package/core-box/builder/tuff-builder.example.ts.bak +0 -258
  111. package/core-box/run-tests.sh +0 -7
  112. package/core-box/search.ts +0 -1
package/plugin/index.ts CHANGED
@@ -1,6 +1,10 @@
1
- import { Arch, SupportOS } from './../base/index';
2
- import type { IPluginLogger } from './log/types';
3
- import type { PluginInstallRequest, PluginInstallSummary } from './providers';
1
+ import type { FSWatcher } from 'chokidar'
2
+ import type { ITuffIcon } from '../types/icon'
3
+ import type { Arch, SupportOS } from './../base/index'
4
+
5
+ import type { IPluginLogger } from './log/types'
6
+
7
+ import type { PluginInstallRequest, PluginInstallSummary } from './providers'
4
8
 
5
9
  export enum PluginStatus {
6
10
  DISABLED,
@@ -15,8 +19,8 @@ export enum PluginStatus {
15
19
  LOADED,
16
20
  LOAD_FAILED,
17
21
 
18
- DEV_DISCONNECTED, // Dev Server 断连
19
- DEV_RECONNECTING, // 正在重连
22
+ DEV_DISCONNECTED, // Dev Server 断连
23
+ DEV_RECONNECTING, // 正在重连
20
24
  }
21
25
 
22
26
  export interface PluginIssue {
@@ -36,9 +40,6 @@ export interface DevServerHealthCheckResult {
36
40
  error?: string
37
41
  }
38
42
 
39
- import type { ITuffIcon } from '../types/icon'
40
-
41
-
42
43
  export interface IPlatformInfo {
43
44
  enable: boolean
44
45
  arch: Arch[]
@@ -73,26 +74,27 @@ export interface ITouchPlugin extends IPluginBaseInfo {
73
74
  logger: IPluginLogger<any>
74
75
  features: IPluginFeature[]
75
76
  issues: PluginIssue[]
77
+ divisionBoxConfig?: import('../types/division-box').ManifestDivisionBoxConfig
76
78
 
77
- addFeature(feature: IPluginFeature): boolean
78
- delFeature(featureId: string): boolean
79
- getFeature(featureId: string): IPluginFeature | null
80
- getFeatures(): IPluginFeature[]
81
- triggerFeature(feature: IPluginFeature, query: any): void
82
- triggerInputChanged(feature: IPluginFeature, query: any): void
79
+ addFeature: (feature: IPluginFeature) => boolean
80
+ delFeature: (featureId: string) => boolean
81
+ getFeature: (featureId: string) => IPluginFeature | null
82
+ getFeatures: () => IPluginFeature[]
83
+ triggerFeature: (feature: IPluginFeature, query: any) => void
84
+ triggerInputChanged: (feature: IPluginFeature, query: any) => void
83
85
 
84
86
  get status(): PluginStatus
85
87
  set status(v: PluginStatus)
86
88
 
87
- enable(): Promise<boolean>
88
- disable(): Promise<boolean>
89
+ enable: () => Promise<boolean>
90
+ disable: () => Promise<boolean>
89
91
 
90
92
  /**
91
93
  * Get the plugin file.
92
94
  * @param fileName The name of the file.
93
95
  * @returns The content of the file.
94
96
  */
95
- getPluginFile(fileName: string): object
97
+ getPluginFile: (fileName: string) => object
96
98
 
97
99
  /**
98
100
  * Save the plugin file.
@@ -100,39 +102,39 @@ export interface ITouchPlugin extends IPluginBaseInfo {
100
102
  * @param content The content of the file.
101
103
  * @returns The result of the save operation.
102
104
  */
103
- savePluginFile(fileName: string, content: object): { success: boolean; error?: string }
105
+ savePluginFile: (fileName: string, content: object) => { success: boolean, error?: string }
104
106
 
105
107
  /**
106
108
  * Delete the plugin file.
107
109
  * @param fileName The name of the file.
108
110
  * @returns The result of the delete operation.
109
111
  */
110
- deletePluginFile(fileName: string): { success: boolean; error?: string }
112
+ deletePluginFile: (fileName: string) => { success: boolean, error?: string }
111
113
 
112
114
  /**
113
115
  * List all files in the plugin.
114
116
  * @returns The list of files.
115
117
  */
116
- listPluginFiles(): string[]
118
+ listPluginFiles: () => string[]
117
119
 
118
120
  /**
119
121
  * Get the plugin configuration.
120
122
  * @returns The configuration content.
121
123
  */
122
- getPluginConfig(): object
124
+ getPluginConfig: () => object
123
125
 
124
126
  /**
125
127
  * Save the plugin configuration.
126
128
  * @param content The configuration content.
127
129
  * @returns The result of the save operation.
128
130
  */
129
- savePluginConfig(content: object): { success: boolean; error?: string }
131
+ savePluginConfig: (content: object) => { success: boolean, error?: string }
130
132
  }
131
133
 
132
134
  export interface IFeatureCommand {
133
- type: "match" | "contain" | "regex" | "function" | "over" | "image" | "files" | "directory" | "window"
135
+ type: 'match' | 'contain' | 'regex' | 'function' | 'over' | 'image' | 'files' | 'directory' | 'window'
134
136
  value: string | string[] | RegExp | Function
135
- onTrigger(): void
137
+ onTrigger: () => void
136
138
  }
137
139
 
138
140
  export interface IPluginFeature {
@@ -161,7 +163,7 @@ export interface IPluginFeature {
161
163
  acceptedInputTypes?: Array<'text' | 'image' | 'files' | 'html'>
162
164
  }
163
165
 
164
- export type IFeatureInteraction = {
166
+ export interface IFeatureInteraction {
165
167
  type: 'webcontent' | 'widget'
166
168
  /**
167
169
  * The relative path to the html file from the plugin root.
@@ -178,20 +180,20 @@ export interface IFeatureLifeCycle {
178
180
  * onInit is called when the feature is initialized.
179
181
  * Can be used to prepare data or UI specific to this session.
180
182
  */
181
- onInit?(): void
183
+ onInit?: () => void
182
184
 
183
185
  /**
184
186
  * Called when a message is received from the main application.
185
187
  * @param key - The key of the message
186
188
  * @param info - The information of the message
187
189
  */
188
- onMessage?(key: string, info: any): void
190
+ onMessage?: (key: string, info: any) => void
189
191
  /**
190
192
  * Called when a feature is actively launched from the launcher.
191
193
  * Can be used to prepare data or UI specific to this session.
192
194
  * @param feature - The feature instance being launched
193
195
  */
194
- onLaunch?(feature: IPluginFeature): void
196
+ onLaunch?: (feature: IPluginFeature) => void
195
197
 
196
198
  /**
197
199
  * Called when a feature is triggered via a matching command.
@@ -203,14 +205,14 @@ export interface IFeatureLifeCycle {
203
205
  * @param signal - An AbortSignal to cancel the operation
204
206
  * @returns If returns false, the feature will not enter activation state (e.g., just opens browser and exits)
205
207
  */
206
- onFeatureTriggered(id: string, data: any, feature: IPluginFeature, signal?: AbortSignal): boolean | void
208
+ onFeatureTriggered: (id: string, data: any, feature: IPluginFeature, signal?: AbortSignal) => boolean | void
207
209
 
208
210
  /**
209
211
  * Called when user input changes within this feature’s input box.
210
212
  * For example, search text or commands typed.
211
213
  * @param input - The new input value
212
214
  */
213
- onInputChanged?(input: string): void
215
+ onInputChanged?: (input: string) => void
214
216
 
215
217
  /**
216
218
  * Called when a user selects or clicks an actionable item inside the feature.
@@ -218,14 +220,14 @@ export interface IFeatureLifeCycle {
218
220
  * @param actionId - A string identifier for the clicked action
219
221
  * @param data - Optional payload associated with that action
220
222
  */
221
- onActionClick?(actionId: string, data?: any): void
223
+ onActionClick?: (actionId: string, data?: any) => void
222
224
 
223
225
  /**
224
226
  * Called when the feature is manually closed by the user or by the system.
225
227
  * Useful for cleanup or state saving.
226
228
  * @param feature - The feature instance being closed
227
229
  */
228
- onClose?(feature: IPluginFeature): void
230
+ onClose?: (feature: IPluginFeature) => void
229
231
 
230
232
  /**
231
233
  * Called when an item generated by this feature is executed.
@@ -234,7 +236,7 @@ export interface IFeatureLifeCycle {
234
236
  * @param item The TuffItem that was executed.
235
237
  * @returns Object indicating whether to activate the feature and any activation data
236
238
  */
237
- onItemAction?(item: any): Promise<{
239
+ onItemAction?: (item: any) => Promise<{
238
240
  /** Whether the action executed an external operation (e.g., opened browser) */
239
241
  externalAction?: boolean
240
242
  /** Whether the feature should be activated after this action */
@@ -248,7 +250,7 @@ export interface IFeatureLifeCycle {
248
250
  * @param key - The storage key that changed
249
251
  * @param value - The new value (undefined if key was removed)
250
252
  */
251
- onStorageChange?(key: string, value: any): void
253
+ onStorageChange?: (key: string, value: any) => void
252
254
  }
253
255
 
254
256
  /**
@@ -261,7 +263,7 @@ export interface ITargetFeatureLifeCycle {
261
263
  * Can be used to prepare data or UI specific to this session.
262
264
  * @param feature - The feature instance being launched
263
265
  */
264
- onLaunch?(feature: IPluginFeature): void
266
+ onLaunch?: (feature: IPluginFeature) => void
265
267
 
266
268
  /**
267
269
  * Called when the feature is triggered via a matching command.
@@ -271,14 +273,14 @@ export interface ITargetFeatureLifeCycle {
271
273
  * @param feature - The full feature definition
272
274
  * @returns If returns false, the feature will not enter activation state (e.g., just opens browser and exits)
273
275
  */
274
- onFeatureTriggered(data: any, feature: IPluginFeature): boolean | void
276
+ onFeatureTriggered: (data: any, feature: IPluginFeature) => boolean | void
275
277
 
276
278
  /**
277
279
  * Called when user input changes within this feature’s input box.
278
280
  * For example, search text or commands typed.
279
281
  * @param input - The new input value
280
282
  */
281
- onInputChanged?(input: string): void
283
+ onInputChanged?: (input: string) => void
282
284
 
283
285
  /**
284
286
  * Called when a user selects or clicks an actionable item inside the feature.
@@ -286,14 +288,14 @@ export interface ITargetFeatureLifeCycle {
286
288
  * @param actionId - A string identifier for the clicked action
287
289
  * @param data - Optional payload associated with that action
288
290
  */
289
- onActionClick?(actionId: string, data?: any): void
291
+ onActionClick?: (actionId: string, data?: any) => void
290
292
 
291
293
  /**
292
294
  * Called when the feature is manually closed by the user or by the system.
293
295
  * Useful for cleanup or state saving.
294
296
  * @param feature - The feature instance being closed
295
297
  */
296
- onClose?(feature: IPluginFeature): void
298
+ onClose?: (feature: IPluginFeature) => void
297
299
 
298
300
  /**
299
301
  * Called when an item generated by this feature is executed.
@@ -302,7 +304,7 @@ export interface ITargetFeatureLifeCycle {
302
304
  * @param item The TuffItem that was executed.
303
305
  * @returns Object indicating whether to activate the feature and any activation data
304
306
  */
305
- onItemAction?(item: any): Promise<{
307
+ onItemAction?: (item: any) => Promise<{
306
308
  /** Whether the action executed an external operation (e.g., opened browser) */
307
309
  externalAction?: boolean
308
310
  /** Whether the feature should be activated after this action */
@@ -331,8 +333,6 @@ export enum PluginSourceType {
331
333
  FILE_SYSTEM = 'file_system',
332
334
  }
333
335
 
334
- import type { FSWatcher } from 'chokidar'
335
-
336
336
  export interface IPluginManager {
337
337
  plugins: Map<string, ITouchPlugin>
338
338
  active: string | null
@@ -345,18 +345,24 @@ export interface IPluginManager {
345
345
  devWatcher: any // Temporarily any, as DevPluginWatcher is internal to core-app
346
346
  healthMonitor: any | null // DevServerHealthMonitor instance, set by PluginModule
347
347
 
348
- getPluginList(): Array<object>
349
- setActivePlugin(pluginName: string): boolean
350
- hasPlugin(name: string): boolean
351
- getPluginByName(name: string): ITouchPlugin | undefined
352
- enablePlugin(pluginName: string): Promise<boolean>
353
- disablePlugin(pluginName: string): Promise<boolean>
354
- reloadPlugin(pluginName: string): Promise<void>
355
- persistEnabledPlugins(): Promise<void>
356
- listPlugins(): Promise<Array<string>>
357
- loadPlugin(pluginName: string): Promise<boolean>
358
- unloadPlugin(pluginName: string): Promise<boolean>
359
- installFromSource(request: PluginInstallRequest): Promise<PluginInstallSummary>
348
+ getPluginList: () => Array<object>
349
+ setActivePlugin: (pluginName: string) => boolean
350
+ hasPlugin: (name: string) => boolean
351
+ getPluginByName: (name: string) => ITouchPlugin | undefined
352
+ enablePlugin: (pluginName: string) => Promise<boolean>
353
+ disablePlugin: (pluginName: string) => Promise<boolean>
354
+ reloadPlugin: (pluginName: string) => Promise<void>
355
+ persistEnabledPlugins: () => Promise<void>
356
+ listPlugins: () => Promise<Array<string>>
357
+ loadPlugin: (pluginName: string) => Promise<boolean>
358
+ unloadPlugin: (pluginName: string) => Promise<boolean>
359
+ installFromSource: (request: PluginInstallRequest) => Promise<PluginInstallSummary>
360
+ uninstallPlugin: (pluginName: string) => Promise<boolean>
361
+ /**
362
+ * Register an internal plugin that is created in code (no manifest / scanning).
363
+ * Internal plugins are always hidden from user-facing plugin lists.
364
+ */
365
+ registerInternalPlugin: (plugin: ITouchPlugin) => void
360
366
  }
361
367
 
362
368
  /**
@@ -369,48 +375,56 @@ export interface IManifest {
369
375
  * Unique identifier for the plugin.
370
376
  * This is typically the package name for npm plugins or a unique string for tpex plugins.
371
377
  */
372
- id: string;
378
+ id: string
373
379
  /**
374
380
  * Display name of the plugin.
375
381
  * This is the human-readable name shown to users.
376
382
  */
377
- name: string;
383
+ name: string
378
384
  /**
379
385
  * Version of the plugin, following semantic versioning (e.g., "1.0.0").
380
386
  */
381
- version: string;
387
+ version: string
382
388
  /**
383
389
  * Short description of the plugin's functionality.
384
390
  */
385
- description: string;
391
+ description: string
386
392
  /**
387
393
  * Author of the plugin, typically a name or email.
388
394
  */
389
- author: string;
395
+ author: string
390
396
  /**
391
397
  * Main entry file for the plugin logic, relative to the plugin's root directory.
392
398
  * This file will be loaded when the plugin is activated.
393
399
  */
394
- main: string;
400
+ main: string
395
401
  /**
396
402
  * Optional icon path or definition for the plugin.
397
403
  * This could be a file path to an image or a specific icon class/identifier.
398
404
  */
399
- icon?: string;
405
+ icon?: string
400
406
  /**
401
407
  * Optional keywords for activating the plugin, e.g., for search or command matching.
402
408
  * These keywords help users discover and launch the plugin.
403
409
  */
404
- activationKeywords?: string[];
410
+ activationKeywords?: string[]
411
+ /**
412
+ * Optional runtime development configuration, typically used when running plugins from a dev server.
413
+ */
414
+ dev?: {
415
+ enable?: boolean
416
+ address?: string
417
+ source?: boolean
418
+ }
405
419
  /**
406
420
  * Optional digital signature of the plugin package, used for verification.
407
421
  */
408
- _signature?: string;
422
+ _signature?: string
409
423
  /**
410
424
  * Optional list of files included in the plugin package.
411
425
  * This can be used for integrity checks or resource management.
412
426
  */
413
- _files?: string[];
427
+ _files?: string[]
414
428
  /**
415
429
  * Development-specific configuration for the plugin.
416
430
  * This section is used during plugin development and might not be present in production builds.
@@ -421,14 +435,14 @@ export interface IManifest {
421
435
  * Whether development mode is enabled for the plugin.
422
436
  * If true, specific development features or debugging tools might be activated.
423
437
  */
424
- enable: boolean;
438
+ enable: boolean
425
439
  /**
426
440
  * Address for development server or resources.
427
441
  * For example, a local URL where the plugin's frontend assets are served during development.
428
442
  */
429
- address: string;
430
- };
431
- };
443
+ address: string
444
+ }
445
+ }
432
446
  /**
433
447
  * Build-specific configuration for the plugin.
434
448
  * This section defines how the plugin is built, packaged, and verified.
@@ -437,14 +451,14 @@ export interface IManifest {
437
451
  /**
438
452
  * List of files to include in the build.
439
453
  */
440
- files: string[];
454
+ files: string[]
441
455
  /**
442
456
  * Secret configuration for the build process.
443
457
  */
444
458
  secret: {
445
- pos: string;
446
- addon: string[];
447
- };
459
+ pos: string
460
+ addon: string[]
461
+ }
448
462
  /**
449
463
  * Verification settings for the plugin build.
450
464
  * Defines how the authenticity and integrity of the plugin are checked.
@@ -453,12 +467,12 @@ export interface IManifest {
453
467
  /**
454
468
  * Whether online verification is enabled.
455
469
  */
456
- enable: boolean;
470
+ enable: boolean
457
471
  /**
458
472
  * Online verification strategy.
459
473
  */
460
- online: 'custom' | 'always' | 'once';
461
- };
474
+ online: 'custom' | 'always' | 'once'
475
+ }
462
476
  /**
463
477
  * Version update settings for the plugin.
464
478
  * Defines how the plugin handles updates and downgrades.
@@ -470,17 +484,17 @@ export interface IManifest {
470
484
  * - 'ask': Prompts the user before updating.
471
485
  * - 'readable': Provides a readable update notification.
472
486
  */
473
- update: 'auto' | 'ask' | 'readable';
487
+ update: 'auto' | 'ask' | 'readable'
474
488
  /**
475
489
  * Whether downgrading the plugin version is allowed.
476
490
  */
477
- downgrade: boolean;
478
- };
479
- };
491
+ downgrade: boolean
492
+ }
493
+ }
480
494
  }
481
495
 
482
- export type { LogLevel, LogItem, LogDataType, IPluginLogger } from './log/types'
483
- export * from './sdk/index'
484
- export * from './providers'
485
496
  export * from './install'
497
+ export type { IPluginLogger, LogDataType, LogItem, LogLevel } from './log/types'
498
+ export * from './providers'
486
499
  export * from './risk'
500
+ export * from './sdk/index'
package/plugin/install.ts CHANGED
@@ -1,11 +1,11 @@
1
- export type PluginInstallTaskStage =
2
- | 'queued'
3
- | 'downloading'
4
- | 'awaiting-confirmation'
5
- | 'installing'
6
- | 'completed'
7
- | 'failed'
8
- | 'cancelled'
1
+ export type PluginInstallTaskStage
2
+ = | 'queued'
3
+ | 'downloading'
4
+ | 'awaiting-confirmation'
5
+ | 'installing'
6
+ | 'completed'
7
+ | 'failed'
8
+ | 'cancelled'
9
9
 
10
10
  export interface PluginInstallProgressEvent {
11
11
  taskId: string
@@ -30,9 +30,9 @@ export interface LogItem {
30
30
  * Minimal contract for plugin loggers so web 端只依赖接口定义
31
31
  */
32
32
  export interface IPluginLogger<TManager = unknown> {
33
- info(...args: LogDataType[]): void
34
- warn(...args: LogDataType[]): void
35
- error(...args: LogDataType[]): void
36
- debug(...args: LogDataType[]): void
37
- getManager(): TManager
33
+ info: (...args: LogDataType[]) => void
34
+ warn: (...args: LogDataType[]) => void
35
+ error: (...args: LogDataType[]) => void
36
+ debug: (...args: LogDataType[]) => void
37
+ getManager: () => TManager
38
38
  }
@@ -1,4 +1,4 @@
1
1
  export * from '..'
2
+ export type { IPluginLogger, LogDataType, LogItem, LogLevel } from '../log/types'
2
3
  export { PluginLogger } from './logger'
3
4
  export { PluginLoggerManager } from './logger-manager'
4
- export type { LogLevel, LogItem, LogDataType, IPluginLogger } from '../log/types'
@@ -1,7 +1,7 @@
1
- import fs from 'fs'
2
- import path from 'path'
3
- import { LogItem } from '../log/types'
4
- import { ITouchPlugin } from '..'
1
+ import type { ITouchPlugin } from '..'
2
+ import type { LogItem } from '../log/types'
3
+ import fs from 'node:fs'
4
+ import path from 'node:path'
5
5
  import { structuredStrictStringify } from '@talex-touch/utils'
6
6
 
7
7
  /**
@@ -28,7 +28,7 @@ export class PluginLoggerManager {
28
28
  this.onLogAppend = onLogAppend
29
29
  this.sessionStart = new Date().toISOString()
30
30
  const timestamp = this.sessionStart.replace(/[:.]/g, '-')
31
- const sessionFolder = `${timestamp}_${pluginInfo.name.replace(/[^a-zA-Z0-9-_]/g, '_')}`
31
+ const sessionFolder = `${timestamp}_${pluginInfo.name.replace(/[^\w-]/g, '_')}`
32
32
 
33
33
  this.pluginLogDir = path.resolve(baseDir, 'logs', sessionFolder)
34
34
  this.sessionLogPath = path.resolve(this.pluginLogDir, 'session.log')
@@ -51,14 +51,17 @@ export class PluginLoggerManager {
51
51
  * Flushes all buffered log items to the current session log file.
52
52
  */
53
53
  flush(): void {
54
- if (this.buffer.length === 0) return
55
- const lines = this.buffer.map((item) => structuredStrictStringify(item)).join('\n') + '\n'
54
+ if (this.buffer.length === 0)
55
+ return
56
+ const lines = `${this.buffer.map(item => structuredStrictStringify(item)).join('\n')}\n`
56
57
  try {
57
58
  this.ensureLogEnvironment()
58
59
  fs.appendFileSync(this.sessionLogPath, lines)
59
60
  this.buffer = []
60
- } catch (error) {
61
- if ((error as NodeJS.ErrnoException)?.code !== 'ENOENT') throw error
61
+ }
62
+ catch (error) {
63
+ if ((error as NodeJS.ErrnoException)?.code !== 'ENOENT')
64
+ throw error
62
65
  // Directory or file was removed; rebuild and retry once.
63
66
  this.ensureLogEnvironment(true)
64
67
  fs.appendFileSync(this.sessionLogPath, lines)
@@ -105,8 +108,8 @@ export class PluginLoggerManager {
105
108
  features: this.pluginInfo.features.map(feature => ({
106
109
  id: feature.id,
107
110
  name: feature.name,
108
- desc: feature.desc
109
- }))
111
+ desc: feature.desc,
112
+ })),
110
113
  }
111
114
 
112
115
  fs.writeFileSync(this.pluginInfoPath, JSON.stringify(pluginInfo, null, 2))
@@ -1,5 +1,5 @@
1
- import { IPluginLogger, LogLevel, LogItem, LogDataType } from '../log/types'
2
- import { PluginLoggerManager } from './logger-manager'
1
+ import type { IPluginLogger, LogDataType, LogItem, LogLevel } from '../log/types'
2
+ import type { PluginLoggerManager } from './logger-manager'
3
3
  import chalk from 'chalk'
4
4
 
5
5
  /**
@@ -71,7 +71,7 @@ export class PluginLogger implements IPluginLogger<PluginLoggerManager> {
71
71
  : 'INFO')
72
72
  if (resolvedLevel === 'INFO' && normalizedLevel !== 'INFO') {
73
73
  console.warn(
74
- `${chalk.bgMagenta('[PluginLog]')} ${chalk.bgYellow('WARN')} ${this.pluginName} - Unknown log level "${String(level)}", fallback to INFO`
74
+ `${chalk.bgMagenta('[PluginLog]')} ${chalk.bgYellow('WARN')} ${this.pluginName} - Unknown log level "${String(level)}", fallback to INFO`,
75
75
  )
76
76
  }
77
77
 
@@ -79,7 +79,7 @@ export class PluginLogger implements IPluginLogger<PluginLoggerManager> {
79
79
  INFO: chalk.bgBlue,
80
80
  WARN: chalk.bgYellow,
81
81
  ERROR: chalk.bgRed,
82
- DEBUG: chalk.bgGray
82
+ DEBUG: chalk.bgGray,
83
83
  }
84
84
  const colorize = levelColorMap[resolvedLevel] ?? ((input: string) => input)
85
85
 
@@ -96,14 +96,14 @@ export class PluginLogger implements IPluginLogger<PluginLoggerManager> {
96
96
  if (resolvedLevel === 'DEBUG') {
97
97
  console.debug(
98
98
  `${chalk.bgMagenta('[PluginLog]')} ${colorize(resolvedLevel)} ${this.pluginName} - ${message}`,
99
- ...data
99
+ ...data,
100
100
  )
101
- } else {
101
+ }
102
+ else {
102
103
  console.log(
103
104
  `${chalk.bgMagenta('[PluginLog]')} ${colorize(resolvedLevel)} ${this.pluginName} - ${message}`,
104
- ...data
105
+ ...data,
105
106
  )
106
107
  }
107
-
108
108
  }
109
109
  }
@@ -1,4 +1,4 @@
1
- import { IManifest } from '@talex-touch/utils/plugin'
1
+ import type { IManifest } from '@talex-touch/utils/plugin'
2
2
 
3
3
  /**
4
4
  * Interface for plugin download options.
@@ -7,15 +7,15 @@ export interface IDownloadOptions {
7
7
  /**
8
8
  * Timeout configuration for download in milliseconds.
9
9
  */
10
- timeout?: number;
10
+ timeout?: number
11
11
  /**
12
12
  * List of fallback download URLs.
13
13
  */
14
- fallbackUrls?: string[];
14
+ fallbackUrls?: string[]
15
15
  /**
16
16
  * Callback function for download progress, with progress value (0-100).
17
17
  */
18
- onProgress?: (progress: number) => void;
18
+ onProgress?: (progress: number) => void
19
19
  }
20
20
 
21
21
  /**
@@ -25,7 +25,7 @@ export interface IDownloadResult {
25
25
  /**
26
26
  * Local file path after download, which can be the plugin's compressed package or the unzipped folder path.
27
27
  */
28
- filePath?: string;
28
+ filePath?: string
29
29
  }
30
30
 
31
31
  /**
@@ -43,16 +43,16 @@ export interface IPluginSource {
43
43
  * Get the name of the plugin source.
44
44
  * @returns The name of the plugin source.
45
45
  */
46
- getSourceName(): string;
46
+ getSourceName: () => string
47
47
  /**
48
48
  * Get the description of the plugin source.
49
49
  * @returns The description of the plugin source.
50
50
  */
51
- getSourceDesc(): string;
51
+ getSourceDesc: () => string
52
52
  /**
53
53
  * Timestamp of the last update for this plugin source.
54
54
  */
55
- lastUpdateTime?: number;
55
+ lastUpdateTime?: number
56
56
 
57
57
  /**
58
58
  * Attempts to resolve a plugin manifest from the specified path or URL.
@@ -62,7 +62,7 @@ export interface IPluginSource {
62
62
  * @param options Resolution options.
63
63
  * @returns A Promise containing the plugin manifest, or undefined if resolution fails.
64
64
  */
65
- resolveManifest(sourcePath: string, options?: IResolveManifestOptions): Promise<IManifest | undefined>
65
+ resolveManifest: (sourcePath: string, options?: IResolveManifestOptions) => Promise<IManifest | undefined>
66
66
 
67
67
  /**
68
68
  * Downloads the plugin source.
@@ -70,5 +70,5 @@ export interface IPluginSource {
70
70
  * @param options Download options.
71
71
  * @returns A Promise containing the download result. The filePath must be the path to the plugin's compressed package or unzipped folder.
72
72
  */
73
- downloadPlugin(sourceUrl: string, options?: IDownloadOptions): Promise<IDownloadResult>
74
- }
73
+ downloadPlugin: (sourceUrl: string, options?: IDownloadOptions) => Promise<IDownloadResult>
74
+ }
package/plugin/preload.ts CHANGED
@@ -8,7 +8,7 @@ declare global {
8
8
  interface Window {
9
9
  $plugin: {
10
10
  name: string
11
- path: Object
11
+ path: object
12
12
  }
13
13
  $channel: ITouchClientChannel
14
14
  $crash: (message: string, extraData: any) => void