2
0
mirror of https://github.com/frappe/books.git synced 2024-12-25 20:11:15 +00:00
books/src/App.vue

132 lines
3.4 KiB
Vue
Raw Normal View History

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"
>
<WindowsTitleBar v-if="platform === 'Windows'" />
<Desk
class="flex-1"
v-if="activeScreen === 'Desk'"
@change-db-file="changeDbFile"
/>
<DatabaseSelector
v-if="activeScreen === 'DatabaseSelector'"
2020-02-03 17:42:34 +00:00
@database-connect="showSetupWizardOrDesk(true)"
/>
<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"
/>
<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>
import './styles/index.css';
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';
import WindowsTitleBar from '@/components/WindowsTitleBar';
import { ipcRenderer } from 'electron';
import config from '@/config';
import { IPC_MESSAGES, IPC_ACTIONS } from '@/messages';
import { connectToLocalDatabase, purgeCache } from '@/initialization';
import { routeTo, showErrorDialog } from './utils';
2021-12-20 09:52:31 +00:00
import fs from 'fs/promises';
2018-06-01 12:35:51 +00:00
export default {
name: 'App',
data() {
return {
activeScreen: null,
};
},
watch: {
async activeScreen(value) {
if (!value) return;
2021-11-05 19:41:39 +00:00
const { width, height } = await ipcRenderer.invoke(
IPC_ACTIONS.GET_PRIMARY_DISPLAY_SIZE
);
let size = {
2020-01-23 12:58:51 +00:00
Desk: [width, height],
DatabaseSelector: [600, 600],
SetupWizard: [600, 600],
}[value];
let resizable = value === 'Desk';
if (size.length) {
ipcRenderer.send(IPC_MESSAGES.RESIZE_MAIN_WINDOW, size, resizable);
}
},
},
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,
WindowsTitleBar,
},
async mounted() {
2021-11-05 19:41:39 +00:00
const lastSelectedFilePath = config.get('lastSelectedFilePath', null);
const { connectionSuccess, reason } = await connectToLocalDatabase(
2021-11-05 19:41:39 +00:00
lastSelectedFilePath
);
if (connectionSuccess) {
this.showSetupWizardOrDesk();
return;
}
if (lastSelectedFilePath) {
await showErrorDialog({
title: 'DB Connection Error',
content: `reason: ${reason}, filePath: ${lastSelectedFilePath}`,
});
2018-10-23 12:42:36 +00:00
}
this.activeScreen = 'DatabaseSelector';
},
methods: {
async showSetupWizardOrDesk(resetRoute = false) {
const { setupComplete } = frappe.AccountingSettings;
if (!setupComplete) {
this.activeScreen = 'SetupWizard';
2019-10-24 10:39:57 +00:00
} else {
this.activeScreen = 'Desk';
this.checkForUpdates();
2019-10-24 10:39:57 +00:00
}
if (!resetRoute) {
return;
}
const { onboardingComplete } = await frappe.getSingle('GetStarted');
const { hideGetStarted } = await frappe.getSingle('SystemSettings');
if (hideGetStarted || onboardingComplete) {
routeTo('/');
} else {
routeTo('/get-started');
}
},
checkForUpdates() {
frappe.events.trigger('check-for-updates');
},
changeDbFile() {
config.set('lastSelectedFilePath', null);
purgeCache(true);
this.activeScreen = 'DatabaseSelector';
},
2021-12-20 09:52:31 +00:00
async setupCanceled() {
const filePath = config.get('lastSelectedFilePath');
await fs.unlink(filePath);
this.changeDbFile();
2021-12-20 09:52:31 +00:00
},
},
};
2018-06-01 12:35:51 +00:00
</script>