@talex-touch/utils 1.0.17 → 1.0.20

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 (82) hide show
  1. package/animation/window.ts +191 -0
  2. package/channel/index.ts +49 -1
  3. package/common/index.ts +2 -0
  4. package/common/search/gather.ts +45 -0
  5. package/common/search/index.ts +67 -0
  6. package/common/storage/constants.ts +16 -2
  7. package/common/storage/entity/index.ts +2 -1
  8. package/common/storage/entity/openers.ts +32 -0
  9. package/common/storage/entity/shortcut-settings.ts +22 -0
  10. package/common/storage/shortcut-storage.ts +58 -0
  11. package/common/utils/file.ts +62 -0
  12. package/common/{utils.ts → utils/index.ts} +14 -2
  13. package/common/utils/polling.ts +184 -0
  14. package/common/utils/task-queue.ts +108 -0
  15. package/common/utils/time.ts +374 -0
  16. package/core-box/README.md +8 -8
  17. package/core-box/builder/index.ts +6 -0
  18. package/core-box/builder/tuff-builder.example.ts.bak +258 -0
  19. package/core-box/builder/tuff-builder.ts +1162 -0
  20. package/core-box/index.ts +5 -2
  21. package/core-box/run-tests.sh +7 -0
  22. package/core-box/search.ts +1 -536
  23. package/core-box/tuff/index.ts +6 -0
  24. package/core-box/tuff/tuff-dsl.ts +1412 -0
  25. package/electron/clipboard-helper.ts +199 -0
  26. package/electron/env-tool.ts +36 -2
  27. package/electron/file-parsers/index.ts +8 -0
  28. package/electron/file-parsers/parsers/text-parser.ts +109 -0
  29. package/electron/file-parsers/registry.ts +92 -0
  30. package/electron/file-parsers/types.ts +58 -0
  31. package/electron/index.ts +3 -0
  32. package/eventbus/index.ts +0 -7
  33. package/index.ts +3 -1
  34. package/package.json +4 -28
  35. package/plugin/channel.ts +48 -16
  36. package/plugin/index.ts +194 -30
  37. package/plugin/log/types.ts +11 -0
  38. package/plugin/node/index.ts +4 -0
  39. package/plugin/node/logger-manager.ts +113 -0
  40. package/plugin/{log → node}/logger.ts +41 -7
  41. package/plugin/plugin-source.ts +74 -0
  42. package/plugin/preload.ts +5 -15
  43. package/plugin/providers/index.ts +2 -0
  44. package/plugin/providers/registry.ts +47 -0
  45. package/plugin/providers/types.ts +54 -0
  46. package/plugin/risk/index.ts +1 -0
  47. package/plugin/risk/types.ts +20 -0
  48. package/plugin/sdk/enum/bridge-event.ts +4 -0
  49. package/plugin/sdk/enum/index.ts +1 -0
  50. package/plugin/sdk/hooks/bridge.ts +68 -0
  51. package/plugin/sdk/hooks/index.ts +2 -1
  52. package/plugin/sdk/hooks/life-cycle.ts +2 -4
  53. package/plugin/sdk/index.ts +2 -0
  54. package/plugin/sdk/storage.ts +84 -0
  55. package/plugin/sdk/types.ts +2 -2
  56. package/plugin/sdk/window/index.ts +5 -3
  57. package/preload/index.ts +2 -0
  58. package/preload/loading.ts +15 -0
  59. package/preload/renderer.ts +41 -0
  60. package/renderer/hooks/arg-mapper.ts +79 -0
  61. package/renderer/hooks/index.ts +2 -0
  62. package/renderer/hooks/initialize.ts +198 -0
  63. package/renderer/index.ts +3 -0
  64. package/renderer/storage/app-settings.ts +2 -0
  65. package/renderer/storage/base-storage.ts +1 -0
  66. package/renderer/storage/openers.ts +11 -0
  67. package/renderer/touch-sdk/env.ts +106 -0
  68. package/renderer/touch-sdk/index.ts +108 -0
  69. package/renderer/touch-sdk/terminal.ts +85 -0
  70. package/renderer/touch-sdk/utils.ts +61 -0
  71. package/search/levenshtein-utils.ts +39 -0
  72. package/search/types.ts +16 -16
  73. package/types/index.ts +2 -1
  74. package/types/modules/base.ts +146 -0
  75. package/types/modules/index.ts +4 -0
  76. package/types/modules/module-lifecycle.ts +148 -0
  77. package/types/modules/module-manager.ts +99 -0
  78. package/types/modules/module.ts +112 -0
  79. package/types/touch-app-core.ts +16 -93
  80. package/core-box/types.ts +0 -384
  81. package/electron/window.ts +0 -71
  82. package/plugin/log/logger-manager.ts +0 -60
