diff --git a/plugin/lib/nodeFns.js b/plugin/lib/nodeFns.js deleted file mode 100644 index f84bf1e..0000000 --- a/plugin/lib/nodeFns.js +++ /dev/null @@ -1,51 +0,0 @@ -const nodeFns = { - AbortController, - AbortSignal, - Array, - ArrayBuffer, - Boolean, - Buffer, - DataView, - Date, - Error, - EvalError, - Float32Array, - Float64Array, - Function, - Int16Array, - Int32Array, - Int8Array, - Intl, - JSON, - Math, - Number, - Object, - RangeError, - ReferenceError, - RegExp, - String, - SyntaxError, - TypeError, - URIError, - URL, - URLSearchParams, - Uint16Array, - Uint32Array, - Uint8Array, - Uint8ClampedArray, - atob, - btoa, - decodeURI, - decodeURIComponent, - encodeURI, - encodeURIComponent, - escape, - isFinite, - isNaN, - parseFloat, - parseInt, - require, - unescape, -}; - -module.exports = nodeFns diff --git a/plugin/lib/sandbox.js b/plugin/lib/sandbox.js index aaf1463..dcfa3b2 100644 --- a/plugin/lib/sandbox.js +++ b/plugin/lib/sandbox.js @@ -1,7 +1,13 @@ -const nodeFns = require("./nodeFns") window._ = require("lodash") window.utools = require("./utoolsLite")() - -Object.keys(nodeFns).forEach(key => { - window[key] = nodeFns[key] -}) +window.exit = () => { + process.exit() +} +// 绕过限制 +setTimeout(() => { + Object.assign(window, { + process, + Buffer, + require + }) +}, 100); diff --git a/plugin/preload.js b/plugin/preload.js index 566d98c..5db3108 100644 --- a/plugin/preload.js +++ b/plugin/preload.js @@ -7,7 +7,6 @@ const path = require("path") const axios = require('axios'); const http = require('http'); const url = require('url') -const nodeFns = require("./lib/nodeFns") const kill = require('tree-kill') require('ses') @@ -63,6 +62,7 @@ const shortCodes = [ const ctlKey = utools.isMacOs() ? 'command' : 'control' const createBrowserWindow = utools.createBrowserWindow +let browserWindow window.quickcommand = { // 模拟复制操作 simulateCopy: function() { @@ -179,23 +179,19 @@ window.quickcommand = { // 显示一个全功能的 devTools showDevTools: function() { - const browserWindow = createBrowserWindow('lib/sandbox.html', { - show: false, - title: '快捷命令', - webPreferences: { - preload: 'lib/sandbox.js', - }, - }, () => { - browserWindow.webContents.openDevTools({ - mode: 'detach' - }) - let timer = setInterval(() => { - if (!browserWindow.webContents.isDevToolsOpened()) { - clearInterval(timer) - browserWindow.destroy() - } - }, 1000) + if (!browserWindow || browserWindow.webContents.isDestroyed()) { + browserWindow = createBrowserWindow('lib/sandbox.html', { + show: false, + title: '快捷命令', + webPreferences: { + preload: 'lib/sandbox.js', + }, + }, () => {}) + } + browserWindow.webContents.openDevTools({ + mode: 'detach' }) + // browserWindow.webContents.executeJavaScript(``) return browserWindow } } @@ -482,6 +478,10 @@ let getSandboxFuns = () => { axios, Audio, _, + AbortController, + AbortSignal, + Buffer, + require, // 兼容老版本 fs, path, @@ -491,7 +491,7 @@ let getSandboxFuns = () => { shortCodes.forEach(f => { sandbox[f.name] = f }) - Object.assign(sandbox, nodeFns) + // Object.assign(sandbox, nodeFns) return sandbox }