2
0
mirror of https://github.com/frappe/books.git synced 2025-01-27 09:08:24 +00:00
books/src/App.vue

177 lines
4.8 KiB
Vue
Raw Normal View History

2018-06-01 18:05:51 +05:30
<template>
2020-01-28 13:50:42 +05:30
<div
id="app"
class="h-screen flex flex-col font-sans overflow-hidden antialiased"
2023-01-07 13:25:08 +03:00
:dir="direction"
:language="language"
2020-01-28 13:50:42 +05:30
>
2022-05-28 09:07:14 +05:30
<WindowsTitleBar
v-if="platform === 'Windows'"
:db-path="dbPath"
:company-name="companyName"
/>
<!-- Main Contents -->
<Desk
class="flex-1"
v-if="activeScreen === 'Desk'"
2022-05-23 11:51:06 +05:30
@change-db-file="showDbSelector"
2022-04-25 15:56:01 +05:30
/>
<DatabaseSelector
v-if="activeScreen === 'DatabaseSelector'"
2022-04-22 16:32:03 +05:30
@file-selected="fileSelected"
/>
2022-04-22 16:32:03 +05:30
<SetupWizard
v-if="activeScreen === 'SetupWizard'"
@setup-complete="setupComplete"
2022-05-23 11:51:06 +05:30
@setup-canceled="showDbSelector"
/>
2022-05-23 11:51:06 +05:30
<!-- Render target for toasts -->
<div
id="toast-container"
class="absolute bottom-0 flex flex-col items-end mb-3 pr-6"
style="width: 100%"
>
<div id="toast-target" />
</div>
2018-06-01 18:05:51 +05:30
</div>
</template>
<script>
import { ConfigKeys } from 'fyo/core/types';
2023-01-07 13:25:08 +03:00
import { RTL_LAGNUAGES } from 'fyo/utils/consts';
import { ModelNameEnum } from 'models/types';
2022-05-30 14:20:54 +05:30
import { computed } from 'vue';
import WindowsTitleBar from './components/WindowsTitleBar.vue';
import { handleErrorWithDialog } from './errorHandling';
import { fyo } from './initFyo';
2022-04-22 16:32:03 +05:30
import DatabaseSelector from './pages/DatabaseSelector.vue';
2022-04-25 15:56:01 +05:30
import Desk from './pages/Desk.vue';
2022-04-22 16:32:03 +05:30
import SetupWizard from './pages/SetupWizard/SetupWizard.vue';
import setupInstance from './setup/setupInstance';
import './styles/index.css';
import { initializeInstance } from './utils/initialization';
2022-04-22 16:32:03 +05:30
import { checkForUpdates } from './utils/ipcCalls';
2022-07-20 14:14:36 +05:30
import { updateConfigFiles } from './utils/misc';
2022-05-30 14:20:54 +05:30
import { Search } from './utils/search';
2022-04-22 16:32:03 +05:30
import { routeTo } from './utils/ui';
2022-12-08 15:19:22 +05:30
import { Shortcuts, useKeys } from './utils/vueUtils';
2018-06-01 18:05:51 +05:30
export default {
name: 'App',
2022-12-08 15:19:22 +05:30
setup() {
return { keys: useKeys() };
},
data() {
return {
activeScreen: null,
2022-05-28 09:07:14 +05:30
dbPath: '',
companyName: '',
2022-05-30 14:20:54 +05:30
searcher: null,
2022-12-08 15:19:22 +05:30
shortcuts: null,
2023-01-07 13:25:08 +03:00
direction: 'ltr',
language: '',
2022-05-30 14:20:54 +05:30
};
},
provide() {
return {
searcher: computed(() => this.searcher),
2022-12-08 15:19:22 +05:30
shortcuts: computed(() => this.shortcuts),
keys: computed(() => this.keys),
};
},
2018-06-01 18:05:51 +05:30
components: {
2022-04-25 15:56:01 +05:30
Desk,
2022-04-22 16:32:03 +05:30
SetupWizard,
2019-10-19 19:56:13 +05:30
DatabaseSelector,
2022-04-22 16:32:03 +05:30
WindowsTitleBar,
},
async mounted() {
2023-01-07 13:25:08 +03:00
this.language = fyo.config.get("language");
this.direction = RTL_LAGNUAGES.includes(this.language) ? 'rtl' : 'ltr';
2022-12-08 15:19:22 +05:30
this.shortcuts = new Shortcuts(this.keys);
const lastSelectedFilePath = fyo.config.get(
ConfigKeys.LastSelectedFilePath,
null
);
if (!lastSelectedFilePath) {
return (this.activeScreen = 'DatabaseSelector');
2018-10-23 18:12:36 +05:30
}
try {
await this.fileSelected(lastSelectedFilePath, false);
} catch (err) {
await handleErrorWithDialog(err, undefined, true, true);
2022-05-28 09:07:14 +05:30
await this.showDbSelector();
}
},
methods: {
2022-05-23 11:51:06 +05:30
async setDesk(filePath) {
this.activeScreen = 'Desk';
2022-05-23 11:51:06 +05:30
await this.setDeskRoute();
await fyo.telemetry.start(true);
await checkForUpdates(false);
2022-05-28 09:07:14 +05:30
this.dbPath = filePath;
this.companyName = await fyo.getValue(
ModelNameEnum.AccountingSettings,
'companyName'
);
2022-05-30 14:20:54 +05:30
await this.setSearcher();
2022-07-30 03:20:21 -07:00
await updateConfigFiles(fyo);
2022-05-30 14:20:54 +05:30
},
async setSearcher() {
this.searcher = new Search(fyo);
await this.searcher.initializeKeywords();
},
2022-04-22 16:32:03 +05:30
async fileSelected(filePath, isNew) {
fyo.config.set(ConfigKeys.LastSelectedFilePath, filePath);
2022-04-22 16:32:03 +05:30
if (isNew) {
this.activeScreen = 'SetupWizard';
return;
}
await this.showSetupWizardOrDesk(filePath);
},
async setupComplete(setupWizardOptions) {
const filePath = fyo.config.get(ConfigKeys.LastSelectedFilePath);
await setupInstance(filePath, setupWizardOptions, fyo);
2022-05-23 11:51:06 +05:30
await this.setDesk(filePath);
},
async showSetupWizardOrDesk(filePath) {
2022-04-22 16:32:03 +05:30
const countryCode = await fyo.db.connectToDatabase(filePath);
const setupComplete = await fyo.getValue(
ModelNameEnum.AccountingSettings,
'setupComplete'
);
2022-04-22 16:32:03 +05:30
if (!setupComplete) {
this.activeScreen = 'SetupWizard';
2022-04-22 16:32:03 +05:30
return;
2019-10-24 16:09:57 +05:30
}
await initializeInstance(filePath, false, countryCode, fyo);
2022-05-23 11:51:06 +05:30
await this.setDesk(filePath);
2022-04-22 16:32:03 +05:30
},
async setDeskRoute() {
const { onboardingComplete } = await fyo.doc.getDoc('GetStarted');
const { hideGetStarted } = await fyo.doc.getDoc('SystemSettings');
if (hideGetStarted || onboardingComplete) {
routeTo('/');
} else {
2022-04-27 17:32:43 +05:30
routeTo('/get-started');
}
},
2022-05-23 11:51:06 +05:30
async showDbSelector() {
fyo.config.set('lastSelectedFilePath', null);
2022-04-22 16:32:03 +05:30
fyo.telemetry.stop();
2022-07-30 16:33:09 +05:30
await fyo.purgeCache();
this.activeScreen = 'DatabaseSelector';
2022-05-28 09:07:14 +05:30
this.dbPath = '';
2022-05-30 14:20:54 +05:30
this.searcher = null;
2022-05-28 09:07:14 +05:30
this.companyName = '';
},
},
};
2018-06-01 18:05:51 +05:30
</script>