diff --git a/models/doctype/AccountingSettings/AccountingSettings.js b/models/doctype/AccountingSettings/AccountingSettings.js
index 6801e13b..125d15ca 100644
--- a/models/doctype/AccountingSettings/AccountingSettings.js
+++ b/models/doctype/AccountingSettings/AccountingSettings.js
@@ -1,6 +1,4 @@
-const countryList = Object.keys(
- require('../../../fixtures/countryInfo.json')
-).sort();
+const countryList = Object.keys(require('~/fixtures/countryInfo.json')).sort();
module.exports = {
name: 'AccountingSettings',
@@ -100,6 +98,13 @@ module.exports = {
required: 1
},
+ {
+ fieldname: 'setupComplete',
+ label: 'Setup Complete',
+ fieldtype: 'Check',
+ default: 0
+ },
+
{
fieldname: 'autoUpdate',
label: 'Auto Update',
diff --git a/models/doctype/SetupWizard/SetupWizard.js b/models/doctype/SetupWizard/SetupWizard.js
index a0344e72..1230f870 100644
--- a/models/doctype/SetupWizard/SetupWizard.js
+++ b/models/doctype/SetupWizard/SetupWizard.js
@@ -1,5 +1,5 @@
const { DateTime } = require('luxon');
-const countryList = require('../../../fixtures/countryInfo.json');
+const countryList = require('~/fixtures/countryInfo.json');
module.exports = {
name: 'SetupWizard',
diff --git a/src/App.vue b/src/App.vue
index 96ece3d8..8c2e8f30 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -4,10 +4,16 @@
v-if="['Windows', 'Linux'].includes(platform)"
@close="reloadMainWindowOnSettingsClose"
/>
-
-
-
-
+
+
+
+
@@ -22,44 +28,30 @@ import DatabaseSelector from './pages/DatabaseSelector';
import Settings from '@/pages/Settings/Settings.vue';
import WindowsTitleBar from '@/components/WindowsTitleBar';
import { remote } from 'electron';
+import { connectToLocalDatabase } from '@/utils';
export default {
name: 'App',
data() {
return {
- showDatabaseSelector: false,
- showDesk: false,
- showSetupWizard: false,
- showSettings: false
+ activeScreen: null
};
},
watch: {
- showDatabaseSelector(newValue) {
- if (newValue) {
- let win = remote.getCurrentWindow();
- win.setSize(600, 600);
- win.setResizable(false);
- }
- },
- showSetupWizard(newValue) {
- if (newValue) {
- let win = remote.getCurrentWindow();
- win.setSize(600, 600);
- win.setResizable(false);
- }
- },
- showSettings(newValue) {
- if (newValue) {
- let win = remote.getCurrentWindow();
- win.setSize(460, 577);
- win.setResizable(false);
- }
- },
- showDesk(newValue) {
- if (newValue) {
- let win = remote.getCurrentWindow();
- win.setSize(1200, 907);
- win.setResizable(true);
+ activeScreen(value) {
+ if (!value) return;
+ let size = {
+ Desk: [1200, 907],
+ DatabaseSelector: [600, 600],
+ SetupWizard: [600, 600],
+ Settings: [460, 577]
+ }[value];
+ let resizable = value === 'Desk';
+
+ let win = remote.getCurrentWindow();
+ if (size.length) {
+ win.setSize(...size);
+ win.setResizable(resizable);
}
}
},
@@ -70,36 +62,29 @@ export default {
Settings,
WindowsTitleBar
},
- mounted() {
- if (!localStorage.dbPath) {
- this.showDatabaseSelector = true;
+ async mounted() {
+ let dbPath = localStorage.dbPath;
+ if (!dbPath) {
+ this.activeScreen = 'DatabaseSelector';
} else {
- frappe.events.trigger('connect-database', localStorage.dbPath);
+ await connectToLocalDatabase(dbPath);
+ this.showSetupWizardOrDesk();
}
-
- frappe.events.on('show-setup-wizard', () => {
- this.showSetupWizard = true;
- this.showDesk = false;
- this.showDatabaseSelector = false;
- });
-
- frappe.events.on('show-desk', () => {
- if (this.$route.path.startsWith('/settings')) {
- this.showSettings = true;
- } else {
- this.showDesk = true;
- this.checkForUpdates();
- }
- this.showSetupWizard = false;
- this.showDatabaseSelector = false;
- });
},
methods: {
- connectToDBFile(filePath) {
- frappe.events.trigger('DatabaseSelector:file-selected', filePath);
+ showSetupWizardOrDesk() {
+ const { setupComplete } = frappe.AccountingSettings;
+ if (!setupComplete) {
+ this.activeScreen = 'SetupWizard';
+ } else if (this.$route.path.startsWith('/settings')) {
+ this.activeScreen = 'Settings';
+ } else {
+ this.activeScreen = 'Desk';
+ this.checkForUpdates();
+ }
},
reloadMainWindowOnSettingsClose() {
- if (this.showSettings) {
+ if (this.activeScreen === 'Settings') {
frappe.events.trigger('reload-main-window');
}
},
diff --git a/src/main.js b/src/main.js
index ac4e0877..3e72eefb 100644
--- a/src/main.js
+++ b/src/main.js
@@ -1,12 +1,10 @@
// frappejs imports
import frappe from 'frappejs';
-import SQLite from 'frappejs/backends/sqlite';
import common from 'frappejs/common';
import coreModels from 'frappejs/models';
import FeatherIcon from 'frappejs/ui/components/FeatherIcon';
import outsideClickDirective from 'frappejs/ui/plugins/outsideClickDirective';
import models from '../models';
-import postStart from '../server/postStart';
import { ipcRenderer } from 'electron';
// vue imports
@@ -23,39 +21,6 @@ import router from './router';
frappe.registerModels(coreModels);
frappe.registerModels(models);
frappe.fetch = window.fetch.bind();
- frappe.events.on('connect-database', async filepath => {
- await connectToLocalDatabase(filepath);
-
- const { completed } = await frappe.getSingle('SetupWizard');
-
- if (!completed) {
- frappe.events.trigger('show-setup-wizard');
- return;
- }
-
- const { country } = await frappe.getSingle('AccountingSettings');
-
- if (country === 'India') {
- frappe.models.Party = require('../models/doctype/Party/RegionalChanges.js');
- } else {
- frappe.models.Party = require('../models/doctype/Party/Party.js');
- }
-
- frappe.events.trigger('show-desk');
- });
-
- frappe.events.on('DatabaseSelector:file-selected', async filepath => {
- await connectToLocalDatabase(filepath);
-
- localStorage.dbPath = filepath;
-
- const { companyName } = await frappe.getSingle('AccountingSettings');
- if (!companyName) {
- frappe.events.trigger('show-setup-wizard');
- } else {
- frappe.events.trigger('show-desk');
- }
- });
frappe.events.on('reload-main-window', () => {
ipcRenderer.send('reload-main-window');
@@ -68,122 +33,6 @@ import router from './router';
}
});
- frappe.events.on('SetupWizard:setup-complete', async setupWizardValues => {
- const countryList = require('../fixtures/countryInfo.json');
- const {
- companyLogo,
- companyName,
- country,
- name,
- email,
- bankName,
- fiscalYearStart,
- fiscalYearEnd
- } = setupWizardValues;
-
- const doc = await frappe.getSingle('AccountingSettings');
- await doc.set({
- companyName,
- country,
- fullname: name,
- email,
- bankName,
- fiscalYearStart,
- fiscalYearEnd,
- currency: countryList[country]['currency']
- });
-
- await doc.update();
-
- const printSettings = await frappe.getSingle('PrintSettings');
- printSettings.set({
- logo: companyLogo,
- companyName,
- email,
- displayLogo: companyLogo ? 1 : 0
- });
- await printSettings.update();
-
- await setupGlobalCurrencies(countryList);
- await setupChartOfAccounts(bankName);
- await setupRegionalChanges(country);
-
- await setupWizardValues.set({ completed: 1 });
- await setupWizardValues.update();
-
- frappe.events.trigger('show-desk');
- });
-
- async function setupGlobalCurrencies(countries) {
- const promises = [];
- const queue = [];
- for (let country of Object.values(countries)) {
- const {
- currency,
- currency_fraction: fraction,
- currency_fraction_units: fractionUnits,
- smallest_currency_fraction_value: smallestValue,
- currency_symbol: symbol,
- number_format: numberFormat
- } = country;
-
- if (currency) {
- const exists = queue.includes(currency);
- if (!exists) {
- const doc = await frappe.newDoc({
- doctype: 'Currency',
- name: currency,
- fraction,
- fractionUnits,
- smallestValue,
- symbol,
- numberFormat: numberFormat || '#,###.##'
- });
- promises.push(doc.insert());
- queue.push(currency);
- }
- }
- }
- return Promise.all(promises);
- }
-
- async function setupChartOfAccounts(bankName) {
- await frappe.call({
- method: 'import-coa'
- });
-
- const accountDoc = await frappe.newDoc({
- doctype: 'Account'
- });
- Object.assign(accountDoc, {
- name: bankName,
- rootType: 'Asset',
- parentAccount: 'Bank Accounts',
- accountType: 'Bank',
- isGroup: 0
- });
- accountDoc.insert();
- }
-
- async function setupRegionalChanges(country) {
- const generateRegionalTaxes = require('../models/doctype/Tax/RegionalChanges');
- await generateRegionalTaxes(country);
- if (country === 'India') {
- frappe.models.Party = require('../models/doctype/Party/RegionalChanges');
- await frappe.db.migrate();
- }
- }
-
- async function connectToLocalDatabase(filepath) {
- frappe.login('Administrator');
- frappe.db = new SQLite({
- dbPath: filepath
- });
- await frappe.db.connect();
- await frappe.db.migrate();
- await postStart();
- }
-
window.frappe = frappe;
Vue.config.productionTip = false;
diff --git a/src/pages/DatabaseSelector.vue b/src/pages/DatabaseSelector.vue
index 4c93b19a..71b24c0b 100644
--- a/src/pages/DatabaseSelector.vue
+++ b/src/pages/DatabaseSelector.vue
@@ -44,18 +44,26 @@