2022-03-16 11:42:06 +00:00
|
|
|
import { ipcRenderer } from 'electron';
|
|
|
|
import { createApp } from 'vue';
|
2022-03-16 14:56:18 +00:00
|
|
|
import App from './App';
|
|
|
|
import FeatherIcon from './components/FeatherIcon';
|
2022-03-16 11:42:06 +00:00
|
|
|
import config, { ConfigKeys } from './config';
|
|
|
|
import { getErrorHandled, handleError } from './errorHandling';
|
2022-04-20 06:38:47 +00:00
|
|
|
import { fyo } from './initFyo';
|
2022-04-01 13:28:21 +00:00
|
|
|
import { IPC_ACTIONS } from './messages';
|
2022-03-16 11:42:06 +00:00
|
|
|
import { incrementOpenCount } from './renderer/helpers';
|
|
|
|
import registerIpcRendererListeners from './renderer/registerIpcRendererListeners';
|
|
|
|
import router from './router';
|
|
|
|
import { outsideClickDirective } from './ui';
|
|
|
|
import { setLanguageMap, stringifyCircular } from './utils';
|
|
|
|
|
|
|
|
(async () => {
|
2022-04-20 06:38:47 +00:00
|
|
|
const language = fyo.config.get(ConfigKeys.Language);
|
2022-03-16 11:42:06 +00:00
|
|
|
if (language) {
|
|
|
|
await setLanguageMap(language);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (process.env.NODE_ENV === 'development') {
|
|
|
|
window.config = config;
|
|
|
|
}
|
|
|
|
|
2022-04-20 06:38:47 +00:00
|
|
|
fyo.isElectron = true;
|
2022-03-16 11:42:06 +00:00
|
|
|
|
2022-03-28 13:10:18 +00:00
|
|
|
const models = (await import('../models')).default;
|
2022-04-20 06:38:47 +00:00
|
|
|
await fyo.initializeAndRegister(models);
|
2022-03-16 11:42:06 +00:00
|
|
|
|
|
|
|
ipcRenderer.send = getErrorHandled(ipcRenderer.send);
|
|
|
|
ipcRenderer.invoke = getErrorHandled(ipcRenderer.invoke);
|
|
|
|
|
2022-04-20 06:38:47 +00:00
|
|
|
window.frappe = fyo;
|
2022-03-16 11:42:06 +00:00
|
|
|
|
|
|
|
window.onerror = (message, source, lineno, colno, error) => {
|
|
|
|
error = error ?? new Error('triggered in window.onerror');
|
|
|
|
handleError(true, error, { message, source, lineno, colno });
|
|
|
|
};
|
|
|
|
|
|
|
|
registerIpcRendererListeners();
|
|
|
|
|
|
|
|
const app = createApp({
|
|
|
|
template: '<App/>',
|
|
|
|
});
|
|
|
|
|
|
|
|
app.use(router);
|
|
|
|
app.component('App', App);
|
|
|
|
app.component('feather-icon', FeatherIcon);
|
|
|
|
app.directive('on-outside-click', outsideClickDirective);
|
|
|
|
app.mixin({
|
|
|
|
computed: {
|
|
|
|
frappe() {
|
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
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
app.config.errorHandler = (err, vm, info) => {
|
2022-03-16 14:56:18 +00:00
|
|
|
const more = {
|
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-03-16 14:56:18 +00:00
|
|
|
handleError(false, err, more);
|
2022-03-16 11:42:06 +00:00
|
|
|
console.error(err, vm, info);
|
|
|
|
};
|
|
|
|
|
2022-04-20 06:38:47 +00:00
|
|
|
fyo.store.appVersion = await ipcRenderer.invoke(IPC_ACTIONS.GET_VERSION);
|
2022-03-16 11:42:06 +00:00
|
|
|
incrementOpenCount();
|
|
|
|
app.mount('body');
|
2022-03-16 14:37:15 +00:00
|
|
|
|
2022-03-16 14:56:18 +00:00
|
|
|
process.on('unhandledRejection', (error) => {
|
2022-03-16 14:37:15 +00:00
|
|
|
handleError(true, error);
|
|
|
|
});
|
|
|
|
|
|
|
|
process.on('uncaughtException', (error) => {
|
|
|
|
handleError(true, error, {}, () => process.exit(1));
|
|
|
|
});
|
2022-03-16 11:42:06 +00:00
|
|
|
})();
|