@talex-touch/utils 1.0.14 → 1.0.16

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 (41) hide show
  1. package/base/index.ts +181 -181
  2. package/channel/index.ts +108 -99
  3. package/common/index.ts +2 -39
  4. package/common/storage/constants.ts +3 -0
  5. package/common/storage/entity/app-settings.ts +47 -0
  6. package/common/storage/entity/index.ts +1 -0
  7. package/common/storage/index.ts +3 -0
  8. package/common/utils.ts +160 -0
  9. package/core-box/README.md +218 -0
  10. package/core-box/index.ts +7 -0
  11. package/core-box/search.ts +536 -0
  12. package/core-box/types.ts +384 -0
  13. package/electron/download-manager.ts +118 -0
  14. package/{common → electron}/env-tool.ts +56 -56
  15. package/electron/touch-core.ts +167 -0
  16. package/electron/window.ts +71 -0
  17. package/eventbus/index.ts +86 -87
  18. package/index.ts +5 -0
  19. package/package.json +55 -30
  20. package/permission/index.ts +48 -48
  21. package/plugin/channel.ts +203 -193
  22. package/plugin/index.ts +216 -121
  23. package/plugin/log/logger-manager.ts +60 -0
  24. package/plugin/log/logger.ts +75 -0
  25. package/plugin/log/types.ts +27 -0
  26. package/plugin/preload.ts +39 -39
  27. package/plugin/sdk/common.ts +27 -27
  28. package/plugin/sdk/hooks/life-cycle.ts +95 -95
  29. package/plugin/sdk/index.ts +18 -13
  30. package/plugin/sdk/service/index.ts +29 -29
  31. package/plugin/sdk/types.ts +578 -0
  32. package/plugin/sdk/window/index.ts +40 -40
  33. package/renderer/index.ts +2 -0
  34. package/renderer/ref.ts +54 -54
  35. package/renderer/slots.ts +124 -0
  36. package/renderer/storage/app-settings.ts +34 -0
  37. package/renderer/storage/base-storage.ts +335 -0
  38. package/renderer/storage/index.ts +1 -0
  39. package/search/types.ts +726 -0
  40. package/service/index.ts +67 -67
  41. package/service/protocol/index.ts +77 -77
