mirror of
https://github.com/frappe/books.git
synced 2025-01-05 08:02:15 +00:00
incr: circumv window reload issue
This commit is contained in:
parent
8116bd097a
commit
12f4162162
11
main.ts
11
main.ts
@ -15,7 +15,6 @@ import registerAutoUpdaterListeners from './main/registerAutoUpdaterListeners';
|
|||||||
import registerIpcMainActionListeners from './main/registerIpcMainActionListeners';
|
import registerIpcMainActionListeners from './main/registerIpcMainActionListeners';
|
||||||
import registerIpcMainMessageListeners from './main/registerIpcMainMessageListeners';
|
import registerIpcMainMessageListeners from './main/registerIpcMainMessageListeners';
|
||||||
import registerProcessListeners from './main/registerProcessListeners';
|
import registerProcessListeners from './main/registerProcessListeners';
|
||||||
import { IPC_CHANNELS } from './utils/messages';
|
|
||||||
|
|
||||||
export class Main {
|
export class Main {
|
||||||
title: string = 'Frappe Books';
|
title: string = 'Frappe Books';
|
||||||
@ -54,6 +53,10 @@ export class Main {
|
|||||||
return process.env.NODE_ENV !== 'production';
|
return process.env.NODE_ENV !== 'production';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get isTest() {
|
||||||
|
return !!process.env.IS_TEST;
|
||||||
|
}
|
||||||
|
|
||||||
get isMac() {
|
get isMac() {
|
||||||
return process.platform === 'darwin';
|
return process.platform === 'darwin';
|
||||||
}
|
}
|
||||||
@ -119,7 +122,7 @@ export class Main {
|
|||||||
this.winURL = process.env.WEBPACK_DEV_SERVER_URL as string;
|
this.winURL = process.env.WEBPACK_DEV_SERVER_URL as string;
|
||||||
this.mainWindow!.loadURL(this.winURL);
|
this.mainWindow!.loadURL(this.winURL);
|
||||||
|
|
||||||
if (!process.env.IS_TEST) {
|
if (this.isDevelopment && !this.isTest) {
|
||||||
this.mainWindow!.webContents.openDevTools();
|
this.mainWindow!.webContents.openDevTools();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -139,6 +142,10 @@ export class Main {
|
|||||||
this.mainWindow.on('closed', () => {
|
this.mainWindow.on('closed', () => {
|
||||||
this.mainWindow = null;
|
this.mainWindow = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.mainWindow.webContents.on('did-fail-load', () => {
|
||||||
|
this.mainWindow!.loadURL(this.winURL);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
import { constants } from 'fs';
|
import { constants } from 'fs';
|
||||||
import fs from 'fs/promises';
|
import fs from 'fs/promises';
|
||||||
import { ConfigFile, ConfigKeys } from 'fyo/core/types';
|
import { ConfigFile, ConfigKeys } from 'fyo/core/types';
|
||||||
|
import { Main } from 'main';
|
||||||
import config from 'utils/config';
|
import config from 'utils/config';
|
||||||
import { DatabaseResponse } from 'utils/ipc/types';
|
import { DatabaseResponse } from 'utils/ipc/types';
|
||||||
|
import { IPC_CHANNELS } from 'utils/messages';
|
||||||
|
|
||||||
interface ConfigFilesWithModified extends ConfigFile {
|
interface ConfigFilesWithModified extends ConfigFile {
|
||||||
modified: string;
|
modified: string;
|
||||||
@ -66,3 +68,7 @@ export async function getErrorHandledReponse(func: () => Promise<unknown>) {
|
|||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function rendererLog(main: Main, ...args: unknown[]) {
|
||||||
|
main.mainWindow?.webContents.send(IPC_CHANNELS.CONSOLE_LOG, ...args);
|
||||||
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { app } from 'electron';
|
import { app } from 'electron';
|
||||||
import installExtension, { VUEJS3_DEVTOOLS } from 'electron-devtools-installer';
|
import installExtension, { VUEJS3_DEVTOOLS } from 'electron-devtools-installer';
|
||||||
import { Main } from '../main';
|
import { Main } from '../main';
|
||||||
|
import { rendererLog } from './helpers';
|
||||||
|
|
||||||
export default function registerAppLifecycleListeners(main: Main) {
|
export default function registerAppLifecycleListeners(main: Main) {
|
||||||
app.on('window-all-closed', () => {
|
app.on('window-all-closed', () => {
|
||||||
@ -16,17 +17,18 @@ export default function registerAppLifecycleListeners(main: Main) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.on('ready', async () => {
|
app.on('ready', async () => {
|
||||||
if (main.isDevelopment && !process.env.IS_TEST) {
|
if (main.isDevelopment && !main.isTest) {
|
||||||
try {
|
await installDevTools(main);
|
||||||
await installExtension(VUEJS3_DEVTOOLS);
|
|
||||||
} catch (e) {
|
|
||||||
console.error(
|
|
||||||
'Vue Devtools failed to install:',
|
|
||||||
(e as Error).toString()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main.createWindow();
|
main.createWindow();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function installDevTools(main: Main) {
|
||||||
|
try {
|
||||||
|
await installExtension(VUEJS3_DEVTOOLS);
|
||||||
|
} catch (e) {
|
||||||
|
rendererLog(main, 'Vue Devtools failed to install', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -55,6 +55,8 @@ export default function registerIpcRendererListeners() {
|
|||||||
await handleError(true, error as Error);
|
await handleError(true, error as Error);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ipcRenderer.on(IPC_CHANNELS.CONSOLE_LOG, console.log);
|
||||||
|
|
||||||
document.addEventListener('visibilitychange', function () {
|
document.addEventListener('visibilitychange', function () {
|
||||||
const { visibilityState } = document;
|
const { visibilityState } = document;
|
||||||
if (visibilityState === 'visible' && !fyo.telemetry.started) {
|
if (visibilityState === 'visible' && !fyo.telemetry.started) {
|
||||||
|
@ -44,6 +44,7 @@ export enum IPC_CHANNELS {
|
|||||||
UPDATE_DOWNLOADED = 'update-downloaded',
|
UPDATE_DOWNLOADED = 'update-downloaded',
|
||||||
UPDATE_ERROR = 'update-error',
|
UPDATE_ERROR = 'update-error',
|
||||||
MAIN_PROCESS_ERROR = 'main-process-error',
|
MAIN_PROCESS_ERROR = 'main-process-error',
|
||||||
|
CONSOLE_LOG = 'console-log',
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum DB_CONN_FAILURE {
|
export enum DB_CONN_FAILURE {
|
||||||
|
Loading…
Reference in New Issue
Block a user