removed dependencies on electron remote

This commit is contained in:
Jan Prochazka
2021-12-16 15:41:34 +01:00
parent 588b8b23f9
commit 3d841ef8fe
15 changed files with 87 additions and 54 deletions

View File

@@ -9,7 +9,7 @@ export async function exportElectronFile(dataName, reader, format) {
const electron = getElectron();
const filters = [{ name: format.label, extensions: [format.extension] }];
const filePath = electron.remote.dialog.showSaveDialogSync(electron.remote.getCurrentWindow(), {
const filePath = await electron.showSaveDialog({
filters,
defaultPath: `${dataName}.${format.extension}`,
properties: ['showOverwriteConfirmation'],
@@ -65,14 +65,14 @@ export async function saveFileToDisk(
if (electron) {
const filters = [{ name: formatLabel, extensions: [formatExtension] }];
const filePath = electron.remote.dialog.showSaveDialogSync(electron.remote.getCurrentWindow(), {
const filePath = await electron.showSaveDialog({
filters,
defaultPath: `file.${formatExtension}`,
properties: ['showOverwriteConfirmation'],
});
if (!filePath) return;
await filePathFunc(filePath);
electron.shell.openExternal('file:///' + filePath);
electron.openExternal('file:///' + filePath);
} else {
const resp = await axiosInstance().get('files/generate-uploads-file');
await filePathFunc(resp.data.filePath);

View File

@@ -8,9 +8,28 @@ class ElectronApi {
this.authorization = args.authorization;
}
send(msg, args) {
send(msg, args = null) {
this.ipcRenderer.send(msg, args);
}
async showOpenDialog(options) {
const res = await this.ipcRenderer.invoke('showOpenDialog', options);
return res;
}
async showSaveDialog(options) {
const res = await this.ipcRenderer.invoke('showSaveDialog', options);
return res;
}
async showItemInFolder(path) {
const res = await this.ipcRenderer.invoke('showItemInFolder', path);
return res;
}
async openExternal(url) {
await this.ipcRenderer.invoke('openExternal', url);
}
}
let apiInstance = null;
@@ -39,6 +58,10 @@ export function shouldWaitForElectronInitialize() {
return !!getIpcRenderer() && !apiInstance;
}
export function isElectronAvailable() {
return !!getIpcRenderer();
}
export default function getElectron(): ElectronApi {
return apiInstance;
// try {

View File

@@ -7,7 +7,7 @@ import { showSnackbarSuccess } from './snackbar';
export async function openArchiveFolder() {
const electron = getElectron();
const ext = get(extensions);
const filePaths = electron.remote.dialog.showOpenDialogSync(electron.remote.getCurrentWindow(), {
const filePaths = await electron.showOpenDialog({
properties: ['openDirectory'],
});
const linkedFolder = filePaths && filePaths[0];

View File

@@ -107,10 +107,10 @@ function getFileFormatExtensions(extensions) {
return extensions.fileFormats.filter(x => x.readerFunc).map(x => x.extension);
}
export function openElectronFile() {
export async function openElectronFile() {
const electron = getElectron();
const ext = get(extensions);
const filePaths = electron.remote.dialog.showOpenDialogSync(electron.remote.getCurrentWindow(), {
const filePaths = await electron.showOpenDialog({
filters: [
{ name: `All supported files`, extensions: ['sql', 'sqlite', 'db', 'sqlite3', ...getFileFormatExtensions(ext)] },
{ name: `SQL files`, extensions: ['sql'] },