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

incr: circumv window reload issue

This commit is contained in:
18alantom 2022-05-27 14:00:25 +05:30 committed by Alan
parent 8116bd097a
commit 12f4162162
5 changed files with 29 additions and 11 deletions

11
main.ts
View File

@ -15,7 +15,6 @@ import registerAutoUpdaterListeners from './main/registerAutoUpdaterListeners';
import registerIpcMainActionListeners from './main/registerIpcMainActionListeners';
import registerIpcMainMessageListeners from './main/registerIpcMainMessageListeners';
import registerProcessListeners from './main/registerProcessListeners';
import { IPC_CHANNELS } from './utils/messages';
export class Main {
title: string = 'Frappe Books';
@ -54,6 +53,10 @@ export class Main {
return process.env.NODE_ENV !== 'production';
}
get isTest() {
return !!process.env.IS_TEST;
}
get isMac() {
return process.platform === 'darwin';
}
@ -119,7 +122,7 @@ export class Main {
this.winURL = process.env.WEBPACK_DEV_SERVER_URL as string;
this.mainWindow!.loadURL(this.winURL);
if (!process.env.IS_TEST) {
if (this.isDevelopment && !this.isTest) {
this.mainWindow!.webContents.openDevTools();
}
}
@ -139,6 +142,10 @@ export class Main {
this.mainWindow.on('closed', () => {
this.mainWindow = null;
});
this.mainWindow.webContents.on('did-fail-load', () => {
this.mainWindow!.loadURL(this.winURL);
});
}
}

View File

@ -1,8 +1,10 @@
import { constants } from 'fs';
import fs from 'fs/promises';
import { ConfigFile, ConfigKeys } from 'fyo/core/types';
import { Main } from 'main';
import config from 'utils/config';
import { DatabaseResponse } from 'utils/ipc/types';
import { IPC_CHANNELS } from 'utils/messages';
interface ConfigFilesWithModified extends ConfigFile {
modified: string;
@ -66,3 +68,7 @@ export async function getErrorHandledReponse(func: () => Promise<unknown>) {
return response;
}
export function rendererLog(main: Main, ...args: unknown[]) {
main.mainWindow?.webContents.send(IPC_CHANNELS.CONSOLE_LOG, ...args);
}

View File

@ -1,6 +1,7 @@
import { app } from 'electron';
import installExtension, { VUEJS3_DEVTOOLS } from 'electron-devtools-installer';
import { Main } from '../main';
import { rendererLog } from './helpers';
export default function registerAppLifecycleListeners(main: Main) {
app.on('window-all-closed', () => {
@ -16,17 +17,18 @@ export default function registerAppLifecycleListeners(main: Main) {
});
app.on('ready', async () => {
if (main.isDevelopment && !process.env.IS_TEST) {
try {
await installExtension(VUEJS3_DEVTOOLS);
} catch (e) {
console.error(
'Vue Devtools failed to install:',
(e as Error).toString()
);
}
if (main.isDevelopment && !main.isTest) {
await installDevTools(main);
}
main.createWindow();
});
}
async function installDevTools(main: Main) {
try {
await installExtension(VUEJS3_DEVTOOLS);
} catch (e) {
rendererLog(main, 'Vue Devtools failed to install', e);
}
}

View File

@ -55,6 +55,8 @@ export default function registerIpcRendererListeners() {
await handleError(true, error as Error);
});
ipcRenderer.on(IPC_CHANNELS.CONSOLE_LOG, console.log);
document.addEventListener('visibilitychange', function () {
const { visibilityState } = document;
if (visibilityState === 'visible' && !fyo.telemetry.started) {

View File

@ -44,6 +44,7 @@ export enum IPC_CHANNELS {
UPDATE_DOWNLOADED = 'update-downloaded',
UPDATE_ERROR = 'update-error',
MAIN_PROCESS_ERROR = 'main-process-error',
CONSOLE_LOG = 'console-log',
}
export enum DB_CONN_FAILURE {