diff --git a/backend/database/core.ts b/backend/database/core.ts index 26a95a84..874fa826 100644 --- a/backend/database/core.ts +++ b/backend/database/core.ts @@ -1,6 +1,4 @@ import { knex, Knex } from 'knex'; -import { getRandomString, getValueMapFromList } from 'utils'; -import { DatabaseBase, GetAllOptions, QueryFilter } from 'utils/db/types'; import { CannotCommitError, DatabaseError, @@ -16,6 +14,8 @@ import { SchemaMap, TargetField, } from '../../schemas/types'; +import { getRandomString, getValueMapFromList } from '../../utils'; +import { DatabaseBase, GetAllOptions, QueryFilter } from '../../utils/db/types'; import { getDefaultMetaFieldValueMap, sqliteTypeMap, SYSTEM } from '../helpers'; import { ColumnDiff, FieldValueMap, GetQueryBuilderOptions } from './types'; diff --git a/backend/database/manager.ts b/backend/database/manager.ts index 8a9590c6..80519c79 100644 --- a/backend/database/manager.ts +++ b/backend/database/manager.ts @@ -1,7 +1,7 @@ -import { databaseMethodSet } from 'backend/helpers'; import fs from 'fs/promises'; import { DatabaseMethod } from 'utils/db/types'; import { getSchemas } from '../../schemas'; +import { databaseMethodSet } from '../helpers'; import patches from '../patches'; import DatabaseCore from './core'; import { runPatches } from './runPatch'; diff --git a/main.ts b/main.ts index 3c666bfa..39ee7b9a 100644 --- a/main.ts +++ b/main.ts @@ -16,7 +16,7 @@ import registerAutoUpdaterListeners from './main/registerAutoUpdaterListeners'; import registerIpcMainActionListeners from './main/registerIpcMainActionListeners'; import registerIpcMainMessageListeners from './main/registerIpcMainMessageListeners'; import registerProcessListeners from './main/registerProcessListeners'; -import { IPC_CHANNELS } from './src/messages'; +import { IPC_CHANNELS } from './utils/messages'; export class Main { title: string = 'Frappe Books'; diff --git a/main/registerAutoUpdaterListeners.ts b/main/registerAutoUpdaterListeners.ts index a334656f..4137c970 100644 --- a/main/registerAutoUpdaterListeners.ts +++ b/main/registerAutoUpdaterListeners.ts @@ -1,6 +1,6 @@ import { autoUpdater, UpdateInfo } from 'electron-updater'; import { Main } from '../main'; -import { IPC_CHANNELS } from '../src/messages'; +import { IPC_CHANNELS } from '../utils/messages'; export default function registerAutoUpdaterListeners(main: Main) { autoUpdater.autoDownload = false; diff --git a/main/registerIpcMainActionListeners.ts b/main/registerIpcMainActionListeners.ts index 5260800d..4b06857c 100644 --- a/main/registerIpcMainActionListeners.ts +++ b/main/registerIpcMainActionListeners.ts @@ -2,11 +2,13 @@ import { app, dialog, ipcMain } from 'electron'; import { autoUpdater } from 'electron-updater'; import fs from 'fs/promises'; import path from 'path'; +import databaseManager from '../backend/database/manager'; import { Main } from '../main'; import { getUrlAndTokenString, sendError } from '../src/contactMothership'; import { getLanguageMap } from '../src/getLanguageMap'; -import { IPC_ACTIONS } from '../src/messages'; import saveHtmlAsPdf from '../src/saveHtmlAsPdf'; +import { DatabaseMethod } from '../utils/db/types'; +import { IPC_ACTIONS } from '../utils/messages'; import { getMainWindowSize } from './helpers'; export default function registerIpcMainActionListeners(main: Main) { @@ -116,4 +118,29 @@ export default function registerIpcMainActionListeners(main: Main) { ipcMain.handle(IPC_ACTIONS.GET_VERSION, (_) => { return app.getVersion(); }); + + /** + * Database Related Actions + */ + + ipcMain.handle( + IPC_ACTIONS.DB_CREATE, + async (_, dbPath: string, countryCode?: string) => { + return databaseManager.createNewDatabase(dbPath, countryCode); + } + ); + + ipcMain.handle( + IPC_ACTIONS.DB_CONNECT, + async (_, dbPath: string, countryCode?: string) => { + return databaseManager.createNewDatabase(dbPath, countryCode); + } + ); + + ipcMain.handle( + IPC_ACTIONS.DB_CALL, + async (_, method: DatabaseMethod, ...args: unknown[]) => { + return databaseManager.call(method, ...args); + } + ); } diff --git a/main/registerIpcMainMessageListeners.ts b/main/registerIpcMainMessageListeners.ts index b178edb7..aa5da057 100644 --- a/main/registerIpcMainMessageListeners.ts +++ b/main/registerIpcMainMessageListeners.ts @@ -1,7 +1,7 @@ import { ipcMain, Menu, shell } from 'electron'; import { autoUpdater } from 'electron-updater'; import { Main } from '../main'; -import { IPC_MESSAGES } from '../src/messages'; +import { IPC_MESSAGES } from '../utils/messages'; export default function registerIpcMainMessageListeners(main: Main) { ipcMain.on(IPC_MESSAGES.OPEN_MENU, (event) => { diff --git a/src/App.vue b/src/App.vue index c8350880..285cbbf2 100644 --- a/src/App.vue +++ b/src/App.vue @@ -37,7 +37,7 @@ import { postSetup, purgeCache, } from '@/initialization'; -import { IPC_ACTIONS, IPC_MESSAGES } from '@/messages'; +import { IPC_ACTIONS, IPC_MESSAGES } from 'utils/messages'; import { ipcRenderer } from 'electron'; import frappe from 'frappe'; import fs from 'fs/promises'; diff --git a/src/components/Controls/AttachImage.vue b/src/components/Controls/AttachImage.vue index f25210cb..d3b14237 100644 --- a/src/components/Controls/AttachImage.vue +++ b/src/components/Controls/AttachImage.vue @@ -59,7 +59,7 @@ import frappe from 'frappe'; import { ipcRenderer } from 'electron'; import Base from './Base'; -import { IPC_ACTIONS } from '@/messages'; +import { IPC_ACTIONS } from 'utils/messages'; import fs from 'fs'; import path from 'path'; diff --git a/src/components/HowTo.vue b/src/components/HowTo.vue index 749a3d55..131767c8 100644 --- a/src/components/HowTo.vue +++ b/src/components/HowTo.vue @@ -9,7 +9,7 @@