From 9ad3bfd152bbf3f9b19e0223f6e4d8fb5f14e031 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8D=89=E9=9E=8B=E6=B2=A1=E5=8F=B7?= <308487730@qq.com> Date: Sat, 11 Dec 2021 14:12:42 +0800 Subject: [PATCH] reactor: move electron-store to samples folder --- src/main/index.ts | 17 ++--------------- src/main/samples/electron-store.ts | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 15 deletions(-) create mode 100644 src/main/samples/electron-store.ts diff --git a/src/main/index.ts b/src/main/index.ts index b9b27b0..d3eccdb 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -1,7 +1,7 @@ import os from 'os' import { join } from 'path' -import { app, BrowserWindow, ipcMain } from 'electron' -import Store from 'electron-store' +import { app, BrowserWindow } from 'electron' +import './samples/electron-store' const isWin7 = os.release().startsWith('6.1') if (isWin7) app.disableHardwareAcceleration() @@ -54,16 +54,3 @@ app.on('second-instance', () => { win.focus() } }) - -// ------------------------------------- - -/** - * Expose 'electron-store' to renderer through 'ipcMain.handle' - */ -const store = new Store -ipcMain.handle('electron-store', async (_evnet, methodSign: string, ...args: any[]) => { - if (typeof (store as any)[methodSign] === 'function') { - return (store as any)[methodSign](...args) - } - return (store as any)[methodSign] -}) diff --git a/src/main/samples/electron-store.ts b/src/main/samples/electron-store.ts new file mode 100644 index 0000000..7ab0dd6 --- /dev/null +++ b/src/main/samples/electron-store.ts @@ -0,0 +1,17 @@ +/** + * Use 'electron-store' sample code. + */ +import { ipcMain } from 'electron' +import Store from 'electron-store' + +/** + * Expose 'electron-store' to Renderer-process through 'ipcMain.handle' + */ + const store = new Store + ipcMain.handle('electron-store', async (_evnet, methodSign: string, ...args: any[]) => { + if (typeof (store as any)[methodSign] === 'function') { + return (store as any)[methodSign](...args) + } + return (store as any)[methodSign] + }) + \ No newline at end of file