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 f9e8de39..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.` }}

@@ -56,10 +56,10 @@

- {{ t`Existing File` }} + {{ t`Existing Company` }}

- {{ t`Load an existing .db file from your computer.` }} + {{ t`Load an existing company from your computer.` }}

diff --git a/src/utils/ipcCalls.ts b/src/utils/ipcCalls.ts index 2882994e..5932e531 100644 --- a/src/utils/ipcCalls.ts +++ b/src/utils/ipcCalls.ts @@ -51,6 +51,13 @@ export async function selectFile( )) as SelectFileReturn; } +export async function checkDbAccess(filePath: string) { + return (await ipcRenderer.invoke( + IPC_ACTIONS.CHECK_DB_ACCESS, + filePath + )) as boolean; +} + export async function checkForUpdates() { await ipcRenderer.invoke(IPC_ACTIONS.CHECK_FOR_UPDATES); await setLanguageMap(); diff --git a/utils/messages.ts b/utils/messages.ts index 7340d4fb..2f3ec75b 100644 --- a/utils/messages.ts +++ b/utils/messages.ts @@ -19,6 +19,7 @@ export enum IPC_ACTIONS { SEND_ERROR = 'send-error', GET_LANGUAGE_MAP = 'get-language-map', CHECK_FOR_UPDATES = 'check-for-updates', + CHECK_DB_ACCESS = 'check-db-access', SELECT_FILE = 'select-file', GET_CREDS = 'get-creds', GET_DB_LIST = 'get-db-list',