mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-20 11:16:01 +00:00
removed dependencies on electron remote
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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'] },
|
||||
|
||||
Reference in New Issue
Block a user