@talex-touch/utils 1.0.31 → 1.0.33

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 (116) 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 +88 -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 +4 -6
  27. package/core-box/preview/index.ts +1 -0
  28. package/core-box/preview/types.ts +43 -0
  29. package/core-box/recommendation.ts +77 -0
  30. package/core-box/tuff/index.ts +1 -1
  31. package/core-box/tuff/tuff-dsl.ts +328 -266
  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 +2 -2
  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/README.md +216 -0
  57. package/plugin/sdk/box-sdk.ts +219 -0
  58. package/plugin/sdk/channel.ts +20 -20
  59. package/plugin/sdk/clipboard.ts +8 -6
  60. package/plugin/sdk/common.ts +10 -6
  61. package/plugin/sdk/core-box.ts +2 -3
  62. package/plugin/sdk/division-box.ts +266 -0
  63. package/plugin/sdk/enum/bridge-event.ts +1 -1
  64. package/plugin/sdk/examples/storage-onDidChange-example.js +1 -1
  65. package/plugin/sdk/feature-sdk.ts +235 -0
  66. package/plugin/sdk/features.ts +34 -26
  67. package/plugin/sdk/hooks/bridge.ts +3 -6
  68. package/plugin/sdk/hooks/index.ts +1 -1
  69. package/plugin/sdk/hooks/life-cycle.ts +4 -10
  70. package/plugin/sdk/index.ts +10 -7
  71. package/plugin/sdk/service/index.ts +3 -3
  72. package/plugin/sdk/storage.ts +4 -4
  73. package/plugin/sdk/system.ts +1 -1
  74. package/plugin/sdk/types.ts +165 -146
  75. package/plugin/sdk/window/index.ts +8 -5
  76. package/preload/loading.ts +6 -6
  77. package/preload/renderer.ts +4 -2
  78. package/renderer/hooks/arg-mapper.ts +1 -2
  79. package/renderer/hooks/index.ts +2 -0
  80. package/renderer/hooks/initialize.ts +10 -8
  81. package/renderer/hooks/performance.ts +4 -4
  82. package/renderer/hooks/use-channel.ts +150 -0
  83. package/renderer/hooks/use-intelligence.ts +236 -0
  84. package/renderer/index.ts +6 -2
  85. package/renderer/ref.ts +32 -36
  86. package/renderer/slots.ts +29 -26
  87. package/renderer/storage/app-settings.ts +16 -6
  88. package/renderer/storage/base-storage.ts +222 -114
  89. package/renderer/storage/index.ts +3 -0
  90. package/renderer/storage/intelligence-storage.ts +218 -0
  91. package/renderer/storage/openers.ts +13 -3
  92. package/renderer/touch-sdk/env.ts +41 -41
  93. package/renderer/touch-sdk/index.ts +1 -1
  94. package/renderer/touch-sdk/terminal.ts +5 -5
  95. package/renderer/touch-sdk/utils.ts +4 -3
  96. package/search/levenshtein-utils.ts +11 -11
  97. package/search/types.ts +102 -102
  98. package/service/index.ts +11 -11
  99. package/service/protocol/index.ts +217 -14
  100. package/types/division-box.ts +248 -0
  101. package/types/download.ts +72 -34
  102. package/types/index.ts +3 -1
  103. package/types/intelligence.ts +607 -0
  104. package/types/modules/base.ts +16 -16
  105. package/types/modules/index.ts +1 -1
  106. package/types/modules/module-lifecycle.ts +21 -21
  107. package/types/modules/module-manager.ts +11 -11
  108. package/types/modules/module.ts +16 -16
  109. package/types/storage.ts +0 -1
  110. package/types/touch-app-core.ts +32 -32
  111. package/types/update.ts +91 -21
  112. package/core-box/README.md +0 -218
  113. package/core-box/builder/tuff-builder.example.ts.bak +0 -258
  114. package/core-box/run-tests.sh +0 -7
  115. package/core-box/search.ts +0 -1
  116. package/electron/clipboard-helper.ts +0 -199
package/plugin/channel.ts CHANGED
@@ -1,33 +1,38 @@
1
1
  import type { IpcRenderer, IpcRendererEvent } from 'electron'
2
- import {
3
- ChannelType,
4
- DataCode,
2
+ import type {
5
3
  ITouchClientChannel,
6
4
  RawChannelSyncData,
7
5
  RawStandardChannelData,
8
6
  StandardChannelData,
9
- } from "../channel";
7
+ } from '../channel'
8
+ import {
9
+ ChannelType,
10
+ DataCode,
11
+ } from '../channel'
10
12
 
11
13
  let cachedIpcRenderer: IpcRenderer | null = null
12
14
 
13
15
  // 使用惰性解析避免在打包阶段静态引入 electron
