mirror of
https://github.com/frappe/books.git
synced 2024-11-09 23:30:56 +00:00
fix(ux): check db access before opening
This commit is contained in:
parent
16ba36982f
commit
c1b3687221
@ -7,6 +7,7 @@ import {
|
|||||||
ipcMain,
|
ipcMain,
|
||||||
} from 'electron';
|
} from 'electron';
|
||||||
import { autoUpdater } from 'electron-updater';
|
import { autoUpdater } from 'electron-updater';
|
||||||
|
import { constants } from 'fs';
|
||||||
import fs from 'fs/promises';
|
import fs from 'fs/promises';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { SelectFileOptions, SelectFileReturn } from 'utils/types';
|
import { SelectFileOptions, SelectFileReturn } from 'utils/types';
|
||||||
@ -27,6 +28,16 @@ import {
|
|||||||
import { saveHtmlAsPdf } from './saveHtmlAsPdf';
|
import { saveHtmlAsPdf } from './saveHtmlAsPdf';
|
||||||
|
|
||||||
export default function registerIpcMainActionListeners(main: Main) {
|
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(
|
ipcMain.handle(
|
||||||
IPC_ACTIONS.GET_OPEN_FILEPATH,
|
IPC_ACTIONS.GET_OPEN_FILEPATH,
|
||||||
async (_, options: OpenDialogOptions) => {
|
async (_, options: OpenDialogOptions) => {
|
||||||
|
15
src/App.vue
15
src/App.vue
@ -52,7 +52,8 @@ import './styles/index.css';
|
|||||||
import { connectToDatabase, dbErrorActionSymbols } from './utils/db';
|
import { connectToDatabase, dbErrorActionSymbols } from './utils/db';
|
||||||
import { initializeInstance } from './utils/initialization';
|
import { initializeInstance } from './utils/initialization';
|
||||||
import * as injectionKeys from './utils/injectionKeys';
|
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 { updateConfigFiles } from './utils/misc';
|
||||||
import { updatePrintTemplates } from './utils/printTemplates';
|
import { updatePrintTemplates } from './utils/printTemplates';
|
||||||
import { Search } from './utils/search';
|
import { Search } from './utils/search';
|
||||||
@ -161,6 +162,18 @@ export default defineComponent({
|
|||||||
return;
|
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 {
|
try {
|
||||||
await this.showSetupWizardOrDesk(filePath);
|
await this.showSetupWizardOrDesk(filePath);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -37,10 +37,10 @@
|
|||||||
|
|
||||||
<div>
|
<div>
|
||||||
<p class="font-medium">
|
<p class="font-medium">
|
||||||
{{ t`New File` }}
|
{{ t`New Company` }}
|
||||||
</p>
|
</p>
|
||||||
<p class="text-sm text-gray-600">
|
<p class="text-sm text-gray-600">
|
||||||
{{ t`Create a new file and store it in your computer.` }}
|
{{ t`Create a new company and store it on your computer.` }}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -56,10 +56,10 @@
|
|||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<p class="font-medium">
|
<p class="font-medium">
|
||||||
{{ t`Existing File` }}
|
{{ t`Existing Company` }}
|
||||||
</p>
|
</p>
|
||||||
<p class="text-sm text-gray-600">
|
<p class="text-sm text-gray-600">
|
||||||
{{ t`Load an existing .db file from your computer.` }}
|
{{ t`Load an existing company from your computer.` }}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -51,6 +51,13 @@ export async function selectFile(
|
|||||||
)) as SelectFileReturn;
|
)) as SelectFileReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function checkDbAccess(filePath: string) {
|
||||||
|
return (await ipcRenderer.invoke(
|
||||||
|
IPC_ACTIONS.CHECK_DB_ACCESS,
|
||||||
|
filePath
|
||||||
|
)) as boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export async function checkForUpdates() {
|
export async function checkForUpdates() {
|
||||||
await ipcRenderer.invoke(IPC_ACTIONS.CHECK_FOR_UPDATES);
|
await ipcRenderer.invoke(IPC_ACTIONS.CHECK_FOR_UPDATES);
|
||||||
await setLanguageMap();
|
await setLanguageMap();
|
||||||
|
@ -19,6 +19,7 @@ export enum IPC_ACTIONS {
|
|||||||
SEND_ERROR = 'send-error',
|
SEND_ERROR = 'send-error',
|
||||||
GET_LANGUAGE_MAP = 'get-language-map',
|
GET_LANGUAGE_MAP = 'get-language-map',
|
||||||
CHECK_FOR_UPDATES = 'check-for-updates',
|
CHECK_FOR_UPDATES = 'check-for-updates',
|
||||||
|
CHECK_DB_ACCESS = 'check-db-access',
|
||||||
SELECT_FILE = 'select-file',
|
SELECT_FILE = 'select-file',
|
||||||
GET_CREDS = 'get-creds',
|
GET_CREDS = 'get-creds',
|
||||||
GET_DB_LIST = 'get-db-list',
|
GET_DB_LIST = 'get-db-list',
|
||||||
|
Loading…
Reference in New Issue
Block a user