mirror of
https://github.com/frappe/books.git
synced 2024-12-22 02:49:03 +00:00
chore: fix all fixable eslint errors in main and main.ts
This commit is contained in:
parent
e67e6ae257
commit
f2b620f256
9
main.ts
9
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)
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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',
|
||||
|
@ -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 () => {
|
||||
|
@ -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) => {
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user