Skip to content

Commit a7d9d47

Browse files
committed
# Conflicts: # dist/index.js resolved by master version # src/main.ts resolved by master version
2 parents 8cd55cd + ef795a4 commit a7d9d47

2 files changed

Lines changed: 21 additions & 20 deletions

File tree

src/services/storage.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ export class OrcaStorageService {
7878
*
7979
* @param key 存储键 - 用于标识数据的唯一键名
8080
* @param data 要保存的数据 - 可以是任何可序列化的数据类型
81-
* @param pluginName 插件名称 - 默认为'orca-tabs-plugin'
81+
* @param pluginName 插件名称
8282
* @returns Promise<boolean> 保存是否成功
8383
* @throws 当Orca API和localStorage都不可用时抛出错误
8484
*/
85-
async saveConfig(key: string, data: any, pluginName: string = 'orca-tabs-plugin'): Promise<boolean> {
85+
async saveConfig(key: string, data: any, pluginName: string): Promise<boolean> {
8686
try {
8787
// 数据序列化 - 将复杂对象转换为JSON字符串,确保存储格式一致
8888
const serializedData = typeof data === 'string' ? data : JSON.stringify(data);
@@ -119,12 +119,12 @@ export class OrcaStorageService {
119119
*
120120
* @template T 返回数据的类型
121121
* @param key 存储键 - 要读取的数据键名
122-
* @param pluginName 插件名称 - 默认为'orca-tabs-plugin'
122+
* @param pluginName 插件名称
123123
* @param defaultValue 默认值 - 当数据不存在时返回的默认值
124124
* @returns Promise<T | null> 读取的数据或null
125125
* @throws 当Orca API和localStorage都不可用时抛出错误
126126
*/
127-
async getConfig<T>(key: string, pluginName: string = 'orca-tabs-plugin', defaultValue?: T): Promise<T | null> {
127+
async getConfig<T>(key: string, pluginName: string, defaultValue?: T): Promise<T | null> {
128128
try {
129129
// 调用Orca API读取数据
130130
const result = await orca.plugins.getData(pluginName, key);
@@ -166,11 +166,11 @@ export class OrcaStorageService {
166166
* 如果Orca API不可用,会自动降级到localStorage删除。
167167
*
168168
* @param key 存储键 - 要删除的数据键名
169-
* @param pluginName 插件名称 - 默认为'orca-tabs-plugin'
169+
* @param pluginName 插件名称
170170
* @returns Promise<boolean> 删除是否成功
171171
* @throws 当Orca API和localStorage都不可用时抛出错误
172172
*/
173-
async removeConfig(key: string, pluginName: string = 'orca-tabs-plugin'): Promise<boolean> {
173+
async removeConfig(key: string, pluginName: string): Promise<boolean> {
174174
try {
175175
// 调用Orca API删除数据
176176
await orca.plugins.removeData(pluginName, key);
@@ -322,40 +322,41 @@ export class OrcaStorageService {
322322
*
323323
* 测试完成后会自动清理测试数据,不会影响实际使用。
324324
*
325+
* @param pluginName 插件名称 - 用于测试的插件名称
325326
* @async
326327
* @returns Promise<void> 测试完成
327328
* @throws 当测试过程中发生错误时抛出
328329
*/
329-
async testConfigSerialization(): Promise<void> {
330+
async testConfigSerialization(pluginName: string): Promise<void> {
330331
try {
331332
this.log("🧪 开始测试API配置序列化...");
332333

333334
// ==================== 字符串数据测试 ====================
334335
// 测试简单字符串的保存和读取
335336
const testString = "test string";
336-
await this.saveConfig('test-string', testString);
337-
const retrievedString = await this.getConfig<string>('test-string', 'orca-tabs-plugin');
337+
await this.saveConfig('test-string', testString, pluginName);
338+
const retrievedString = await this.getConfig<string>('test-string', pluginName);
338339
this.log(`字符串测试: ${testString === retrievedString ? '✅' : '❌'}`);
339340

340341
// ==================== 复杂对象测试 ====================
341342
// 测试嵌套对象的序列化和反序列化
342343
const testObject = { name: "test", value: 123, nested: { data: [1, 2, 3] } };
343-
await this.saveConfig('test-object', testObject);
344-
const retrievedObject = await this.getConfig<typeof testObject>('test-object', 'orca-tabs-plugin');
344+
await this.saveConfig('test-object', testObject, pluginName);
345+
const retrievedObject = await this.getConfig<typeof testObject>('test-object', pluginName);
345346
this.log(`对象测试: ${JSON.stringify(testObject) === JSON.stringify(retrievedObject) ? '✅' : '❌'}`);
346347

347348
// ==================== 数组数据测试 ====================
348349
// 测试数组的保存和读取
349350
const testArray = [1, 2, 3, { nested: true }];
350-
await this.saveConfig('test-array', testArray);
351-
const retrievedArray = await this.getConfig<typeof testArray>('test-array', 'orca-tabs-plugin');
351+
await this.saveConfig('test-array', testArray, pluginName);
352+
const retrievedArray = await this.getConfig<typeof testArray>('test-array', pluginName);
352353
this.log(`数组测试: ${JSON.stringify(testArray) === JSON.stringify(retrievedArray) ? '✅' : '❌'}`);
353354

354355
// ==================== 清理测试数据 ====================
355356
// 删除所有测试数据,避免影响实际使用
356-
await this.removeConfig('test-string');
357-
await this.removeConfig('test-object');
358-
await this.removeConfig('test-array');
357+
await this.removeConfig('test-string', pluginName);
358+
await this.removeConfig('test-object', pluginName);
359+
await this.removeConfig('test-array', pluginName);
359360

360361
this.log("🧪 API配置序列化测试完成");
361362
} catch (error) {

src/services/tabStorage.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,10 @@ export class TabStorageService {
236236
*/
237237
async loadWorkspaces(): Promise<{ workspaces: Workspace[], enableWorkspaces: boolean }> {
238238
try {
239-
const workspacesData = await this.storageService.getConfig(PLUGIN_STORAGE_KEYS.WORKSPACES);
239+
const workspacesData = await this.storageService.getConfig(PLUGIN_STORAGE_KEYS.WORKSPACES, this.pluginName);
240240
const workspaces: Workspace[] = workspacesData && Array.isArray(workspacesData) ? workspacesData : [];
241241

242-
const enableWorkspaces = await this.storageService.getConfig(PLUGIN_STORAGE_KEYS.ENABLE_WORKSPACES);
242+
const enableWorkspaces = await this.storageService.getConfig(PLUGIN_STORAGE_KEYS.ENABLE_WORKSPACES, this.pluginName);
243243
const enableWorkspacesValue = typeof enableWorkspaces === 'boolean' ? enableWorkspaces : false;
244244

245245
this.log(`📁 已加载 ${workspaces.length} 个工作区`);
@@ -427,8 +427,8 @@ export class TabStorageService {
427427
*/
428428
async clearCache(): Promise<void> {
429429
try {
430-
await this.storageService.removeConfig(PLUGIN_STORAGE_KEYS.FIRST_PANEL_TABS);
431-
await this.storageService.removeConfig(PLUGIN_STORAGE_KEYS.CLOSED_TABS);
430+
await this.storageService.removeConfig(PLUGIN_STORAGE_KEYS.FIRST_PANEL_TABS, this.pluginName);
431+
await this.storageService.removeConfig(PLUGIN_STORAGE_KEYS.CLOSED_TABS, this.pluginName);
432432
this.log(`🗑️ 已删除API配置缓存: 标签页数据和已关闭标签列表`);
433433
} catch (e) {
434434
this.warn("删除API配置缓存失败:", e);

0 commit comments

Comments
 (0)