2
0
mirror of https://github.com/frappe/books.git synced 2024-11-08 14:50:56 +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 = 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();
});
ipcMain.handle(IPC_ACTIONS.GET_VERSION, (_) => {
return app.getVersion();
});
ipcMain.handle(IPC_ACTIONS.DELETE_FILE, async (_, filePath) => {
await fs.unlink(filePath);
});
@ -129,6 +125,14 @@ export default function registerIpcMainActionListeners(main: Main) {
return await getConfigFilesWithModified(files);
});
ipcMain.handle(IPC_ACTIONS.GET_ENV, async (_) => {
return {
isDevelopment: main.isDevelopment,
platform: process.platform,
version: app.getVersion(),
};
});
/**
* Database Related Actions
*/

View File

@ -1,4 +1,5 @@
import { app } from 'electron';
import { IPC_CHANNELS } from 'utils/messages';
import { Main } from '../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) {
return;
}
@ -38,10 +38,9 @@ async function reportError(errorLogObj: ErrorLog, cb?: Function) {
}
await ipcRenderer.invoke(IPC_ACTIONS.SEND_ERROR, JSON.stringify(body));
cb?.();
}
function getToastProps(errorLogObj: ErrorLog, cb?: Function) {
function getToastProps(errorLogObj: ErrorLog) {
const props: ToastOptions = {
message: errorLogObj.name ?? t`Error`,
type: 'error',
@ -68,8 +67,7 @@ export function getErrorLogObject(
export async function handleError(
shouldLog: boolean,
error: Error,
more?: Record<string, unknown>,
cb?: Function
more?: Record<string, unknown>
) {
if (shouldLog) {
console.error(error);
@ -81,8 +79,8 @@ export async function handleError(
const errorLogObj = getErrorLogObject(error, more ?? {});
await reportError(errorLogObj, cb);
const toastProps = getToastProps(errorLogObj, cb);
await reportError(errorLogObj);
const toastProps = getToastProps(errorLogObj);
await showToast(toastProps);
}

View File

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

View File

@ -5,10 +5,6 @@ import { showToast } from 'src/utils/ui';
import { IPC_CHANNELS, IPC_MESSAGES } from 'utils/messages';
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, (_) => {
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';
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 () {

View File

@ -17,6 +17,7 @@ export enum IPC_ACTIONS {
GET_OPEN_FILEPATH = 'open-dialog',
GET_SAVE_FILEPATH = 'save-dialog',
GET_DIALOG_RESPONSE = 'show-message-box',
GET_ENV = 'get-env',
SAVE_HTML_AS_PDF = 'save-html-as-pdf',
SAVE_DATA = 'save-data',
SHOW_ERROR = 'show-error',
@ -25,7 +26,6 @@ export enum IPC_ACTIONS {
CHECK_FOR_UPDATES = 'check-for-updates',
GET_FILE = 'get-file',
GET_CREDS = 'get-creds',
GET_VERSION = 'get-version',
GET_DB_LIST = 'get-db-list',
DELETE_FILE = 'delete-file',
// Database messages
@ -38,12 +38,12 @@ export enum IPC_ACTIONS {
// 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',
MAIN_PROCESS_ERROR = 'main-process-error',
}
export enum DB_CONN_FAILURE {