@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
@@ -1,18 +1,18 @@
1
- import { IService } from './../index';
1
+ import type { IService } from './../index'
2
2
 
3
3
  export abstract class ProtocolService<T extends string> implements IService {
4
- id: symbol;
5
- name: string;
6
- description: string;
4
+ id: symbol
5
+ name: string
6
+ description: string
7
7
 
8
8
  protocol: string[]
9
9
 
10
10
  type: T
11
11
 
12
12
  constructor(id: symbol, protocol: string[]) {
13
- this.id = id;
14
- this.name = id.description!;
15
- this.description = `${this.name} Protocol Service`;
13
+ this.id = id
14
+ this.name = id.description!
15
+ this.description = `${this.name} Protocol Service`
16
16
  this.protocol = protocol
17
17
 
18
18
  this.type = id.description as T
@@ -20,7 +20,17 @@ export abstract class ProtocolService<T extends string> implements IService {
20
20
  }
21
21
 
22
22
  export const IMAGE_SUFFIX = [
23
- 'jpg', 'png', 'gif', 'bmp', 'webp', 'svg', 'ico', 'tiff', 'tif', 'jpeg', 'avif'
23
+ 'jpg',
24
+ 'png',
25
+ 'gif',
26
+ 'bmp',
27
+ 'webp',
28
+ 'svg',
29
+ 'ico',
30
+ 'tiff',
31
+ 'tif',
32
+ 'jpeg',
33
+ 'avif',
24
34
  ]
25
35
 
26
36
  export class ImageProtocolService extends ProtocolService<'image'> {
@@ -30,7 +40,69 @@ export class ImageProtocolService extends ProtocolService<'image'> {
30
40
  }
31
41
 
32
42
  export const AUDIO_SUFFIX = [
33
- 'mp3', 'wav', 'ogg', 'aac', 'flac', 'wma', 'ape', 'm4a', 'm4r', 'm4b', 'm4p', 'm4v', 'mp4', '3gp', 'avi', 'mov', 'wmv', 'flv', 'mkv', 'rmvb', 'rm', 'asf', 'dat', 'mpg', 'mpeg', 'vob', 'f4v', 'm3u8', 'webm', 'ts', 'mts', 'm2ts', 'mts', 'dv', 'divx', 'xvid', 'mpe', 'mod', 'sdp', 'm2v', 'm2p', 'm2t', 'm2ts', 'm2v', 'm2p', 'm2t', 'm2ts', 'm2v', 'm2p', 'm2t', 'm2ts', 'm2v', 'm2p', 'm2t', 'm2ts', 'm2v', 'm2p', 'm2t', 'm2ts', 'm2v', 'm2p', 'm2t', 'm2ts'
43
+ 'mp3',
44
+ 'wav',
45
+ 'ogg',
46
+ 'aac',
47
+ 'flac',
48
+ 'wma',
49
+ 'ape',
50
+ 'm4a',
51
+ 'm4r',
52
+ 'm4b',
53
+ 'm4p',
54
+ 'm4v',
55
+ 'mp4',
56
+ '3gp',
57
+ 'avi',
58
+ 'mov',
59
+ 'wmv',
60
+ 'flv',
61
+ 'mkv',
62
+ 'rmvb',
63
+ 'rm',
64
+ 'asf',
65
+ 'dat',
66
+ 'mpg',
67
+ 'mpeg',
68
+ 'vob',
69
+ 'f4v',
70
+ 'm3u8',
71
+ 'webm',
72
+ 'ts',
73
+ 'mts',
74
+ 'm2ts',
75
+ 'mts',
76
+ 'dv',
77
+ 'divx',
78
+ 'xvid',
79
+ 'mpe',
80
+ 'mod',
81
+ 'sdp',
82
+ 'm2v',
83
+ 'm2p',
84
+ 'm2t',
85
+ 'm2ts',
86
+ 'm2v',
87
+ 'm2p',
88
+ 'm2t',
89
+ 'm2ts',
90
+ 'm2v',
91
+ 'm2p',
92
+ 'm2t',
93
+ 'm2ts',
94
+ 'm2v',
95
+ 'm2p',
96
+ 'm2t',
97
+ 'm2ts',
98
+ 'm2v',
99
+ 'm2p',
100
+ 'm2t',
101
+ 'm2ts',
102
+ 'm2v',
103
+ 'm2p',
104
+ 'm2t',
105
+ 'm2ts',
34
106
  ]
35
107
 
36
108
  export class AudioProtocolService extends ProtocolService<'audio'> {
@@ -40,7 +112,53 @@ export class AudioProtocolService extends ProtocolService<'audio'> {
40
112
  }
41
113
 
42
114
  export const VIDEO_SUFFIX = [
43
- 'mp4', '3gp', 'avi', 'mov', 'wmv', 'flv', 'mkv', 'rmvb', 'rm', 'asf', 'dat', 'mpg', 'mpeg', 'vob', 'f4v', 'm3u8', 'webm', 'ts', 'mts', 'm2ts', 'mts', 'dv', 'divx', 'xvid', 'mpe', 'mod', 'sdp', 'm2v', 'm2p', 'm2t', 'm2ts', 'm2v', 'm2p', 'm2t', 'm2ts', 'm2v', 'm2p', 'm2t', 'm2ts', 'm2v', 'm2p', 'm2t', 'm2ts', 'm2v', 'm2p', 'm2t', 'm2ts'
115
+ 'mp4',
116
+ '3gp',
117
+ 'avi',
118
+ 'mov',
119
+ 'wmv',
120
+ 'flv',
121
+ 'mkv',
122
+ 'rmvb',
123
+ 'rm',
124
+ 'asf',
125
+ 'dat',
126
+ 'mpg',
127
+ 'mpeg',
128
+ 'vob',
129
+ 'f4v',
130
+ 'm3u8',
131
+ 'webm',
132
+ 'ts',
133
+ 'mts',
134
+ 'm2ts',
135
+ 'mts',
136
+ 'dv',
137
+ 'divx',
138
+ 'xvid',
139
+ 'mpe',
140
+ 'mod',
141
+ 'sdp',
142
+ 'm2v',
143
+ 'm2p',
144
+ 'm2t',
145
+ 'm2ts',
146
+ 'm2v',
147
+ 'm2p',
148
+ 'm2t',
149
+ 'm2ts',
150
+ 'm2v',
151
+ 'm2p',
152
+ 'm2t',
153
+ 'm2ts',
154
+ 'm2v',
155
+ 'm2p',
156
+ 'm2t',
157
+ 'm2ts',
158
+ 'm2v',
159
+ 'm2p',
160
+ 'm2t',
161
+ 'm2ts',
44
162
  ]
45
163
 
46
164
  export class VideoProtocolService extends ProtocolService<'video'> {
@@ -50,7 +168,93 @@ export class VideoProtocolService extends ProtocolService<'video'> {
50
168
  }
51
169
 
52
170
  export const TEXT_SUFFIX = [
53
- 'txt', 'md', 'markdown', 'json', 'js', 'ts', 'html', 'css', 'scss', 'sass', 'less', 'xml', 'yaml', 'yml', 'ini', 'log', 'bat', 'sh', 'cmd', 'c', 'cpp', 'h', 'hpp', 'java', 'py', 'go', 'php', 'sql', 'swift', 'vb', 'vbs', 'lua', 'rb', 'r', 'cs', 'm', 'mm', 'pl', 'perl', 'asm', 'asmx', 'inc', 'coffee', 'ts', 'tsx', 'jsx', 'vue', 'php', 'php3', 'php4', 'php5', 'php7', 'phps', 'phtml', 'pht', 'phar', 'phpt', 'php-cgi', 'php-cs-fixer', 'phpunit', 'phpunit.xml', 'phpunit.xml.dist', 'phpunit.phar', 'phpunit.phar.dist', 'phpunit-4.8.36.phar', 'phpunit-4.8.36.phar.dist', 'phpunit-5.7.27.phar', 'phpunit-5.7.27.phar.dist', 'phpunit-6.5.14.phar', 'phpunit-6.5.14.phar.dist', 'phpunit-7.5.20.phar', 'phpunit-7.5.20.phar.dist', 'phpunit-8.5.8.phar', 'phpunit-8.5.8.phar.dist', 'phpunit-9.3.10.phar', 'phpunit-9.3.10.phar.dist', 'phpunit-9.4.3.phar', 'phpunit-9.4.3.phar.dist', 'phpunit-9.5.0.phar', 'phpunit-9.5.0.phar.dist', 'phpunit-9.5.1.phar', 'phpunit-9.5.1.phar.dist', 'phpunit-9.5.2.phar', 'phpunit-9.5.2.phar.dist', 'phpunit-9.5.4.phar', 'phpunit-9.5.4.phar.dist', 'php'
171
+ 'txt',
172
+ 'md',
173
+ 'markdown',
174
+ 'json',
175
+ 'js',
176
+ 'ts',
177
+ 'html',
178
+ 'css',
179
+ 'scss',
180
+ 'sass',
181
+ 'less',
182
+ 'xml',
183
+ 'yaml',
184
+ 'yml',
185
+ 'ini',
186
+ 'log',
187
+ 'bat',
188
+ 'sh',
189
+ 'cmd',
190
+ 'c',
191
+ 'cpp',
192
+ 'h',
193
+ 'hpp',
194
+ 'java',
195
+ 'py',
196
+ 'go',
197
+ 'php',
198
+ 'sql',
199
+ 'swift',
200
+ 'vb',
201
+ 'vbs',
202
+ 'lua',
203
+ 'rb',
204
+ 'r',
205
+ 'cs',
206
+ 'm',
207
+ 'mm',
208
+ 'pl',
209
+ 'perl',
210
+ 'asm',
211
+ 'asmx',
212
+ 'inc',
213
+ 'coffee',
214
+ 'ts',
215
+ 'tsx',
216
+ 'jsx',
217
+ 'vue',
218
+ 'php',
219
+ 'php3',
220
+ 'php4',
221
+ 'php5',
222
+ 'php7',
223
+ 'phps',
224
+ 'phtml',
225
+ 'pht',
226
+ 'phar',
227
+ 'phpt',
228
+ 'php-cgi',
229
+ 'php-cs-fixer',
230
+ 'phpunit',
231
+ 'phpunit.xml',
232
+ 'phpunit.xml.dist',
233
+ 'phpunit.phar',
234
+ 'phpunit.phar.dist',
235
+ 'phpunit-4.8.36.phar',
236
+ 'phpunit-4.8.36.phar.dist',
237
+ 'phpunit-5.7.27.phar',
238
+ 'phpunit-5.7.27.phar.dist',
239
+ 'phpunit-6.5.14.phar',
240
+ 'phpunit-6.5.14.phar.dist',
241
+ 'phpunit-7.5.20.phar',
242
+ 'phpunit-7.5.20.phar.dist',
243
+ 'phpunit-8.5.8.phar',
244
+ 'phpunit-8.5.8.phar.dist',
245
+ 'phpunit-9.3.10.phar',
246
+ 'phpunit-9.3.10.phar.dist',
247
+ 'phpunit-9.4.3.phar',
248
+ 'phpunit-9.4.3.phar.dist',
249
+ 'phpunit-9.5.0.phar',
250
+ 'phpunit-9.5.0.phar.dist',
251
+ 'phpunit-9.5.1.phar',
252
+ 'phpunit-9.5.1.phar.dist',
253
+ 'phpunit-9.5.2.phar',
254
+ 'phpunit-9.5.2.phar.dist',
255
+ 'phpunit-9.5.4.phar',
256
+ 'phpunit-9.5.4.phar.dist',
257
+ 'php',
54
258
  ]
55
259
 
56
260
  export class TextProtocolService extends ProtocolService<'text'> {
@@ -59,7 +263,7 @@ export class TextProtocolService extends ProtocolService<'text'> {
59
263
  }
60
264
  }
61
265
 
62
- export const serviceSuffixMap = new Map<ProtocolService<string>, string[]>
266
+ export const serviceSuffixMap = new Map<ProtocolService<string>, string[]>()
63
267
 
64
268
  serviceSuffixMap.set(new ImageProtocolService(), IMAGE_SUFFIX)
65
269
  serviceSuffixMap.set(new AudioProtocolService(), AUDIO_SUFFIX)
@@ -67,7 +271,6 @@ serviceSuffixMap.set(new VideoProtocolService(), VIDEO_SUFFIX)
67
271
  serviceSuffixMap.set(new TextProtocolService(), TEXT_SUFFIX)
68
272
 
69
273
  export function suffix2Service(suffix: string): ProtocolService<string> | null {
70
-
71
274
  for (const [type, suffixes] of serviceSuffixMap.entries()) {
72
275
  if (suffixes.includes(suffix)) {
73
276
  return type
@@ -75,4 +278,4 @@ export function suffix2Service(suffix: string): ProtocolService<string> | null {
75
278
  }
76
279
 
77
280
  return null
78
- }
281
+ }
@@ -0,0 +1,248 @@
1
+ /**
2
+ * DivisionBox Type Definitions
3
+ *
4
+ * Shared types for DivisionBox system across main and renderer processes.
5
+ * These types define the contract for inter-process communication and state management.
6
+ */
7
+
8
+ /**
9
+ * DivisionBox lifecycle states
10
+ * State machine: prepare → attach → active → inactive → detach → destroy
11
+ */
12
+ export enum DivisionBoxState {
13
+ PREPARE = 'prepare',
14
+ ATTACH = 'attach',
15
+ ACTIVE = 'active',
16
+ INACTIVE = 'inactive',
17
+ DETACH = 'detach',
18
+ DESTROY = 'destroy'
19
+ }
20
+
21
+ /**
22
+ * Error codes for DivisionBox operations
23
+ */
24
+ export enum DivisionBoxErrorCode {
25
+ RESOURCE_ERROR = 'RESOURCE_ERROR',
26
+ STATE_ERROR = 'STATE_ERROR',
27
+ IPC_ERROR = 'IPC_ERROR',
28
+ PERMISSION_DENIED = 'PERMISSION_DENIED',
29
+ CONFIG_ERROR = 'CONFIG_ERROR',
30
+ INVALID_TRANSITION = 'INVALID_TRANSITION',
31
+ SESSION_NOT_FOUND = 'SESSION_NOT_FOUND',
32
+ LIMIT_EXCEEDED = 'LIMIT_EXCEEDED'
33
+ }
34
+
35
+ /**
36
+ * Error messages for each error code
37
+ */
38
+ export const ERROR_MESSAGES: Record<DivisionBoxErrorCode, string> = {
39
+ [DivisionBoxErrorCode.RESOURCE_ERROR]: 'Resource allocation or management failed',
40
+ [DivisionBoxErrorCode.STATE_ERROR]: 'Invalid state or state operation',
41
+ [DivisionBoxErrorCode.IPC_ERROR]: 'Inter-process communication failed',
42
+ [DivisionBoxErrorCode.PERMISSION_DENIED]: 'Permission denied for requested operation',
43
+ [DivisionBoxErrorCode.CONFIG_ERROR]: 'Invalid configuration provided',
44
+ [DivisionBoxErrorCode.INVALID_TRANSITION]: 'Invalid state transition attempted',
45
+ [DivisionBoxErrorCode.SESSION_NOT_FOUND]: 'Session not found',
46
+ [DivisionBoxErrorCode.LIMIT_EXCEEDED]: 'Resource limit exceeded'
47
+ }
48
+
49
+ /**
50
+ * Custom error class for DivisionBox operations
51
+ */
52
+ export class DivisionBoxError extends Error {
53
+ constructor(
54
+ public readonly code: DivisionBoxErrorCode,
55
+ message: string,
56
+ public readonly sessionId?: string,
57
+ public readonly timestamp: number = Date.now()
58
+ ) {
59
+ super(message)
60
+ this.name = 'DivisionBoxError'
61
+ Error.captureStackTrace(this, DivisionBoxError)
62
+ }
63
+
64
+ /**
65
+ * Gets a user-friendly error message
66
+ */
67
+ getUserMessage(): string {
68
+ return ERROR_MESSAGES[this.code] || 'An unknown error occurred'
69
+ }
70
+ }
71
+
72
+ /**
73
+ * Header action button configuration
74
+ */
75
+ export interface HeaderAction {
76
+ label: string
77
+ icon?: string
78
+ onClick: () => void
79
+ }
80
+
81
+ /**
82
+ * Header configuration for DivisionBox
83
+ */
84
+ export interface HeaderConfig {
85
+ show: boolean
86
+ title?: string
87
+ icon?: string
88
+ actions?: HeaderAction[]
89
+ }
90
+
91
+ /**
92
+ * Size presets for DivisionBox
93
+ */
94
+ export type DivisionBoxSize = 'compact' | 'medium' | 'expanded'
95
+
96
+ /**
97
+ * Configuration for creating a DivisionBox instance
98
+ */
99
+ export interface DivisionBoxConfig {
100
+ /** URL to load in the WebContentsView */
101
+ url: string
102
+
103
+ /** Associated plugin ID (optional) */
104
+ pluginId?: string
105
+
106
+ /** Display title */
107
+ title: string
108
+
109
+ /** Icon (supports iconify format) */
110
+ icon?: string
111
+
112
+ /** Size preset */
113
+ size?: DivisionBoxSize
114
+
115
+ /** Enable keepAlive caching mode */
116
+ keepAlive?: boolean
117
+
118
+ /** Header configuration */
119
+ header?: HeaderConfig
120
+
121
+ /** WebContentsView preferences (main process only) */
122
+ webPreferences?: any
123
+ }
124
+
125
+ /**
126
+ * Session metadata
127
+ */
128
+ export interface SessionMeta {
129
+ /** Associated plugin ID */
130
+ pluginId?: string
131
+
132
+ /** Display title */
133
+ title: string
134
+
135
+ /** Icon */
136
+ icon?: string
137
+
138
+ /** Size preset */
139
+ size: DivisionBoxSize
140
+
141
+ /** KeepAlive mode enabled */
142
+ keepAlive: boolean
143
+
144
+ /** Creation timestamp */
145
+ createdAt: number
146
+
147
+ /** Last accessed timestamp */
148
+ lastAccessedAt: number
149
+ }
150
+
151
+ /**
152
+ * Bounds information for DivisionBox positioning
153
+ */
154
+ export interface DivisionBoxBounds {
155
+ x: number
156
+ y: number
157
+ width: number
158
+ height: number
159
+ }
160
+
161
+ /**
162
+ * Session information returned to clients
163
+ */
164
+ export interface SessionInfo {
165
+ /** Unique session identifier */
166
+ sessionId: string
167
+
168
+ /** Current lifecycle state */
169
+ state: DivisionBoxState
170
+
171
+ /** Session metadata */
172
+ meta: SessionMeta
173
+
174
+ /** Position and size bounds */
175
+ bounds?: DivisionBoxBounds
176
+ }
177
+
178
+ /**
179
+ * Options for closing a DivisionBox
180
+ */
181
+ export interface CloseOptions {
182
+ /** Delay before closing (milliseconds) */
183
+ delay?: number
184
+
185
+ /** Play closing animation */
186
+ animation?: boolean
187
+
188
+ /** Force close (ignore keepAlive) */
189
+ force?: boolean
190
+ }
191
+
192
+ /**
193
+ * State change event data
194
+ */
195
+ export interface StateChangeEvent {
196
+ sessionId: string
197
+ oldState: DivisionBoxState
198
+ newState: DivisionBoxState
199
+ timestamp: number
200
+ }
201
+
202
+ /**
203
+ * IPC message types for DivisionBox operations
204
+ */
205
+ export enum DivisionBoxIPCChannel {
206
+ OPEN = 'division-box:open',
207
+ CLOSE = 'division-box:close',
208
+ GET_STATE = 'division-box:get-state',
209
+ UPDATE_STATE = 'division-box:update-state',
210
+ GET_ACTIVE_SESSIONS = 'division-box:get-active-sessions',
211
+ STATE_CHANGED = 'division-box:state-changed',
212
+ SESSION_DESTROYED = 'division-box:session-destroyed'
213
+ }
214
+
215
+ /**
216
+ * IPC response wrapper
217
+ */
218
+ export interface IPCResponse<T = any> {
219
+ success: boolean
220
+ data?: T
221
+ error?: {
222
+ code: DivisionBoxErrorCode
223
+ message: string
224
+ }
225
+ }
226
+
227
+ /**
228
+ * DivisionBox configuration in plugin manifest
229
+ * This configuration is declared in the plugin's manifest.json file
230
+ * and provides default settings for DivisionBox instances created by the plugin.
231
+ */
232
+ export interface ManifestDivisionBoxConfig {
233
+ /** Default size preset for DivisionBox instances */
234
+ defaultSize?: DivisionBoxSize
235
+
236
+ /** Enable keepAlive caching mode by default */
237
+ keepAlive?: boolean
238
+
239
+ /** Default header configuration */
240
+ header?: {
241
+ /** Whether to show the header by default */
242
+ show?: boolean
243
+ /** Default title (can be overridden at runtime) */
244
+ title?: string
245
+ /** Default icon (can be overridden at runtime) */
246
+ icon?: string
247
+ }
248
+ }
package/types/download.ts CHANGED
@@ -1,10 +1,31 @@
1
1
  // 下载优先级枚举
2
2
  export enum DownloadPriority {
3
- CRITICAL = 100, // 用户手动触发
4
- HIGH = 80, // 插件安装
5
- NORMAL = 50, // 应用更新
6
- LOW = 20, // 资源文件
7
- BACKGROUND = 10 // 后台预加载
3
+ CRITICAL = 100, // 用户手动触发
4
+ HIGH = 80, // 插件安装
5
+ NORMAL = 50, // 应用更新
6
+ LOW = 20, // 资源文件
7
+ BACKGROUND = 10, // 后台预加载
8
+ }
9
+
10
+ // 错误类型枚举
11
+ export enum DownloadErrorType {
12
+ NETWORK_ERROR = 'network_error',
13
+ TIMEOUT_ERROR = 'timeout_error',
14
+ DISK_SPACE_ERROR = 'disk_space_error',
15
+ PERMISSION_ERROR = 'permission_error',
16
+ CHECKSUM_ERROR = 'checksum_error',
17
+ FILE_NOT_FOUND = 'file_not_found',
18
+ INVALID_URL = 'invalid_url',
19
+ CANCELLED = 'cancelled',
20
+ UNKNOWN_ERROR = 'unknown_error',
21
+ }
22
+
23
+ // 错误严重程度
24
+ export enum ErrorSeverity {
25
+ LOW = 'low',
26
+ MEDIUM = 'medium',
27
+ HIGH = 'high',
28
+ CRITICAL = 'critical',
8
29
  }
9
30
 
10
31
  // 下载模块枚举
@@ -12,17 +33,17 @@ export enum DownloadModule {
12
33
  APP_UPDATE = 'app_update',
13
34
  PLUGIN_INSTALL = 'plugin_install',
14
35
  RESOURCE_DOWNLOAD = 'resource_download',
15
- USER_MANUAL = 'user_manual'
36
+ USER_MANUAL = 'user_manual',
16
37
  }
17
38
 
18
39
  // 下载状态枚举
19
40
  export enum DownloadStatus {
20
- PENDING = 'pending', // 等待中
41
+ PENDING = 'pending', // 等待中
21
42
  DOWNLOADING = 'downloading', // 下载中
22
- PAUSED = 'paused', // 已暂停
23
- COMPLETED = 'completed', // 已完成
24
- FAILED = 'failed', // 失败
25
- CANCELLED = 'cancelled' // 已取消
43
+ PAUSED = 'paused', // 已暂停
44
+ COMPLETED = 'completed', // 已完成
45
+ FAILED = 'failed', // 失败
46
+ CANCELLED = 'cancelled', // 已取消
26
47
  }
27
48
 
28
49
  // 切片状态枚举
@@ -30,7 +51,7 @@ export enum ChunkStatus {
30
51
  PENDING = 'pending',
31
52
  DOWNLOADING = 'downloading',
32
53
  COMPLETED = 'completed',
33
- FAILED = 'failed'
54
+ FAILED = 'failed',
34
55
  }
35
56
 
36
57
  // 下载任务请求接口
@@ -86,34 +107,34 @@ export interface ChunkInfo {
86
107
  // 下载配置接口
87
108
  export interface DownloadConfig {
88
109
  concurrency: {
89
- maxConcurrent: number // 最大并发数 (1-10)
90
- autoAdjust: boolean // 自动调整
91
- networkAware: boolean // 网络感知
92
- priorityBased: boolean // 基于优先级
110
+ maxConcurrent: number // 最大并发数 (1-10)
111
+ autoAdjust: boolean // 自动调整
112
+ networkAware: boolean // 网络感知
113
+ priorityBased: boolean // 基于优先级
93
114
  }
94
115
  chunk: {
95
- size: number // 切片大小
96
- resume: boolean // 断点续传
97
- autoRetry: boolean // 自动重试
98
- maxRetries: number // 最大重试次数
116
+ size: number // 切片大小
117
+ resume: boolean // 断点续传
118
+ autoRetry: boolean // 自动重试
119
+ maxRetries: number // 最大重试次数
99
120
  }
100
121
  storage: {
101
- tempDir: string // 临时目录
102
- historyRetention: number // 历史保留天数
103
- autoCleanup: boolean // 自动清理
122
+ tempDir: string // 临时目录
123
+ historyRetention: number // 历史保留天数
124
+ autoCleanup: boolean // 自动清理
104
125
  }
105
126
  network: {
106
- timeout: number // 超时时间
107
- retryDelay: number // 重试延迟
108
- maxRetries: number // 最大重试次数
127
+ timeout: number // 超时时间
128
+ retryDelay: number // 重试延迟
129
+ maxRetries: number // 最大重试次数
109
130
  }
110
131
  }
111
132
 
112
133
  // 网络状态接口
113
134
  export interface NetworkStatus {
114
- speed: number // bytes/s
115
- latency: number // ms
116
- stability: number // 0-1
135
+ speed: number // bytes/s
136
+ latency: number // ms
137
+ stability: number // 0-1
117
138
  recommendedConcurrency: number
118
139
  }
119
140
 
@@ -135,28 +156,45 @@ export interface DownloadStats {
135
156
  averageSpeed: number
136
157
  }
137
158
 
159
+ // 下载历史记录接口
160
+ export interface DownloadHistory {
161
+ id: string
162
+ taskId: string
163
+ url: string
164
+ filename: string
165
+ module: DownloadModule
166
+ status: DownloadStatus
167
+ totalSize?: number
168
+ downloadedSize: number
169
+ duration?: number // seconds
170
+ averageSpeed?: number // bytes/s
171
+ destination: string
172
+ createdAt: Date
173
+ completedAt?: Date
174
+ }
175
+
138
176
  // 默认下载配置
139
177
  export const defaultDownloadConfig: DownloadConfig = {
140
178
  concurrency: {
141
179
  maxConcurrent: 3,
142
180
  autoAdjust: true,
143
181
  networkAware: true,
144
- priorityBased: true
182
+ priorityBased: true,
145
183
  },
146
184
  chunk: {
147
185
  size: 1024 * 1024, // 1MB
148
186
  resume: true,
149
187
  autoRetry: true,
150
- maxRetries: 3
188
+ maxRetries: 3,
151
189
  },
152
190
  storage: {
153
191
  tempDir: '', // 将在运行时设置
154
192
  historyRetention: 30,
155
- autoCleanup: true
193
+ autoCleanup: true,
156
194
  },
157
195
  network: {
158
196
  timeout: 30000,
159
197
  retryDelay: 5000,
160
- maxRetries: 3
161
- }
198
+ maxRetries: 3,
199
+ },
162
200
  }