diff --git a/main.ts b/main.ts index 36b4a6c2..a74b9df8 100644 --- a/main.ts +++ b/main.ts @@ -21,6 +21,7 @@ import registerAutoUpdaterListeners from './main/registerAutoUpdaterListeners'; import registerIpcMainActionListeners from './main/registerIpcMainActionListeners'; import registerIpcMainMessageListeners from './main/registerIpcMainMessageListeners'; import registerProcessListeners from './main/registerProcessListeners'; +import { emitMainProcessError } from 'backend/helpers'; export class Main { title = 'Frappe Books'; @@ -121,7 +122,7 @@ export class Main { return options; } - createWindow() { + async createWindow() { const options = this.getOptions(); this.mainWindow = new BrowserWindow(options); @@ -131,7 +132,7 @@ export class Main { this.registerAppProtocol(); } - this.mainWindow.loadURL(this.winURL); + await this.mainWindow.loadURL(this.winURL); if (this.isDevelopment && !this.isTest) { this.mainWindow.webContents.openDevTools(); } @@ -169,7 +170,9 @@ export class Main { }); this.mainWindow.webContents.on('did-fail-load', () => { - this.mainWindow!.loadURL(this.winURL); + this.mainWindow!.loadURL(this.winURL).catch((err) => + emitMainProcessError(err) + ); }); } } diff --git a/main/contactMothership.ts b/main/contactMothership.ts index f411eb92..486d7dfe 100644 --- a/main/contactMothership.ts +++ b/main/contactMothership.ts @@ -18,6 +18,7 @@ export function getUrlAndTokenString(): Creds { } if (!fs.existsSync(errLogCredsPath)) { + // eslint-disable-next-line no-console !inProduction && console.log(`${errLogCredsPath} doesn't exist, can't log`); return empty; } @@ -30,7 +31,9 @@ export function getUrlAndTokenString(): Creds { .filter((f) => f.length); } catch (err) { if (!inProduction) { + // eslint-disable-next-line no-console console.log(`logging error using creds at: ${errLogCredsPath} failed`); + // eslint-disable-next-line no-console console.log(err); } return empty; diff --git a/main/registerAppLifecycleListeners.ts b/main/registerAppLifecycleListeners.ts index 6959e41e..588dffb6 100644 --- a/main/registerAppLifecycleListeners.ts +++ b/main/registerAppLifecycleListeners.ts @@ -2,6 +2,7 @@ import { app } from 'electron'; import installExtension, { VUEJS3_DEVTOOLS } from 'electron-devtools-installer'; import { Main } from '../main'; import { rendererLog } from './helpers'; +import { emitMainProcessError } from 'backend/helpers'; export default function registerAppLifecycleListeners(main: Main) { app.on('window-all-closed', () => { @@ -12,16 +13,16 @@ export default function registerAppLifecycleListeners(main: Main) { app.on('activate', () => { if (main.mainWindow === null) { - main.createWindow(); + main.createWindow().catch((err) => emitMainProcessError(err)); } }); - app.on('ready', async () => { + app.on('ready', () => { if (main.isDevelopment && !main.isTest) { - await installDevTools(main); + installDevTools(main).catch((err) => emitMainProcessError(err)); } - main.createWindow(); + main.createWindow().catch((err) => emitMainProcessError(err)); }); } diff --git a/main/registerAutoUpdaterListeners.ts b/main/registerAutoUpdaterListeners.ts index ac85ec86..73ada930 100644 --- a/main/registerAutoUpdaterListeners.ts +++ b/main/registerAutoUpdaterListeners.ts @@ -21,6 +21,7 @@ export default function registerAutoUpdaterListeners(main: Main) { emitMainProcessError(error); }); + // eslint-disable-next-line @typescript-eslint/no-misused-promises autoUpdater.on('update-available', async (info: UpdateInfo) => { const currentVersion = app.getVersion(); const nextVersion = info.version; @@ -46,6 +47,7 @@ export default function registerAutoUpdaterListeners(main: Main) { await autoUpdater.downloadUpdate(); }); + // eslint-disable-next-line @typescript-eslint/no-misused-promises autoUpdater.on('update-downloaded', async () => { const option = await dialog.showMessageBox({ type: 'info', diff --git a/main/registerIpcMainActionListeners.ts b/main/registerIpcMainActionListeners.ts index 7e34d979..814e8a6a 100644 --- a/main/registerIpcMainActionListeners.ts +++ b/main/registerIpcMainActionListeners.ts @@ -79,8 +79,8 @@ export default function registerIpcMainActionListeners(main: Main) { } ); - ipcMain.handle(IPC_ACTIONS.SEND_ERROR, (_, bodyJson: string) => { - sendError(bodyJson, main); + ipcMain.handle(IPC_ACTIONS.SEND_ERROR, async (_, bodyJson: string) => { + await sendError(bodyJson, main); }); ipcMain.handle(IPC_ACTIONS.CHECK_FOR_UPDATES, async () => { diff --git a/main/registerIpcMainMessageListeners.ts b/main/registerIpcMainMessageListeners.ts index c3400447..65c42039 100644 --- a/main/registerIpcMainMessageListeners.ts +++ b/main/registerIpcMainMessageListeners.ts @@ -1,6 +1,7 @@ import { ipcMain, Menu, shell } from 'electron'; import { Main } from '../main'; import { IPC_MESSAGES } from '../utils/messages'; +import { emitMainProcessError } from 'backend/helpers'; export default function registerIpcMainMessageListeners(main: Main) { ipcMain.on(IPC_MESSAGES.OPEN_MENU, (event) => { @@ -21,7 +22,7 @@ export default function registerIpcMainMessageListeners(main: Main) { }); ipcMain.on(IPC_MESSAGES.OPEN_EXTERNAL, (_, link: string) => { - shell.openExternal(link); + shell.openExternal(link).catch((err) => emitMainProcessError(err)); }); ipcMain.on(IPC_MESSAGES.SHOW_ITEM_IN_FOLDER, (_, filePath: string) => { diff --git a/main/saveHtmlAsPdf.ts b/main/saveHtmlAsPdf.ts index dbf9e422..68a075fe 100644 --- a/main/saveHtmlAsPdf.ts +++ b/main/saveHtmlAsPdf.ts @@ -1,3 +1,4 @@ +import { emitMainProcessError } from 'backend/helpers'; import { App, BrowserWindow } from 'electron'; import fs from 'fs/promises'; import path from 'path'; @@ -18,7 +19,7 @@ export async function saveHtmlAsPdf( const htmlPath = path.join(tempRoot, `${filename}.html`); await fs.writeFile(htmlPath, html, { encoding: 'utf-8' }); - const printWindow = getInitializedPrintWindow(htmlPath, width, height); + const printWindow = await getInitializedPrintWindow(htmlPath, width, height); const printOptions = { marginsType: 1, // no margin pageSize: { @@ -36,19 +37,26 @@ export async function saveHtmlAsPdf( */ return await new Promise((resolve) => { printWindow.webContents.once('did-finish-load', () => { - printWindow.webContents.printToPDF(printOptions).then((data) => { - fs.writeFile(savePath, data).then(() => { - printWindow.close(); - fs.unlink(htmlPath).then(() => { - resolve(true); - }); - }); - }); + printWindow.webContents + .printToPDF(printOptions) + .then((data) => { + fs.writeFile(savePath, data) + .then(() => { + printWindow.close(); + fs.unlink(htmlPath) + .then(() => { + resolve(true); + }) + .catch((err) => emitMainProcessError(err)); + }) + .catch((err) => emitMainProcessError(err)); + }) + .catch((err) => emitMainProcessError(err)); }); }); } -function getInitializedPrintWindow( +async function getInitializedPrintWindow( printFilePath: string, width: number, height: number @@ -59,6 +67,6 @@ function getInitializedPrintWindow( show: false, }); - printWindow.loadFile(printFilePath); + await printWindow.loadFile(printFilePath); return printWindow; }