2
0
mirror of https://github.com/frappe/books.git synced 2025-01-03 07:12:21 +00:00

incr: move messages, add DB_ actions

This commit is contained in:
18alantom 2022-03-31 13:03:58 +05:30
parent 9765707d21
commit 804d841466
26 changed files with 102 additions and 74 deletions

View File

@ -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';

View File

@ -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';

View File

@ -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';

View File

@ -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;

View File

@ -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);
}
);
}

View File

@ -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) => {

View File

@ -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';

View File

@ -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';

View File

@ -9,7 +9,7 @@
</button>
</template>
<script>
import { IPC_MESSAGES } from '@/messages';
import { IPC_MESSAGES } from 'utils/messages';
import { ipcRenderer } from 'electron';
import FeatherIcon from './FeatherIcon.vue';

View File

@ -32,7 +32,7 @@
<script>
import { ipcRenderer } from 'electron';
import { runWindowAction } from '@/utils';
import { IPC_MESSAGES } from '@/messages';
import { IPC_MESSAGES } from 'utils/messages';
export default {
name: 'WindowsTitleBar',

View File

@ -7,8 +7,8 @@ import {
MandatoryError,
ValidationError,
} from 'frappe/utils/errors';
import { IPC_ACTIONS, IPC_MESSAGES } from 'utils/messages';
import config, { ConfigKeys, TelemetrySetting } from './config';
import { IPC_ACTIONS, IPC_MESSAGES } from './messages';
import telemetry from './telemetry/telemetry';
import { showMessageDialog, showToast } from './utils';

View File

@ -3,7 +3,7 @@ import SQLiteDatabase from 'frappe/backends/sqlite';
import fs from 'fs';
import regionalModelUpdates from '../models/regionalModelUpdates';
import postStart, { setCurrencySymbols } from '../server/postStart';
import { DB_CONN_FAILURE } from './messages';
import { DB_CONN_FAILURE } from '../utils/messages';
import runMigrate from './migrate';
import { getId } from './telemetry/helpers';
import telemetry from './telemetry/telemetry';

View File

@ -1,8 +1,6 @@
import { ipcRenderer } from 'electron';
import frappe from 'frappe';
import { createApp } from 'vue';
import { getBuiltTestSchemaMap } from '../backend/database/tests/helpers';
import { getSchemas } from '../schemas';
import App from './App';
import FeatherIcon from './components/FeatherIcon';
import config, { ConfigKeys } from './config';
@ -104,5 +102,3 @@ import { setLanguageMap, stringifyCircular } from './utils';
});
})();
window.gs = getSchemas;
window.gst = getBuiltTestSchemaMap;

View File

@ -1,47 +0,0 @@
// ipcRenderer.send(...)
export const IPC_MESSAGES = {
OPEN_MENU: 'open-menu',
OPEN_SETTINGS: 'open-settings',
OPEN_EXTERNAL: 'open-external',
SHOW_ITEM_IN_FOLDER: 'show-item-in-folder',
RELOAD_MAIN_WINDOW: 'reload-main-window',
RESIZE_MAIN_WINDOW: 'resize-main-window',
CLOSE_CURRENT_WINDOW: 'close-current-window',
MINIMIZE_CURRENT_WINDOW: 'minimize-current-window',
DOWNLOAD_UPDATE: 'download-update',
INSTALL_UPDATE: 'install-update',
};
// ipcRenderer.invoke(...)
export const IPC_ACTIONS = {
TOGGLE_MAXIMIZE_CURRENT_WINDOW: 'toggle-maximize-current-window',
GET_OPEN_FILEPATH: 'open-dialog',
GET_SAVE_FILEPATH: 'save-dialog',
GET_DIALOG_RESPONSE: 'show-message-box',
GET_PRIMARY_DISPLAY_SIZE: 'get-primary-display-size',
SAVE_HTML_AS_PDF: 'save-html-as-pdf',
SAVE_DATA: 'save-data',
SHOW_ERROR: 'show-error',
SEND_ERROR: 'send-error',
GET_LANGUAGE_MAP: 'get-language-map',
CHECK_FOR_UPDATES: 'check-for-updates',
GET_FILE: 'get-file',
GET_CREDS: 'get-creds',
GET_VERSION: 'get-version',
};
// ipcMain.send(...)
export const IPC_CHANNELS = {
STORE_ON_WINDOW: 'store-on-window',
CHECKING_FOR_UPDATE: 'checking-for-update',
UPDATE_AVAILABLE: 'update-available',
UPDATE_NOT_AVAILABLE: 'update-not-available',
UPDATE_DOWNLOADED: 'update-downloaded',
UPDATE_ERROR: 'update-error',
};
export const DB_CONN_FAILURE = {
INVALID_FILE: 'invalid-file',
CANT_OPEN: 'cant-open',
CANT_CONNECT: 'cant-connect',
};

