diff --git a/main/preload.ts b/main/preload.ts
index 679f62b2a..e0a700e98 100644
--- a/main/preload.ts
+++ b/main/preload.ts
@@ -117,6 +117,13 @@ const ipc = {
)) as ConfigFilesWithModified[];
},
+ async getDbDefaultPath(companyName: string) {
+ return (await ipcRenderer.invoke(
+ IPC_ACTIONS.GET_DB_DEFAULT_PATH,
+ companyName
+ )) as string;
+ },
+
async getEnv() {
return (await ipcRenderer.invoke(IPC_ACTIONS.GET_ENV)) as {
isDevelopment: boolean;
diff --git a/main/registerIpcMainActionListeners.ts b/main/registerIpcMainActionListeners.ts
index d92e8c628..7194dad0e 100644
--- a/main/registerIpcMainActionListeners.ts
+++ b/main/registerIpcMainActionListeners.ts
@@ -8,7 +8,7 @@ import {
} from 'electron';
import { autoUpdater } from 'electron-updater';
import { constants } from 'fs';
-import fs from 'fs/promises';
+import fs from 'fs-extra';
import path from 'path';
import { SelectFileOptions, SelectFileReturn } from 'utils/types';
import databaseManager from '../backend/database/manager';
@@ -38,6 +38,22 @@ export default function registerIpcMainActionListeners(main: Main) {
return true;
});
+ ipcMain.handle(
+ IPC_ACTIONS.GET_DB_DEFAULT_PATH,
+ async (_, companyName: string) => {
+ let root = app.getPath('documents');
+ if (main.isDevelopment) {
+ root = 'dbs';
+ }
+
+ const dbsPath = path.join(root, 'Frappe Books');
+ const backupPath = path.join(dbsPath, 'backups');
+ await fs.ensureDir(backupPath);
+
+ return path.join(dbsPath, `${companyName}.books.db`);
+ }
+ );
+
ipcMain.handle(
IPC_ACTIONS.GET_OPEN_FILEPATH,
async (_, options: OpenDialogOptions) => {
diff --git a/src/App.vue b/src/App.vue
index 71fab550d..c40b1b279 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -19,6 +19,7 @@
{
this.searcher = new Search(fyo);
@@ -156,13 +157,11 @@ export default defineComponent({
await this.setSearcher();
updateConfigFiles(fyo);
},
- async fileSelected(filePath: string, isNew?: boolean): Promise {
+ newDatabase() {
+ this.activeScreen = Screen.SetupWizard;
+ },
+ async fileSelected(filePath: string): Promise {
fyo.config.set('lastSelectedFilePath', filePath);
- if (isNew) {
- this.activeScreen = Screen.SetupWizard;
- return;
- }
-
if (filePath !== ':memory:' && !(await ipc.checkDbAccess(filePath))) {
await showDialog({
title: this.t`Cannot open file`,
@@ -183,12 +182,10 @@ export default defineComponent({
}
},
async setupComplete(setupWizardOptions: SetupWizardOptions): Promise {
- const filePath = fyo.config.get('lastSelectedFilePath');
- if (typeof filePath !== 'string') {
- return;
- }
-
+ const companyName = setupWizardOptions.companyName;
+ const filePath = await ipc.getDbDefaultPath(companyName);
await setupInstance(filePath, setupWizardOptions, fyo);
+ fyo.config.set('lastSelectedFilePath', filePath);
await this.setDesk(filePath);
},
async showSetupWizardOrDesk(filePath: string): Promise {
diff --git a/src/pages/DatabaseSelector.vue b/src/pages/DatabaseSelector.vue
index b4a0cb894..f4e76bd68 100644
--- a/src/pages/DatabaseSelector.vue
+++ b/src/pages/DatabaseSelector.vue
@@ -260,7 +260,7 @@ export default defineComponent({
Modal,
Button,
},
- emits: ['file-selected'],
+ emits: ['file-selected', 'new-database'],
data() {
return {
openModal: false,
@@ -363,17 +363,12 @@ export default defineComponent({
(a, b) => Date.parse(b.modified) - Date.parse(a.modified)
);
},
- async newDatabase() {
+ newDatabase() {
if (this.creatingDemo) {
return;
}
- const { filePath, canceled } = await getSavePath('books', 'db');
- if (canceled || !filePath) {
- return;
- }
-
- this.emitFileSelected(filePath, true);
+ this.$emit('new-database');
},
async existingDatabase() {
if (this.creatingDemo) {
@@ -390,17 +385,12 @@ export default defineComponent({
this.emitFileSelected(file.dbPath);
},
- emitFileSelected(filePath: string, isNew?: boolean) {
+ emitFileSelected(filePath: string) {
if (!filePath) {
return;
}
- if (isNew) {
- this.$emit('file-selected', filePath, isNew);
- return;
- }
-
- this.$emit('file-selected', filePath, !!isNew);
+ this.$emit('file-selected', filePath);
},
},
});
diff --git a/uitest/index.mjs b/uitest/index.mjs
index ed3c6cb9b..cbeb8c5b7 100644
--- a/uitest/index.mjs
+++ b/uitest/index.mjs
@@ -44,10 +44,6 @@ const appSourcePath = path.join(root, 'dist_electron', 'build', 'main.js');
});
test('fill setup form', async (t) => {
- await electronApp.evaluate(({ dialog }, filePath) => {
- dialog.showSaveDialog = () =>
- Promise.resolve({ canceled: false, filePath });
- }, ':memory:');
await window.getByTestId('create-new-file').click();
await window.getByTestId('submit-button').waitFor();
diff --git a/utils/messages.ts b/utils/messages.ts
index 2f3ec75be..d470556d4 100644
--- a/utils/messages.ts
+++ b/utils/messages.ts
@@ -25,6 +25,7 @@ export enum IPC_ACTIONS {
GET_DB_LIST = 'get-db-list',
GET_TEMPLATES = 'get-templates',
DELETE_FILE = 'delete-file',
+ GET_DB_DEFAULT_PATH = 'get-db-default-path',
// Database messages
DB_CREATE = 'db-create',
DB_CONNECT = 'db-connect',