mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-13 09:34:10 +08:00
新增 showDevTools
This commit is contained in:
parent
219d0146e0
commit
8f2d332cda
0
plugin/lib/sandbox.html
Normal file
0
plugin/lib/sandbox.html
Normal file
7
plugin/lib/sandbox.js
Normal file
7
plugin/lib/sandbox.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
const nodeFns = require("./nodeFns")
|
||||||
|
window._ = require("lodash")
|
||||||
|
window.utools = require("./utoolsLite")()
|
||||||
|
|
||||||
|
Object.keys(nodeFns).forEach(key => {
|
||||||
|
window[key] = nodeFns[key]
|
||||||
|
})
|
14
plugin/lib/utoolsLite.js
Normal file
14
plugin/lib/utoolsLite.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
const getuToolsLite = () => {
|
||||||
|
var utoolsLite = Object.assign({}, _.cloneDeep(utools))
|
||||||
|
// if (utools.isDev()) return utoolsLite
|
||||||
|
const dbBlackList = ['db', 'dbStorage', 'removeFeature', 'setFeature', 'onDbPull']
|
||||||
|
const payBlackList = ['fetchUserServerTemporaryToken', 'getUserServerTemporaryToken', 'openPayment', 'fetchUserPayments']
|
||||||
|
const etcBlackList = ['onPluginEnter', 'onPluginOut', 'createBrowserWindow']
|
||||||
|
_.concat(dbBlackList, payBlackList, etcBlackList).forEach(item => {
|
||||||
|
delete utoolsLite[item]
|
||||||
|
})
|
||||||
|
Object.freeze(utoolsLite)
|
||||||
|
return utoolsLite
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = getuToolsLite
|
@ -12,6 +12,7 @@ const kill = require('tree-kill')
|
|||||||
require('ses')
|
require('ses')
|
||||||
|
|
||||||
window._ = require("lodash")
|
window._ = require("lodash")
|
||||||
|
window.getuToolsLite = require("./lib/utoolsLite")
|
||||||
window.yuQueClient = axios.create({
|
window.yuQueClient = axios.create({
|
||||||
baseURL: 'https://www.yuque.com/api/v2/',
|
baseURL: 'https://www.yuque.com/api/v2/',
|
||||||
headers: {
|
headers: {
|
||||||
@ -61,6 +62,7 @@ const shortCodes = [
|
|||||||
|
|
||||||
const ctlKey = utools.isMacOs() ? 'command' : 'control'
|
const ctlKey = utools.isMacOs() ? 'command' : 'control'
|
||||||
|
|
||||||
|
const createBrowserWindow = utools.createBrowserWindow
|
||||||
window.quickcommand = {
|
window.quickcommand = {
|
||||||
// 模拟复制操作
|
// 模拟复制操作
|
||||||
simulateCopy: function() {
|
simulateCopy: function() {
|
||||||
@ -173,6 +175,28 @@ window.quickcommand = {
|
|||||||
process.execPath.replace(/\/Frameworks\/.*/, "/MacOS/uTools") :
|
process.execPath.replace(/\/Frameworks\/.*/, "/MacOS/uTools") :
|
||||||
process.execPath
|
process.execPath
|
||||||
child_process.exec(uToolsPath, () => {})
|
child_process.exec(uToolsPath, () => {})
|
||||||
|
},
|
||||||
|
|
||||||
|
// 显示一个全功能的 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)
|
||||||
|
})
|
||||||
|
return browserWindow
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -450,28 +474,6 @@ let parseItem = item => {
|
|||||||
|
|
||||||
let parseStdout = stdout => stdout.map(x => parseItem(x)).join("\n")
|
let parseStdout = stdout => stdout.map(x => parseItem(x)).join("\n")
|
||||||
|
|
||||||
// 屏蔽危险函数
|
|
||||||
window.getuToolsLite = () => {
|
|
||||||
var utoolsLite = Object.assign({}, _.cloneDeep(utools))
|
|
||||||
// if (utools.isDev()) return utoolsLite
|
|
||||||
// 数据库相关接口
|
|
||||||
delete utoolsLite.db
|
|
||||||
delete utoolsLite.dbStorage
|
|
||||||
delete utoolsLite.removeFeature
|
|
||||||
delete utoolsLite.setFeature
|
|
||||||
delete utoolsLite.onDbPull
|
|
||||||
// 支付相关接口
|
|
||||||
delete utoolsLite.fetchUserServerTemporaryToken
|
|
||||||
delete utoolsLite.getUserServerTemporaryToken
|
|
||||||
delete utoolsLite.openPayment
|
|
||||||
delete utoolsLite.fetchUserPayments
|
|
||||||
// 其他
|
|
||||||
delete utoolsLite.onPluginEnter
|
|
||||||
delete utoolsLite.onPluginOut
|
|
||||||
Object.freeze(utoolsLite)
|
|
||||||
return utoolsLite
|
|
||||||
}
|
|
||||||
|
|
||||||
let getSandboxFuns = () => {
|
let getSandboxFuns = () => {
|
||||||
var sandbox = {
|
var sandbox = {
|
||||||
fetch: fetch.bind(window),
|
fetch: fetch.bind(window),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user