View File

@ -343,7 +343,7 @@ import FeatherIcon from '@/components/FeatherIcon.vue';
import HowTo from '@/components/HowTo.vue';
import PageHeader from '@/components/PageHeader.vue';
import { importable, Importer } from '@/dataImport';
import { IPC_ACTIONS } from '@/messages';
import { IPC_ACTIONS } from 'utils/messages';
import { getSavePath, saveData, showMessageDialog } from '@/utils';
import { ipcRenderer } from 'electron';
import frappe from 'frappe';

View File

@ -165,7 +165,7 @@ import { ipcRenderer } from 'electron';
import fs from 'fs';
import { DateTime } from 'luxon';
import { showErrorDialog } from '../errorHandling';
import { DB_CONN_FAILURE, IPC_ACTIONS } from '../messages';
import { DB_CONN_FAILURE, IPC_ACTIONS } from '../../utils/messages';
export default {
name: 'DatabaseSelector',

View File

@ -87,7 +87,7 @@
import Button from '@/components/Button';
import Icon from '@/components/Icon';
import PageHeader from '@/components/PageHeader';
import { IPC_MESSAGES } from '@/messages';
import { IPC_MESSAGES } from 'utils/messages';
import { openSettings, routeTo } from '@/utils';
import { ipcRenderer } from 'electron';
import frappe, { t } from 'frappe';

View File

@ -56,7 +56,7 @@ import Button from '@/components/Button';
import PageHeader from '@/components/PageHeader';
import SearchBar from '@/components/SearchBar';
import TwoColumnForm from '@/components/TwoColumnForm';
import { IPC_ACTIONS } from '@/messages';
import { IPC_ACTIONS } from 'utils/messages';
import telemetry from '@/telemetry/telemetry';
import { Verb } from '@/telemetry/types';
import { makePDF } from '@/utils';

View File

@ -66,7 +66,7 @@ import { callInitializeMoneyMaker } from '../../utils';
import { showToast } from '../../utils';
import { h, markRaw } from 'vue';
import { ipcRenderer } from 'electron';
import { IPC_MESSAGES } from '@/messages';
import { IPC_MESSAGES } from 'utils/messages';
export default {
name: 'Settings',

View File

@ -50,7 +50,7 @@ import frappe from 'frappe';
import { ipcRenderer } from 'electron';
import TwoColumnForm from '@/components/TwoColumnForm';
import FormControl from '@/components/Controls/FormControl';
import { IPC_ACTIONS } from '@/messages';
import { IPC_ACTIONS } from 'utils/messages';
export default {
name: 'TabInvoice',

View File

@ -95,7 +95,7 @@ import Popover from '@/components/Popover';
import TwoColumnForm from '@/components/TwoColumnForm';
import config from '@/config';
import { connectToLocalDatabase, purgeCache } from '@/initialization';
import { IPC_MESSAGES } from '@/messages';
import { IPC_MESSAGES } from 'utils/messages';
import { setLanguageMap, showMessageDialog } from '@/utils';
import { ipcRenderer } from 'electron';
import frappe from 'frappe';

View File

@ -1,5 +1,5 @@
import { handleError } from '@/errorHandling';
import { IPC_CHANNELS, IPC_MESSAGES } from '@/messages';
import { IPC_CHANNELS, IPC_MESSAGES } from 'utils/messages';
import telemetry from '@/telemetry/telemetry';
import { showToast } from '@/utils';
import { ipcRenderer } from 'electron';

View File

@ -1,5 +1,5 @@
import config, { ConfigFile, ConfigKeys, TelemetrySetting } from '@/config';
import { IPC_ACTIONS } from '@/messages';
import { IPC_ACTIONS } from 'utils/messages';
import { ipcRenderer } from 'electron';
import frappe, { t } from 'frappe';
import { DoctypeName } from '../../models/types';

View File

@ -6,11 +6,11 @@ import frappe, { t } from 'frappe';
import { isPesa } from 'frappe/utils';
import { DEFAULT_LANGUAGE } from 'frappe/utils/consts';
import { setLanguageMapOnTranslationString } from 'frappe/utils/translation';
import { IPC_ACTIONS, IPC_MESSAGES } from 'utils/messages';
import { createApp, h } from 'vue';
import config from './config';
import { handleErrorWithDialog } from './errorHandling';
import { languageCodeMap } from './languageCodeMap';
import { IPC_ACTIONS, IPC_MESSAGES } from './messages';
export async function showMessageDialog({
message,

51
utils/messages.ts Normal file
View File

@ -0,0 +1,51 @@
// ipcRenderer.send(...)
export enum IPC_MESSAGES {
OPEN_MENU = 'open-menu',
OPEN_SETTINGS = 'open-settings',
OPEN_EXTERNAL = 'open-external',
SHOW_ITEM_IN_FOLDER = 'show-item-in-folder',
RELOAD_MAIN_WINDOW = 'reload-main-window',
RESIZE_MAIN_WINDOW = 'resize-main-window',
CLOSE_CURRENT_WINDOW = 'close-current-window',
MINIMIZE_CURRENT_WINDOW = 'minimize-current-window',
DOWNLOAD_UPDATE = 'download-update',
INSTALL_UPDATE = 'install-update',
}
// ipcRenderer.invoke(...)
export enum IPC_ACTIONS {
TOGGLE_MAXIMIZE_CURRENT_WINDOW = 'toggle-maximize-current-window',
GET_OPEN_FILEPATH = 'open-dialog',
GET_SAVE_FILEPATH = 'save-dialog',
GET_DIALOG_RESPONSE = 'show-message-box',
GET_PRIMARY_DISPLAY_SIZE = 'get-primary-display-size',
SAVE_HTML_AS_PDF = 'save-html-as-pdf',
SAVE_DATA = 'save-data',
SHOW_ERROR = 'show-error',
SEND_ERROR = 'send-error',
GET_LANGUAGE_MAP = 'get-language-map',
CHECK_FOR_UPDATES = 'check-for-updates',
GET_FILE = 'get-file',
GET_CREDS = 'get-creds',
GET_VERSION = 'get-version',
// Database messages
DB_CREATE = 'db-create',
DB_CONNECT = 'db-connect',
DB_CALL = 'db-call',
}
// ipcMain.send(...)
export enum IPC_CHANNELS {
STORE_ON_WINDOW = 'store-on-window',
CHECKING_FOR_UPDATE = 'checking-for-update',
UPDATE_AVAILABLE = 'update-available',
UPDATE_NOT_AVAILABLE = 'update-not-available',
UPDATE_DOWNLOADED = 'update-downloaded',
UPDATE_ERROR = 'update-error',
}
export enum DB_CONN_FAILURE {
INVALID_FILE = 'invalid-file',
CANT_OPEN = 'cant-open',
CANT_CONNECT = 'cant-connect',
}

View File

@ -4,6 +4,7 @@ const webpack = require('webpack');
module.exports = {
pluginOptions: {
electronBuilder: {
externals: ['knex', 'sqlite3'],
nodeIntegration: true,
mainProcessFile: 'main.ts',
// rendererProcessFile: 'src/renderer.js',