@@ -0,0 +1,536 @@
1
+ /**
2
+ * Search utility functions and helpers
3
+ * Provides tools for creating, managing, and manipulating search results
4
+ */
5
+
6
+ import {
7
+ ISearchItem,
8
+ IDataItem,
9
+ IAppItem,
10
+ IFileItem,
11
+ IFeatureItem,
12
+ RenderMode,
13
+ IRenderConfig
14
+ } from './types';
15
+
16
+ /**
17
+ * Search result utility functions
18
+ * Collection of helper functions for working with search results
19
+ */
20
+ export const SearchUtils = {
21
+ /**
22
+ * Creates a basic search result item with standard configuration
23
+ *
24
+ * @param options - Configuration options for the search item
25
+ * @returns A configured ISearchItem instance
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * const item = SearchUtils.createSearchItem({
30
+ * name: "My Feature",
31
+ * desc: "A useful feature",
32
+ * pluginName: "my-plugin",
33
+ * keyWords: ["feature", "utility"]
34
+ * });
35
+ * ```
36
+ */
37
+ createSearchItem(options: {
38
+ /** Display name of the item */
39
+ name: string;
40
+ /** Description text */
41
+ desc: string;
42
+ /** Name of the associated plugin */
43
+ pluginName: string;
44
+ /** Plugin type classification */
45
+ pluginType?: string;
46
+ /** General type classification */
47
+ type?: string;
48
+ /** Whether push mode is supported */
49
+ push?: boolean;
50
+ /** Additional search keywords */
51
+ keyWords?: string[];
52
+ /** Icon type (e.g., 'remix', 'file') */
53
+ iconType?: string;
54
+ /** Icon value/name */
55
+ iconValue?: string;
56
+ /** Custom render configuration */
57
+ render?: IRenderConfig;
58
+ /** Additional properties */
59
+ [key: string]: any;
60
+ }): ISearchItem {
61
+ const {
62
+ name,
63
+ desc,
64
+ pluginName,
65
+ pluginType = 'feature',
66
+ type = 'plugin',
67
+ push = false,
68
+ keyWords = [],
69
+ iconType = 'remix',
70
+ iconValue = 'function',
71
+ render,
72
+ ...extra
73
+ } = options;
74
+
75
+ return {
76
+ name,
77
+ desc,
78
+ icon: {
79
+ type: iconType,
80
+ value: iconValue,
81
+ init: async () => {}
82
+ },
83
+ push,
84
+ names: [name],
85
+ keyWords: [name, ...keyWords],
86
+ pluginType,
87
+ type,
88
+ value: pluginName,
89
+ amo: 0,
90
+ render: render || { mode: RenderMode.STANDARD },
91
+ ...extra
92
+ };
93
+ },
94
+
95
+ /**
96
+ * Creates a data processing result item
97
+ * Specialized for items that represent processed data
98
+ *
99
+ * @param options - Configuration options for the data item
100
+ * @returns A configured IDataItem instance
101
+ */
102
+ createDataItem(options: {
103
+ /** Display name of the processed result */
104
+ name: string;
105
+ /** Description of the processing */
106
+ desc: string;
107
+ /** Name of the plugin that processed the data */
108
+ pluginName: string;
109
+ /** Source service or system */
110
+ source?: string;
111
+ /** Type of data processing */
112
+ dataType?: string;
113
+ /** Original input data */
114
+ originalData?: any;
115
+ /** Processed output data */
116
+ processedData?: any;
117
+ /** Quality score (0-100) */
118
+ quality?: number;
119
+ /** Whether result is from cache */
120
+ cached?: boolean;
121
+ /** Processing duration in ms */
122
+ duration?: number;
123
+ /** Confidence level (0-100) */
124
+ confidence?: number;
125
+ /** Additional metadata */
126
+ metadata?: Record<string, any>;
127
+ /** Icon configuration */
128
+ iconType?: string;
129
+ iconValue?: string;
130
+ /** Search keywords */
131
+ keyWords?: string[];
132
+ /** Plugin type */
133
+ pluginType?: string;
134
+ /** Custom render configuration */
135
+ render?: IRenderConfig;
136
+ }): IDataItem {
137
+ const {
138
+ name,
139
+ desc,
140
+ pluginName,
141
+ source,
142
+ dataType,
143
+ originalData,
144
+ processedData,
145
+ quality,
146
+ cached,
147
+ duration,
148
+ confidence,
149
+ metadata,
150
+ iconType = 'remix',
151
+ iconValue = 'function',
152
+ keyWords = [],
153
+ pluginType = 'data',
154
+ render
155
+ } = options;
156
+
157
+ return {
158
+ name,
159
+ desc,
160
+ icon: {
161
+ type: iconType,
162
+ value: iconValue,
163
+ init: async () => {}
164
+ },
165
+ push: false,
166
+ names: [name],
167
+ keyWords: [name, ...keyWords],
168
+ pluginType,
169
+ type: 'plugin',
170
+ value: pluginName,
171
+ source,
172
+ dataType,
173
+ originalData,
174
+ processedData,
175
+ quality,
176
+ cached,
177
+ duration,
178
+ confidence,
179
+ metadata,
180
+ amo: 0,
181
+ render: render || { mode: RenderMode.STANDARD }
182
+ };
183
+ },
184
+
185
+ /**
186
+ * Creates an application search result item
187
+ * Specialized for representing applications in search results
188
+ *
189
+ * @param options - Configuration options for the app item
190
+ * @returns A configured IAppItem instance
191
+ */
192
+ createAppItem(options: {
193
+ /** Application name */
194
+ name: string;
195
+ /** Application description */
196
+ desc: string;
197
+ /** Action to execute when selected */
198
+ action: string;
199
+ /** Application file path */
200
+ path?: string;
201
+ /** Application version */
202
+ version?: string;
203
+ /** File size in bytes */
204
+ size?: number;
205
+ /** Last used timestamp */
206
+ lastUsed?: number;
207
+ /** Application category */
208
+ category?: string;
209
+ /** Whether app is running */
210
+ isRunning?: boolean;
211
+ /** Icon file path */
212
+ iconPath?: string;
213
+ /** Search keywords */
214
+ keyWords?: string[];
215
+ /** Custom render configuration */
216
+ render?: IRenderConfig;
217
+ }): IAppItem {
218
+ const {
219
+ name,
220
+ desc,
221
+ action,
222
+ path,
223
+ version,
224
+ size,
225
+ lastUsed,
226
+ category,
227
+ isRunning,
228
+ iconPath,
229
+ keyWords = [],
230
+ render
231
+ } = options;
232
+
233
+ return {
234
+ name,
235
+ desc,
236
+ icon: {
237
+ type: iconPath ? 'file' : 'remix',
238
+ value: iconPath || 'apps',
239
+ init: async () => {}
240
+ },
241
+ push: false,
242
+ names: [name],
243
+ keyWords: [name, ...keyWords],
244
+ pluginType: 'app',
245
+ type: 'app',
246
+ value: name,
247
+ action,
248
+ path,
249
+ version,
250
+ size,
251
+ lastUsed,
252
+ category,
253
+ isRunning,
254
+ amo: 0,
255
+ render: render || { mode: RenderMode.STANDARD }
256
+ };
257
+ },
258
+
259
+ /**
260
+ * Creates a file search result item
261
+ * Specialized for representing files in search results
262
+ *
263
+ * @param options - Configuration options for the file item
264
+ * @returns A configured IFileItem instance
265
+ */
266
+ createFileItem(options: {
267
+ /** File name */
268
+ name: string;
269
+ /** Full file path */
270
+ filePath: string;
271
+ /** File description */
272
+ desc?: string;
273
+ /** File size in bytes */
274
+ fileSize?: number;
275
+ /** MIME type */
276
+ fileType?: string;
277
+ /** File extension */
278
+ extension?: string;
279
+ /** Modified timestamp */
280
+ modifiedTime?: number;
281
+ /** Created timestamp */
282
+ createdTime?: number;
283
+ /** Whether file is accessible */
284
+ accessible?: boolean;
285
+ /** Search keywords */
286
+ keyWords?: string[];
287
+ /** Custom render configuration */
288
+ render?: IRenderConfig;
289
+ }): IFileItem {
290
+ const {
291
+ name,
292
+ filePath,
293
+ desc,
294
+ fileSize,
295
+ fileType,
296
+ extension,
297
+ modifiedTime,
298
+ createdTime,
299
+ accessible,
300
+ keyWords = [],
301
+ render
302
+ } = options;
303
+
304
+ return {
305
+ name,
306
+ desc: desc || filePath,
307
+ icon: {
308
+ type: 'remix',
309
+ value: 'file',
310
+ init: async () => {}
311
+ },
312
+ push: false,
313
+ names: [name],
314
+ keyWords: [name, filePath, ...keyWords],
315
+ pluginType: 'file',
316
+ type: 'file',
317
+ value: filePath,
318
+ action: `open "${filePath}"`,
319
+ filePath,
320
+ fileSize,
321
+ fileType,
322
+ extension,
323
+ modifiedTime,
324
+ createdTime,
325
+ accessible,
326
+ amo: 0,
327
+ render: render || { mode: RenderMode.STANDARD }
328
+ };
329
+ },
330
+
331
+ /**
332
+ * Creates a feature search result item
333
+ * Specialized for representing plugin features in search results
334
+ *
335
+ * @param options - Configuration options for the feature item
336
+ * @returns A configured IFeatureItem instance
337
+ */
338
+ createFeatureItem(options: {
339
+ /** Feature name */
340
+ name: string;
341
+ /** Feature description */
342
+ desc: string;
343
+ /** Unique feature identifier */
344
+ featureId: string;
345
+ /** Name of the owning plugin */
346
+ pluginName: string;
347
+ /** Detailed feature description */
348
+ featureDesc?: string;
349
+ /** Feature parameters */
350
+ parameters?: Record<string, any>;
351
+ /** Whether feature is enabled */
352
+ enabled?: boolean;
353
+ /** Feature category */
354
+ category?: string;
355
+ /** Icon configuration */
356
+ iconType?: string;
357
+ iconValue?: string;
358
+ /** Search keywords */
359
+ keyWords?: string[];
360
+ /** Custom render configuration */
361
+ render?: IRenderConfig;
362
+ }): IFeatureItem {
363
+ const {
364
+ name,
365
+ desc,
366
+ featureId,
367
+ pluginName,
368
+ featureDesc,
369
+ parameters,
370
+ enabled,
371
+ category,
372
+ iconType = 'remix',
373
+ iconValue = 'function',
374
+ keyWords = [],
375
+ render
376
+ } = options;
377
+
378
+ return {
379
+ name,
380
+ desc,
381
+ icon: {
382
+ type: iconType,
383
+ value: iconValue,
384
+ init: async () => {}
385
+ },
386
+ push: false,
387
+ names: [name],
388
+ keyWords: [name, ...keyWords],
389
+ pluginType: 'feature',
390
+ type: 'plugin',
391
+ value: pluginName,
392
+ featureId,
393
+ pluginName,
394
+ featureDesc,
395
+ parameters,
396
+ enabled,
397
+ category,
398
+ amo: 0,
399
+ render: render || { mode: RenderMode.STANDARD }
400
+ };
401
+ },
402
+
403
+ /**
404
+ * Creates an error search result item
405
+ * Used to display error states in search results
406
+ *
407
+ * @param options - Configuration options for the error item
408
+ * @returns A configured ISearchItem representing an error
409
+ */
410
+ createErrorItem(options: {
411
+ /** Error title */
412
+ title: string;
413
+ /** Error message */
414
+ error: string;
415
+ /** Plugin that generated the error */
416
+ pluginName: string;
417
+ /** Original query that caused the error */
418
+ originalQuery?: string;
419
+ /** Custom render configuration */
420
+ render?: IRenderConfig;
421
+ }): ISearchItem {
422
+ const { title, error, pluginName, originalQuery, render } = options;
423
+
424
+ return {
425
+ name: title,
426
+ desc: `Error: ${error}`,
427
+ icon: {
428
+ type: 'remix',
429
+ value: 'error-warning',
430
+ init: async () => {}
431
+ },
432
+ push: false,
433
+ names: [title],
434
+ keyWords: originalQuery ? [originalQuery, 'error', 'failed'] : ['error', 'failed'],
435
+ pluginType: 'error',
436
+ type: 'plugin',
437
+ value: pluginName,
438
+ error,
439
+ originalQuery,
440
+ amo: 0,
441
+ render: render || { mode: RenderMode.STANDARD }
442
+ };
443
+ },
444
+
445
+ /**
446
+ * Sorts search results by priority and relevance
447
+ * Uses a weighted scoring system based on type, usage, and name
448
+ *
449
+ * @param items - Array of search items to sort
450
+ * @returns Sorted array of search items
451
+ */
452
+ sortByPriority(items: ISearchItem[]): ISearchItem[] {
453
+ return items.sort((a, b) => {
454
+ // Type-based weight scoring
455
+ const typeWeights: Record<string, number> = {
456
+ app: 10,
457
+ feature: 5,
458
+ cmd: 5,
459
+ plugin: 3,
460
+ file: 2,
461
+ text: 1,
462
+ error: 0
463
+ };
464
+
465
+ const aWeight = typeWeights[a.pluginType] || typeWeights[a.type] || 0;
466
+ const bWeight = typeWeights[b.pluginType] || typeWeights[b.type] || 0;
467
+
468
+ if (aWeight !== bWeight) {
469
+ return bWeight - aWeight;
470
+ }
471
+
472
+ // Usage frequency scoring
473
+ const aAmo = a.amo || 0;
474
+ const bAmo = b.amo || 0;
475
+
476
+ if (aAmo !== bAmo) {
477
+ return bAmo - aAmo;
478
+ }
479
+
480
+ // Alphabetical sorting as final tiebreaker
481
+ return a.name.localeCompare(b.name);
482
+ });
483
+ },
484
+
485
+ /**
486
+ * Removes duplicate search result items
487
+ * Uses a combination of name, description, and value for uniqueness
488
+ *
489
+ * @param items - Array of search items that may contain duplicates
490
+ * @returns Array with duplicate items removed
491
+ */
492
+ removeDuplicates(items: ISearchItem[]): ISearchItem[] {
493
+ const seen = new Set<string>();
494
+ return items.filter(item => {
495
+ const key = `${item.name}-${item.desc}-${item.value}`;
496
+ if (seen.has(key)) {
497
+ return false;
498
+ }
499
+ seen.add(key);
500
+ return true;
501
+ });
502
+ },
503
+
504
+ /**
505
+ * Filters search results based on confidence score
506
+ * Only returns items that meet the minimum confidence threshold
507
+ *
508
+ * @param items - Array of search items to filter
509
+ * @param minConfidence - Minimum confidence score (0-100)
510
+ * @returns Filtered array of search items
511
+ */
512
+ filterByConfidence(items: ISearchItem[], minConfidence: number = 0): ISearchItem[] {
513
+ return items.filter(item => {
514
+ const confidence = (item as IDataItem).confidence;
515
+ return confidence === undefined || confidence >= minConfidence;
516
+ });
517
+ },
518
+
519
+ /**
520
+ * Groups search results by their plugin type
521
+ * Useful for organizing results in the UI
522
+ *
523
+ * @param items - Array of search items to group
524
+ * @returns Object with plugin types as keys and arrays of items as values
525
+ */
526
+ groupByPluginType(items: ISearchItem[]): Record<string, ISearchItem[]> {
527
+ return items.reduce((groups, item) => {
528
+ const type = item.pluginType;
529
+ if (!groups[type]) {
530
+ groups[type] = [];
531
+ }
532
+ groups[type].push(item);
533
+ return groups;
534
+ }, {} as Record<string, ISearchItem[]>);
535
+ }
536
+ };