diff --git a/main/preload.ts b/main/preload.ts index 1a538087..f6e04711 100644 --- a/main/preload.ts +++ b/main/preload.ts @@ -82,6 +82,10 @@ const ipc = { )) as TemplateFile[]; }, + async initScheduler(time: string) { + await ipcRenderer.invoke(IPC_ACTIONS.INIT_SHEDULER, time); + }, + async selectFile(options: SelectFileOptions): Promise { return (await ipcRenderer.invoke( IPC_ACTIONS.SELECT_FILE, @@ -210,6 +214,10 @@ const ipc = { ipcRenderer.on(IPC_CHANNELS.LOG_MAIN_PROCESS_ERROR, listener); }, + registerTriggerFrontendActionListener(listener: IPCRendererListener) { + ipcRenderer.on(IPC_CHANNELS.TRIGGER_FRONTEND_ACTION, listener); + }, + registerConsoleLogListener(listener: IPCRendererListener) { ipcRenderer.on(IPC_CHANNELS.CONSOLE_LOG, listener); }, diff --git a/main/registerIpcMainActionListeners.ts b/main/registerIpcMainActionListeners.ts index 4706a2b7..29a740bc 100644 --- a/main/registerIpcMainActionListeners.ts +++ b/main/registerIpcMainActionListeners.ts @@ -28,6 +28,7 @@ import { } from './helpers'; import { saveHtmlAsPdf } from './saveHtmlAsPdf'; import { sendAPIRequest } from './api'; +import { initScheduler } from './initSheduler'; export default function registerIpcMainActionListeners(main: Main) { ipcMain.handle(IPC_ACTIONS.CHECK_DB_ACCESS, async (_, filePath: string) => { @@ -246,6 +247,10 @@ export default function registerIpcMainActionListeners(main: Main) { } ); + ipcMain.handle(IPC_ACTIONS.INIT_SHEDULER, async (_, interval: string) => { + return initScheduler(interval); + }); + ipcMain.handle( IPC_ACTIONS.SEND_API_REQUEST, async (e, endpoint: string, options: RequestInit | undefined) => { diff --git a/package.json b/package.json index 91d7d03f..b70108a8 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "@codemirror/lang-vue": "^0.1.1", "@popperjs/core": "^2.10.2", "better-sqlite3": "^9.2.2", + "bree": "^9.2.4", "codemirror": "^6.0.1", "core-js": "^3.19.0", "electron-store": "^8.0.1", diff --git a/src/App.vue b/src/App.vue index 31a812dd..9dcc72f2 100644 --- a/src/App.vue +++ b/src/App.vue @@ -71,7 +71,6 @@ import { routeTo } from './utils/ui'; import { useKeys } from './utils/vueUtils'; import { setDarkMode } from 'src/utils/theme'; import { - initERPNSync, registerInstanceToERPNext, updateERPNSyncSettings, } from './utils/erpnextSync'; @@ -231,7 +230,9 @@ export default defineComponent({ await updatePrintTemplates(fyo); await registerInstanceToERPNext(fyo); await updateERPNSyncSettings(fyo); - initERPNSync(fyo); + await ipc.initScheduler( + `${fyo.singles.ERPNextSyncSettings?.dataSyncInterval as string}m` + ); await this.setDesk(filePath); }, async handleConnectionFailed(error: Error, actionSymbol: symbol) { diff --git a/utils/messages.ts b/utils/messages.ts index 0375b768..5f04bf5b 100644 --- a/utils/messages.ts +++ b/utils/messages.ts @@ -32,6 +32,7 @@ export enum IPC_ACTIONS { GET_CREDS = 'get-creds', GET_DB_LIST = 'get-db-list', GET_TEMPLATES = 'get-templates', + INIT_SHEDULER = 'init-scheduler', DELETE_FILE = 'delete-file', GET_DB_DEFAULT_PATH = 'get-db-default-path', SEND_API_REQUEST = 'send-api-request', @@ -47,6 +48,7 @@ export enum IPC_ACTIONS { export enum IPC_CHANNELS { LOG_MAIN_PROCESS_ERROR = 'main-process-error', CONSOLE_LOG = 'console-log', + TRIGGER_FRONTEND_ACTION = 'trigger-frontend-action', } export enum DB_CONN_FAILURE {