mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-10 07:24:37 +08:00
更改enterData的赋值方式
This commit is contained in:
parent
6d8034d950
commit
219d0146e0
@ -212,22 +212,22 @@ if (process.platform !== 'linux') quickcommand.runInTerminal = function(cmdline,
|
|||||||
}
|
}
|
||||||
|
|
||||||
let getCommandToLaunchTerminal = (cmdline, dir) => {
|
let getCommandToLaunchTerminal = (cmdline, dir) => {
|
||||||
let cd = ''
|
let cd = ''
|
||||||
if (utools.isWindows()) {
|
if (utools.isWindows()) {
|
||||||
let appPath = path.join(utools.getPath('home'), '/AppData/Local/Microsoft/WindowsApps/')
|
let appPath = path.join(utools.getPath('home'), '/AppData/Local/Microsoft/WindowsApps/')
|
||||||
// 直接 existsSync wt.exe 无效
|
// 直接 existsSync wt.exe 无效
|
||||||
if (fs.existsSync(appPath) && fs.readdirSync(appPath).includes('wt.exe')) {
|
if (fs.existsSync(appPath) && fs.readdirSync(appPath).includes('wt.exe')) {
|
||||||
cmdline = cmdline.replace(/"/g, `\\"`)
|
|
||||||
if (dir) cd = `-d "${dir.replace(/\\/g, '/')}"`
|
|
||||||
command = `${appPath}wt.exe ${cd} cmd /k "${cmdline}"`
|
|
||||||
} else {
|
|
||||||
cmdline = cmdline.replace(/"/g, `^"`)
|
|
||||||
if (dir) cd = `cd /d "${dir.replace(/\\/g, '/')}" &&`
|
|
||||||
command = `${cd} start "" cmd /k "${cmdline}"`
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
cmdline = cmdline.replace(/"/g, `\\"`)
|
cmdline = cmdline.replace(/"/g, `\\"`)
|
||||||
if (dir) cd = `cd ${dir.replace(/ /g, `\\\\ `)} &&`
|
if (dir) cd = `-d "${dir.replace(/\\/g, '/')}"`
|
||||||
|
command = `${appPath}wt.exe ${cd} cmd /k "${cmdline}"`
|
||||||
|
} else {
|
||||||
|
cmdline = cmdline.replace(/"/g, `^"`)
|
||||||
|
if (dir) cd = `cd /d "${dir.replace(/\\/g, '/')}" &&`
|
||||||
|
command = `${cd} start "" cmd /k "${cmdline}"`
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cmdline = cmdline.replace(/"/g, `\\"`)
|
||||||
|
if (dir) cd = `cd ${dir.replace(/ /g, `\\\\ `)} &&`
|
||||||
if (fs.existsSync('/Applications/iTerm.app')) {
|
if (fs.existsSync('/Applications/iTerm.app')) {
|
||||||
command = `osascript -e 'tell application "iTerm"
|
command = `osascript -e 'tell application "iTerm"
|
||||||
create window with default profile
|
create window with default profile
|
||||||
@ -504,6 +504,7 @@ utools.isDev() && (window.godMode = code => eval(code))
|
|||||||
// vm 模块将无法在渲染进程中使用,改用 ses 来执行代码
|
// vm 模块将无法在渲染进程中使用,改用 ses 来执行代码
|
||||||
window.evalCodeInSandbox = (code, addVars = {}) => {
|
window.evalCodeInSandbox = (code, addVars = {}) => {
|
||||||
let sandboxWithAD = Object.assign(addVars, getSandboxFuns())
|
let sandboxWithAD = Object.assign(addVars, getSandboxFuns())
|
||||||
|
sandboxWithAD.quickcommand = _.cloneDeep(quickcommand)
|
||||||
try {
|
try {
|
||||||
return new Compartment(sandboxWithAD).evaluate(code);
|
return new Compartment(sandboxWithAD).evaluate(code);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -524,6 +525,11 @@ window.runCodeInSandbox = (code, callback, addVars = {}) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
let sandboxWithAD = Object.assign(addVars, sandbox)
|
let sandboxWithAD = Object.assign(addVars, sandbox)
|
||||||
|
sandboxWithAD.quickcommand = _.cloneDeep(quickcommand)
|
||||||
|
if (addVars.enterData) {
|
||||||
|
sandboxWithAD.quickcommand.enterData = addVars.enterData
|
||||||
|
sandboxWithAD.quickcommand.payload = addVars.enterData.payload
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
new Compartment(sandboxWithAD).evaluate(code)
|
new Compartment(sandboxWithAD).evaluate(code)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -628,7 +634,7 @@ window.quickcommandHttpServer = () => {
|
|||||||
// 错误返回 500
|
// 错误返回 500
|
||||||
if (stderr) return httpResponse(res, 500, stderr)
|
if (stderr) return httpResponse(res, 500, stderr)
|
||||||
return httpResponse(res, 200, stdout)
|
return httpResponse(res, 200, stdout)
|
||||||
}, Object.assign(userVars, _.cloneDeep(quickcommand)))
|
})
|
||||||
}
|
}
|
||||||
httpServer = http.createServer()
|
httpServer = http.createServer()
|
||||||
httpServer.on('request', (req, res) => {
|
httpServer.on('request', (req, res) => {
|
||||||
|
@ -105,9 +105,7 @@ export default defineComponent({
|
|||||||
runCommandSilently(featureCode) {
|
runCommandSilently(featureCode) {
|
||||||
let command = this.utools.getDB(this.utools.DBPRE.QC + featureCode);
|
let command = this.utools.getDB(this.utools.DBPRE.QC + featureCode);
|
||||||
if (command.program === "quickcommand") {
|
if (command.program === "quickcommand") {
|
||||||
window.runCodeInSandbox(command.cmd, () => {}, {
|
window.runCodeInSandbox(command.cmd, () => {});
|
||||||
quickcommand: _.cloneDeep(quickcommand),
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
let option =
|
let option =
|
||||||
command.program === "custom"
|
command.program === "custom"
|
||||||
|
@ -113,9 +113,6 @@ export default {
|
|||||||
utools.outPlugin();
|
utools.outPlugin();
|
||||||
}, 500);
|
}, 500);
|
||||||
if (currentCommand.program === "quickcommand") {
|
if (currentCommand.program === "quickcommand") {
|
||||||
let qc = _.cloneDeep(quickcommand);
|
|
||||||
qc.enterData = this.$root.enterData;
|
|
||||||
qc.type = this.$root.enterData.type;
|
|
||||||
window.runCodeInSandbox(
|
window.runCodeInSandbox(
|
||||||
currentCommand.cmd,
|
currentCommand.cmd,
|
||||||
(stdout, stderr) => {
|
(stdout, stderr) => {
|
||||||
@ -126,7 +123,7 @@ export default {
|
|||||||
}
|
}
|
||||||
!outPlugin && this.showRunResult(stdout, true, action);
|
!outPlugin && this.showRunResult(stdout, true, action);
|
||||||
},
|
},
|
||||||
{ quickcommand: qc }
|
{ enterData: this.$root.enterData }
|
||||||
);
|
);
|
||||||
} else if (currentCommand.program === "html") {
|
} else if (currentCommand.program === "html") {
|
||||||
this.showRunResult(currentCommand.cmd, true, action);
|
this.showRunResult(currentCommand.cmd, true, action);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user