2
0
mirror of https://github.com/frappe/books.git synced 2025-01-08 17:24:05 +00:00

incr: shift process out of src/**

This commit is contained in:
18alantom 2022-05-27 13:20:14 +05:30 committed by Alan
parent cda198bc69
commit 8116bd097a
7 changed files with 52 additions and 52 deletions

10
main.ts
View File

@ -139,16 +139,6 @@ export class Main {
this.mainWindow.on('closed', () => { this.mainWindow.on('closed', () => {
this.mainWindow = null; this.mainWindow = null;
}); });
this.mainWindow.webContents.on('did-finish-load', () => {
if (this.mainWindow === null) {
return;
}
this.mainWindow.webContents.send(IPC_CHANNELS.STORE_ON_WINDOW, {
isDevelopment: this.isDevelopment,
});
});
} }
} }

View File

@ -116,10 +116,6 @@ export default function registerIpcMainActionListeners(main: Main) {
return await getUrlAndTokenString(); return await getUrlAndTokenString();
}); });
ipcMain.handle(IPC_ACTIONS.GET_VERSION, (_) => {
return app.getVersion();
});
ipcMain.handle(IPC_ACTIONS.DELETE_FILE, async (_, filePath) => { ipcMain.handle(IPC_ACTIONS.DELETE_FILE, async (_, filePath) => {
await fs.unlink(filePath); await fs.unlink(filePath);
}); });
@ -129,6 +125,14 @@ export default function registerIpcMainActionListeners(main: Main) {
return await getConfigFilesWithModified(files); return await getConfigFilesWithModified(files);
}); });
ipcMain.handle(IPC_ACTIONS.GET_ENV, async (_) => {
return {
isDevelopment: main.isDevelopment,
platform: process.platform,
version: app.getVersion(),
};
});
/** /**
* Database Related Actions * Database Related Actions
*/ */

View File

@ -1,4 +1,5 @@
import { app } from 'electron'; import { app } from 'electron';
import { IPC_CHANNELS } from 'utils/messages';
import { Main } from '../main'; import { Main } from '../main';
export default function registerProcessListeners(main: Main) { export default function registerProcessListeners(main: Main) {
@ -15,4 +16,13 @@ export default function registerProcessListeners(main: Main) {
}); });
} }
} }
process.on('unhandledRejection', (error) => {
main.mainWindow!.webContents.send(IPC_CHANNELS.MAIN_PROCESS_ERROR, error);
});
process.on('uncaughtException', (error) => {
main.mainWindow!.webContents.send(IPC_CHANNELS.MAIN_PROCESS_ERROR, error);
setTimeout(() => process.exit(1), 10000);
});
} }

View File

@ -21,7 +21,7 @@ function shouldNotStore(error: Error) {
); );
} }
async function reportError(errorLogObj: ErrorLog, cb?: Function) { async function reportError(errorLogObj: ErrorLog) {
if (!errorLogObj.stack) { if (!errorLogObj.stack) {
return; return;
} }
@ -38,10 +38,9 @@ async function reportError(errorLogObj: ErrorLog, cb?: Function) {
} }
await ipcRenderer.invoke(IPC_ACTIONS.SEND_ERROR, JSON.stringify(body)); await ipcRenderer.invoke(IPC_ACTIONS.SEND_ERROR, JSON.stringify(body));
cb?.();
} }
function getToastProps(errorLogObj: ErrorLog, cb?: Function) { function getToastProps(errorLogObj: ErrorLog) {
const props: ToastOptions = { const props: ToastOptions = {
message: errorLogObj.name ?? t`Error`, message: errorLogObj.name ?? t`Error`,
type: 'error', type: 'error',
@ -68,8 +67,7 @@ export function getErrorLogObject(
export async function handleError( export async function handleError(
shouldLog: boolean, shouldLog: boolean,
error: Error, error: Error,
more?: Record<string, unknown>, more?: Record<string, unknown>
cb?: Function
) { ) {
if (shouldLog) { if (shouldLog) {
console.error(error); console.error(error);
@ -81,8 +79,8 @@ export async function handleError(
const errorLogObj = getErrorLogObject(error, more ?? {}); const errorLogObj = getErrorLogObject(error, more ?? {});
await reportError(errorLogObj, cb); await reportError(errorLogObj);
const toastProps = getToastProps(errorLogObj, cb); const toastProps = getToastProps(errorLogObj);
await showToast(toastProps); await showToast(toastProps);
} }

View File

@ -2,7 +2,6 @@ import { ipcRenderer } from 'electron';
import { ConfigKeys } from 'fyo/core/types'; import { ConfigKeys } from 'fyo/core/types';
import { DateTime } from 'luxon'; import { DateTime } from 'luxon';
import { IPC_ACTIONS } from 'utils/messages'; import { IPC_ACTIONS } from 'utils/messages';
import { Version } from 'utils/version';
import { App as VueApp, createApp } from 'vue'; import { App as VueApp, createApp } from 'vue';
import App from './App.vue'; import App from './App.vue';
import Badge from './components/Badge.vue'; import Badge from './components/Badge.vue';
@ -21,12 +20,18 @@ import { setLanguageMap } from './utils/language';
await setLanguageMap(language); await setLanguageMap(language);
} }
setOnWindow();
ipcRenderer.send = getErrorHandled(ipcRenderer.send); ipcRenderer.send = getErrorHandled(ipcRenderer.send);
ipcRenderer.invoke = getErrorHandled(ipcRenderer.invoke); ipcRenderer.invoke = getErrorHandled(ipcRenderer.invoke);
registerIpcRendererListeners(); registerIpcRendererListeners();
const { isDevelopment, platform, version } = (await ipcRenderer.invoke(
IPC_ACTIONS.GET_ENV
)) as { isDevelopment: boolean; platform: string; version: string };
fyo.store.isDevelopment = isDevelopment;
fyo.store.appVersion = version;
setOnWindow(isDevelopment);
const app = createApp({ const app = createApp({
template: '<App/>', template: '<App/>',
@ -45,7 +50,7 @@ import { setLanguageMap } from './utils/language';
return fyo; return fyo;
}, },
platform() { platform() {
switch (process.platform) { switch (platform) {
case 'win32': case 'win32':
return 'Windows'; return 'Windows';
case 'darwin': case 'darwin':
@ -63,7 +68,6 @@ import { setLanguageMap } from './utils/language';
}, },
}); });
fyo.store.appVersion = await ipcRenderer.invoke(IPC_ACTIONS.GET_VERSION);
app.mount('body'); app.mount('body');
})(); })();
@ -88,25 +92,17 @@ function setErrorHandlers(app: VueApp) {
handleError(false, err as Error, more); handleError(false, err as Error, more);
console.error(err, vm, info); console.error(err, vm, info);
}; };
process.on('unhandledRejection', (error) => {
handleError(true, error as Error);
});
process.on('uncaughtException', (error) => {
handleError(true, error, {}, () => process.exit(1));
});
} }
function setOnWindow() { function setOnWindow(isDevelopment: boolean) {
if (process.env.NODE_ENV === 'development') { if (!isDevelopment) {
return;
}
// @ts-ignore // @ts-ignore
window.router = router; window.router = router;
// @ts-ignore // @ts-ignore
window.fyo = fyo; window.fyo = fyo;
// @ts-ignore // @ts-ignore
window.DateTime = DateTime; window.DateTime = DateTime;
// @ts-ignore
window.Version = Version;
}
} }