14
- const resolveIpcRenderer = (): IpcRenderer | null => {
16
+ function resolveIpcRenderer(): IpcRenderer | null {
15
17
  if (typeof window !== 'undefined') {
16
18
  const bridge = (window as any)?.electron
17
- if (bridge?.ipcRenderer) return bridge.ipcRenderer as IpcRenderer
19
+ if (bridge?.ipcRenderer)
20
+ return bridge.ipcRenderer as IpcRenderer
18
21
  }
19
22
 
20
23
  try {
21
24
  const electron = (globalThis as any)?.electron ?? (eval('require') as any)?.('electron')
22
- if (electron?.ipcRenderer) return electron.ipcRenderer as IpcRenderer
23
- } catch (error) {
25
+ if (electron?.ipcRenderer)
26
+ return electron.ipcRenderer as IpcRenderer
27
+ }
28
+ catch (error) {
24
29
  // ignore – will throw below if no ipcRenderer is resolved
25
30
  }
26
31
 
27
32
  return null
28
33
  }
29
34
 
30
- const ensureIpcRenderer = (): IpcRenderer => {
35
+ function ensureIpcRenderer(): IpcRenderer {
31
36
  if (!cachedIpcRenderer) {
32
37
  cachedIpcRenderer = resolveIpcRenderer()
33
38
  }
@@ -44,55 +49,56 @@ const ensureIpcRenderer = (): IpcRenderer => {
44
49
  * Due to the new secret system, ipc message transmission should unique Key, and will inject when ui view attached.
45
50
  */
46
51
  class TouchChannel implements ITouchClientChannel {
47
- channelMap: Map<string, Function[]> = new Map();
52
+ channelMap: Map<string, Function[]> = new Map()
48
53
 
49
- pendingMap: Map<string, Function> = new Map();
54
+ pendingMap: Map<string, Function> = new Map()
50
55
 
51
- plugin: string;
56
+ plugin: string
52
57
 
53
58
  private ipcRenderer: IpcRenderer
54
59
 
55
60
  constructor(pluginName: string) {
56
- this.plugin = pluginName;
61
+ this.plugin = pluginName
57
62
  this.ipcRenderer = ensureIpcRenderer()
58
- this.ipcRenderer.on("@plugin-process-message", this.__handle_main.bind(this));
63
+ this.ipcRenderer.on('@plugin-process-message', this.__handle_main.bind(this))
59
64
  }
60
65
 
61
66
  __parse_raw_data(e: IpcRendererEvent | undefined, arg: any): RawStandardChannelData | null {
62
- console.debug("Raw data: ", arg, e);
67
+ console.debug('Raw data: ', arg, e)
63
68
  if (arg) {
64
- const { name, header, code, data, sync } = arg;
69
+ const { name, header, code, data, sync } = arg
65
70
 
66
71
  if (header) {
67
72
  return {
68
73
  header: {
69
- status: header.status || "request",
74
+ status: header.status || 'request',
70
75
  type: ChannelType.PLUGIN,
71
76
  _originData: arg,
72
- event: e
77
+ event: e,
73
78
  },
74
79
  sync,
75
80
  code,
76
81
  data,
77
82
  name: name as string,
78
- };
83
+ }
79
84
  }
80
85
  }
81
86
 
82
- console.error(e, arg);
83
- return null;
87
+ console.error(e, arg)
88
+ return null
84
89
  // throw new Error("Invalid message!");
85
90
  }
86
91
 
87
92
  __handle_main(e: IpcRendererEvent, _arg: any): any {
88
93
  const arg = JSON.parse(_arg)
89
- const rawData = this.__parse_raw_data(e, arg);
90
- if ( !rawData ) return
94
+ const rawData = this.__parse_raw_data(e, arg)
95
+ if (!rawData)
96
+ return
91
97
 
92
- if ( rawData.header.status === 'reply' && rawData.sync ) {
93
- const { id } = rawData.sync;
98
+ if (rawData.header.status === 'reply' && rawData.sync) {
99
+ const { id } = rawData.sync
94
100
 
95
- return this.pendingMap.get(id)?.(rawData);
101
+ return this.pendingMap.get(id)?.(rawData)
96
102
  }
97
103
 
98
104
  // if ( rawData.plugin !== this.plugin ) return
@@ -101,26 +107,27 @@ class TouchChannel implements ITouchClientChannel {
101
107
  const handInData: StandardChannelData = {
102
108
  reply: (code: DataCode, data: any) => {
103
109
  e.sender.send(
104
- "@plugin-process-message",
105
- this.__parse_sender(code, rawData, data, rawData.sync)
106
- );
110
+ '@plugin-process-message',
111
+ this.__parse_sender(code, rawData, data, rawData.sync),
112
+ )
107
113
  },
108
114
  ...rawData,
109
- };
115
+ }
110
116
 
111
- const res = func(handInData);
117
+ const res = func(handInData)
112
118
 
113
- if (res && res instanceof Promise) return;
119
+ if (res && res instanceof Promise)
120
+ return
114
121
 
115
- handInData.reply(DataCode.SUCCESS, res);
116
- });
122
+ handInData.reply(DataCode.SUCCESS, res)
123
+ })
117
124
  }
