⬆️ 升级 electron 到 26

This commit is contained in:
muwoo
2023-08-22 13:52:47 +08:00
parent 6e5a08b9d8
commit d2d94c13b7
21 changed files with 199 additions and 196 deletions

View File

@@ -1,89 +1,86 @@
import { app } from "electron";
import path from "path";
import { app } from 'electron';
import path from 'path';
const appPath = app.getPath("cache");
const appPath = app.getPath('userData');
console.log(appPath);
const PLUGIN_INSTALL_DIR = path.join(appPath, "./rubick-plugins");
const PLUGIN_INSTALL_DIR = path.join(appPath, './rubick-plugins');
const DECODE_KEY = {
Backspace: "Backspace",
Tab: "Tab",
Enter: "Enter",
MediaPlayPause: "MediaPlayPause",
Escape: "Escape",
Space: "Space",
PageUp: "PageUp",
PageDown: "PageDown",
End: "End",
Home: "Home",
ArrowLeft: "Left",
ArrowUp: "Up",
ArrowRight: "Right",
ArrowDown: "Down",
PrintScreen: "PrintScreen",
Insert: "Insert",
Delete: "Delete",
Digit0: "0",
Digit1: "1",
Digit2: "2",
Digit3: "3",
Digit4: "4",
Digit5: "5",
Digit6: "6",
Digit7: "7",
Digit8: "8",
Digit9: "9",
KeyA: "A",
KeyB: "B",
KeyC: "C",
KeyD: "D",
KeyE: "E",
KeyF: "F",
KeyG: "G",
KeyH: "H",
KeyI: "I",
KeyJ: "J",
KeyK: "K",
KeyL: "L",
KeyM: "M",
KeyN: "N",
KeyO: "O",
KeyP: "P",
KeyQ: "Q",
KeyR: "R",
KeyS: "S",
KeyT: "T",
KeyU: "U",
KeyV: "V",
KeyW: "W",
KeyX: "X",
KeyY: "Y",
KeyZ: "Z",
F1: "F1",
F2: "F2",
F3: "F3",
F4: "F4",
F5: "F5",
F6: "F6",
F7: "F7",
F8: "F8",
F9: "F9",
F10: "F10",
F11: "F11",
F12: "F12",
Semicolon: ";",
Equal: "=",
Comma: ",",
Minus: "-",
Period: ".",
Slash: "/",
Backquote: "`",
BracketLeft: "[",
Backslash: "\\",
BracketRight: "]",
Backspace: 'Backspace',
Tab: 'Tab',
Enter: 'Enter',
MediaPlayPause: 'MediaPlayPause',
Escape: 'Escape',
Space: 'Space',
PageUp: 'PageUp',
PageDown: 'PageDown',
End: 'End',
Home: 'Home',
ArrowLeft: 'Left',
ArrowUp: 'Up',
ArrowRight: 'Right',
ArrowDown: 'Down',
PrintScreen: 'PrintScreen',
Insert: 'Insert',
Delete: 'Delete',
Digit0: '0',
Digit1: '1',
Digit2: '2',
Digit3: '3',
Digit4: '4',
Digit5: '5',
Digit6: '6',
Digit7: '7',
Digit8: '8',
Digit9: '9',
KeyA: 'A',
KeyB: 'B',
KeyC: 'C',
KeyD: 'D',
KeyE: 'E',
KeyF: 'F',
KeyG: 'G',
KeyH: 'H',
KeyI: 'I',
KeyJ: 'J',
KeyK: 'K',
KeyL: 'L',
KeyM: 'M',
KeyN: 'N',
KeyO: 'O',
KeyP: 'P',
KeyQ: 'Q',
KeyR: 'R',
KeyS: 'S',
KeyT: 'T',
KeyU: 'U',
KeyV: 'V',
KeyW: 'W',
KeyX: 'X',
KeyY: 'Y',
KeyZ: 'Z',
F1: 'F1',
F2: 'F2',
F3: 'F3',
F4: 'F4',
F5: 'F5',
F6: 'F6',
F7: 'F7',
F8: 'F8',
F9: 'F9',
F10: 'F10',
F11: 'F11',
F12: 'F12',
Semicolon: ';',
Equal: '=',
Comma: ',',
Minus: '-',
Period: '.',
Slash: '/',
Backquote: '`',
BracketLeft: '[',
Backslash: '\\',
BracketRight: ']',
Quote: "'",
};

View File

