feat: 支持openDialog api

This commit is contained in:
muwoo 2021-06-11 10:03:42 +08:00
parent 31d57fc404
commit d0e489c36a
4 changed files with 24 additions and 5 deletions

View File

@ -1,4 +1,4 @@
import {app, BrowserWindow} from 'electron'; import {app, BrowserWindow, dialog} from 'electron';
import {getlocalDataFile, saveData, getData} from './utils'; import {getlocalDataFile, saveData, getData} from './utils';
import path from "path"; import path from "path";
@ -25,6 +25,9 @@ export default {
showMainWindow(arg, mainWindow) { showMainWindow(arg, mainWindow) {
mainWindow.show(); mainWindow.show();
}, },
showOpenDialog({options}) {
return JSON.parse(JSON.stringify(dialog.showOpenDialogSync(options)));
},
onPluginEnter(arg) { onPluginEnter(arg) {
return arg return arg
}, },

View File

@ -63,7 +63,7 @@ export default function init(mainWindow) {
fn = fn[op]; fn = fn[op];
}); });
const data = await fn(arg, window); const data = await fn(arg, window);
window.webContents.send(`msg-back-${arg.type}`, data); event.sender.send(`msg-back-${arg.type}`, data);
}); });
ipcMain.on('new-window', (event, arg) => { ipcMain.on('new-window', (event, arg) => {

View File

@ -14,7 +14,10 @@ function getWindowHeight(searchList) {
} }
function searchKeyValues(lists, value){ function searchKeyValues(lists, value){
return lists.filter(item => item.indexOf(value) >= 0) return lists.filter(item => {
if (typeof item === 'string') return item.indexOf(value) >= 0;
return item.type.indexOf(value) >= 0;
})
} }
function existOrNot(path) { function existOrNot(path) {

View File

@ -16,7 +16,7 @@ function getQueryVariable(variable) {
if (location.href.indexOf('targetFile') > -1) { if (location.href.indexOf('targetFile') > -1) {
filePath = decodeURIComponent(getQueryVariable('targetFile')); filePath = decodeURIComponent(getQueryVariable('targetFile'));
} else { } else {
filePath = location.href.replace('file://', ''); filePath = location.pathname.replace('file://', '');
} }
const {ipcRenderer, nativeImage, clipboard, remote} = require('electron'); const {ipcRenderer, nativeImage, clipboard, remote} = require('electron');
@ -105,7 +105,8 @@ window.utools = window.rubick = {
name, name,
}); });
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
ipcRenderer.once(`msg-back-getPath`, (e, result) => { ipcRenderer.on(`msg-back-getPath`, (e, result) => {
console.log(result)
result ? resolve(result) : reject(); result ? resolve(result) : reject();
}); });
}) })
@ -118,6 +119,18 @@ window.utools = window.rubick = {
return myNotification; return myNotification;
// todo 实现 clickFeatureCode // todo 实现 clickFeatureCode
}, },
showOpenDialog(options) {
ipcRenderer.send('msg-trigger', {
type: 'showOpenDialog',
options: {...options},
});
return new Promise((resolve, reject) => {
ipcRenderer.once(`msg-back-showOpenDialog`, (e, result) => {
result ? resolve(result) : reject();
});
})
},
copyImage(img) { copyImage(img) {
convertImgToBase64(img,function(base64Image) { convertImgToBase64(img,function(base64Image) {
const image = nativeImage.createFromDataURL(base64Image) const image = nativeImage.createFromDataURL(base64Image)