118
125
 
119
126
  __parse_sender(
120
127
  code: DataCode,
121
128
  rawData: RawStandardChannelData,
122
129
  data: any,
123
- sync?: RawChannelSyncData
130
+ sync?: RawChannelSyncData,
124
131
  ): RawStandardChannelData {
125
132
  return {
126
133
  code,
@@ -136,61 +143,64 @@ class TouchChannel implements ITouchClientChannel {
136
143
  name: rawData.name,
137
144
  header: {
138
145
  event: rawData.header.event,
139
- status: "reply",
146
+ status: 'reply',
140
147
  type: rawData.header.type,
141
148
  _originData: rawData.header._originData,
142
149
  },
143
- };
150
+ }
144
151
  }
145
152
 
146
153
  regChannel(
147
154
  eventName: string,
148
- callback: Function
155
+ callback: Function,
149
156
  ): () => void {
150
- const listeners = this.channelMap.get(eventName) || [];
157
+ const listeners = this.channelMap.get(eventName) || []
151
158
 
152
159
  if (!listeners.includes(callback)) {
153
- listeners.push(callback);
154
- } else return () => void 0;
160
+ listeners.push(callback)
161
+ }
162
+ else {
163
+ return () => void 0
164
+ }
155
165
 
156
- this.channelMap.set(eventName, listeners);
166
+ this.channelMap.set(eventName, listeners)
157
167
 
158
168
  return () => {
159
- const index = listeners.indexOf(callback);
169
+ const index = listeners.indexOf(callback)
160
170
 
161
171
  if (index !== -1) {
162
- listeners.splice(index, 1);
172
+ listeners.splice(index, 1)
163
173
  }
164
- };
174
+ }
165
175
  }
166
176
 
167
177
  unRegChannel(eventName: string, callback: Function): boolean {
168
- const listeners = this.channelMap.get(eventName);
178
+ const listeners = this.channelMap.get(eventName)
169
179
 
170
180
  if (!listeners) {
171
- return false;
181
+ return false
172
182
  }
173
183
 
174
- const index = listeners.indexOf(callback);
184
+ const index = listeners.indexOf(callback)
175
185
 
176
186
  if (index === -1) {
177
- return false;
187
+ return false
178
188
  }
179
189
 
180
- listeners.splice(index, 1);
190
+ listeners.splice(index, 1)
181
191
 
182
192
  // If no listeners remain for this event, remove the event from the map
183
193
  if (listeners.length === 0) {
184
- this.channelMap.delete(eventName);
194
+ this.channelMap.delete(eventName)
185
195
  }
186
196
 
187
- return true;
197
+ return true
188
198
  }
189
199
 
190
200
  send(eventName: string, arg: any): Promise<any> {
191
201
  const uniqueId = `${new Date().getTime()}#${eventName}@${Math.random().toString(
192
- 12
193
- )}`;
202
+ 12,
203
+ )}`
194
204
 
195
205
  const data = {
196
206
  code: DataCode.SUCCESS,
@@ -203,21 +213,20 @@ class TouchChannel implements ITouchClientChannel {
203
213
  name: eventName,
204
214
  plugin: this.plugin,
205
215
  header: {
206
- status: "request",
216
+ status: 'request',
207
217
  type: ChannelType.PLUGIN,
208
218
  },
209
- } as RawStandardChannelData;
219
+ } as RawStandardChannelData
210
220
 
211
221
  return new Promise((resolve) => {
212
-
213
- this.ipcRenderer.send("@plugin-process-message", data);
222
+ this.ipcRenderer.send('@plugin-process-message', data)
214
223
 
215
224
  this.pendingMap.set(uniqueId, (res: any) => {
216
- this.pendingMap.delete(uniqueId);
225
+ this.pendingMap.delete(uniqueId)
217
226
 
218
- resolve(res.data);
219
- });
220
- });
227
+ resolve(res.data)
228
+ })
229
+ })
221
230
  }
222
231
 
223
232
  sendSync(eventName: string, arg?: any): any {
@@ -227,17 +236,17 @@ class TouchChannel implements ITouchClientChannel {
227
236
  name: eventName,
228
237
  plugin: this.plugin,
229
238
  header: {
230
- status: "request",
239
+ status: 'request',
231
240
  type: ChannelType.PLUGIN,
232
241
  },
233
- } as RawStandardChannelData;
234
-
235
- const res = this.__parse_raw_data(void 0, this.ipcRenderer.sendSync("@plugin-process-message", data))!
242
+ } as RawStandardChannelData
236
243
 
237
- if ( res.header.status === 'reply' ) return res.data;
244
+ const res = this.__parse_raw_data(void 0, this.ipcRenderer.sendSync('@plugin-process-message', data))!
238
245
 
239
- return res;
246
+ if (res.header.status === 'reply')
247
+ return res.data
240
248
 
249
+ return res
241
250
  }
242
251
  }
243
252