mirror of
https://github.com/frappe/books.git
synced 2024-11-08 14:50:56 +00:00
incr: move all ipccalls to single file
This commit is contained in:
parent
6cb2fed6d7
commit
62a920ced7
@ -1,15 +1,18 @@
|
|||||||
import { t } from 'fyo';
|
import { t } from 'fyo';
|
||||||
import { Doc } from 'fyo/model/doc';
|
import type { Doc } from 'fyo/model/doc';
|
||||||
import { BaseError } from 'fyo/utils/errors';
|
import { BaseError } from 'fyo/utils/errors';
|
||||||
import { ErrorLog } from 'fyo/utils/types';
|
import { ErrorLog } from 'fyo/utils/types';
|
||||||
import { truncate } from 'lodash';
|
import { truncate } from 'lodash';
|
||||||
import { showDialog } from 'src/utils/interactive';
|
import { showDialog } from 'src/utils/interactive';
|
||||||
import { IPC_ACTIONS, IPC_MESSAGES } from 'utils/messages';
|
|
||||||
import { fyo } from './initFyo';
|
import { fyo } from './initFyo';
|
||||||
import router from './router';
|
import router from './router';
|
||||||
import { getErrorMessage, stringifyCircular } from './utils';
|
import { getErrorMessage, stringifyCircular } from './utils';
|
||||||
import { DialogOptions, ToastOptions } from './utils/types';
|
import {
|
||||||
const { ipcRenderer } = require('electron');
|
sendError as ipcSendError,
|
||||||
|
openExternalUrl,
|
||||||
|
showError,
|
||||||
|
} from './utils/ipcCalls';
|
||||||
|
import type { DialogOptions, ToastOptions } from './utils/types';
|
||||||
|
|
||||||
function shouldNotStore(error: Error) {
|
function shouldNotStore(error: Error) {
|
||||||
const shouldLog = (error as BaseError).shouldStore ?? true;
|
const shouldLog = (error as BaseError).shouldStore ?? true;
|
||||||
@ -43,7 +46,7 @@ export async function sendError(errorLogObj: ErrorLog) {
|
|||||||
console.log('sendError', body);
|
console.log('sendError', body);
|
||||||
}
|
}
|
||||||
|
|
||||||
await ipcRenderer.invoke(IPC_ACTIONS.SEND_ERROR, JSON.stringify(body));
|
await ipcSendError(JSON.stringify(body));
|
||||||
}
|
}
|
||||||
|
|
||||||
function getToastProps(errorLogObj: ErrorLog) {
|
function getToastProps(errorLogObj: ErrorLog) {
|
||||||
@ -119,7 +122,7 @@ export async function handleErrorWithDialog(
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (reportError) {
|
if (reportError) {
|
||||||
options.detail = truncate(options.detail, { length: 128 });
|
options.detail = truncate(String(options.detail), { length: 128 });
|
||||||
options.buttons = [
|
options.buttons = [
|
||||||
{
|
{
|
||||||
label: t`Report`,
|
label: t`Report`,
|
||||||
@ -154,8 +157,7 @@ export async function showErrorDialog(title?: string, content?: string) {
|
|||||||
// To be used for show stopper errors
|
// To be used for show stopper errors
|
||||||
title ??= t`Error`;
|
title ??= t`Error`;
|
||||||
content ??= t`Something has gone terribly wrong. Please check the console and raise an issue.`;
|
content ??= t`Something has gone terribly wrong. Please check the console and raise an issue.`;
|
||||||
|
await showError(title, content);
|
||||||
await ipcRenderer.invoke(IPC_ACTIONS.SHOW_ERROR, { title, content });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
@ -232,7 +234,7 @@ function getIssueUrlQuery(errorLogObj?: ErrorLog): string {
|
|||||||
|
|
||||||
export function reportIssue(errorLogObj?: ErrorLog) {
|
export function reportIssue(errorLogObj?: ErrorLog) {
|
||||||
const urlQuery = getIssueUrlQuery(errorLogObj);
|
const urlQuery = getIssueUrlQuery(errorLogObj);
|
||||||
ipcRenderer.send(IPC_MESSAGES.OPEN_EXTERNAL, urlQuery);
|
openExternalUrl(urlQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getErrorLabel(error: Error) {
|
function getErrorLabel(error: Error) {
|
||||||
|
@ -246,12 +246,15 @@ import Loading from 'src/components/Loading.vue';
|
|||||||
import Modal from 'src/components/Modal.vue';
|
import Modal from 'src/components/Modal.vue';
|
||||||
import { fyo } from 'src/initFyo';
|
import { fyo } from 'src/initFyo';
|
||||||
import { showDialog } from 'src/utils/interactive';
|
import { showDialog } from 'src/utils/interactive';
|
||||||
import { deleteDb, getSavePath, getSelectedFilePath } from 'src/utils/ipcCalls';
|
import {
|
||||||
|
deleteDb,
|
||||||
|
getDbList,
|
||||||
|
getSavePath,
|
||||||
|
getSelectedFilePath,
|
||||||
|
} from 'src/utils/ipcCalls';
|
||||||
import { updateConfigFiles } from 'src/utils/misc';
|
import { updateConfigFiles } from 'src/utils/misc';
|
||||||
import { IPC_ACTIONS } from 'utils/messages';
|
|
||||||
import type { ConfigFilesWithModified } from 'utils/types';
|
import type { ConfigFilesWithModified } from 'utils/types';
|
||||||
import { defineComponent } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
const { ipcRenderer } = require('electron');
|
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'DatabaseSelector',
|
name: 'DatabaseSelector',
|
||||||
@ -360,10 +363,7 @@ export default defineComponent({
|
|||||||
this.creatingDemo = false;
|
this.creatingDemo = false;
|
||||||
},
|
},
|
||||||
async setFiles() {
|
async setFiles() {
|
||||||
const dbList: ConfigFilesWithModified[] = await ipcRenderer.invoke(
|
const dbList = await getDbList();
|
||||||
IPC_ACTIONS.GET_DB_LIST
|
|
||||||
);
|
|
||||||
|
|
||||||
this.files = dbList?.sort(
|
this.files = dbList?.sort(
|
||||||
(a, b) => Date.parse(b.modified) - Date.parse(a.modified)
|
(a, b) => Date.parse(b.modified) - Date.parse(a.modified)
|
||||||
);
|
);
|
||||||
|
@ -1,22 +1,16 @@
|
|||||||
const { ipcRenderer } = require('electron');
|
import { CUSTOM_EVENTS } from 'utils/messages';
|
||||||
import { DateTime } from 'luxon';
|
|
||||||
import { CUSTOM_EVENTS, IPC_ACTIONS } from 'utils/messages';
|
|
||||||
import { UnexpectedLogObject } from 'utils/types';
|
import { UnexpectedLogObject } from 'utils/types';
|
||||||
import { App as VueApp, createApp } from 'vue';
|
import { App as VueApp, createApp } from 'vue';
|
||||||
import App from './App.vue';
|
import App from './App.vue';
|
||||||
import Badge from './components/Badge.vue';
|
import Badge from './components/Badge.vue';
|
||||||
import FeatherIcon from './components/FeatherIcon.vue';
|
import FeatherIcon from './components/FeatherIcon.vue';
|
||||||
import {
|
import { handleError, sendError } from './errorHandling';
|
||||||
getErrorHandled,
|
|
||||||
getErrorHandledSync,
|
|
||||||
handleError,
|
|
||||||
sendError,
|
|
||||||
} from './errorHandling';
|
|
||||||
import { fyo } from './initFyo';
|
import { fyo } from './initFyo';
|
||||||
import { outsideClickDirective } from './renderer/helpers';
|
import { outsideClickDirective } from './renderer/helpers';
|
||||||
import registerIpcRendererListeners from './renderer/registerIpcRendererListeners';
|
import registerIpcRendererListeners from './renderer/registerIpcRendererListeners';
|
||||||
import router from './router';
|
import router from './router';
|
||||||
import { stringifyCircular } from './utils';
|
import { stringifyCircular } from './utils';
|
||||||
|
import { getEnv } from './utils/ipcCalls';
|
||||||
import { setLanguageMap } from './utils/language';
|
import { setLanguageMap } from './utils/language';
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||||
@ -27,13 +21,8 @@ import { setLanguageMap } from './utils/language';
|
|||||||
}
|
}
|
||||||
fyo.store.language = language || 'English';
|
fyo.store.language = language || 'English';
|
||||||
|
|
||||||
ipcRenderer.send = getErrorHandledSync(ipcRenderer.send.bind(ipcRenderer));
|
|
||||||
ipcRenderer.invoke = getErrorHandled(ipcRenderer.invoke.bind(ipcRenderer));
|
|
||||||
|
|
||||||
registerIpcRendererListeners();
|
registerIpcRendererListeners();
|
||||||
const { isDevelopment, platform, version } = (await ipcRenderer.invoke(
|
const { isDevelopment, platform, version } = await getEnv();
|
||||||
IPC_ACTIONS.GET_ENV
|
|
||||||
)) as { isDevelopment: boolean; platform: string; version: string };
|
|
||||||
|
|
||||||
fyo.store.isDevelopment = isDevelopment;
|
fyo.store.isDevelopment = isDevelopment;
|
||||||
fyo.store.appVersion = version;
|
fyo.store.appVersion = version;
|
||||||
@ -125,10 +114,6 @@ function setOnWindow(isDevelopment: boolean) {
|
|||||||
window.router = router;
|
window.router = router;
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
window.fyo = fyo;
|
window.fyo = fyo;
|
||||||
// @ts-ignore
|
|
||||||
window.DateTime = DateTime;
|
|
||||||
// @ts-ignore
|
|
||||||
window.ipcRenderer = ipcRenderer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPlatformName(platform: string) {
|
function getPlatformName(platform: string) {
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
const { ipcRenderer } = require('electron');
|
|
||||||
import { handleError } from 'src/errorHandling';
|
import { handleError } from 'src/errorHandling';
|
||||||
import { fyo } from 'src/initFyo';
|
import { fyo } from 'src/initFyo';
|
||||||
import { IPC_CHANNELS } from 'utils/messages';
|
import {
|
||||||
|
registerConsoleLogListener,
|
||||||
|
registerMainProcessErrorListener,
|
||||||
|
} from 'src/utils/ipcCalls';
|
||||||
|
|
||||||
export default function registerIpcRendererListeners() {
|
export default function registerIpcRendererListeners() {
|
||||||
ipcRenderer.on(
|
registerMainProcessErrorListener(
|
||||||
IPC_CHANNELS.LOG_MAIN_PROCESS_ERROR,
|
|
||||||
(_, error: unknown, more?: Record<string, unknown>) => {
|
(_, error: unknown, more?: Record<string, unknown>) => {
|
||||||
if (!(error instanceof Error)) {
|
if (!(error instanceof Error)) {
|
||||||
throw error;
|
throw error;
|
||||||
@ -27,7 +28,7 @@ export default function registerIpcRendererListeners() {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
ipcRenderer.on(IPC_CHANNELS.CONSOLE_LOG, (_, ...stuff: unknown[]) => {
|
registerConsoleLogListener((_, ...stuff: unknown[]) => {
|
||||||
if (!fyo.store.isDevelopment) {
|
if (!fyo.store.isDevelopment) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,9 @@ const { ipcRenderer } = require('electron');
|
|||||||
import { t } from 'fyo';
|
import { t } from 'fyo';
|
||||||
import { BaseError } from 'fyo/utils/errors';
|
import { BaseError } from 'fyo/utils/errors';
|
||||||
import type { BackendResponse } from 'utils/ipc/types';
|
import type { BackendResponse } from 'utils/ipc/types';
|
||||||
import { IPC_ACTIONS, IPC_MESSAGES } from 'utils/messages';
|
import { IPC_ACTIONS, IPC_CHANNELS, IPC_MESSAGES } from 'utils/messages';
|
||||||
import type {
|
import type {
|
||||||
|
ConfigFilesWithModified,
|
||||||
LanguageMap,
|
LanguageMap,
|
||||||
SelectFileOptions,
|
SelectFileOptions,
|
||||||
SelectFileReturn,
|
SelectFileReturn,
|
||||||
@ -154,3 +155,40 @@ export async function getSavePath(name: string, extention: string) {
|
|||||||
|
|
||||||
return { canceled, filePath };
|
return { canceled, filePath };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getDbList() {
|
||||||
|
return (await ipcRenderer.invoke(
|
||||||
|
IPC_ACTIONS.GET_DB_LIST
|
||||||
|
)) as ConfigFilesWithModified[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getEnv() {
|
||||||
|
return (await ipcRenderer.invoke(IPC_ACTIONS.GET_ENV)) as {
|
||||||
|
isDevelopment: boolean;
|
||||||
|
platform: string;
|
||||||
|
version: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function openExternalUrl(url: string) {
|
||||||
|
ipcRenderer.send(IPC_MESSAGES.OPEN_EXTERNAL, url);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function showError(title: string, content: string) {
|
||||||
|
await ipcRenderer.invoke(IPC_ACTIONS.SHOW_ERROR, { title, content });
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function sendError(body: string) {
|
||||||
|
await ipcRenderer.invoke(IPC_ACTIONS.SEND_ERROR, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
type IPCRendererListener = Parameters<typeof ipcRenderer.on>[1];
|
||||||
|
export function registerMainProcessErrorListener(
|
||||||
|
listener: IPCRendererListener
|
||||||
|
) {
|
||||||
|
ipcRenderer.on(IPC_CHANNELS.LOG_MAIN_PROCESS_ERROR, listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function registerConsoleLogListener(listener: IPCRendererListener) {
|
||||||
|
ipcRenderer.on(IPC_CHANNELS.CONSOLE_LOG, listener);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user