@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/plugin/sdk/features.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* @module plugin/sdk/features
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import { IPluginFeature } from '../index'
|
|
11
|
+
import type { IPluginFeature } from '../index'
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Features管理器接口
|
|
@@ -22,27 +22,27 @@ export interface IFeaturesManager {
|
|
|
22
22
|
* @param feature - 功能定义
|
|
23
23
|
* @returns 是否添加成功
|
|
24
24
|
*/
|
|
25
|
-
addFeature(feature: IPluginFeature)
|
|
25
|
+
addFeature: (feature: IPluginFeature) => boolean
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* 删除功能
|
|
29
29
|
* @param featureId - 功能ID
|
|
30
30
|
* @returns 是否删除成功
|
|
31
31
|
*/
|
|
32
|
-
removeFeature(featureId: string)
|
|
32
|
+
removeFeature: (featureId: string) => boolean
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* 获取所有功能
|
|
36
36
|
* @returns 所有功能列表
|
|
37
37
|
*/
|
|
38
|
-
getFeatures()
|
|
38
|
+
getFeatures: () => IPluginFeature[]
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
41
|
* 获取指定功能
|
|
42
42
|
* @param featureId - 功能ID
|
|
43
43
|
* @returns 功能对象,如果不存在返回null
|
|
44
44
|
*/
|
|
45
|
-
getFeature(featureId: string)
|
|
45
|
+
getFeature: (featureId: string) => IPluginFeature | null
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
48
|
* 设置功能优先级
|
|
@@ -50,40 +50,40 @@ export interface IFeaturesManager {
|
|
|
50
50
|
* @param priority - 优先级值(数字越大优先级越高)
|
|
51
51
|
* @returns 是否设置成功
|
|
52
52
|
*/
|
|
53
|
-
setPriority(featureId: string, priority: number)
|
|
53
|
+
setPriority: (featureId: string, priority: number) => boolean
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
56
|
* 获取功能优先级
|
|
57
57
|
* @param featureId - 功能ID
|
|
58
58
|
* @returns 优先级值,如果功能不存在返回null
|
|
59
59
|
*/
|
|
60
|
-
getPriority(featureId: string)
|
|
60
|
+
getPriority: (featureId: string) => number | null
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
63
|
* 按优先级排序获取所有功能
|
|
64
64
|
* @returns 按优先级排序的功能列表(高优先级在前)
|
|
65
65
|
*/
|
|
66
|
-
getFeaturesByPriority()
|
|
66
|
+
getFeaturesByPriority: () => IPluginFeature[]
|
|
67
67
|
|
|
68
68
|
/**
|
|
69
69
|
* 批量设置功能优先级
|
|
70
70
|
* @param priorities - 优先级映射对象 {featureId: priority}
|
|
71
71
|
* @returns 设置成功的功能数量
|
|
72
72
|
*/
|
|
73
|
-
setPriorities(priorities: Record<string, number>)
|
|
73
|
+
setPriorities: (priorities: Record<string, number>) => number
|
|
74
74
|
|
|
75
75
|
/**
|
|
76
76
|
* 重置功能优先级为默认值(0)
|
|
77
77
|
* @param featureId - 功能ID
|
|
78
78
|
* @returns 是否重置成功
|
|
79
79
|
*/
|
|
80
|
-
resetPriority(featureId: string)
|
|
80
|
+
resetPriority: (featureId: string) => boolean
|
|
81
81
|
|
|
82
82
|
/**
|
|
83
83
|
* 获取功能统计信息
|
|
84
84
|
* @returns 功能统计对象
|
|
85
85
|
*/
|
|
86
|
-
getStats()
|
|
86
|
+
getStats: () => {
|
|
87
87
|
total: number
|
|
88
88
|
byPriority: Record<number, number>
|
|
89
89
|
averagePriority: number
|
|
@@ -122,7 +122,7 @@ export interface IFeaturesManager {
|
|
|
122
122
|
*/
|
|
123
123
|
export function createFeaturesManager(
|
|
124
124
|
_pluginName: string,
|
|
125
|
-
utils: any
|
|
125
|
+
utils: any,
|
|
126
126
|
): IFeaturesManager {
|
|
127
127
|
return {
|
|
128
128
|
/**
|
|
@@ -131,7 +131,8 @@ export function createFeaturesManager(
|
|
|
131
131
|
addFeature(feature: IPluginFeature): boolean {
|
|
132
132
|
try {
|
|
133
133
|
return utils.features.addFeature(feature)
|
|
134
|
-
}
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
135
136
|
console.error(`[FeaturesManager] Failed to add feature ${feature.id}:`, error)
|
|
136
137
|
return false
|
|
137
138
|
}
|
|
@@ -143,7 +144,8 @@ export function createFeaturesManager(
|
|
|
143
144
|
removeFeature(featureId: string): boolean {
|
|
144
145
|
try {
|
|
145
146
|
return utils.features.removeFeature(featureId)
|
|
146
|
-
}
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
147
149
|
console.error(`[FeaturesManager] Failed to remove feature ${featureId}:`, error)
|
|
148
150
|
return false
|
|
149
151
|
}
|
|
@@ -155,7 +157,8 @@ export function createFeaturesManager(
|
|
|
155
157
|
getFeatures(): IPluginFeature[] {
|
|
156
158
|
try {
|
|
157
159
|
return utils.features.getFeatures()
|
|
158
|
-
}
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
159
162
|
console.error(`[FeaturesManager] Failed to get features:`, error)
|
|
160
163
|
return []
|
|
161
164
|
}
|
|
@@ -167,7 +170,8 @@ export function createFeaturesManager(
|
|
|
167
170
|
getFeature(featureId: string): IPluginFeature | null {
|
|
168
171
|
try {
|
|
169
172
|
return utils.features.getFeature(featureId)
|
|
170
|
-
}
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
171
175
|
console.error(`[FeaturesManager] Failed to get feature ${featureId}:`, error)
|
|
172
176
|
return null
|
|
173
177
|
}
|
|
@@ -179,7 +183,8 @@ export function createFeaturesManager(
|
|
|
179
183
|
setPriority(featureId: string, priority: number): boolean {
|
|
180
184
|
try {
|
|
181
185
|
return utils.features.setPriority(featureId, priority)
|
|
182
|
-
}
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
183
188
|
console.error(`[FeaturesManager] Failed to set priority for ${featureId}:`, error)
|
|
184
189
|
return false
|
|
185
190
|
}
|
|
@@ -191,7 +196,8 @@ export function createFeaturesManager(
|
|
|
191
196
|
getPriority(featureId: string): number | null {
|
|
192
197
|
try {
|
|
193
198
|
return utils.features.getPriority(featureId)
|
|
194
|
-
}
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
195
201
|
console.error(`[FeaturesManager] Failed to get priority for ${featureId}:`, error)
|
|
196
202
|
return null
|
|
197
203
|
}
|
|
@@ -203,7 +209,8 @@ export function createFeaturesManager(
|
|
|
203
209
|
getFeaturesByPriority(): IPluginFeature[] {
|
|
204
210
|
try {
|
|
205
211
|
return utils.features.getFeaturesByPriority()
|
|
206
|
-
}
|
|
212
|
+
}
|
|
213
|
+
catch (error) {
|
|
207
214
|
console.error(`[FeaturesManager] Failed to get features by priority:`, error)
|
|
208
215
|
return []
|
|
209
216
|
}
|
|
@@ -244,7 +251,7 @@ export function createFeaturesManager(
|
|
|
244
251
|
const byPriority: Record<number, number> = {}
|
|
245
252
|
let totalPriority = 0
|
|
246
253
|
|
|
247
|
-
features.forEach(feature => {
|
|
254
|
+
features.forEach((feature) => {
|
|
248
255
|
const priority = feature.priority ?? 0
|
|
249
256
|
byPriority[priority] = (byPriority[priority] || 0) + 1
|
|
250
257
|
totalPriority += priority
|
|
@@ -255,17 +262,18 @@ export function createFeaturesManager(
|
|
|
255
262
|
return {
|
|
256
263
|
total,
|
|
257
264
|
byPriority,
|
|
258
|
-
averagePriority
|
|
265
|
+
averagePriority,
|
|
259
266
|
}
|
|
260
|
-
}
|
|
267
|
+
}
|
|
268
|
+
catch (error) {
|
|
261
269
|
console.error(`[FeaturesManager] Failed to get stats:`, error)
|
|
262
270
|
return {
|
|
263
271
|
total: 0,
|
|
264
272
|
byPriority: {},
|
|
265
|
-
averagePriority: 0
|
|
273
|
+
averagePriority: 0,
|
|
266
274
|
}
|
|
267
275
|
}
|
|
268
|
-
}
|
|
276
|
+
},
|
|
269
277
|
}
|
|
270
278
|
}
|
|
271
279
|
|
|
@@ -299,7 +307,7 @@ export const FEATURE_PRIORITIES = {
|
|
|
299
307
|
/** 低优先级 */
|
|
300
308
|
LOW: -500,
|
|
301
309
|
/** 最低优先级 */
|
|
302
|
-
LOWEST: -1000
|
|
310
|
+
LOWEST: -1000,
|
|
303
311
|
} as const
|
|
304
312
|
|
|
305
313
|
/**
|
|
@@ -320,5 +328,5 @@ export const FEATURE_TYPES = {
|
|
|
320
328
|
/** 文件功能 */
|
|
321
329
|
FILE: 'file',
|
|
322
330
|
/** 应用功能 */
|
|
323
|
-
APP: 'app'
|
|
331
|
+
APP: 'app',
|
|
324
332
|
} as const
|
|
@@ -10,7 +10,7 @@ export type BridgeHook<T = any> = (data: T) => void
|
|
|
10
10
|
|
|
11
11
|
const __hooks: Record<BridgeEvent, Array<BridgeHook>> = {
|
|
12
12
|
[BridgeEventForCoreBox.CORE_BOX_INPUT_CHANGE]: [],
|
|
13
|
-
[BridgeEventForCoreBox.CORE_BOX_CLIPBOARD_CHANGE]: []
|
|
13
|
+
[BridgeEventForCoreBox.CORE_BOX_CLIPBOARD_CHANGE]: [],
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
/**
|
|
@@ -37,15 +37,12 @@ export function injectBridgeEvent<T>(type: BridgeEvent, hook: BridgeHook<T>) {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
const wrappedHook = (data: T) => {
|
|
40
|
-
|
|
41
40
|
try {
|
|
42
|
-
|
|
43
41
|
hook(data)
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
46
44
|
console.error(`[TouchSDK] ${type} hook error: `, e)
|
|
47
45
|
}
|
|
48
|
-
|
|
49
46
|
}
|
|
50
47
|
|
|
51
48
|
hooks.push(wrappedHook)
|
|
@@ -4,7 +4,7 @@ export enum LifecycleHooks {
|
|
|
4
4
|
ACTIVE = 'ac',
|
|
5
5
|
INACTIVE = 'in',
|
|
6
6
|
// FORE_PAUSED = 'fp',
|
|
7
|
-
CRASH = 'cr'
|
|
7
|
+
CRASH = 'cr',
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
// @ts-ignore
|
|
@@ -22,27 +22,21 @@ export function injectHook(type: LifecycleHooks, hook: Function, processFunc = (
|
|
|
22
22
|
const hooks: Array<Function> = __hooks[type] || (__hooks[type] = [])
|
|
23
23
|
|
|
24
24
|
if (hooks.length === 0) {
|
|
25
|
-
|
|
26
|
-
window.$channel.regChannel("@lifecycle:" + type, (obj: any) => {
|
|
27
|
-
|
|
25
|
+
window.$channel.regChannel(`@lifecycle:${type}`, (obj: any) => {
|
|
28
26
|
processFunc(obj)
|
|
29
27
|
|
|
30
28
|
// @ts-ignore
|
|
31
29
|
delete window.$touchSDK.__hooks[type]
|
|
32
30
|
})
|
|
33
|
-
|
|
34
31
|
}
|
|
35
32
|
|
|
36
33
|
const wrappedHook = (data: any) => {
|
|
37
|
-
|
|
38
34
|
try {
|
|
39
|
-
|
|
40
35
|
hook(data)
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
43
38
|
console.error(`[TouchSDK] ${type} hook error: `, e)
|
|
44
39
|
}
|
|
45
|
-
|
|
46
40
|
}
|
|
47
41
|
|
|
48
42
|
hooks.push(wrappedHook)
|
package/plugin/sdk/index.ts
CHANGED
|
@@ -1,25 +1,21 @@
|
|
|
1
|
-
import * as HOOKS from './hooks/index'
|
|
1
|
+
import type * as HOOKS from './hooks/index'
|
|
2
2
|
|
|
3
3
|
export interface ITouchSDK {
|
|
4
4
|
hooks: typeof HOOKS
|
|
5
5
|
__hooks: {}
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
//
|
|
9
|
-
declare global {
|
|
10
|
-
export interface Window {
|
|
11
|
-
$touchSDK: ITouchSDK
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export * from './types'
|
|
16
|
-
export * from './window/index'
|
|
17
|
-
export * from './hooks/index'
|
|
18
|
-
export * from './service/index'
|
|
8
|
+
// Note: Window.$touchSDK is declared in ../preload.ts to avoid duplicate declarations
|
|
19
9
|
|
|
20
10
|
export * from './channel'
|
|
21
11
|
export * from './clipboard'
|
|
22
12
|
export * from './core-box'
|
|
13
|
+
export * from './division-box'
|
|
14
|
+
export { createFeaturesManager, useFeatures } from './features'
|
|
15
|
+
|
|
16
|
+
export * from './hooks/index'
|
|
17
|
+
export * from './service/index'
|
|
23
18
|
export * from './storage'
|
|
24
19
|
export * from './system'
|
|
25
|
-
export
|
|
20
|
+
export * from './types'
|
|
21
|
+
export * from './window/index'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { IService } from '../../../service'
|
|
2
|
+
import { genChannel } from '../../channel'
|
|
3
3
|
|
|
4
4
|
export function regService(service: IService, handler: Function): boolean {
|
|
5
5
|
const res = !!genChannel().sendSync('service:reg', { service: service.name })
|
|
@@ -27,4 +27,4 @@ export function onHandleService(service: IService, handler: Function) {
|
|
|
27
27
|
|
|
28
28
|
return false
|
|
29
29
|
})
|
|
30
|
-
}
|
|
30
|
+
}
|
package/plugin/sdk/storage.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { StorageStats, StorageTreeNode
|
|
1
|
+
import type { FileDetails, StorageStats, StorageTreeNode } from '../../types/storage'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Get the storage for the current plugin.
|
|
@@ -103,8 +103,8 @@ export function usePluginStorage() {
|
|
|
103
103
|
*/
|
|
104
104
|
onDidChange: (fileName: string, callback: (newConfig: any) => void) => {
|
|
105
105
|
const listener = (data: { name: string, fileName?: string }) => {
|
|
106
|
-
if (data.name === pluginName
|
|
107
|
-
|
|
106
|
+
if (data.name === pluginName
|
|
107
|
+
&& (data.fileName === fileName || data.fileName === undefined)) {
|
|
108
108
|
callback(data)
|
|
109
109
|
}
|
|
110
110
|
}
|
|
@@ -114,6 +114,6 @@ export function usePluginStorage() {
|
|
|
114
114
|
return () => {
|
|
115
115
|
channel.unRegChannel('plugin:storage:update', listener)
|
|
116
116
|
}
|
|
117
|
-
}
|
|
117
|
+
},
|
|
118
118
|
}
|
|
119
119
|
}
|
package/plugin/sdk/system.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ActiveAppSnapshot } from './types'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
function ensurePluginChannel() {
|
|
4
4
|
const channel = (window as any)?.$channel
|
|
5
5
|
if (!channel) {
|
|
6
6
|
throw new Error('[Plugin SDK] System channel requires plugin renderer context with $channel available.')
|