@lynker-desktop/electron-sdk 0.0.9-alpha.78 → 0.0.9-alpha.79

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.
@@ -9,6 +9,6 @@ export type AppStoreOptions = {
9
9
  [key: string]: any;
10
10
  };
11
11
  export declare const initializeStore: () => void;
12
- export declare const getAppStore: (name: string) => any;
13
- export declare const appStoreInit: (stores: string[]) => boolean;
12
+ export declare const getAppStore: (name: string, encryptionKey?: string) => any;
13
+ export declare const appStoreInit: (stores: string[], encryptionKey?: string) => boolean;
14
14
  //# sourceMappingURL=store.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/main/store.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAa,CAAC;AAErD,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,KAAK,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,KAAK,GAAG,OAAO,CAAC;IAC7D,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,GAAG,CAAC;CACb;AAED,MAAM,MAAM,eAAe,GAAG;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAC,CAAC;AAkCnD,eAAO,MAAM,eAAe,YAsB3B,CAAA;AAED,eAAO,MAAM,WAAW,SAAU,MAAM,QAEvC,CAAA;AAED,eAAO,MAAM,YAAY,WAAY,MAAM,EAAE,YAa5C,CAAA"}
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/main/store.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAa,CAAC;AAErD,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,KAAK,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,KAAK,GAAG,OAAO,CAAC;IAC7D,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,GAAG,CAAC;CACb;AAED,MAAM,MAAM,eAAe,GAAG;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAC,CAAC;AAoCnD,eAAO,MAAM,eAAe,YAsB3B,CAAA;AAED,eAAO,MAAM,WAAW,SAAU,MAAM,kBAAkB,MAAM,QAE/D,CAAA;AAED,eAAO,MAAM,YAAY,WAAY,MAAM,EAAE,kBAAkB,MAAM,YAapE,CAAA"}
package/esm/main/store.js CHANGED
@@ -5,17 +5,19 @@ const _appStore = new Map();
5
5
  /**
6
6
  * 确保 store 存在并已初始化,如果不存在则创建
7
7
  */