View File

@ -5,10 +5,6 @@ import { showToast } from 'src/utils/ui';
import { IPC_CHANNELS, IPC_MESSAGES } from 'utils/messages'; import { IPC_CHANNELS, IPC_MESSAGES } from 'utils/messages';
export default function registerIpcRendererListeners() { export default function registerIpcRendererListeners() {
ipcRenderer.on(IPC_CHANNELS.STORE_ON_WINDOW, (event, message) => {
Object.assign(fyo.store, message);
});
ipcRenderer.on(IPC_CHANNELS.CHECKING_FOR_UPDATE, (_) => { ipcRenderer.on(IPC_CHANNELS.CHECKING_FOR_UPDATE, (_) => {
showToast({ message: fyo.t`Checking for updates` }); showToast({ message: fyo.t`Checking for updates` });
}); });
@ -48,9 +44,15 @@ export default function registerIpcRendererListeners() {
}); });
}); });
ipcRenderer.on(IPC_CHANNELS.UPDATE_ERROR, (_, error) => { ipcRenderer.on(IPC_CHANNELS.UPDATE_ERROR, async (_, error) => {
error.name = 'Updation Error'; error.name = 'Updation Error';
handleError(true, error); await handleError(true, error as Error);
});
ipcRenderer.on(IPC_CHANNELS.MAIN_PROCESS_ERROR, async (_, error) => {
console.error('main process error');
console.error(error);
await handleError(true, error as Error);
}); });
document.addEventListener('visibilitychange', function () { document.addEventListener('visibilitychange', function () {

View File

@ -17,6 +17,7 @@ export enum IPC_ACTIONS {
GET_OPEN_FILEPATH = 'open-dialog', GET_OPEN_FILEPATH = 'open-dialog',
GET_SAVE_FILEPATH = 'save-dialog', GET_SAVE_FILEPATH = 'save-dialog',
GET_DIALOG_RESPONSE = 'show-message-box', GET_DIALOG_RESPONSE = 'show-message-box',
GET_ENV = 'get-env',
SAVE_HTML_AS_PDF = 'save-html-as-pdf', SAVE_HTML_AS_PDF = 'save-html-as-pdf',
SAVE_DATA = 'save-data', SAVE_DATA = 'save-data',
SHOW_ERROR = 'show-error', SHOW_ERROR = 'show-error',
@ -25,7 +26,6 @@ export enum IPC_ACTIONS {
CHECK_FOR_UPDATES = 'check-for-updates', CHECK_FOR_UPDATES = 'check-for-updates',
GET_FILE = 'get-file', GET_FILE = 'get-file',
GET_CREDS = 'get-creds', GET_CREDS = 'get-creds',
GET_VERSION = 'get-version',
GET_DB_LIST = 'get-db-list', GET_DB_LIST = 'get-db-list',
DELETE_FILE = 'delete-file', DELETE_FILE = 'delete-file',
// Database messages // Database messages
@ -38,12 +38,12 @@ export enum IPC_ACTIONS {
// ipcMain.send(...) // ipcMain.send(...)
export enum IPC_CHANNELS { export enum IPC_CHANNELS {
STORE_ON_WINDOW = 'store-on-window',
CHECKING_FOR_UPDATE = 'checking-for-update', CHECKING_FOR_UPDATE = 'checking-for-update',
UPDATE_AVAILABLE = 'update-available', UPDATE_AVAILABLE = 'update-available',
UPDATE_NOT_AVAILABLE = 'update-not-available', UPDATE_NOT_AVAILABLE = 'update-not-available',
UPDATE_DOWNLOADED = 'update-downloaded', UPDATE_DOWNLOADED = 'update-downloaded',
UPDATE_ERROR = 'update-error', UPDATE_ERROR = 'update-error',
MAIN_PROCESS_ERROR = 'main-process-error',
} }
export enum DB_CONN_FAILURE { export enum DB_CONN_FAILURE {