-
Notifications
You must be signed in to change notification settings - Fork 1
/
ai-chat-setting-storage.ts
70 lines (58 loc) · 2.69 KB
/
ai-chat-setting-storage.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { Storage } from '@plasmohq/storage';
class AiChatSettingStorage {
private static instance: AiChatSettingStorage;
storage: Storage;
syncInputAiChatStorageKey = "syncInputAiChats";
quickOpenAiChatStorageKey = "quickOpenAiChats";
quickOpenMethodStorageKey = "quickOpenMethod";
static getInstance() {
if (!AiChatSettingStorage.instance) {
AiChatSettingStorage.instance = new AiChatSettingStorage();
}
return AiChatSettingStorage.instance;
}
private constructor() {
this.storage = new Storage();
}
async getSyncInputAiChat(): Promise<string[]> {
return await this.storage.get<string[]>(this.syncInputAiChatStorageKey) ?? [];
}
async addSyncInputAiChat(aiChatId: string) {
let syncInputAiChats = await this.storage.get<string[]>(this.syncInputAiChatStorageKey) ?? [];
if (!syncInputAiChats.includes(aiChatId)) {
syncInputAiChats.push(aiChatId);
await this.storage.set(this.syncInputAiChatStorageKey, syncInputAiChats);
}
}
async removeSyncInputAiChat(aiChatId: string) {
let syncInputAiChats = await this.storage.get<string[]>(this.syncInputAiChatStorageKey) ?? [];
if (syncInputAiChats.includes(aiChatId)) {
syncInputAiChats = syncInputAiChats.filter(id => id !== aiChatId);
await this.storage.set(this.syncInputAiChatStorageKey, syncInputAiChats);
}
}
async getQuickOpenAiChat(): Promise<string[]> {
return await this.storage.get<string[]>(this.quickOpenAiChatStorageKey) ?? [];
}
async addQuickOpenAiChat(aiChatId: string) {
let quickOpenAiChats = await this.storage.get<string[]>(this.quickOpenAiChatStorageKey) ?? [];
if (!quickOpenAiChats.includes(aiChatId)) {
quickOpenAiChats.push(aiChatId);
await this.storage.set(this.quickOpenAiChatStorageKey, quickOpenAiChats);
}
}
async removeQuickOpenAiChat(aiChatId: string) {
let quickOpenAiChats = await this.storage.get<string[]>(this.quickOpenAiChatStorageKey) ?? [];
if (quickOpenAiChats.includes(aiChatId)) {
quickOpenAiChats = quickOpenAiChats.filter(id => id !== aiChatId);
await this.storage.set(this.quickOpenAiChatStorageKey, quickOpenAiChats);
}
}
async setQuickOpenMethod(quickOpenMethod: 'tab' | 'newWindowTab' | 'windowHorizontal' | 'windowVertical' | 'windowGrid') {
await this.storage.set(this.quickOpenMethodStorageKey, quickOpenMethod);
}
async getQuickOpenMethod(): Promise<string> {
return await this.storage.get<string>(this.quickOpenMethodStorageKey) ?? "tab";
}
}
export default AiChatSettingStorage;