2
0
mirror of https://github.com/frappe/books.git synced 2025-02-14 01:40:26 +00:00

refactor: remove load existing database cause just ipcRenderer invoke

This commit is contained in:
18alantom 2021-11-29 15:15:23 +05:30
parent 512e16d910
commit 77144ddebe
2 changed files with 9 additions and 24 deletions

View File

@ -4,8 +4,8 @@ import { _ } from 'frappejs';
import SQLite from 'frappejs/backends/sqlite';
import fs from 'fs';
import postStart from '../server/postStart';
import migrate from './migrate';
import { IPC_ACTIONS } from './messages';
import migrate from './migrate';
export async function createNewDatabase() {
const options = {
@ -36,23 +36,6 @@ export async function createNewDatabase() {
return filePath;
}
export async function loadExistingDatabase() {
const options = {
title: _('Select file'),
properties: ['openFile'],
filters: [{ name: 'SQLite DB File', extensions: ['db'] }],
};
const { filePaths } = await ipcRenderer.invoke(
IPC_ACTIONS.GET_OPEN_FILEPATH,
options
);
if (filePaths && filePaths[0]) {
return filePaths[0];
}
}
export async function connectToLocalDatabase(filePath) {
if (!filePath) {
return false;

View File

@ -152,12 +152,10 @@
import fs from 'fs';
import config from '@/config';
import { DateTime } from 'luxon';
import { ipcRenderer } from 'electron';
import { IPC_ACTIONS } from '../messages';
import {
createNewDatabase,
loadExistingDatabase,
connectToLocalDatabase,
} from '@/initialization';
import { createNewDatabase, connectToLocalDatabase } from '@/initialization';
export default {
name: 'DatabaseSelector',
@ -191,7 +189,11 @@ export default {
},
async existingDatabase() {
this.fileSelectedFrom = 'Existing File';
let filePath = await loadExistingDatabase();
const filePath = (await ipcRenderer.invoke(IPC_ACTIONS.GET_OPEN_FILEPATH, {
title: this._('Select file'),
properties: ['openFile'],
filters: [{ name: 'SQLite DB File', extensions: ['db'] }],
}))?.filePaths?.[0];
this.connectToDatabase(filePath);
},
async selectFile(file) {