2018-06-01 12:35:51 +00:00
|
|
|
<template>
|
2020-01-28 08:20:42 +00:00
|
|
|
<div
|
|
|
|
id="app"
|
|
|
|
class="h-screen flex flex-col font-sans overflow-hidden antialiased"
|
|
|
|
>
|
2021-11-24 09:08:13 +00:00
|
|
|
<WindowsTitleBar v-if="platform === 'Windows'" />
|
|
|
|
<Desk
|
|
|
|
class="flex-1"
|
|
|
|
v-if="activeScreen === 'Desk'"
|
|
|
|
@change-db-file="changeDbFile"
|
2019-12-16 11:34:22 +00:00
|
|
|
/>
|
2020-01-01 08:11:57 +00:00
|
|
|
<DatabaseSelector
|
|
|
|
v-if="activeScreen === 'DatabaseSelector'"
|
2020-02-03 17:42:34 +00:00
|
|
|
@database-connect="showSetupWizardOrDesk(true)"
|
2020-01-01 08:11:57 +00:00
|
|
|
/>
|
|
|
|
<SetupWizard
|
|
|
|
v-if="activeScreen === 'SetupWizard'"
|
2020-02-03 17:42:34 +00:00
|
|
|
@setup-complete="showSetupWizardOrDesk(true)"
|
2021-12-20 09:52:31 +00:00
|
|
|
@setup-canceled="setupCanceled"
|
2020-01-01 08:11:57 +00:00
|
|
|
/>
|
2021-12-21 12:33:30 +00:00
|
|
|
<div id="toast-container" class="absolute bottom-0 right-0 mr-6 mb-3">
|
|
|
|
<div id="toast-target" />
|
|
|
|
</div>
|
2018-06-01 12:35:51 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2019-10-03 13:46:12 +00:00
|
|
|
import './styles/index.css';
|
2022-01-20 20:57:29 +00:00
|
|
|
import frappe from 'frappe';
|
2018-10-23 12:42:36 +00:00
|
|
|
import Desk from './pages/Desk';
|
2018-10-05 05:35:20 +00:00
|
|
|
import SetupWizard from './pages/SetupWizard/SetupWizard';
|
2018-10-23 12:42:36 +00:00
|
|
|
import DatabaseSelector from './pages/DatabaseSelector';
|
2019-12-16 11:34:22 +00:00
|
|
|
import WindowsTitleBar from '@/components/WindowsTitleBar';
|
2021-11-04 09:33:51 +00:00
|
|
|
import { ipcRenderer } from 'electron';
|
2020-01-28 08:20:01 +00:00
|
|
|
import config from '@/config';
|
2021-11-04 09:33:51 +00:00
|
|
|
import { IPC_MESSAGES, IPC_ACTIONS } from '@/messages';
|
2021-11-29 09:32:05 +00:00
|
|
|
import { connectToLocalDatabase, purgeCache } from '@/initialization';
|
2022-01-19 07:39:39 +00:00
|
|
|
import { routeTo } from './utils';
|
2021-12-20 09:52:31 +00:00
|
|
|
import fs from 'fs/promises';
|
2022-01-19 07:39:39 +00:00
|
|
|
import { showErrorDialog } from './errorHandling';
|
2018-06-01 12:35:51 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'App',
|
2018-06-11 09:46:25 +00:00
|
|
|
data() {
|
|
|
|
return {
|
2021-11-04 09:33:51 +00:00
|
|
|
activeScreen: null,
|
2019-08-20 08:57:27 +00:00
|
|
|
};
|
2018-06-11 09:46:25 +00:00
|
|
|
},
|
2019-10-13 12:03:01 +00:00
|
|
|
watch: {
|
2021-11-04 09:33:51 +00:00
|
|
|
async activeScreen(value) {
|
2020-01-01 08:11:57 +00:00
|
|
|
if (!value) return;
|
2021-11-05 19:41:39 +00:00
|
|
|
const { width, height } = await ipcRenderer.invoke(
|
2021-11-04 09:33:51 +00:00
|
|
|
IPC_ACTIONS.GET_PRIMARY_DISPLAY_SIZE
|
|
|
|
);
|
2021-11-24 09:08:13 +00:00
|
|
|
|
2020-01-01 08:11:57 +00:00
|
|
|
let size = {
|
2020-01-23 12:58:51 +00:00
|
|
|
Desk: [width, height],
|
2020-01-01 08:11:57 +00:00
|
|
|
DatabaseSelector: [600, 600],
|
|
|
|
SetupWizard: [600, 600],
|
|
|
|
}[value];
|
|
|
|
let resizable = value === 'Desk';
|
|
|
|
|
2021-11-24 09:08:13 +00:00
|
|
|
if (size.length) {
|
2021-11-04 09:33:51 +00:00
|
|
|
ipcRenderer.send(IPC_MESSAGES.RESIZE_MAIN_WINDOW, size, resizable);
|
2019-10-13 12:03:01 +00:00
|
|
|
}
|
2021-11-04 09:33:51 +00:00
|
|
|
},
|
2019-10-13 12:03:01 +00:00
|
|
|
},
|
2018-06-01 12:35:51 +00:00
|
|
|
components: {
|
2018-10-23 12:42:36 +00:00
|
|
|
Desk,
|
2018-10-22 18:10:22 +00:00
|
|
|
SetupWizard,
|
2019-10-19 14:26:13 +00:00
|
|
|
DatabaseSelector,
|
2021-11-04 09:33:51 +00:00
|
|
|
WindowsTitleBar,
|
2018-06-11 09:46:25 +00:00
|
|
|
},
|
2020-01-01 08:11:57 +00:00
|
|
|
async mounted() {
|
2021-11-05 19:41:39 +00:00
|
|
|
const lastSelectedFilePath = config.get('lastSelectedFilePath', null);
|
2021-12-10 08:06:38 +00:00
|
|
|
const { connectionSuccess, reason } = await connectToLocalDatabase(
|
2021-11-05 19:41:39 +00:00
|
|
|
lastSelectedFilePath
|
|
|
|
);
|
|
|
|
|
|
|
|
if (connectionSuccess) {
|
2020-01-01 08:11:57 +00:00
|
|
|
this.showSetupWizardOrDesk();
|
2021-12-10 08:06:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lastSelectedFilePath) {
|
2022-01-24 09:04:37 +00:00
|
|
|
const title = this.t`DB Connection Error`;
|
|
|
|
const content = `reason: ${reason}, filePath: ${lastSelectedFilePath}`;
|
|
|
|
|
|
|
|
await showErrorDialog(title, content);
|
2018-10-23 12:42:36 +00:00
|
|
|
}
|
2021-12-10 08:06:38 +00:00
|
|
|
|
|
|
|
this.activeScreen = 'DatabaseSelector';
|
2020-01-01 08:11:57 +00:00
|
|
|
},
|
|
|
|
methods: {
|
2021-12-02 13:20:51 +00:00
|
|
|
async showSetupWizardOrDesk(resetRoute = false) {
|
2020-01-01 08:11:57 +00:00
|
|
|
const { setupComplete } = frappe.AccountingSettings;
|
|
|
|
if (!setupComplete) {
|
|
|
|
this.activeScreen = 'SetupWizard';
|
2019-10-24 10:39:57 +00:00
|
|
|
} else {
|
2020-01-01 08:11:57 +00:00
|
|
|
this.activeScreen = 'Desk';
|
2019-12-27 06:37:39 +00:00
|
|
|
this.checkForUpdates();
|
2019-10-24 10:39:57 +00:00
|
|
|
}
|
2021-12-02 13:20:51 +00:00
|
|
|
|
|
|
|
if (!resetRoute) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { onboardingComplete } = await frappe.getSingle('GetStarted');
|
|
|
|
const { hideGetStarted } = await frappe.getSingle('SystemSettings');
|
|
|
|
|
|
|
|
if (hideGetStarted || onboardingComplete) {
|
2021-11-24 09:08:13 +00:00
|
|
|
routeTo('/');
|
2021-12-02 13:20:51 +00:00
|
|
|
} else {
|
|
|
|
routeTo('/get-started');
|
2019-12-16 11:34:22 +00:00
|
|
|
}
|
2019-12-27 06:37:39 +00:00
|
|
|
},
|
|
|
|
checkForUpdates() {
|
|
|
|
frappe.events.trigger('check-for-updates');
|
2021-11-04 09:33:51 +00:00
|
|
|
},
|
2021-11-24 09:08:13 +00:00
|
|
|
changeDbFile() {
|
|
|
|
config.set('lastSelectedFilePath', null);
|
|
|
|
purgeCache(true);
|
|
|
|
this.activeScreen = 'DatabaseSelector';
|
|
|
|
},
|
2021-12-20 09:52:31 +00:00
|
|
|
async setupCanceled() {
|
2021-12-21 12:33:30 +00:00
|
|
|
const filePath = config.get('lastSelectedFilePath');
|
|
|
|
await fs.unlink(filePath);
|
|
|
|
this.changeDbFile();
|
2021-12-20 09:52:31 +00:00
|
|
|
},
|
2021-11-04 09:33:51 +00:00
|
|
|
},
|
2019-08-20 08:57:27 +00:00
|
|
|
};
|
2018-06-01 12:35:51 +00:00
|
|
|
</script>
|