@@ -1,8 +1,8 @@
import { remote } from "electron";
import path from "path";
import { app } from '@electron/remote';
import path from 'path';
const appPath = remote.app.getPath("cache");
const appPath = app.getPath('userData');
const PLUGIN_INSTALL_DIR = path.join(appPath, "./rubick-plugins");
const PLUGIN_INSTALL_DIR = path.join(appPath, './rubick-plugins');
export { PLUGIN_INSTALL_DIR };

View File

@@ -10,7 +10,7 @@ const useDrag = () => {
let draggable = true;
const onMouseDown = (e) => {
if (commonConst.macOS()) return;
// if (commonConst.macOS()) return;
draggable = true;
mouseX = e.clientX;
mouseY = e.clientY;

View File

@@ -1,33 +1,33 @@
import commonConst from "./commonConst";
import { clipboard, remote } from "electron";
import plist from "plist";
import fs from "fs";
import path from "path";
import ofs from "original-fs";
import commonConst from './commonConst';
import { clipboard } from 'electron';
import plist from 'plist';
import fs from 'fs';
import path from 'path';
import ofs from 'original-fs';
export default function getCopyFiles(): Array<any> | null {
let fileInfo;
if (commonConst.macOS()) {
if (!clipboard.has("NSFilenamesPboardType")) return null;
const result = clipboard.read("NSFilenamesPboardType");
if (!clipboard.has('NSFilenamesPboardType')) return null;
const result = clipboard.read('NSFilenamesPboardType');
if (!result) return null;
try {
fileInfo = plist.parse(result);
} catch (e) {
return null;
}
} else if (process.platform === "win32") {
} else if (process.platform === 'win32') {
/* eslint-disable */
const clipboardEx = require("electron-clipboard-ex");
const clipboardEx = require('electron-clipboard-ex');
fileInfo = clipboardEx.readFilePaths();
// todo
} else {
if (!commonConst.linux()) return null;
if (!clipboard.has("text/uri-list")) return null;
const result = clipboard.read("text/uri-list").match(/^file:\/\/\/.*/gm);
if (!clipboard.has('text/uri-list')) return null;
const result = clipboard.read('text/uri-list').match(/^file:\/\/\/.*/gm);
if (!result || !result.length) return null;
fileInfo = result.map((e) =>
decodeURIComponent(e).replace(/^file:\/\//, "")
decodeURIComponent(e).replace(/^file:\/\//, '')
);
}
if (!Array.isArray(fileInfo)) return null;

View File

@@ -2,11 +2,16 @@ import { app, BrowserWindow, protocol, nativeTheme } from 'electron';
import path from 'path';
import { createProtocol } from 'vue-cli-plugin-electron-builder/lib';
import versonHandler from '../common/versionHandler';
// eslint-disable-next-line @typescript-eslint/no-var-requires
require('@electron/remote/main').initialize();
export default () => {
let win: any;
const init = () => {
createWindow();
// eslint-disable-next-line @typescript-eslint/no-var-requires
require('@electron/remote/main').enable(win.webContents);
};
const createWindow = async () => {
@@ -22,7 +27,6 @@ export default () => {
backgroundColor: nativeTheme.shouldUseDarkColors ? '#1c1c28' : '#fff',
webPreferences: {
webSecurity: false,
enableRemoteModule: true,
backgroundThrottling: false,
contextIsolation: false,
webviewTag: true,

View File

@@ -33,6 +33,8 @@ export default () => {
const init = (plugin, window: BrowserWindow) => {
if (view === null || view === undefined) {
createView(plugin, window);
// eslint-disable-next-line @typescript-eslint/no-var-requires
require('@electron/remote/main').enable(view.webContents);
}
};
@@ -65,7 +67,6 @@ export default () => {
view = new BrowserView({
webPreferences: {
enableRemoteModule: true,
webSecurity: false,
nodeIntegration: true,
contextIsolation: false,

View File

@@ -1,7 +1,6 @@
<template>
<div
id="components-layout"
:class="commonConst.macOS() && 'drag'"
@mousedown="onMouseDown"
>
<Search
@@ -32,7 +31,7 @@
<script setup lang="ts">
import { watch, ref, nextTick, toRaw } from 'vue';
import { ipcRenderer, remote } from 'electron';
import { ipcRenderer } from 'electron';
import Result from './components/result.vue';
import Search from './components/search.vue';
import getWindowHeight from '../common/utils/getWindowHeight';
@@ -41,6 +40,7 @@ import useDrag from '../common/utils/dragWindow';
import commonConst from '@/common/utils/commonConst';
const { onMouseDown } = useDrag();
const remote = window.require('@electron/remote');
const {
initPlugins,

View File

@@ -53,9 +53,10 @@
<script setup lang="ts">
import { defineProps, defineEmits, ref } from 'vue';
import { ipcRenderer, remote } from 'electron';
import { ipcRenderer } from 'electron';
import { LoadingOutlined, MoreOutlined } from '@ant-design/icons-vue';
const remote = window.require('@electron/remote');
const opConfig = remote.getGlobal('OP_CONFIG');
const { Menu } = remote;
@@ -261,6 +262,9 @@ window.rubick.hooks.onHide = () => {
left: 0;
width: 100%;
align-items: center;
height: 60px;
display: flex;
align-items: center;
.ellipse {
overflow: hidden;
text-overflow: ellipsis;
@@ -284,7 +288,7 @@ window.rubick.hooks.onHide = () => {
}
.main-input {
height: 60px !important;
height: 40px !important;
box-sizing: border-box;
flex: 1;
border: none;

View File

@@ -12,9 +12,9 @@ import App from './App.vue';
import 'ant-design-vue/dist/antd.variable.min.css';
const { remote } = window.require('electron');
const { getGlobal } = window.require('@electron/remote');
const { perf } = remote.getGlobal('OP_CONFIG').get();
const { perf } = getGlobal('OP_CONFIG').get();
ConfigProvider.config({
theme: perf.custom || {},

View File

@@ -1,5 +1,6 @@
import getCopyFiles from '@/common/utils/getCopyFiles';
import { clipboard, nativeImage, remote, ipcRenderer } from 'electron';
import { clipboard, nativeImage, ipcRenderer } from 'electron';
import { getGlobal } from '@electron/remote';
import path from 'path';
import pluginClickEvent from './pluginClickEvent';
import { ref } from 'vue';
@@ -7,7 +8,7 @@ import { ref } from 'vue';
export default ({ currentPlugin, optionsRef, openPlugin, setOptionsRef }) => {
const clipboardFile: any = ref([]);
const searchFocus = () => {
const config = remote.getGlobal('OP_CONFIG').get();
const config = getGlobal('OP_CONFIG').get();
// 未开启自动粘贴
if (!config.perf.common.autoPast) return;
@@ -17,7 +18,7 @@ export default ({ currentPlugin, optionsRef, openPlugin, setOptionsRef }) => {
if (fileList) {
window.setSubInputValue({ value: '' });
clipboardFile.value = fileList;
const localPlugins = remote.getGlobal('LOCAL_PLUGINS').getLocalPlugins();
const localPlugins = getGlobal('LOCAL_PLUGINS').getLocalPlugins();
const options: any = [
{
name: '复制路径',
@@ -143,7 +144,7 @@ export default ({ currentPlugin, optionsRef, openPlugin, setOptionsRef }) => {
dataUrl,
},
];
const localPlugins = remote.getGlobal('LOCAL_PLUGINS').getLocalPlugins();
const localPlugins = getGlobal('LOCAL_PLUGINS').getLocalPlugins();
const options: any = [];
// 再正则插件
localPlugins.forEach((plugin) => {

View File

@@ -1,5 +1,6 @@
import { reactive, toRefs, ref } from 'vue';
import { nativeImage, remote, ipcRenderer } from 'electron';
import { nativeImage, ipcRenderer } from 'electron';
import { getGlobal } from '@electron/remote';
import appSearch from '@/core/app-search';
import { PluginHandler } from '@/core';
import path from 'path';
@@ -112,7 +113,7 @@ const createPluginManager = (): any => {
window.updatePlugin = ({ currentPlugin }: any) => {
state.currentPlugin = currentPlugin;
remote.getGlobal('LOCAL_PLUGINS').updatePlugin(currentPlugin);
getGlobal('LOCAL_PLUGINS').updatePlugin(currentPlugin);
};
window.setCurrentPlugin = ({ currentPlugin }) => {

View File

@@ -1,6 +1,7 @@
import { ref, watch } from 'vue';
import throttle from 'lodash.throttle';
import { remote, ipcRenderer } from 'electron';
import { ipcRenderer } from 'electron';
import { getGlobal } from '@electron/remote';
import pluginClickEvent from './pluginClickEvent';
import useFocus from './clipboardWatch';
@@ -40,7 +41,7 @@ const optionsManager = ({
});
const getOptionsFromSearchValue = (value, strict = false) => {
const localPlugins = remote.getGlobal('LOCAL_PLUGINS').getLocalPlugins();
const localPlugins = getGlobal('LOCAL_PLUGINS').getLocalPlugins();
let options: any = [];
// todo 先搜索 plugin
localPlugins.forEach((plugin) => {