diff --git a/feature/public/preload.js b/feature/public/preload.js index cb9b158..896da73 100644 --- a/feature/public/preload.js +++ b/feature/public/preload.js @@ -1,16 +1,16 @@ -const {remote} = require("electron"); +const remote = require('@electron/remote'); window.market = { getLocalPlugins() { - return remote.getGlobal("LOCAL_PLUGINS").getLocalPlugins(); + return remote.getGlobal('LOCAL_PLUGINS').getLocalPlugins(); }, downloadPlugin(plugin) { - return remote.getGlobal("LOCAL_PLUGINS").downloadPlugin(plugin); + return remote.getGlobal('LOCAL_PLUGINS').downloadPlugin(plugin); }, deletePlugin(plugin) { - return remote.getGlobal("LOCAL_PLUGINS").deletePlugin(plugin); + return remote.getGlobal('LOCAL_PLUGINS').deletePlugin(plugin); }, refreshPlugin(plugin) { - return remote.getGlobal("LOCAL_PLUGINS").refreshPlugin(plugin); + return remote.getGlobal('LOCAL_PLUGINS').refreshPlugin(plugin); }, }; diff --git a/feature/src/App.vue b/feature/src/App.vue index 38f6eb3..a13b1d6 100644 --- a/feature/src/App.vue +++ b/feature/src/App.vue @@ -69,6 +69,7 @@ init(); } .main-container { + -webkit-app-region: no-drag; display: flex; align-items: flex-start; background: var(--color-body-bg); diff --git a/feature/src/languages/i18n.ts b/feature/src/languages/i18n.ts index 3e44e8c..c55b806 100644 --- a/feature/src/languages/i18n.ts +++ b/feature/src/languages/i18n.ts @@ -1,11 +1,8 @@ import { createI18n } from 'vue-i18n'; import messages from './langs'; -const { remote } = window.require('electron'); +const remote = window.require('@electron/remote'); const { perf } = remote.getGlobal('OP_CONFIG').get(); -console.log(messages); -console.log(perf); - // 2. Create i18n instance with options const i18n = createI18n({ legacy: false, diff --git a/feature/src/main.ts b/feature/src/main.ts index f27ac05..29b8bf5 100644 --- a/feature/src/main.ts +++ b/feature/src/main.ts @@ -7,7 +7,7 @@ import './assets/ant-reset.less'; import 'ant-design-vue/dist/antd.variable.min.css'; import registerI18n from './languages/i18n'; -const { remote } = window.require('electron'); +const remote = window.require('@electron/remote'); const { perf } = remote.getGlobal('OP_CONFIG').get(); diff --git a/feature/src/views/installed/index.vue b/feature/src/views/installed/index.vue index ab12000..45663b2 100644 --- a/feature/src/views/installed/index.vue +++ b/feature/src/views/installed/index.vue @@ -121,7 +121,7 @@ import { message } from 'ant-design-vue'; const { ipcRenderer } = window.require('electron'); -const { remote } = window.require('electron'); +const remote = window.require('@electron/remote'); const fs = window.require('fs'); const md = new MarkdownIt(); diff --git a/feature/src/views/settings/index.vue b/feature/src/views/settings/index.vue index 8ec0773..e132795 100644 --- a/feature/src/views/settings/index.vue +++ b/feature/src/views/settings/index.vue @@ -243,7 +243,8 @@ import UserInfo from './user-info'; import { useI18n } from 'vue-i18n'; const { locale, t } = useI18n(); -const { remote, ipcRenderer } = window.require('electron'); +const { ipcRenderer } = window.require('electron'); +const remote = window.require('@electron/remote'); const examples = [ { diff --git a/feature/src/views/settings/user-info.vue b/feature/src/views/settings/user-info.vue index 170428b..1d37077 100644 --- a/feature/src/views/settings/user-info.vue +++ b/feature/src/views/settings/user-info.vue @@ -139,7 +139,8 @@ import debounce from 'lodash.debounce'; import service from '../../assets/service'; -const { remote, ipcRenderer } = window.require('electron'); +const { ipcRenderer } = window.require('electron'); +const remote = window.require('@electron/remote'); const state = reactive({ custom: {}, diff --git a/package.json b/package.json index f58ec22..8150551 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ }, "dependencies": { "@better-scroll/core": "^2.4.2", + "@electron/remote": "^2.0.10", "ant-design-vue": "3.2.14", "axios": "^1.3.4", "core-js": "^3.6.5", @@ -52,7 +53,7 @@ "@vue/eslint-config-prettier": "^6.0.0", "@vue/eslint-config-typescript": "^7.0.0", "babel-plugin-import": "^1.13.3", - "electron": "^13.0.0", + "electron": "26.0.0", "electron-builder": "22.13.1", "electron-devtools-installer": "^3.1.0", "eslint": "^6.7.2", diff --git a/src/common/constans/main.ts b/src/common/constans/main.ts index 396f216..9526cd0 100644 --- a/src/common/constans/main.ts +++ b/src/common/constans/main.ts @@ -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: "'", }; diff --git a/src/common/constans/renderer.ts b/src/common/constans/renderer.ts index ba1e559..58d7335 100644 --- a/src/common/constans/renderer.ts +++ b/src/common/constans/renderer.ts @@ -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 }; diff --git a/src/common/utils/dragWindow.ts b/src/common/utils/dragWindow.ts index 16788df..48518f6 100644 --- a/src/common/utils/dragWindow.ts +++ b/src/common/utils/dragWindow.ts @@ -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; diff --git a/src/common/utils/getCopyFiles.ts b/src/common/utils/getCopyFiles.ts index e26f865..566acc0 100644 --- a/src/common/utils/getCopyFiles.ts +++ b/src/common/utils/getCopyFiles.ts @@ -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 | 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; diff --git a/src/main/browsers/main.ts b/src/main/browsers/main.ts index c55c530..6a8b968 100644 --- a/src/main/browsers/main.ts +++ b/src/main/browsers/main.ts @@ -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, diff --git a/src/main/browsers/runner.ts b/src/main/browsers/runner.ts index 6b02de3..1d59423 100644 --- a/src/main/browsers/runner.ts +++ b/src/main/browsers/runner.ts @@ -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, diff --git a/src/renderer/App.vue b/src/renderer/App.vue index 8ac3026..5d72f51 100644 --- a/src/renderer/App.vue +++ b/src/renderer/App.vue @@ -1,7 +1,6 @@