2
0
mirror of https://github.com/frappe/books.git synced 2024-11-08 23:00:56 +00:00

Merge pull request #678 from frappe/dbaccess

fix(ux): check db access before opening file
This commit is contained in:
Alan 2023-06-28 22:42:02 -07:00 committed by GitHub
commit 8976d4c44b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 58 additions and 5 deletions

View File

@ -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) => {

View File

@ -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) {

View File

@ -37,10 +37,10 @@
<div>
<p class="font-medium">
{{ t`New File` }}
{{ t`New Company` }}
</p>
<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>
</div>
</div>
@ -56,10 +56,30 @@
</div>
<div>
<p class="font-medium">
{{ t`Existing File` }}
{{ t`Existing Company` }}
</p>
<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>
</div>
</div>
<!-- Create Demo (Pink Icon) -->
<div
v-if="!files?.length"
class="px-4 h-row-largest flex flex-row items-center gap-4 p-2"
:class="creatingDemo ? '' : 'hover:bg-gray-50 cursor-pointer'"
@click="createDemo"
>
<div class="w-8 h-8 rounded-full bg-pink-500 relative flex-center">
<feather-icon name="monitor" class="w-4 h-4 text-white" />
</div>
<div>
<p class="font-medium">
{{ t`Create Demo` }}
</p>
<p class="text-sm text-gray-600">
{{ t`Create an instance with demo data to try out Frappe Books.` }}
</p>
</div>
</div>
@ -146,6 +166,7 @@
>
<LanguageSelector v-show="!creatingDemo" class="text-sm w-28" />
<button
v-if="files?.length"
class="
text-sm
bg-gray-100

View File

@ -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();

View File

@ -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',