@talex-touch/utils 1.0.23 → 1.0.25
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/common/file-scan-constants.ts +543 -0
- package/common/file-scan-utils.ts +432 -0
- package/common/index.ts +2 -0
- package/common/storage/entity/app-settings.ts +7 -1
- package/common/utils/polling.ts +4 -4
- package/common/utils/timing.ts +257 -13
- package/core-box/tuff/tuff-dsl.ts +17 -0
- package/package.json +1 -1
- package/plugin/index.ts +78 -3
- package/plugin/sdk/common.ts +63 -14
- package/plugin/sdk/core-box.ts +27 -0
- package/plugin/sdk/examples/storage-onDidChange-example.js +201 -0
- package/plugin/sdk/features.ts +324 -0
- package/plugin/sdk/index.ts +2 -0
- package/plugin/sdk/types.ts +142 -0
- package/renderer/touch-sdk/index.ts +9 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage onDidChange 示例
|
|
3
|
+
* 展示如何使用 storage.onDidChange 监听存储文件变化
|
|
4
|
+
* 注意:这里只能获取新值,旧值无法获取
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// 获取SDK实例
|
|
8
|
+
const sdk = window.$touchSDK
|
|
9
|
+
|
|
10
|
+
// 示例1: 监听整个配置文件的变化
|
|
11
|
+
function setupConfigListener() {
|
|
12
|
+
console.log('[Storage] Setting up listener for entire config changes')
|
|
13
|
+
|
|
14
|
+
const unsubscribe = sdk.storage.onDidChange((newConfig) => {
|
|
15
|
+
console.log('[Storage] Config changed:')
|
|
16
|
+
console.log(' New config:', newConfig)
|
|
17
|
+
|
|
18
|
+
// 处理特定键的变化
|
|
19
|
+
if (newConfig && newConfig.user_preference && newConfig.user_preference.theme) {
|
|
20
|
+
console.log(`[Storage] Theme changed to: ${newConfig.user_preference.theme}`)
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
// 返回取消监听的函数
|
|
25
|
+
return unsubscribe
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// 示例2: 监听配置变化并处理特定键
|
|
29
|
+
function setupConfigChangeHandler() {
|
|
30
|
+
console.log('[Storage] Setting up config change handler')
|
|
31
|
+
|
|
32
|
+
const unsubscribe = sdk.storage.onDidChange((newConfig) => {
|
|
33
|
+
console.log('[Storage] Config changed:')
|
|
34
|
+
console.log(' New config:', newConfig)
|
|
35
|
+
|
|
36
|
+
// 处理特定键的变化
|
|
37
|
+
if (newConfig.user_preference) {
|
|
38
|
+
handleUserPreferenceChange(newConfig.user_preference)
|
|
39
|
+
}
|
|
40
|
+
if (newConfig.settings) {
|
|
41
|
+
handleSettingsChange(newConfig.settings)
|
|
42
|
+
}
|
|
43
|
+
if (newConfig.cache) {
|
|
44
|
+
handleCacheChange(newConfig.cache)
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
return unsubscribe
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// 示例3: 动态监听
|
|
52
|
+
function setupDynamicListener() {
|
|
53
|
+
let currentListener = null
|
|
54
|
+
|
|
55
|
+
// 开始监听
|
|
56
|
+
function startListening() {
|
|
57
|
+
console.log('[Storage] Starting to listen for config changes')
|
|
58
|
+
|
|
59
|
+
// 如果已有监听器,先取消
|
|
60
|
+
if (currentListener) {
|
|
61
|
+
currentListener()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
currentListener = sdk.storage.onDidChange((newConfig) => {
|
|
65
|
+
console.log('[Storage] Dynamic listener for config changes:')
|
|
66
|
+
console.log(' New config:', newConfig)
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// 停止监听
|
|
71
|
+
function stopListening() {
|
|
72
|
+
if (currentListener) {
|
|
73
|
+
console.log('[Storage] Stopping current listener')
|
|
74
|
+
currentListener()
|
|
75
|
+
currentListener = null
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return { startListening, stopListening }
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 示例4: 条件监听
|
|
83
|
+
function setupConditionalListener() {
|
|
84
|
+
console.log('[Storage] Setting up conditional listener')
|
|
85
|
+
|
|
86
|
+
const unsubscribe = sdk.storage.onDidChange((newConfig) => {
|
|
87
|
+
// 处理用户偏好变化
|
|
88
|
+
if (newConfig.user_preference) {
|
|
89
|
+
const pref = newConfig.user_preference
|
|
90
|
+
|
|
91
|
+
// 处理主题变化
|
|
92
|
+
if (pref.theme) {
|
|
93
|
+
console.log(`[Storage] Theme: ${pref.theme}`)
|
|
94
|
+
applyTheme(pref.theme)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// 处理语言变化
|
|
98
|
+
if (pref.language) {
|
|
99
|
+
console.log(`[Storage] Language: ${pref.language}`)
|
|
100
|
+
reloadInterface(pref.language)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
return unsubscribe
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// 示例5: 批量操作监听
|
|
109
|
+
function setupBatchOperationListener() {
|
|
110
|
+
console.log('[Storage] Setting up batch operation listener')
|
|
111
|
+
|
|
112
|
+
const unsubscribe = sdk.storage.onDidChange((newConfig) => {
|
|
113
|
+
console.log('[Storage] Config changed:')
|
|
114
|
+
console.log(' New config keys:', Object.keys(newConfig))
|
|
115
|
+
|
|
116
|
+
// 处理批量数据变化
|
|
117
|
+
if (newConfig.batch_data) {
|
|
118
|
+
console.log('[Storage] Processing batch data changes')
|
|
119
|
+
console.log(' Batch data count:', Object.keys(newConfig.batch_data).length)
|
|
120
|
+
|
|
121
|
+
// 应用变化
|
|
122
|
+
applyChanges(newConfig.batch_data)
|
|
123
|
+
}
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
return unsubscribe
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// 辅助函数
|
|
130
|
+
function handleUserPreferenceChange(newValue) {
|
|
131
|
+
console.log('[Storage] Handling user preference change')
|
|
132
|
+
// 处理用户偏好变化
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function handleSettingsChange(newValue) {
|
|
136
|
+
console.log('[Storage] Handling settings change')
|
|
137
|
+
// 处理设置变化
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function handleCacheChange(newValue) {
|
|
141
|
+
console.log('[Storage] Handling cache change')
|
|
142
|
+
// 处理缓存变化
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function applyTheme(theme) {
|
|
146
|
+
console.log(`[Storage] Applying theme: ${theme}`)
|
|
147
|
+
// 应用主题逻辑
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function reloadInterface(language) {
|
|
151
|
+
console.log(`[Storage] Reloading interface for language: ${language}`)
|
|
152
|
+
// 重新加载界面逻辑
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function findChanges(oldValue, newValue) {
|
|
156
|
+
const changes = []
|
|
157
|
+
// 比较两个对象并找出变化
|
|
158
|
+
return changes
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function applyChanges(changes) {
|
|
162
|
+
console.log('[Storage] Applying changes:', changes)
|
|
163
|
+
// 应用变化逻辑
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// 导出函数供外部调用
|
|
167
|
+
window.storageOnDidChangeExample = {
|
|
168
|
+
setupConfigListener,
|
|
169
|
+
setupConfigChangeHandler,
|
|
170
|
+
setupDynamicListener,
|
|
171
|
+
setupConditionalListener,
|
|
172
|
+
setupBatchOperationListener
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// 自动运行示例(可选)
|
|
176
|
+
if (typeof window !== 'undefined' && window.location.hostname === 'localhost') {
|
|
177
|
+
console.log('[Auto] Setting up storage listeners...')
|
|
178
|
+
|
|
179
|
+
// 设置配置监听
|
|
180
|
+
const unsubscribe1 = setupConfigListener()
|
|
181
|
+
|
|
182
|
+
// 设置配置变化处理器
|
|
183
|
+
const unsubscribeAll = setupConfigChangeHandler()
|
|
184
|
+
|
|
185
|
+
// 设置动态监听
|
|
186
|
+
const { startListening, stopListening } = setupDynamicListener()
|
|
187
|
+
|
|
188
|
+
// 5秒后切换到监听其他键
|
|
189
|
+
setTimeout(() => {
|
|
190
|
+
stopListening()
|
|
191
|
+
startListening('settings')
|
|
192
|
+
}, 5000)
|
|
193
|
+
|
|
194
|
+
// 10秒后停止所有监听
|
|
195
|
+
setTimeout(() => {
|
|
196
|
+
console.log('[Auto] Stopping all listeners...')
|
|
197
|
+
unsubscribe1()
|
|
198
|
+
unsubscribeAll()
|
|
199
|
+
stopListening()
|
|
200
|
+
}, 10000)
|
|
201
|
+
}
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin Features SDK
|
|
3
|
+
*
|
|
4
|
+
* @description
|
|
5
|
+
* 提供插件features管理的SDK功能,包括动态添加、删除、查询和优先级管理
|
|
6
|
+
*
|
|
7
|
+
* @version 1.0.0
|
|
8
|
+
* @module plugin/sdk/features
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { IPluginFeature } from '../index'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Features管理器接口
|
|
15
|
+
*
|
|
16
|
+
* @description
|
|
17
|
+
* 提供完整的features管理功能,包括CRUD操作和优先级管理
|
|
18
|
+
*/
|
|
19
|
+
export interface IFeaturesManager {
|
|
20
|
+
/**
|
|
21
|
+
* 动态添加功能到插件
|
|
22
|
+
* @param feature - 功能定义
|
|
23
|
+
* @returns 是否添加成功
|
|
24
|
+
*/
|
|
25
|
+
addFeature(feature: IPluginFeature): boolean
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 删除功能
|
|
29
|
+
* @param featureId - 功能ID
|
|
30
|
+
* @returns 是否删除成功
|
|
31
|
+
*/
|
|
32
|
+
removeFeature(featureId: string): boolean
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 获取所有功能
|
|
36
|
+
* @returns 所有功能列表
|
|
37
|
+
*/
|
|
38
|
+
getFeatures(): IPluginFeature[]
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 获取指定功能
|
|
42
|
+
* @param featureId - 功能ID
|
|
43
|
+
* @returns 功能对象,如果不存在返回null
|
|
44
|
+
*/
|
|
45
|
+
getFeature(featureId: string): IPluginFeature | null
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 设置功能优先级
|
|
49
|
+
* @param featureId - 功能ID
|
|
50
|
+
* @param priority - 优先级值(数字越大优先级越高)
|
|
51
|
+
* @returns 是否设置成功
|
|
52
|
+
*/
|
|
53
|
+
setPriority(featureId: string, priority: number): boolean
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 获取功能优先级
|
|
57
|
+
* @param featureId - 功能ID
|
|
58
|
+
* @returns 优先级值,如果功能不存在返回null
|
|
59
|
+
*/
|
|
60
|
+
getPriority(featureId: string): number | null
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 按优先级排序获取所有功能
|
|
64
|
+
* @returns 按优先级排序的功能列表(高优先级在前)
|
|
65
|
+
*/
|
|
66
|
+
getFeaturesByPriority(): IPluginFeature[]
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 批量设置功能优先级
|
|
70
|
+
* @param priorities - 优先级映射对象 {featureId: priority}
|
|
71
|
+
* @returns 设置成功的功能数量
|
|
72
|
+
*/
|
|
73
|
+
setPriorities(priorities: Record<string, number>): number
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 重置功能优先级为默认值(0)
|
|
77
|
+
* @param featureId - 功能ID
|
|
78
|
+
* @returns 是否重置成功
|
|
79
|
+
*/
|
|
80
|
+
resetPriority(featureId: string): boolean
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 获取功能统计信息
|
|
84
|
+
* @returns 功能统计对象
|
|
85
|
+
*/
|
|
86
|
+
getStats(): {
|
|
87
|
+
total: number
|
|
88
|
+
byPriority: Record<number, number>
|
|
89
|
+
averagePriority: number
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* 创建Features管理器
|
|
95
|
+
*
|
|
96
|
+
* @description
|
|
97
|
+
* 为插件创建features管理器实例
|
|
98
|
+
*
|
|
99
|
+
* @param pluginName - 插件名称
|
|
100
|
+
* @param utils - 插件工具对象
|
|
101
|
+
* @returns Features管理器实例
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const featuresManager = createFeaturesManager('my-plugin', utils)
|
|
106
|
+
*
|
|
107
|
+
* // 添加功能
|
|
108
|
+
* featuresManager.addFeature({
|
|
109
|
+
* id: 'search',
|
|
110
|
+
* name: '搜索功能',
|
|
111
|
+
* desc: '提供搜索能力',
|
|
112
|
+
* commands: [{ type: 'over', value: ['search'] }],
|
|
113
|
+
* priority: 100
|
|
114
|
+
* })
|
|
115
|
+
*
|
|
116
|
+
* // 设置优先级
|
|
117
|
+
* featuresManager.setPriority('search', 200)
|
|
118
|
+
*
|
|
119
|
+
* // 获取按优先级排序的功能
|
|
120
|
+
* const sortedFeatures = featuresManager.getFeaturesByPriority()
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
export function createFeaturesManager(
|
|
124
|
+
pluginName: string,
|
|
125
|
+
utils: any
|
|
126
|
+
): IFeaturesManager {
|
|
127
|
+
return {
|
|
128
|
+
/**
|
|
129
|
+
* 动态添加功能到插件
|
|
130
|
+
*/
|
|
131
|
+
addFeature(feature: IPluginFeature): boolean {
|
|
132
|
+
try {
|
|
133
|
+
return utils.features.addFeature(feature)
|
|
134
|
+
} catch (error) {
|
|
135
|
+
console.error(`[FeaturesManager] Failed to add feature ${feature.id}:`, error)
|
|
136
|
+
return false
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* 删除功能
|
|
142
|
+
*/
|
|
143
|
+
removeFeature(featureId: string): boolean {
|
|
144
|
+
try {
|
|
145
|
+
return utils.features.removeFeature(featureId)
|
|
146
|
+
} catch (error) {
|
|
147
|
+
console.error(`[FeaturesManager] Failed to remove feature ${featureId}:`, error)
|
|
148
|
+
return false
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* 获取所有功能
|
|
154
|
+
*/
|
|
155
|
+
getFeatures(): IPluginFeature[] {
|
|
156
|
+
try {
|
|
157
|
+
return utils.features.getFeatures()
|
|
158
|
+
} catch (error) {
|
|
159
|
+
console.error(`[FeaturesManager] Failed to get features:`, error)
|
|
160
|
+
return []
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* 获取指定功能
|
|
166
|
+
*/
|
|
167
|
+
getFeature(featureId: string): IPluginFeature | null {
|
|
168
|
+
try {
|
|
169
|
+
return utils.features.getFeature(featureId)
|
|
170
|
+
} catch (error) {
|
|
171
|
+
console.error(`[FeaturesManager] Failed to get feature ${featureId}:`, error)
|
|
172
|
+
return null
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* 设置功能优先级
|
|
178
|
+
*/
|
|
179
|
+
setPriority(featureId: string, priority: number): boolean {
|
|
180
|
+
try {
|
|
181
|
+
return utils.features.setPriority(featureId, priority)
|
|
182
|
+
} catch (error) {
|
|
183
|
+
console.error(`[FeaturesManager] Failed to set priority for ${featureId}:`, error)
|
|
184
|
+
return false
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* 获取功能优先级
|
|
190
|
+
*/
|
|
191
|
+
getPriority(featureId: string): number | null {
|
|
192
|
+
try {
|
|
193
|
+
return utils.features.getPriority(featureId)
|
|
194
|
+
} catch (error) {
|
|
195
|
+
console.error(`[FeaturesManager] Failed to get priority for ${featureId}:`, error)
|
|
196
|
+
return null
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* 按优先级排序获取所有功能
|
|
202
|
+
*/
|
|
203
|
+
getFeaturesByPriority(): IPluginFeature[] {
|
|
204
|
+
try {
|
|
205
|
+
return utils.features.getFeaturesByPriority()
|
|
206
|
+
} catch (error) {
|
|
207
|
+
console.error(`[FeaturesManager] Failed to get features by priority:`, error)
|
|
208
|
+
return []
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* 批量设置功能优先级
|
|
214
|
+
*/
|
|
215
|
+
setPriorities(priorities: Record<string, number>): number {
|
|
216
|
+
let successCount = 0
|
|
217
|
+
for (const [featureId, priority] of Object.entries(priorities)) {
|
|
218
|
+
if (this.setPriority(featureId, priority)) {
|
|
219
|
+
successCount++
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return successCount
|
|
223
|
+
},
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* 重置功能优先级为默认值
|
|
227
|
+
*/
|
|
228
|
+
resetPriority(featureId: string): boolean {
|
|
229
|
+
return this.setPriority(featureId, 0)
|
|
230
|
+
},
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* 获取功能统计信息
|
|
234
|
+
*/
|
|
235
|
+
getStats(): {
|
|
236
|
+
total: number
|
|
237
|
+
byPriority: Record<number, number>
|
|
238
|
+
averagePriority: number
|
|
239
|
+
} {
|
|
240
|
+
try {
|
|
241
|
+
const features = this.getFeatures()
|
|
242
|
+
const total = features.length
|
|
243
|
+
|
|
244
|
+
const byPriority: Record<number, number> = {}
|
|
245
|
+
let totalPriority = 0
|
|
246
|
+
|
|
247
|
+
features.forEach(feature => {
|
|
248
|
+
const priority = feature.priority ?? 0
|
|
249
|
+
byPriority[priority] = (byPriority[priority] || 0) + 1
|
|
250
|
+
totalPriority += priority
|
|
251
|
+
})
|
|
252
|
+
|
|
253
|
+
const averagePriority = total > 0 ? totalPriority / total : 0
|
|
254
|
+
|
|
255
|
+
return {
|
|
256
|
+
total,
|
|
257
|
+
byPriority,
|
|
258
|
+
averagePriority
|
|
259
|
+
}
|
|
260
|
+
} catch (error) {
|
|
261
|
+
console.error(`[FeaturesManager] Failed to get stats:`, error)
|
|
262
|
+
return {
|
|
263
|
+
total: 0,
|
|
264
|
+
byPriority: {},
|
|
265
|
+
averagePriority: 0
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Features管理器工厂函数
|
|
274
|
+
*
|
|
275
|
+
* @description
|
|
276
|
+
* 为插件创建features管理器的便捷工厂函数
|
|
277
|
+
*
|
|
278
|
+
* @param utils - 插件工具对象
|
|
279
|
+
* @returns Features管理器实例
|
|
280
|
+
*/
|
|
281
|
+
export function useFeatures(utils: any): IFeaturesManager {
|
|
282
|
+
const pluginName = utils.plugin?.getInfo()?.name || 'unknown'
|
|
283
|
+
return createFeaturesManager(pluginName, utils)
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* 功能优先级常量
|
|
288
|
+
*
|
|
289
|
+
* @description
|
|
290
|
+
* 提供常用的优先级值,便于插件开发者使用
|
|
291
|
+
*/
|
|
292
|
+
export const FEATURE_PRIORITIES = {
|
|
293
|
+
/** 最高优先级 */
|
|
294
|
+
HIGHEST: 1000,
|
|
295
|
+
/** 高优先级 */
|
|
296
|
+
HIGH: 500,
|
|
297
|
+
/** 默认优先级 */
|
|
298
|
+
NORMAL: 0,
|
|
299
|
+
/** 低优先级 */
|
|
300
|
+
LOW: -500,
|
|
301
|
+
/** 最低优先级 */
|
|
302
|
+
LOWEST: -1000
|
|
303
|
+
} as const
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* 功能类型枚举
|
|
307
|
+
*
|
|
308
|
+
* @description
|
|
309
|
+
* 预定义的功能类型,便于分类管理
|
|
310
|
+
*/
|
|
311
|
+
export const FEATURE_TYPES = {
|
|
312
|
+
/** 搜索功能 */
|
|
313
|
+
SEARCH: 'search',
|
|
314
|
+
/** 工具功能 */
|
|
315
|
+
TOOL: 'tool',
|
|
316
|
+
/** 系统功能 */
|
|
317
|
+
SYSTEM: 'system',
|
|
318
|
+
/** 网络功能 */
|
|
319
|
+
NETWORK: 'network',
|
|
320
|
+
/** 文件功能 */
|
|
321
|
+
FILE: 'file',
|
|
322
|
+
/** 应用功能 */
|
|
323
|
+
APP: 'app'
|
|
324
|
+
} as const
|
package/plugin/sdk/index.ts
CHANGED
package/plugin/sdk/types.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import type { ITouchChannel, ITouchClientChannel, StandardChannelData } from '@talex-touch/utils/channel';
|
|
8
|
+
import type { IPluginFeature } from '../index';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Handler signature for plugin channel events.
|
|
@@ -198,6 +199,18 @@ export interface IPluginUtils {
|
|
|
198
199
|
* @returns Array of current search result items
|
|
199
200
|
*/
|
|
200
201
|
getItems: () => any[];
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Features manager for dynamic feature management
|
|
205
|
+
* @see {@link IFeaturesManager}
|
|
206
|
+
*/
|
|
207
|
+
features: IFeaturesManager;
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Plugin information manager
|
|
211
|
+
* @see {@link IPluginInfoManager}
|
|
212
|
+
*/
|
|
213
|
+
plugin: IPluginInfoManager;
|
|
201
214
|
}
|
|
202
215
|
|
|
203
216
|
/**
|
|
@@ -700,3 +713,132 @@ export function createSearchManager(): ISearchManager {
|
|
|
700
713
|
}
|
|
701
714
|
};
|
|
702
715
|
}
|
|
716
|
+
|
|
717
|
+
/**
|
|
718
|
+
* Features管理器接口
|
|
719
|
+
*
|
|
720
|
+
* @description
|
|
721
|
+
* 提供完整的features管理功能,包括CRUD操作和优先级管理
|
|
722
|
+
*/
|
|
723
|
+
export interface IFeaturesManager {
|
|
724
|
+
/**
|
|
725
|
+
* 动态添加功能到插件
|
|
726
|
+
* @param feature - 功能定义
|
|
727
|
+
* @returns 是否添加成功
|
|
728
|
+
*/
|
|
729
|
+
addFeature(feature: IPluginFeature): boolean
|
|
730
|
+
|
|
731
|
+
/**
|
|
732
|
+
* 删除功能
|
|
733
|
+
* @param featureId - 功能ID
|
|
734
|
+
* @returns 是否删除成功
|
|
735
|
+
*/
|
|
736
|
+
removeFeature(featureId: string): boolean
|
|
737
|
+
|
|
738
|
+
/**
|
|
739
|
+
* 获取所有功能
|
|
740
|
+
* @returns 所有功能列表
|
|
741
|
+
*/
|
|
742
|
+
getFeatures(): IPluginFeature[]
|
|
743
|
+
|
|
744
|
+
/**
|
|
745
|
+
* 获取指定功能
|
|
746
|
+
* @param featureId - 功能ID
|
|
747
|
+
* @returns 功能对象,如果不存在返回null
|
|
748
|
+
*/
|
|
749
|
+
getFeature(featureId: string): IPluginFeature | null
|
|
750
|
+
|
|
751
|
+
/**
|
|
752
|
+
* 设置功能优先级
|
|
753
|
+
* @param featureId - 功能ID
|
|
754
|
+
* @param priority - 优先级值(数字越大优先级越高)
|
|
755
|
+
* @returns 是否设置成功
|
|
756
|
+
*/
|
|
757
|
+
setPriority(featureId: string, priority: number): boolean
|
|
758
|
+
|
|
759
|
+
/**
|
|
760
|
+
* 获取功能优先级
|
|
761
|
+
* @param featureId - 功能ID
|
|
762
|
+
* @returns 优先级值,如果功能不存在返回null
|
|
763
|
+
*/
|
|
764
|
+
getPriority(featureId: string): number | null
|
|
765
|
+
|
|
766
|
+
/**
|
|
767
|
+
* 按优先级排序获取所有功能
|
|
768
|
+
* @returns 按优先级排序的功能列表(高优先级在前)
|
|
769
|
+
*/
|
|
770
|
+
getFeaturesByPriority(): IPluginFeature[]
|
|
771
|
+
|
|
772
|
+
/**
|
|
773
|
+
* 批量设置功能优先级
|
|
774
|
+
* @param priorities - 优先级映射对象 {featureId: priority}
|
|
775
|
+
* @returns 设置成功的功能数量
|
|
776
|
+
*/
|
|
777
|
+
setPriorities(priorities: Record<string, number>): number
|
|
778
|
+
|
|
779
|
+
/**
|
|
780
|
+
* 重置功能优先级为默认值(0)
|
|
781
|
+
* @param featureId - 功能ID
|
|
782
|
+
* @returns 是否重置成功
|
|
783
|
+
*/
|
|
784
|
+
resetPriority(featureId: string): boolean
|
|
785
|
+
|
|
786
|
+
/**
|
|
787
|
+
* 获取功能统计信息
|
|
788
|
+
* @returns 功能统计对象
|
|
789
|
+
*/
|
|
790
|
+
getStats(): {
|
|
791
|
+
total: number
|
|
792
|
+
byPriority: Record<number, number>
|
|
793
|
+
averagePriority: number
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
/**
|
|
798
|
+
* 插件信息管理器接口
|
|
799
|
+
*
|
|
800
|
+
* @description
|
|
801
|
+
* 提供插件信息查询功能
|
|
802
|
+
*/
|
|
803
|
+
export interface IPluginInfoManager {
|
|
804
|
+
/**
|
|
805
|
+
* 获取完整插件信息
|
|
806
|
+
* @returns 包含所有插件信息的对象
|
|
807
|
+
*/
|
|
808
|
+
getInfo(): {
|
|
809
|
+
name: string
|
|
810
|
+
version: string
|
|
811
|
+
desc: string
|
|
812
|
+
readme: string
|
|
813
|
+
dev: any
|
|
814
|
+
status: number
|
|
815
|
+
platforms: any
|
|
816
|
+
pluginPath: string
|
|
817
|
+
features: any[]
|
|
818
|
+
issues: any[]
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
/**
|
|
822
|
+
* 获取插件路径
|
|
823
|
+
* @returns 插件文件系统路径
|
|
824
|
+
*/
|
|
825
|
+
getPath(): string
|
|
826
|
+
|
|
827
|
+
/**
|
|
828
|
+
* 获取插件状态
|
|
829
|
+
* @returns 当前插件状态
|
|
830
|
+
*/
|
|
831
|
+
getStatus(): number
|
|
832
|
+
|
|
833
|
+
/**
|
|
834
|
+
* 获取开发信息
|
|
835
|
+
* @returns 开发配置信息
|
|
836
|
+
*/
|
|
837
|
+
getDevInfo(): any
|
|
838
|
+
|
|
839
|
+
/**
|
|
840
|
+
* 获取平台支持信息
|
|
841
|
+
* @returns 平台兼容性信息
|
|
842
|
+
*/
|
|
843
|
+
getPlatforms(): any
|
|
844
|
+
}
|
|
@@ -85,6 +85,15 @@ export class TouchSDK {
|
|
|
85
85
|
return this.channel.send('plugin:explorer', pluginName)
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
/**
|
|
89
|
+
* Reloads a plugin by its name
|
|
90
|
+
* @param pluginName - The name of the plugin to reload
|
|
91
|
+
* @returns Promise that resolves when the reload operation completes
|
|
92
|
+
*/
|
|
93
|
+
async reloadPlugin(pluginName: string): Promise<void> {
|
|
94
|
+
return this.channel.send('reload-plugin', { name: pluginName })
|
|
95
|
+
}
|
|
96
|
+
|
|
88
97
|
/**
|
|
89
98
|
* Module Operations
|
|
90
99
|
*/
|