2022-03-16 11:42:06 +00:00
|
|
|
import { ipcRenderer } from 'electron';
|
2022-04-20 10:41:27 +00:00
|
|
|
import { ConfigKeys } from 'fyo/core/types';
|
|
|
|
import { IPC_ACTIONS } from 'utils/messages';
|
|
|
|
import { App as VueApp, createApp } from 'vue';
|
|
|
|
import App from './App.vue';
|
|
|
|
import Badge from './components/Badge.vue';
|
|
|
|
import FeatherIcon from './components/FeatherIcon.vue';
|
2022-03-16 11:42:06 +00:00
|
|
|
import { getErrorHandled, handleError } from './errorHandling';
|
2022-04-20 06:38:47 +00:00
|
|
|
import { fyo } from './initFyo';
|
2022-04-23 09:23:44 +00:00
|
|
|
import { outsideClickDirective } from './renderer/helpers';
|
2022-03-16 11:42:06 +00:00
|
|
|
import registerIpcRendererListeners from './renderer/registerIpcRendererListeners';
|
|
|
|
import router from './router';
|
2022-04-20 10:41:27 +00:00
|
|
|
import { stringifyCircular } from './utils';
|
|
|
|
import { setLanguageMap } from './utils/language';
|
2022-03-16 11:42:06 +00:00
|
|
|
|
|
|
|
(async () => {
|
2022-04-20 10:41:27 +00:00
|
|
|
const language = fyo.config.get(ConfigKeys.Language) as string;
|
2022-03-16 11:42:06 +00:00
|
|
|
if (language) {
|
|
|
|
await setLanguageMap(language);
|
|
|
|
}
|
|
|
|
|
2022-04-20 10:41:27 +00:00
|
|
|
setOnWindow();
|
2022-03-16 11:42:06 +00:00
|
|
|
|
|
|
|
ipcRenderer.send = getErrorHandled(ipcRenderer.send);
|
|
|
|
ipcRenderer.invoke = getErrorHandled(ipcRenderer.invoke);
|
|
|
|
|
|
|
|
registerIpcRendererListeners();
|
|
|
|
|
|
|
|
const app = createApp({
|
2022-04-21 13:17:06 +00:00
|
|
|
template: '<App/>',
|
2022-03-16 11:42:06 +00:00
|
|
|
});
|
2022-04-20 10:41:27 +00:00
|
|
|
setErrorHandlers(app);
|
2022-03-16 11:42:06 +00:00
|
|
|
|
|
|
|
app.use(router);
|
|
|
|
app.component('App', App);
|
2022-04-23 09:23:44 +00:00
|
|
|
app.component('FeatherIcon', FeatherIcon);
|
2022-04-20 10:41:27 +00:00
|
|
|
app.component('Badge', Badge);
|
|
|
|
|
2022-03-16 11:42:06 +00:00
|
|
|
app.directive('on-outside-click', outsideClickDirective);
|
|
|
|
app.mixin({
|
|
|
|
computed: {
|
2022-04-20 10:41:27 +00:00
|
|
|
fyo() {
|
2022-04-20 06:38:47 +00:00
|
|
|
return fyo;
|
2022-03-16 11:42:06 +00:00
|
|
|
},
|
2022-03-16 14:56:18 +00:00
|
|
|
platform() {
|
2022-03-16 11:42:06 +00:00
|
|
|
switch (process.platform) {
|
|
|
|
case 'win32':
|
|
|
|
return 'Windows';
|
|
|
|
case 'darwin':
|
|
|
|
return 'Mac';
|
|
|
|
case 'linux':
|
|
|
|
return 'Linux';
|
|
|
|
default:
|
|
|
|
return 'Linux';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
2022-04-20 06:38:47 +00:00
|
|
|
t: fyo.t,
|
|
|
|
T: fyo.T,
|
2022-03-16 11:42:06 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-04-20 10:41:27 +00:00
|
|
|
fyo.store.appVersion = await ipcRenderer.invoke(IPC_ACTIONS.GET_VERSION);
|
|
|
|
app.mount('body');
|
|
|
|
})();
|
|
|
|
|
|
|
|
function setErrorHandlers(app: VueApp) {
|
|
|
|
window.onerror = (message, source, lineno, colno, error) => {
|
|
|
|
error = error ?? new Error('triggered in window.onerror');
|
|
|
|
handleError(true, error, { message, source, lineno, colno });
|
|
|
|
};
|
|
|
|
|
2022-03-16 11:42:06 +00:00
|
|
|
app.config.errorHandler = (err, vm, info) => {
|
2022-04-20 10:41:27 +00:00
|
|
|
const more: Record<string, unknown> = {
|
2022-03-16 11:42:06 +00:00
|
|
|
info,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (vm) {
|
|
|
|
const { fullPath, params } = vm.$route;
|
|
|
|
more.fullPath = fullPath;
|
|
|
|
more.params = stringifyCircular(params ?? {});
|
|
|
|
more.data = stringifyCircular(vm.$data ?? {}, true, true);
|
|
|
|
more.props = stringifyCircular(vm.$props ?? {}, true, true);
|
|
|
|
}
|
|
|
|
|
2022-04-20 10:41:27 +00:00
|
|
|
handleError(false, err as Error, more);
|
2022-03-16 11:42:06 +00:00
|
|
|
console.error(err, vm, info);
|
|
|
|
};
|
|
|
|
|
2022-03-16 14:56:18 +00:00
|
|
|
process.on('unhandledRejection', (error) => {
|
2022-04-20 10:41:27 +00:00
|
|
|
handleError(true, error as Error);
|
2022-03-16 14:37:15 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
process.on('uncaughtException', (error) => {
|
|
|
|
handleError(true, error, {}, () => process.exit(1));
|
|
|
|
});
|
2022-04-20 10:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function setOnWindow() {
|
|
|
|
if (process.env.NODE_ENV === 'development') {
|
|
|
|
// @ts-ignore
|
|
|
|
window.router = router;
|
|
|
|
// @ts-ignore
|
|
|
|
window.fyo = fyo;
|
|
|
|
}
|
|
|
|
}
|