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';
|
2022-05-14 08:46:05 +00:00
|
|
|
import { DateTime } from 'luxon';
|
2022-09-20 17:19:09 +00:00
|
|
|
import { CUSTOM_EVENTS, IPC_ACTIONS } from 'utils/messages';
|
|
|
|
import { UnexpectedLogObject } from 'utils/types';
|
2022-04-20 10:41:27 +00:00
|
|
|
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-09-20 17:19:09 +00:00
|
|
|
import { getErrorHandled, handleError, sendError } 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-07-18 11:13:56 +00:00
|
|
|
fyo.store.language = language || 'English';
|
2022-03-16 11:42:06 +00:00
|
|
|
|
|
|
|
ipcRenderer.send = getErrorHandled(ipcRenderer.send);
|
|
|
|
ipcRenderer.invoke = getErrorHandled(ipcRenderer.invoke);
|
|
|
|
|
|
|
|
registerIpcRendererListeners();
|
2022-05-27 07:50:14 +00:00
|
|
|
const { isDevelopment, platform, version } = (await ipcRenderer.invoke(
|
|
|
|
IPC_ACTIONS.GET_ENV
|
|
|
|
)) as { isDevelopment: boolean; platform: string; version: string };
|
|
|
|
|
|
|
|
fyo.store.isDevelopment = isDevelopment;
|
|
|
|
fyo.store.appVersion = version;
|
2022-07-07 12:29:06 +00:00
|
|
|
fyo.store.platform = platform;
|
2022-05-28 11:14:38 +00:00
|
|
|
const platformName = getPlatformName(platform);
|
2022-05-27 07:50:14 +00:00
|
|
|
|
|
|
|
setOnWindow(isDevelopment);
|
2022-03-16 11:42:06 +00:00
|
|
|
|
|
|
|
const app = createApp({
|
2022-04-21 13:17:06 +00:00
|
|
|
template: '<App/>',
|
2022-03-16 11:42:06 +00:00
|
|
|
});
|
2022-04-29 19:04:08 +00:00
|
|
|
app.config.unwrapInjectedRef = true;
|
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-05-28 11:14:38 +00:00
|
|
|
return platformName;
|
2022-03-16 11:42:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
2022-04-20 06:38:47 +00:00
|
|
|
t: fyo.t,
|
|
|
|
T: fyo.T,
|
2022-03-16 11:42:06 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-05-28 11:14:38 +00:00
|
|
|
await fyo.telemetry.logOpened();
|
2022-04-20 10:41:27 +00:00
|
|
|
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-09-20 17:19:09 +00:00
|
|
|
window.onunhandledrejection = (event: PromiseRejectionEvent) => {
|
|
|
|
const error = event.reason;
|
|
|
|
handleError(true, error).catch((err) => console.error(err));
|
|
|
|
};
|
|
|
|
|
|
|
|
window.addEventListener(CUSTOM_EVENTS.LOG_UNEXPECTED, (event) => {
|
|
|
|
const details = (event as CustomEvent)?.detail as UnexpectedLogObject;
|
|
|
|
sendError(details);
|
|
|
|
});
|
|
|
|
|
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.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-04-20 10:41:27 +00:00
|
|
|
}
|
|
|
|
|
2022-05-27 07:50:14 +00:00
|
|
|
function setOnWindow(isDevelopment: boolean) {
|
|
|
|
if (!isDevelopment) {
|
|
|
|
return;
|
2022-04-20 10:41:27 +00:00
|
|
|
}
|
2022-05-27 07:50:14 +00:00
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
window.router = router;
|
|
|
|
// @ts-ignore
|
|
|
|
window.fyo = fyo;
|
|
|
|
// @ts-ignore
|
|
|
|
window.DateTime = DateTime;
|
2022-04-20 10:41:27 +00:00
|
|
|
}
|
2022-05-28 11:14:38 +00:00
|
|
|
|
|
|
|
function getPlatformName(platform: string) {
|
|
|
|
switch (platform) {
|
|
|
|
case 'win32':
|
|
|
|
return 'Windows';
|
|
|
|
case 'darwin':
|
|
|
|
return 'Mac';
|
|
|
|
case 'linux':
|
|
|
|
return 'Linux';
|
|
|
|
default:
|
|
|
|
return 'Linux';
|
|
|
|
}
|
|
|
|
}
|