修复反引号错误

This commit is contained in:
fofolee 2022-04-26 21:49:52 +08:00
parent fafe7465f2
commit ae4461cfe7

View File

@ -189,9 +189,9 @@ window.quickcommand = {
}, () => {}) }, () => {})
} }
browserWindow.webContents.openDevTools({ browserWindow.webContents.openDevTools({
mode: 'detach' mode: 'detach'
}) })
// browserWindow.webContents.executeJavaScript(``) // browserWindow.webContents.executeJavaScript(``)
return browserWindow return browserWindow
} }
} }
@ -232,36 +232,35 @@ if (process.platform !== 'linux') quickcommand.runInTerminal = function(cmdline,
} }
let getCommandToLaunchTerminal = (cmdline, dir) => { let getCommandToLaunchTerminal = (cmdline, dir) => {
let cd = '' let cd, command;
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, `\\"`) cmdline = cmdline.replace(/"/g, `\\"`);
if (dir) cd = `-d "${dir.replace(/\\/g, '/')}"` cd = dir ? `-d "${dir.replace(/\\/g, '/')}"` : '';
command = `${appPath}wt.exe ${cd} cmd /k "${cmdline}"` command = `${appPath}wt.exe ${cd} cmd /k "${cmdline}"`;
} else { } else {
cmdline = cmdline.replace(/"/g, `^"`) cmdline = cmdline.replace(/"/g, `^"`);
if (dir) cd = `cd /d "${dir.replace(/\\/g, '/')}" &&` cd = dir ? `cd /d "${dir.replace(/\\/g, '/')}" &&` : '';
command = `${cd} start "" cmd /k "${cmdline}"` command = `${cd} start "" cmd /k "${cmdline}"`;
} }
} else { } else if (utools.isMacOs()) {
cmdline = cmdline.replace(/"/g, `\\"`) cmdline = cmdline.replace(/"/g, `\\"`);
if (dir) cd = `cd ${dir.replace(/ /g, `\\\\ `)} &&` cd = dir ? `cd ${dir.replace(/ /g, '\\\\ ')} &&` : '';
if (fs.existsSync('/Applications/iTerm.app')) { command = fs.existsSync('/Applications/iTerm.app') ?
command = `osascript -e 'tell application "iTerm" `osascript -e 'tell application "iTerm"
create window with default profile create window with default profile
tell current session of current window to write text "clear && ${cd} ${cmdline}" tell current session of current window to write text "clear && ${cd} ${cmdline}"
end tell'` end tell'` :
} else { `osascript -e 'tell application "Terminal"
command = `osascript -e 'tell application "Terminal" do script "clear && ${cd} ${cmdline}"
do script "clear && ${cd} ${cmdline}"
activate activate
end tell'` end tell'`;
}
} }
console.log(command); console.log(command);
return command return command;
} }
window.pluginInfo = () => { window.pluginInfo = () => {
@ -491,7 +490,6 @@ let getSandboxFuns = () => {
shortCodes.forEach(f => { shortCodes.forEach(f => {
sandbox[f.name] = f sandbox[f.name] = f
}) })
// Object.assign(sandbox, nodeFns)
return sandbox return sandbox
} }
@ -501,8 +499,6 @@ let liteErr = e => {
return e.error ? e.error.stack.replace(/([ ] +at.+)|(.+\.js:\d+)/g, '').trim() : e.message return e.error ? e.error.stack.replace(/([ ] +at.+)|(.+\.js:\d+)/g, '').trim() : e.message
} }
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())
@ -571,7 +567,7 @@ window.runCodeFile = (cmd, option, terminal, callback) => {
charset = option.charset, charset = option.charset,
scptarg = option.scptarg || ""; scptarg = option.scptarg || "";
let script = getQuickcommandTempFile(ext) let script = getQuickcommandTempFile(ext)
// 批处理和 powershell 默认编码为 GBK, 解决批处理的换行问题 // 批处理和 powershell 默认编码为 GBK, 解决批处理的换行问题
if (charset.scriptCode) cmd = iconv.encode(cmd.replace(/\n/g, '\r\n'), charset.scriptCode); if (charset.scriptCode) cmd = iconv.encode(cmd.replace(/\n/g, '\r\n'), charset.scriptCode);
fs.writeFileSync(script, cmd); fs.writeFileSync(script, cmd);
// var argvs = [script] // var argvs = [script]
@ -593,27 +589,27 @@ window.runCodeFile = (cmd, option, terminal, callback) => {
// 在终端中输出 // 在终端中输出
if (terminal) cmdline = getCommandToLaunchTerminal(cmdline) if (terminal) cmdline = getCommandToLaunchTerminal(cmdline)
child = child_process.spawn(cmdline, { child = child_process.spawn(cmdline, {
encoding: 'buffer', encoding: 'buffer',
shell: true shell: true
}) })
// var chunks = [], // var chunks = [],
// err_chunks = []; // err_chunks = [];
console.log('running: ' + cmdline); console.log('running: ' + cmdline);
child.stdout.on('data', chunk => { child.stdout.on('data', chunk => {
if (charset.outputCode) chunk = iconv.decode(chunk, charset.outputCode) if (charset.outputCode) chunk = iconv.decode(chunk, charset.outputCode)
callback(chunk.toString(), null) callback(chunk.toString(), null)
// chunks.push(chunk) // chunks.push(chunk)
}) })
child.stderr.on('data', stderr => { child.stderr.on('data', stderr => {
if (charset.outputCode) stderr = iconv.decode(stderr, charset.outputCode) if (charset.outputCode) stderr = iconv.decode(stderr, charset.outputCode)
callback(null, stderr.toString()) callback(null, stderr.toString())
// err_chunks.push(err_chunk) // err_chunks.push(err_chunk)
}) })
// child.on('close', code => { // child.on('close', code => {
// let stdout = chunks.join(""); // let stdout = chunks.join("");
// let stderr = err_chunks.join(""); // let stderr = err_chunks.join("");
// callback(stdout, stderr) // callback(stdout, stderr)
// }) // })
return child return child
} }
@ -651,7 +647,7 @@ window.quickcommandHttpServer = () => {
req.on('end', () => { req.on('end', () => {
let parsedParams let parsedParams
let params = data.join("").toString() let params = data.join("").toString()
// 先尝试作为 json 解析 // 先尝试作为 json 解析
try { try {
parsedParams = JSON.parse(params) parsedParams = JSON.parse(params)
} catch (error) { } catch (error) {