mirror of
https://github.com/frappe/books.git
synced 2024-11-08 14:50:56 +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 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 { emitMainProcessError } from 'backend/helpers';
|
||||||
|
|
||||||
export class Main {
|
export class Main {
|
||||||
title = 'Frappe Books';
|
title = 'Frappe Books';
|
||||||
@ -121,7 +122,7 @@ export class Main {
|
|||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
createWindow() {
|
async createWindow() {
|
||||||
const options = this.getOptions();
|
const options = this.getOptions();
|
||||||
this.mainWindow = new BrowserWindow(options);
|
this.mainWindow = new BrowserWindow(options);
|
||||||
|
|
||||||
@ -131,7 +132,7 @@ export class Main {
|
|||||||
this.registerAppProtocol();
|
this.registerAppProtocol();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.mainWindow.loadURL(this.winURL);
|
await this.mainWindow.loadURL(this.winURL);
|
||||||
if (this.isDevelopment && !this.isTest) {
|
if (this.isDevelopment && !this.isTest) {
|
||||||
this.mainWindow.webContents.openDevTools();
|
this.mainWindow.webContents.openDevTools();
|
||||||
}
|
}
|
||||||
@ -169,7 +170,9 @@ export class Main {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.mainWindow.webContents.on('did-fail-load', () => {
|
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)) {
|
if (!fs.existsSync(errLogCredsPath)) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
!inProduction && console.log(`${errLogCredsPath} doesn't exist, can't log`);
|
!inProduction && console.log(`${errLogCredsPath} doesn't exist, can't log`);
|
||||||
return empty;
|
return empty;
|
||||||
}
|
}
|
||||||
@ -30,7 +31,9 @@ export function getUrlAndTokenString(): Creds {
|
|||||||
.filter((f) => f.length);
|
.filter((f) => f.length);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (!inProduction) {
|
if (!inProduction) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
console.log(`logging error using creds at: ${errLogCredsPath} failed`);
|
console.log(`logging error using creds at: ${errLogCredsPath} failed`);
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
return empty;
|
return empty;
|
||||||
|
@ -2,6 +2,7 @@ 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';
|
import { rendererLog } from './helpers';
|
||||||
|
import { emitMainProcessError } from 'backend/helpers';
|
||||||
|
|
||||||
export default function registerAppLifecycleListeners(main: Main) {
|
export default function registerAppLifecycleListeners(main: Main) {
|
||||||
app.on('window-all-closed', () => {
|
app.on('window-all-closed', () => {
|
||||||
@ -12,16 +13,16 @@ export default function registerAppLifecycleListeners(main: Main) {
|
|||||||
|
|
||||||
app.on('activate', () => {
|
app.on('activate', () => {
|
||||||
if (main.mainWindow === null) {
|
if (main.mainWindow === null) {
|
||||||
main.createWindow();
|
main.createWindow().catch((err) => emitMainProcessError(err));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.on('ready', async () => {
|
app.on('ready', () => {
|
||||||
if (main.isDevelopment && !main.isTest) {
|
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);
|
emitMainProcessError(error);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||||
autoUpdater.on('update-available', async (info: UpdateInfo) => {
|
autoUpdater.on('update-available', async (info: UpdateInfo) => {
|
||||||
const currentVersion = app.getVersion();
|
const currentVersion = app.getVersion();
|
||||||
const nextVersion = info.version;
|
const nextVersion = info.version;
|
||||||
@ -46,6 +47,7 @@ export default function registerAutoUpdaterListeners(main: Main) {
|
|||||||
await autoUpdater.downloadUpdate();
|
await autoUpdater.downloadUpdate();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||||
autoUpdater.on('update-downloaded', async () => {
|
autoUpdater.on('update-downloaded', async () => {
|
||||||
const option = await dialog.showMessageBox({
|
const option = await dialog.showMessageBox({
|
||||||
type: 'info',
|
type: 'info',
|
||||||
|
@ -79,8 +79,8 @@ export default function registerIpcMainActionListeners(main: Main) {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
ipcMain.handle(IPC_ACTIONS.SEND_ERROR, (_, bodyJson: string) => {
|
ipcMain.handle(IPC_ACTIONS.SEND_ERROR, async (_, bodyJson: string) => {
|
||||||
sendError(bodyJson, main);
|
await sendError(bodyJson, main);
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle(IPC_ACTIONS.CHECK_FOR_UPDATES, async () => {
|
ipcMain.handle(IPC_ACTIONS.CHECK_FOR_UPDATES, async () => {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { ipcMain, Menu, shell } from 'electron';
|
import { ipcMain, Menu, shell } from 'electron';
|
||||||
import { Main } from '../main';
|
import { Main } from '../main';
|
||||||
import { IPC_MESSAGES } from '../utils/messages';
|
import { IPC_MESSAGES } from '../utils/messages';
|
||||||
|
import { emitMainProcessError } from 'backend/helpers';
|
||||||
|
|
||||||
export default function registerIpcMainMessageListeners(main: Main) {
|
export default function registerIpcMainMessageListeners(main: Main) {
|
||||||
ipcMain.on(IPC_MESSAGES.OPEN_MENU, (event) => {
|
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) => {
|
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) => {
|
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 { App, BrowserWindow } from 'electron';
|
||||||
import fs from 'fs/promises';
|
import fs from 'fs/promises';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
@ -18,7 +19,7 @@ export async function saveHtmlAsPdf(
|
|||||||
const htmlPath = path.join(tempRoot, `${filename}.html`);
|
const htmlPath = path.join(tempRoot, `${filename}.html`);
|
||||||
await fs.writeFile(htmlPath, html, { encoding: 'utf-8' });
|
await fs.writeFile(htmlPath, html, { encoding: 'utf-8' });
|
||||||
|
|
||||||
const printWindow = getInitializedPrintWindow(htmlPath, width, height);
|
const printWindow = await getInitializedPrintWindow(htmlPath, width, height);
|
||||||
const printOptions = {
|
const printOptions = {
|
||||||
marginsType: 1, // no margin
|
marginsType: 1, // no margin
|
||||||
pageSize: {
|
pageSize: {
|
||||||
@ -36,19 +37,26 @@ export async function saveHtmlAsPdf(
|
|||||||
*/
|
*/
|
||||||
return await new Promise((resolve) => {
|
return await new Promise((resolve) => {
|
||||||
printWindow.webContents.once('did-finish-load', () => {
|
printWindow.webContents.once('did-finish-load', () => {
|
||||||
printWindow.webContents.printToPDF(printOptions).then((data) => {
|
printWindow.webContents
|
||||||
fs.writeFile(savePath, data).then(() => {
|
.printToPDF(printOptions)
|
||||||
printWindow.close();
|
.then((data) => {
|
||||||
fs.unlink(htmlPath).then(() => {
|
fs.writeFile(savePath, data)
|
||||||
resolve(true);
|
.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,
|
printFilePath: string,
|
||||||
width: number,
|
width: number,
|
||||||
height: number
|
height: number
|
||||||
@ -59,6 +67,6 @@ function getInitializedPrintWindow(
|
|||||||
show: false,
|
show: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
printWindow.loadFile(printFilePath);
|
await printWindow.loadFile(printFilePath);
|
||||||
return printWindow;
|
return printWindow;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user