diff --git a/main/registerIpcMainActionListeners.ts b/main/registerIpcMainActionListeners.ts index 814e8a6a..a159b1aa 100644 --- a/main/registerIpcMainActionListeners.ts +++ b/main/registerIpcMainActionListeners.ts @@ -7,6 +7,7 @@ import { ipcMain, } from 'electron'; import { autoUpdater } from 'electron-updater'; +import { constants } from 'fs'; import fs from 'fs/promises'; import path from 'path'; import { SelectFileOptions, SelectFileReturn } from 'utils/types'; @@ -27,6 +28,16 @@ import { import { saveHtmlAsPdf } from './saveHtmlAsPdf'; export default function registerIpcMainActionListeners(main: Main) { + ipcMain.handle(IPC_ACTIONS.CHECK_DB_ACCESS, async (_, filePath: string) => { + try { + await fs.access(filePath, constants.W_OK | constants.R_OK); + } catch (err) { + return false; + } + + return true; + }); + ipcMain.handle( IPC_ACTIONS.GET_OPEN_FILEPATH, async (_, options: OpenDialogOptions) => { diff --git a/src/App.vue b/src/App.vue index 58a95371..619362c9 100644 --- a/src/App.vue +++ b/src/App.vue @@ -52,7 +52,8 @@ import './styles/index.css'; import { connectToDatabase, dbErrorActionSymbols } from './utils/db'; import { initializeInstance } from './utils/initialization'; import * as injectionKeys from './utils/injectionKeys'; -import { checkForUpdates } from './utils/ipcCalls'; +import { showDialog } from './utils/interactive'; +import { checkDbAccess, checkForUpdates } from './utils/ipcCalls'; import { updateConfigFiles } from './utils/misc'; import { updatePrintTemplates } from './utils/printTemplates'; import { Search } from './utils/search'; @@ -161,6 +162,18 @@ export default defineComponent({ return; } + if (!(await checkDbAccess(filePath))) { + await showDialog({ + title: this.t`Cannot open file`, + type: 'error', + detail: this + .t`Frappe Books does not have access to the selected file: ${filePath}`, + }); + + fyo.config.set('lastSelectedFilePath', null); + return; + } + try { await this.showSetupWizardOrDesk(filePath); } catch (error) { diff --git a/src/pages/DatabaseSelector.vue b/src/pages/DatabaseSelector.vue index 0e74ebaf..ed574a11 100644 --- a/src/pages/DatabaseSelector.vue +++ b/src/pages/DatabaseSelector.vue @@ -37,10 +37,10 @@
- {{ t`New File` }} + {{ t`New Company` }}
- {{ t`Create a new file and store it in your computer.` }} + {{ t`Create a new company and store it on your computer.` }}
- {{ t`Existing File` }} + {{ t`Existing Company` }}
- {{ t`Load an existing .db file from your computer.` }} + {{ t`Load an existing company from your computer.` }} +
++ {{ t`Create Demo` }} +
++ {{ t`Create an instance with demo data to try out Frappe Books.` }}