@@ -1,6 +1,6 @@
1
1
  # Core Box Package
2
2
 
3
- The Core Box package provides unified type definitions and utility functions for the Talex Touch search box system. This package contains the foundational types and tools used across the entire project for search result management and plugin integration.
3
+ The Core Box package provides unified type definitions and utility functions for the TUFF search box system. This package contains the foundational types and tools used across the entire project for search result management and plugin integration.
4
4
 
5
5
  ## Features
6
6
 
@@ -112,14 +112,14 @@ const codeItem = SearchUtils.createDataItem({
112
112
  ```typescript
113
113
  const urlItem = SearchUtils.createSearchItem({
114
114
  name: "GitHub Repository",
115
- desc: "Talex Touch project",
115
+ desc: "TUFF project",
116
116
  pluginName: "web-search",
117
117
  render: {
118
118
  mode: RenderMode.URL,
119
119
  content: "https://github.com/talex-touch/talex-touch", // The actual URL to load
120
120
  preview: {
121
121
  enabled: true,
122
- title: "Talex Touch", // Preview metadata
122
+ title: "Tuff", // Preview metadata
123
123
  description: "Modern desktop application framework", // Preview description
124
124
  image: "https://github.com/talex-touch.png" // Preview image
125
125
  }
@@ -181,11 +181,11 @@ interface IRenderConfig {
181
181
  This package is automatically exported from `@talex-touch/utils`:
182
182
 
183
183
  ```typescript
184
- import {
185
- ISearchItem,
186
- IDataItem,
187
- SearchUtils,
188
- RenderMode
184
+ import {
185
+ ISearchItem,
186
+ IDataItem,
187
+ SearchUtils,
188
+ RenderMode
189
189
  } from '@talex-touch/utils';
190
190
  ```
191
191
 
@@ -0,0 +1,6 @@
1
+ /**
2
+ * TUFF Builder 模块导出
3
+ * 提供 TuffItem 构建工具和实用函数
4
+ */
5
+
6
+ export * from './tuff-builder';
@@ -0,0 +1,258 @@
1
+ /**
2
+ * TUFF Builder 示例文件
3
+ * 展示如何使用 TuffBuilder 工具类创建和管理 TuffItem 对象
4
+ */
5
+
6
+ import { TuffItemBuilder, TuffFactory, TuffListBuilder, TuffUtils } from './tuff-builder';
7
+ import type { TuffItem } from '../tuff/tuff-dsl';
8
+
9
+ // ==================== 基本用法示例 ====================
10
+
11
+ /**
12
+ * 示例 1: 使用 TuffItemBuilder 创建单个项目
13
+ */
14
+ function createSingleItem(): TuffItem {
15
+ // 使用 Builder 模式创建一个完整的 TuffItem
16
+ const item = new TuffItemBuilder('doc-1')
17
+ .setSource('plugin', 'file-explorer')
18
+ .setTitle('文档.docx')
19
+ .setDescription('Word 文档')
20
+ .setIcon(TuffUtils.createIcon('📄'))
21
+ .setKind('file')
22
+ .addTag(TuffUtils.createTag('文档', '#4285F4'))
23
+ .addTag(TuffUtils.createTag('最近', '#34A853'))
24
+ .setAccessory('2023-06-15')
25
+ .addAction(TuffUtils.createAction('open', 'open', '打开', true))
26
+ .addAction(TuffUtils.createAction('copy', 'copy', '复制路径', false))
27
+ .setMeta({
28
+ file: {
29
+ path: '/Users/documents/文档.docx',
30
+ size: 1024 * 1024 * 2, // 2MB
31
+ modified_at: '2023-06-15T10:30:00Z'
32
+ }
33
+ })
34
+ .build();
35
+
36
+ return item;
37
+ }
38
+
39
+ /**
40
+ * 示例 2: 使用 TuffFactory 快速创建常见类型的项目
41
+ */
42
+ function createCommonItems(): TuffItem[] {
43
+ const items: TuffItem[] = [];
44
+
45
+ // 创建基本项目
46
+ const basicItem = TuffFactory.createBasicItem(
47
+ '基本项目',
48
+ 'system',
49
+ 'basic-example',
50
+ 'text'
51
+ );
52
+ items.push(basicItem);
53
+
54
+ // 创建文件项目
55
+ const fileItem = TuffFactory.createFileItem(
56
+ 'config.json',
57
+ '/Users/config.json',
58
+ 'plugin',
59
+ 'settings-manager'
60
+ );
61
+ items.push(fileItem);
62
+
63
+ // 创建文件夹项目
64
+ const folderItem = TuffFactory.createFolderItem(
65
+ '项目文件夹',
66
+ '/Users/projects',
67
+ 'plugin',
68
+ 'file-explorer'
69
+ );
70
+ items.push(folderItem);
71
+
72
+ // 创建链接项目
73
+ const urlItem = TuffFactory.createUrlItem(
74
+ 'Tuff 文档',
75
+ 'https://example.com/tuff-docs',
76
+ 'plugin',
77
+ 'web-search'
78
+ );
79
+ items.push(urlItem);
80
+
81
+ // 创建应用项目
82
+ const appItem = TuffFactory.createAppItem(
83
+ 'Visual Studio Code',
84
+ '/Applications/Visual Studio Code.app',
85
+ 'com.microsoft.VSCode',
86
+ 'plugin',
87
+ 'app-launcher'
88
+ );
89
+ items.push(appItem);
90
+
91
+ // 创建命令项目
92
+ const commandItem = TuffFactory.createCommandItem(
93
+ '查看系统信息',
94
+ 'system_profiler SPHardwareDataType',
95
+ 'plugin',
96
+ 'terminal'
97
+ );
98
+ items.push(commandItem);
99
+
100
+ return items;
101
+ }
102
+
103
+ /**
104
+ * 示例 3: 使用 TuffBatchBuilder 批量创建项目
105
+ */
106
+ function createBatchItems(): TuffItem[] {
107
+ // 创建批量构建器,设置共享的来源信息
108
+ const batchBuilder = new TuffListBuilder('plugin', 'file-explorer')
109
+ .setSharedKind('file')
110
+
111
+ .addSharedAction(TuffUtils.createAction('open', 'open', '打开', true));
112
+
113
+ // 添加多个项目
114
+ batchBuilder
115
+ .addItem(builder => {
116
+ builder
117
+ .setTitle('文档1.docx')
118
+ .setIcon(TuffUtils.createIcon('📄'))
119
+ .setDescription('Word 文档')
120
+ .addTag(TuffUtils.createTag('文档', '#4285F4'));
121
+ })
122
+ .addItem(builder => {
123
+ builder
124
+ .setTitle('图片.jpg')
125
+ .setIcon(TuffUtils.createIcon('🖼️'))
126
+ .setDescription('JPG 图片')
127
+ .addTag(TuffUtils.createTag('图片', '#FBBC05'));
128
+ })
129
+ .addItem(builder => {
130
+ builder
131
+ .setTitle('表格.xlsx')
132
+ .setIcon(TuffUtils.createIcon('📊'))
133
+ .setDescription('Excel 表格')
134
+ .addTag(TuffUtils.createTag('表格', '#34A853'));
135
+ });
136
+
137
+ // 批量添加简单项目
138
+ batchBuilder.addItemsFromData([
139
+ { name: '笔记1.txt' },
140
+ { name: '笔记2.txt' },
141
+ { name: '笔记3.txt' }
142
+ ], (builder, item) => builder.setTitle(item.name));
143
+
144
+ // 从数据对象批量创建项目
145
+ const fileData = [
146
+ { name: '报告.pdf', type: 'pdf', size: 1024 * 1024 * 3, modified: '2023-06-10' },
147
+ { name: '演示.pptx', type: 'pptx', size: 1024 * 1024 * 5, modified: '2023-06-12' },
148
+ { name: '数据.csv', type: 'csv', size: 1024 * 512, modified: '2023-06-14' }
149
+ ];
150
+
151
+ batchBuilder.addItemsFromData(fileData, (builder, file) => {
152
+ let icon = '📄';
153
+ if (file.type === 'pdf') icon = '📕';
154
+ if (file.type === 'pptx') icon = '📊';
155
+ if (file.type === 'csv') icon = '📈';
156
+
157
+ builder
158
+ .setTitle(file.name)
159
+ .setIcon(TuffUtils.createIcon(icon))
160
+ .setDescription(`${file.type.toUpperCase()} 文件`)
161
+ .setAccessory(file.modified)
162
+ .setMeta({
163
+ file: {
164
+ path: file.name,
165
+ size: file.size,
166
+ modified_at: file.modified
167
+ }
168
+ });
169
+ });
170
+
171
+ return batchBuilder.build();
172
+ }
173
+
174
+ /**
175
+ * 示例 4: 使用 TuffUtils 处理项目列表
176
+ */
177
+ function processItems(items: TuffItem[]): void {
178
+ // 过滤文件类型的项目
179
+ const fileItems = TuffUtils.filterByKind(items, 'file');
180
+ console.log(`文件项目数量: ${fileItems.length}`);
181
+
182
+ // 按标题搜索项目
183
+ const searchResults = TuffUtils.searchByTitle(items, '文档');
184
+ console.log(`包含"文档"的项目数量: ${searchResults.length}`);
185
+
186
+ // 按评分排序项目
187
+ const sortedByScore = TuffUtils.sortByScore(items);
188
+ console.log('按评分排序的前 3 个项目:');
189
+ sortedByScore.slice(0, 3).forEach(item => {
190
+ console.log(` - ${item.render.basic?.title} (评分: ${item.scoring?.final ?? 0})`);
191
+ });
192
+
193
+ // 按标题排序项目
194
+ const sortedByTitle = TuffUtils.sortByTitle(items);
195
+ console.log('按标题排序的前 3 个项目:');
196
+ sortedByTitle.slice(0, 3).forEach(item => {
197
+ console.log(` - ${item.render.basic?.title}`);
198
+ });
199
+ }
200
+
201
+ /**
202
+ * 示例 5: 从普通对象创建 TuffItem
203
+ */
204
+ function createFromObjects(): TuffItem[] {
205
+ // 示例数据
206
+ const data = [
207
+ { name: '项目 A', description: '这是项目 A 的描述', type: 'project' },
208
+ { name: '任务 B', description: '这是任务 B 的描述', type: 'task', priority: 'high' },
209
+ { name: '笔记 C', description: '这是笔记 C 的内容', type: 'note', tags: ['重要', '工作'] }
210
+ ];
211
+
212
+ // 从对象数组创建 TuffItem 数组
213
+ return TuffUtils.fromObjects(data, 'plugin', 'data-converter');
214
+ }
215
+
216
+ /**
217
+ * 运行所有示例
218
+ */
219
+ function runAllExamples(): void {
220
+ console.log('===== 示例 1: 使用 TuffItemBuilder 创建单个项目 =====');
221
+ const singleItem = createSingleItem();
222
+ console.log(JSON.stringify(singleItem, null, 2));
223
+
224
+ console.log('\n===== 示例 2: 使用 TuffFactory 快速创建常见类型的项目 =====');
225
+ const commonItems = createCommonItems();
226
+ console.log(`创建了 ${commonItems.length} 个项目`);
227
+
228
+ console.log('\n===== 示例 3: 使用 TuffBatchBuilder 批量创建项目 =====');
229
+ const batchItems = createBatchItems();
230
+ console.log(`批量创建了 ${batchItems.length} 个项目`);
231
+
232
+ console.log('\n===== 示例 4: 使用 TuffUtils 处理项目列表 =====');
233
+ // 合并所有创建的项目
234
+ const allItems = [singleItem, ...commonItems, ...batchItems];
235
+ processItems(allItems);
236
+
237
+ console.log('\n===== 示例 5: 从普通对象创建 TuffItem =====');
238
+ const objectItems = createFromObjects();
239
+ console.log(`从对象创建了 ${objectItems.length} 个项目`);
240
+ objectItems.forEach(item => {
241
+ console.log(` - ${item.render.basic?.title}`);
242
+ });
243
+ }
244
+
245
+ // 如果直接运行此文件,则执行所有示例
246
+ if (require.main === module) {
247
+ runAllExamples();
248
+ }
249
+
250
+ // 导出示例函数,以便其他模块可以使用
251
+ export {
252
+ createSingleItem,
253
+ createCommonItems,
254
+ createBatchItems,
255
+ processItems,
256
+ createFromObjects,
257
+ runAllExamples
258
+ };