8
- function ensureStore(name) {
8
+ function ensureStore(name, encryptionKey) {
9
+ const isTemp = name && name.startsWith('__temp__');
9
10
  if (!_appStore.has(name) || typeof _appStore.get(name)?.set !== 'function') {
10
11
  const Store = ElectronStore;
11
12
  _appStore.set(name, new Store({
12
13
  name,
13
14
  accessPropertiesByDotNotation: true,
15
+ encryptionKey: encryptionKey,
14
16
  }));
15
17
  /**
16
18
  * 临时存储,每次启动时清空
17
19
  */
18
- if (name.startsWith('__temp__')) {
20
+ if (isTemp) {
19
21
  _appStore.get(name).clear();
20
22
  console.log('clear temp store', name);
21
23
  }
@@ -61,15 +63,15 @@ const initializeStore = () => {
61
63
  }
62
64
  });
63
65
  };
64
- const getAppStore = (name) => {
65
- return ensureStore(name);
66
+ const getAppStore = (name, encryptionKey) => {
67
+ return ensureStore(name, encryptionKey);
66
68
  };
67
- const appStoreInit = (stores) => {
68
- if (stores.length) {
69
+ const appStoreInit = (stores, encryptionKey) => {
70
+ if (stores && stores.length) {
69
71
  stores.forEach((storeName) => {
70
72
  try {
71
73
  if (typeof storeName === 'string') {
72
- ensureStore(storeName);
74
+ ensureStore(storeName, encryptionKey);
73
75
  }
74
76
  }
75
77
  catch (error) {
@@ -1 +1 @@
1
- {"version":3,"file":"store.js","sources":["../../src/main/store.ts"],"sourcesContent":["import ElectronStore from 'electron-store';\nimport ipc from '@lynker-desktop/electron-ipc/main';\n\nexport const _appStore: Map<string, any> = new Map();\n\nexport interface EStoreQuery {\n name?: string;\n method: 'get' | 'set' | 'delete' | 'clear' | 'has' | 'store';\n key?: string;\n value?: any;\n};\n\nexport type AppStoreOptions = {[key: string]: any};\n\n/**\n * 确保 store 存在并已初始化,如果不存在则创建\n */\nfunction ensureStore(name: string) {\n if (!_appStore.has(name) || typeof _appStore.get(name)?.set !== 'function') {\n const Store = ElectronStore;\n _appStore.set(name, new Store({\n name,\n accessPropertiesByDotNotation: true,\n }));\n /**\n * 临时存储,每次启动时清空\n */\n if (name.startsWith('__temp__')) {\n _appStore.get(name).clear();\n console.log('clear temp store', name);\n }\n _appStore.get(name).onDidAnyChange((newValue: any, oldValue: any) => {\n try {\n ipc.mainIPC.invokeAllRendererNotReply('core:estore:didAnyChange', {\n name,\n newValue: newValue ? JSON.stringify(newValue) : undefined,\n oldValue: oldValue ? JSON.stringify(oldValue) : undefined,\n });\n } catch (error) {\n console.error('core:estore:didAnyChange', error);\n }\n });\n }\n return _appStore.get(name);\n}\n\nexport const initializeStore = () => {\n ipc.mainIPC.handleRenderer('core:estore', async (options: EStoreQuery) => {\n const { name = 'appStore', method, key, value } = options;\n const appStore = ensureStore(name);\n\n if (method === 'get') {\n return appStore.get(key);\n } else if (method === 'set') {\n appStore.set(key, value);\n return true;\n } else if (method === 'delete') {\n appStore.delete(key);\n return true;\n } else if (method === 'clear') {\n appStore.clear();\n return true;\n } else if (method === 'has') {\n return appStore.has(key);\n } else if (method === 'store') {\n return appStore.store;\n }\n })\n}\n\nexport const getAppStore = (name: string) => {\n return ensureStore(name);\n}\n\nexport const appStoreInit = (stores: string[]) => {\n if (stores.length) {\n stores.forEach((storeName: string) => {\n try {\n if (typeof storeName === 'string') {\n ensureStore(storeName);\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/C,IAAA,IAAI,MAAM,CAAC,MAAM,EAAE;AACjB,QAAA,MAAM,CAAC,OAAO,CAAC,CAAC,SAAiB,KAAI;AACnC,YAAA,IAAI;AACF,gBAAA,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;oBACjC,WAAW,CAAC,SAAS,CAAC,CAAC;iBACxB;aACF;YAAC,OAAO,KAAK,EAAE;AACd,gBAAA,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;aACtC;AACH,SAAC,CAAC,CAAC;KACJ;AACD,IAAA,OAAO,IAAI,CAAC;AACd;;;;"}
1
+ {"version":3,"file":"store.js","sources":["../../src/main/store.ts"],"sourcesContent":["import ElectronStore from 'electron-store';\nimport ipc from '@lynker-desktop/electron-ipc/main';\n\nexport const _appStore: Map<string, any> = new Map();\n\nexport interface EStoreQuery {\n name?: string;\n method: 'get' | 'set' | 'delete' | 'clear' | 'has' | 'store';\n key?: string;\n value?: any;\n};\n\nexport type AppStoreOptions = {[key: string]: any};\n\n/**\n * 确保 store 存在并已初始化,如果不存在则创建\n */\nfunction ensureStore(name: string, encryptionKey?: string) {\n const isTemp = name && name.startsWith('__temp__');\n if (!_appStore.has(name) || typeof _appStore.get(name)?.set !== 'function') {\n const Store = ElectronStore;\n _appStore.set(name, new Store({\n name,\n accessPropertiesByDotNotation: true,\n encryptionKey: encryptionKey,\n }));\n /**\n * 临时存储,每次启动时清空\n */\n if (isTemp) {\n _appStore.get(name).clear();\n console.log('clear temp store', name);\n }\n _appStore.get(name).onDidAnyChange((newValue: any, oldValue: any) => {\n try {\n ipc.mainIPC.invokeAllRendererNotReply('core:estore:didAnyChange', {\n name,\n newValue: newValue ? JSON.stringify(newValue) : undefined,\n oldValue: oldValue ? JSON.stringify(oldValue) : undefined,\n });\n } catch (error) {\n console.error('core:estore:didAnyChange', error);\n }\n });\n }\n return _appStore.get(name);\n}\n\nexport const initializeStore = () => {\n ipc.mainIPC.handleRenderer('core:estore', async (options: EStoreQuery) => {\n const { name = 'appStore', method, key, value } = options;\n const appStore = ensureStore(name);\n\n if (method === 'get') {\n return appStore.get(key);\n } else if (method === 'set') {\n appStore.set(key, value);\n return true;\n } else if (method === 'delete') {\n appStore.delete(key);\n return true;\n } else if (method === 'clear') {\n appStore.clear();\n return true;\n } else if (method === 'has') {\n return appStore.has(key);\n } else if (method === 'store') {\n return appStore.store;\n }\n })\n}\n\nexport const getAppStore = (name: string, encryptionKey?: string) => {\n return ensureStore(name, encryptionKey);\n}\n\nexport const appStoreInit = (stores: string[], encryptionKey?: string) => {\n if (stores && stores.length) {\n stores.forEach((storeName: string) => {\n try {\n if (typeof storeName === 'string') {\n ensureStore(storeName, encryptionKey);\n }\n } catch (error) {\n console.error('appStoreInit', error);\n }\n });\n }\n return true;\n}\n"],"names":["ipc"],"mappings":";;;AAGa,MAAA,SAAS,GAAqB,IAAI,GAAG,GAAG;AAWrD;;AAEG;AACH,SAAS,WAAW,CAAC,IAAY,EAAE,aAAsB,EAAA;IACvD,MAAM,MAAM,GAAG,IAAI,IAAI,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;IACnD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,OAAO,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,KAAK,UAAU,EAAE;QAC1E,MAAM,KAAK,GAAG,aAAa,CAAC;AAC5B,QAAA,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,KAAK,CAAC;YAC5B,IAAI;AACJ,YAAA,6BAA6B,EAAE,IAAI;AACnC,YAAA,aAAa,EAAE,aAAa;AAC7B,SAAA,CAAC,CAAC,CAAC;AACJ;;AAEG;QACH,IAAI,MAAM,EAAE;YACV,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC;AAC5B,YAAA,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,IAAI,CAAC,CAAC;SACvC;AACD,QAAA,SAAS,C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AI,CAAC;SACb;AAAM,aAAA,IAAI,MAAM,KAAK,OAAO,EAAE;YAC7B,QAAQ,CAAC,KAAK,EAAE,CAAC;AACjB,YAAA,OAAO,IAAI,CAAC;SACb;AAAM,aAAA,IAAI,MAAM,KAAK,KAAK,EAAE;AAC3B,YAAA,OAAO,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;SAC1B;AAAM,aAAA,IAAI,MAAM,KAAK,OAAO,EAAE;YAC7B,OAAO,QAAQ,CAAC,KAAK,CAAC;SACvB;AACH,KAAC,CAAC,CAAA;AACJ,EAAC;MAEY,WAAW,GAAG,CAAC,IAAY,EAAE,aAAsB,KAAI;AAClE,IAAA,OAAO,WAAW,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;AAC1C,EAAC;MAEY,YAAY,GAAG,CAAC,MAAgB,EAAE,aAAsB,KAAI;AACvE,IAAA,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE;AAC3B,QAAA,MAAM,CAAC,OAAO,CAAC,CAAC,SAAiB,KAAI;AACnC,YAAA,IAAI;AACF,gBAAA,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;AACjC,oBAAA,WAAW,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;iBACvC;aACF;YAAC,OAAO,KAAK,EAAE;AACd,gBAAA,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;aACtC;AACH,SAAC,CAAC,CAAC;KACJ;AACD,IAAA,OAAO,IAAI,CAAC;AACd;;;;"}
package/main/store.d.ts CHANGED
@@ -9,6 +9,6 @@ export type AppStoreOptions = {
9
9
  [key: string]: any;
10
10
  };
11
11
  export declare const initializeStore: () => void;
12
- export declare const getAppStore: (name: string) => any;
13
- export declare const appStoreInit: (stores: string[]) => boolean;
12
+ export declare const getAppStore: (name: string, encryptionKey?: string) => any;
13
+ export declare const appStoreInit: (stores: string[], encryptionKey?: string) => boolean;
14
14
  //# sourceMappingURL=store.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/main/store.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAa,CAAC;AAErD,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,KAAK,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,KAAK,GAAG,OAAO,CAAC;IAC7D,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,GAAG,CAAC;CACb;AAED,MAAM,MAAM,eAAe,GAAG;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAC,CAAC;AAkCnD,eAAO,MAAM,eAAe,YAsB3B,CAAA;AAED,eAAO,MAAM,WAAW,SAAU,MAAM,QAEvC,CAAA;AAED,eAAO,MAAM,YAAY,WAAY,MAAM,EAAE,YAa5C,CAAA"}
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/main/store.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAa,CAAC;AAErD,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,KAAK,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,KAAK,GAAG,OAAO,CAAC;IAC7D,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,GAAG,CAAC;CACb;AAED,MAAM,MAAM,eAAe,GAAG;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAC,CAAC;AAoCnD,eAAO,MAAM,eAAe,YAsB3B,CAAA;AAED,eAAO,MAAM,WAAW,SAAU,MAAM,kBAAkB,MAAM,QAE/D,CAAA;AAED,eAAO,MAAM,YAAY,WAAY,MAAM,EAAE,kBAAkB,MAAM,YAapE,CAAA"}
package/main/store.js CHANGED
@@ -5,17 +5,19 @@ const _appStore = new Map();
5
5
  /**
6
6
  * 确保 store 存在并已初始化,如果不存在则创建
7
7
  */
8
- function ensureStore(name) {
8
+ function ensureStore(name, encryptionKey) {
9
+ const isTemp = name && name.startsWith('__temp__');
9
10
  if (!_appStore.has(name) || typeof _appStore.get(name)?.set !== 'function') {
10
11
  const Store = ElectronStore;
11
12
  _appStore.set(name, new Store({
12
13
  name,
13
14
  accessPropertiesByDotNotation: true,
15
+ encryptionKey: encryptionKey,
14
16
  }));
15
17
  /**
16
18
  * 临时存储,每次启动时清空
17
19
  */
18
- if (name.startsWith('__temp__')) {
20
+ if (isTemp) {
19
21
  _appStore.get(name).clear();
20
22
  console.log('clear temp store', name);
21
23
  }
@@ -61,15 +63,15 @@ const initializeStore = () => {
61
63
  }
62
64
  });
63
65
  };
64
- const getAppStore = (name) => {
65
- return ensureStore(name);
66
+ const getAppStore = (name, encryptionKey) => {
67
+ return ensureStore(name, encryptionKey);
66
68
  };
67
- const appStoreInit = (stores) => {
68
- if (stores.length) {
69
+ const appStoreInit = (stores, encryptionKey) => {
70
+ if (stores && stores.length) {
69
71
  stores.forEach((storeName) => {
70
72
  try {
71
73
  if (typeof storeName === 'string') {
72
- ensureStore(storeName);
74
+ ensureStore(storeName, encryptionKey);
73
75
  }
74
76
  }
75
77
  catch (error) {
package/main/store.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"store.js","sources":["../src/src/main/store.ts"],"sourcesContent":["import ElectronStore from 'electron-store';\nimport ipc from '@lynker-desktop/electron-ipc/main';\n\nexport const _appStore: Map<string, any> = new Map();\n\nexport interface EStoreQuery {\n name?: string;\n method: 'get' | 'set' | 'delete' | 'clear' | 'has' | 'store';\n key?: string;\n value?: any;\n};\n\nexport type AppStoreOptions = {[key: string]: any};\n\n/**\n * 确保 store 存在并已初始化,如果不存在则创建\n */\nfunction ensureStore(name: string) {\n if (!_appStore.has(name) || typeof _appStore.get(name)?.set !== 'function') {\n const Store = ElectronStore;\n _appStore.set(name, new Store({\n name,\n accessPropertiesByDotNotation: true,\n }));\n /**\n * 临时存储,每次启动时清空\n */\n if (name.startsWith('__temp__')) {\n _appStore.get(name).clear();\n console.log('clear temp store', name);\n }\n _appStore.get(name).onDidAnyChange((newValue: any, oldValue: any) => {\n try {\n ipc.mainIPC.invokeAllRendererNotReply('core:estore:didAnyChange', {\n name,\n newValue: newValue ? JSON.stringify(newValue) : undefined,\n oldValue: oldValue ? JSON.stringify(oldValue) : undefined,\n });\n } catch (error) {\n console.error('core:estore:didAnyChange', error);\n }\n });\n }\n return _appStore.get(name);\n}\n\nexport const initializeStore = () => {\n ipc.mainIPC.handleRenderer('core:estore', async (options: EStoreQuery) => {\n const { name = 'appStore', method, key, value } = options;\n const appStore = ensureStore(name);\n\n if (method === 'get') {\n return appStore.get(key);\n } else if (method === 'set') {\n appStore.set(key, value);\n return true;\n } else if (method === 'delete') {\n appStore.delete(key);\n return true;\n } else if (method === 'clear') {\n appStore.clear();\n return true;\n } else if (method === 'has') {\n return appStore.has(key);\n } else if (method === 'store') {\n return appStore.store;\n }\n })\n}\n\nexport const getAppStore = (name: string) => {\n return ensureStore(name);\n}\n\nexport const appStoreInit = (stores: string[]) => {\n if (stores.length) {\n stores.forEach((storeName: string) => {\n try {\n if (typeof storeName === 'string') {\n ensureStore(storeName);\n }\n } catch (error) {\n console.error('appStoreInit', error);\n }\n });\n }\n return true;\n}\n"],"names":[],"mappings":";;;AAGa,MAAA,SAAS,GAAqB,IAAI,GAAG,GAAG;AAWrD;;AAEG;AACH,SAAS,WAAW,CAAC,IAAY,EAAA;IAC/B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,OAAO,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,KAAK,UAAU,EAAE;QAC1E,MAAM,KAAK,GAAG,aAAa,CAAC;AAC5B,QAAA,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,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,"file":"store.js","sources":["../src/src/main/store.ts"],"sourcesContent":["import ElectronStore from 'electron-store';\nimport ipc from '@lynker-desktop/electron-ipc/main';\n\nexport const _appStore: Map<string, any> = new Map();\n\nexport interface EStoreQuery {\n name?: string;\n method: 'get' | 'set' | 'delete' | 'clear' | 'has' | 'store';\n key?: string;\n value?: any;\n};\n\nexport type AppStoreOptions = {[key: string]: any};\n\n/**\n * 确保 store 存在并已初始化,如果不存在则创建\n */\nfunction ensureStore(name: string, encryptionKey?: string) {\n const isTemp = name && name.startsWith('__temp__');\n if (!_appStore.has(name) || typeof _appStore.get(name)?.set !== 'function') {\n const Store = ElectronStore;\n _appStore.set(name, new Store({\n name,\n accessPropertiesByDotNotation: true,\n encryptionKey: encryptionKey,\n }));\n /**\n * 临时存储,每次启动时清空\n */\n if (isTemp) {\n _appStore.get(name).clear();\n console.log('clear temp store', name);\n }\n _appStore.get(name).onDidAnyChange((newValue: any, oldValue: any) => {\n try {\n ipc.mainIPC.invokeAllRendererNotReply('core:estore:didAnyChange', {\n name,\n newValue: newValue ? JSON.stringify(newValue) : undefined,\n oldValue: oldValue ? JSON.stringify(oldValue) : undefined,\n });\n } catch (error) {\n console.error('core:estore:didAnyChange', error);\n }\n });\n }\n return _appStore.get(name);\n}\n\nexport const initializeStore = () => {\n ipc.mainIPC.handleRenderer('core:estore', async (options: EStoreQuery) => {\n const { name = 'appStore', method, key, value } = options;\n const appStore = ensureStore(name);\n\n if (method === 'get') {\n return appStore.get(key);\n } else if (method === 'set') {\n appStore.set(key, value);\n return true;\n } else if (method === 'delete') {\n appStore.delete(key);\n return true;\n } else if (method === 'clear') {\n appStore.clear();\n return true;\n } else if (method === 'has') {\n return appStore.has(key);\n } else if (method === 'store') {\n return appStore.store;\n }\n })\n}\n\nexport const getAppStore = (name: string, encryptionKey?: string) => {\n return ensureStore(name, encryptionKey);\n}\n\nexport const appStoreInit = (stores: string[], encryptionKey?: string) => {\n if (stores && stores.length) {\n stores.forEach((storeName: string) => {\n try {\n if (typeof storeName === 'string') {\n ensureStore(storeName, encryptionKey);\n }\n } catch (error) {\n console.error('appStoreInit', error);\n }\n });\n }\n return true;\n}\n"],"names":[],"mappings":";;;AAGa,MAAA,SAAS,GAAqB,IAAI,GAAG,GAAG;AAWrD;;AAEG;AACH,SAAS,WAAW,CAAC,IAAY,EAAE,aAAsB,EAAA;IACvD,MAAM,MAAM,GAAG,IAAI,IAAI,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;IACnD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,OAAO,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,KAAK,UAAU,EAAE;QAC1E,MAAM,KAAK,GAAG,aAAa,CAAC;AAC5B,QAAA,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,KAAK,CAAC;YAC5B,IAAI;AACJ,YAAA,6BAA6B,EAAE,IAAI;AACnC,YAAA,aAAa,EAAE,aAAa;AAC7B,SAAA,CAAC,CAAC,CAAC;AACJ;;AAEG;QACH,IAAI,MAAM,EAAE;YACV,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC;AAC5B,YAAA,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,IAAI,CAAC,CAAC;SACvC;AACD,QAAA,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,cAAc,CAAC,CAAC,QAAa,EAAE,QAAa,KAAI;AAClE,YAAA,IAAI;AACF,gBAAA,GAAG,CAAC,OAAO,CAAC,yBAAyB,CAAC,0BAA0B,EAAE;oBAChE,IAAI;AACJ,oBAAA,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,GAAG,SAAS;AACzD,oBAAA,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,GAAG,SAAS;AAC1D,iBAAA,CAAC,CAAC;aACJ;YAAC,OA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AAE,aAAsB,KAAI;AAClE,IAAA,OAAO,WAAW,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;AAC1C,EAAC;MAEY,YAAY,GAAG,CAAC,MAAgB,EAAE,aAAsB,KAAI;AACvE,IAAA,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE;AAC3B,QAAA,MAAM,CAAC,OAAO,CAAC,CAAC,SAAiB,KAAI;AACnC,YAAA,IAAI;AACF,gBAAA,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;AACjC,oBAAA,WAAW,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;iBACvC;aACF;YAAC,OAAO,KAAK,EAAE;AACd,gBAAA,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;aACtC;AACH,SAAC,CAAC,CAAC;KACJ;AACD,IAAA,OAAO,IAAI,CAAC;AACd;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynker-desktop/electron-sdk",
3
- "version": "0.0.9-alpha.78",
3
+ "version": "0.0.9-alpha.79",
4
4
  "description": "electron-sdk",
5
5
  "keywords": [
6
6
  "electron",
@@ -53,9 +53,9 @@
53
53
  "packageManager": "pnpm@9.6.0",
54
54
  "dependencies": {
55
55
  "@electron/remote": "^2.1.2",
56
- "@lynker-desktop/electron-ipc": "0.0.9-alpha.78",
57
- "@lynker-desktop/electron-logs": "0.0.9-alpha.78",
58
- "@lynker-desktop/electron-window-manager": "0.0.9-alpha.78",
56
+ "@lynker-desktop/electron-ipc": "0.0.9-alpha.79",
57
+ "@lynker-desktop/electron-logs": "0.0.9-alpha.79",
58
+ "@lynker-desktop/electron-window-manager": "0.0.9-alpha.79",
59
59
  "electron-store": "^11.0.2",
60
60
  "events": "^3.3.0",
61
61
  "lodash": "^4.17.21",
@@ -92,5 +92,5 @@
92
92
  "tslib": "^2.6.3",
93
93
  "typescript": "^5.5.3"
94
94
  },
95
- "gitHead": "e1a4ef4af18830dfb334e3539ed6dd3ef2587f73"
95
+ "gitHead": "4c0261335f9edaa7a244da1f80853e3ae2d94645"
96
96
  }