@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.
- package/animation/window-node.ts +205 -0
- package/animation/window.ts +19 -15
- package/auth/clerk-types.ts +1 -1
- package/auth/index.ts +1 -1
- package/auth/useAuthState.ts +6 -5
- package/auth/useClerkConfig.ts +6 -6
- package/auth/useClerkProvider.ts +3 -2
- package/channel/index.ts +28 -21
- package/common/file-scan-constants.ts +137 -121
- package/common/file-scan-utils.ts +49 -25
- package/common/index.ts +3 -3
- package/common/search/gather.ts +1 -1
- package/common/search/index.ts +5 -6
- package/common/storage/constants.ts +3 -2
- package/common/storage/entity/app-settings.ts +19 -3
- package/common/storage/entity/shortcut-settings.ts +10 -10
- package/common/storage/shortcut-storage.ts +6 -4
- package/common/utils/file.ts +15 -4
- package/common/utils/index.ts +62 -52
- package/common/utils/polling.ts +114 -63
- package/common/utils/task-queue.ts +11 -10
- package/common/utils/time.ts +50 -47
- package/common/utils/timing.ts +41 -37
- package/core-box/builder/index.ts +1 -1
- package/core-box/builder/tuff-builder.ts +255 -230
- package/core-box/index.ts +3 -6
- package/core-box/preview/index.ts +1 -0
- package/core-box/preview/types.ts +43 -0
- package/core-box/tuff/index.ts +1 -1
- package/core-box/tuff/tuff-dsl.ts +419 -253
- package/electron/clipboard-helper.ts +20 -12
- package/electron/download-manager.ts +43 -42
- package/electron/env-tool.ts +19 -18
- package/electron/file-parsers/index.ts +2 -2
- package/electron/file-parsers/parsers/text-parser.ts +15 -14
- package/electron/file-parsers/registry.ts +9 -7
- package/electron/file-parsers/types.ts +4 -4
- package/electron/index.ts +1 -1
- package/eventbus/index.ts +11 -11
- package/index.ts +6 -5
- package/intelligence/client.ts +87 -0
- package/intelligence/index.ts +1 -0
- package/package.json +14 -14
- package/permission/index.ts +8 -8
- package/plugin/channel.ts +77 -68
- package/plugin/index.ts +113 -84
- package/plugin/install.ts +8 -8
- package/plugin/log/types.ts +5 -5
- package/plugin/node/index.ts +1 -1
- package/plugin/node/logger-manager.ts +14 -11
- package/plugin/node/logger.ts +8 -8
- package/plugin/plugin-source.ts +11 -11
- package/plugin/preload.ts +6 -3
- package/plugin/providers/registry.ts +8 -7
- package/plugin/providers/types.ts +6 -6
- package/plugin/sdk/channel.ts +20 -20
- package/plugin/sdk/clipboard.ts +8 -6
- package/plugin/sdk/common.ts +10 -6
- package/plugin/sdk/core-box.ts +2 -3
- package/plugin/sdk/division-box.ts +266 -0
- package/plugin/sdk/enum/bridge-event.ts +1 -1
- package/plugin/sdk/examples/storage-onDidChange-example.js +1 -1
- package/plugin/sdk/features.ts +34 -26
- package/plugin/sdk/hooks/bridge.ts +3 -6
- package/plugin/sdk/hooks/index.ts +1 -1
- package/plugin/sdk/hooks/life-cycle.ts +4 -10
- package/plugin/sdk/index.ts +9 -13
- package/plugin/sdk/service/index.ts +3 -3
- package/plugin/sdk/storage.ts +4 -4
- package/plugin/sdk/system.ts +1 -1
- package/plugin/sdk/types.ts +169 -143
- package/plugin/sdk/window/index.ts +8 -5
- package/preload/loading.ts +6 -6
- package/preload/renderer.ts +4 -2
- package/renderer/hooks/arg-mapper.ts +1 -2
- package/renderer/hooks/index.ts +2 -0
- package/renderer/hooks/initialize.ts +10 -8
- package/renderer/hooks/performance.ts +4 -4
- package/renderer/hooks/use-channel.ts +150 -0
- package/renderer/hooks/use-intelligence.ts +236 -0
- package/renderer/index.ts +6 -1
- package/renderer/ref.ts +32 -36
- package/renderer/slots.ts +29 -26
- package/renderer/storage/app-settings.ts +16 -6
- package/renderer/storage/base-storage.ts +236 -88
- package/renderer/storage/index.ts +3 -0
- package/renderer/storage/intelligence-storage.ts +215 -0
- package/renderer/storage/openers.ts +13 -3
- package/renderer/touch-sdk/env.ts +41 -41
- package/renderer/touch-sdk/index.ts +1 -1
- package/renderer/touch-sdk/terminal.ts +5 -5
- package/renderer/touch-sdk/utils.ts +4 -3
- package/search/levenshtein-utils.ts +11 -11
- package/search/types.ts +102 -103
- package/service/index.ts +11 -11
- package/service/protocol/index.ts +217 -14
- package/types/division-box.ts +248 -0
- package/types/download.ts +72 -34
- package/types/icon.ts +2 -1
- package/types/index.ts +3 -1
- package/types/intelligence.ts +413 -0
- package/types/modules/base.ts +16 -16
- package/types/modules/index.ts +1 -1
- package/types/modules/module-lifecycle.ts +21 -21
- package/types/modules/module-manager.ts +11 -11
- package/types/modules/module.ts +16 -16
- package/types/storage.ts +0 -1
- package/types/touch-app-core.ts +32 -32
- package/types/update.ts +79 -21
- package/core-box/README.md +0 -218
- package/core-box/builder/tuff-builder.example.ts.bak +0 -258
- package/core-box/run-tests.sh +0 -7
- package/core-box/search.ts +0 -1
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
|
-
"main": "index.ts",
|
|
3
2
|
"name": "@talex-touch/utils",
|
|
3
|
+
"version": "1.0.32",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Tuff series utils",
|
|
4
6
|
"author": "TalexDreamSoul",
|
|
5
|
-
"module": "./index.ts",
|
|
6
7
|
"license": "MPL-2.0",
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"publish": "npm publish --access public"
|
|
8
|
+
"repository": {
|
|
9
|
+
"url": "https://github.com/talex-touch/talex-touch.git",
|
|
10
|
+
"type": "git"
|
|
11
11
|
},
|
|
12
12
|
"keywords": [
|
|
13
13
|
"vue",
|
|
@@ -15,18 +15,18 @@
|
|
|
15
15
|
"launcher",
|
|
16
16
|
"talex-touch"
|
|
17
17
|
],
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
"main": "index.ts",
|
|
19
|
+
"module": "./index.ts",
|
|
20
|
+
"scripts": {
|
|
21
|
+
"publish": "npm publish --access public"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"electron": "^37.2.4",
|
|
25
|
+
"vue": "^3.5.15"
|
|
21
26
|
},
|
|
22
|
-
"description": "Tuff series utils",
|
|
23
27
|
"dependencies": {
|
|
24
28
|
"@vueuse/core": "^13.6.0",
|
|
25
29
|
"path-browserify": "^1.0.1",
|
|
26
30
|
"vue": "^3.5.18"
|
|
27
|
-
},
|
|
28
|
-
"peerDependencies": {
|
|
29
|
-
"electron": "^37.2.4",
|
|
30
|
-
"vue": "^3.5.15"
|
|
31
31
|
}
|
|
32
32
|
}
|
package/permission/index.ts
CHANGED
|
@@ -2,17 +2,17 @@ export interface Permission {
|
|
|
2
2
|
/**
|
|
3
3
|
* permission id
|
|
4
4
|
*/
|
|
5
|
-
id: symbol
|
|
5
|
+
id: symbol
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* permission name
|
|
9
9
|
*/
|
|
10
|
-
name: string
|
|
10
|
+
name: string
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* permission description
|
|
14
14
|
*/
|
|
15
|
-
description: string
|
|
15
|
+
description: string
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export interface IPermissionCenter {
|
|
@@ -22,7 +22,7 @@ export interface IPermissionCenter {
|
|
|
22
22
|
* @param permission permission
|
|
23
23
|
* @throws if permission already exists
|
|
24
24
|
*/
|
|
25
|
-
addPermission(pluginScope: string, permission: Permission)
|
|
25
|
+
addPermission: (pluginScope: string, permission: Permission) => void
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* remove a permission
|
|
@@ -30,14 +30,14 @@ export interface IPermissionCenter {
|
|
|
30
30
|
* @param permission permission
|
|
31
31
|
* @throws if permission not exists
|
|
32
32
|
*/
|
|
33
|
-
delPermission(pluginScope: string, permission: Permission)
|
|
33
|
+
delPermission: (pluginScope: string, permission: Permission) => void
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* if pluginScope has permission
|
|
37
37
|
* @param pluginScope plugin name
|
|
38
38
|
* @param permission permission
|
|
39
39
|
*/
|
|
40
|
-
hasPermission(pluginScope: string, permission: Permission)
|
|
40
|
+
hasPermission: (pluginScope: string, permission: Permission) => boolean
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* get permission
|
|
@@ -45,5 +45,5 @@ export interface IPermissionCenter {
|
|
|
45
45
|
* @param permission permission id
|
|
46
46
|
* @returns permission
|
|
47
47
|
*/
|
|
48
|
-
getPermission(pluginScope: string, permission: symbol)
|
|
49
|
-
}
|
|
48
|
+
getPermission: (pluginScope: string, permission: symbol) => Permission
|
|
49
|
+
}
|
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
|
|
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
|
-
|
|
16
|
+
function resolveIpcRenderer(): IpcRenderer | null {
|
|
15
17
|
if (typeof window !== 'undefined') {
|
|
16
18
|
const bridge = (window as any)?.electron
|
|
17
|
-
if (bridge?.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)
|
|
23
|
-
|
|
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
|
-
|
|
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(
|
|
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(
|
|
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 ||
|
|
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 (
|
|
94
|
+
const rawData = this.__parse_raw_data(e, arg)
|
|
95
|
+
if (!rawData)
|
|
96
|
+
return
|
|
91
97
|
|
|
92
|
-
if (
|
|
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
|
-
|
|
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)
|
|
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:
|
|
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
|
-
}
|
|
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:
|
|
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:
|
|
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
|
-
|
|
244
|
+
const res = this.__parse_raw_data(void 0, this.ipcRenderer.sendSync('@plugin-process-message', data))!
|
|
238
245
|
|
|
239
|
-
|
|
246
|
+
if (res.header.status === 'reply')
|
|
247
|
+
return res.data
|
|
240
248
|
|
|
249
|
+
return res
|
|
241
250
|
}
|
|
242
251
|
}
|
|
243
252
|
|