修复反引号错误

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

View File

@ -232,36 +232,35 @@ if (process.platform !== 'linux') quickcommand.runInTerminal = function(cmdline,
}
let getCommandToLaunchTerminal = (cmdline, dir) => {
let cd = ''
let cd, command;
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 无效
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}"`
cmdline = cmdline.replace(/"/g, `\\"`);
cd = dir ? `-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}"`
cmdline = cmdline.replace(/"/g, `^"`);
cd = dir ? `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')) {
command = `osascript -e 'tell application "iTerm"
} else if (utools.isMacOs()) {
cmdline = cmdline.replace(/"/g, `\\"`);
cd = dir ? `cd ${dir.replace(/ /g, '\\\\ ')} &&` : '';
command = fs.existsSync('/Applications/iTerm.app') ?
`osascript -e 'tell application "iTerm"
create window with default profile
tell current session of current window to write text "clear && ${cd} ${cmdline}"
end tell'`
} else {
command = `osascript -e 'tell application "Terminal"
end tell'` :
`osascript -e 'tell application "Terminal"
do script "clear && ${cd} ${cmdline}"
activate
end tell'`
}
end tell'`;
}
console.log(command);
return command
return command;
}
window.pluginInfo = () => {
@ -491,7 +490,6 @@ let getSandboxFuns = () => {
shortCodes.forEach(f => {
sandbox[f.name] = f
})
// Object.assign(sandbox, nodeFns)
return sandbox
}
@ -501,8 +499,6 @@ let liteErr = e => {
return e.error ? e.error.stack.replace(/([ ] +at.+)|(.+\.js:\d+)/g, '').trim() : e.message
}
utools.isDev() && (window.godMode = code => eval(code))
// vm 模块将无法在渲染进程中使用,改用 ses 来执行代码
window.evalCodeInSandbox = (code, addVars = {}) => {
let sandboxWithAD = Object.assign(addVars, getSandboxFuns())