From 01993476d62f144d19cfeab3e6c7bf9e91869c3e Mon Sep 17 00:00:00 2001 From: fofolee Date: Sat, 16 May 2020 11:13:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dphp=E4=B9=B1=E7=A0=81?= =?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=AE=9A=E4=B9=89=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E7=BC=96=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/assets/options.js | 32 +++++++++++++++++++++++--------- src/preload.js | 6 +++--- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/assets/options.js b/src/assets/options.js index d496f8a..5991405 100644 --- a/src/assets/options.js +++ b/src/assets/options.js @@ -104,17 +104,20 @@ programs = { cmd: { bin: '', argv: '', - ext: 'bat' + ext: 'bat', + codec: isWin ? 'gbk' : 'utf8' }, powershell: { bin: 'powershell', argv: '-NoProfile -File', - ext: 'ps1' + ext: 'ps1', + codec: isWin ? 'gbk' : 'utf8' }, python: { bin: 'python', argv: '-u', - ext: 'py' + ext: 'py', + codec: isWin ? 'gbk' : 'utf8' }, javascript: { bin: 'node', @@ -144,7 +147,8 @@ programs = { custom: { bin: '', argv: '', - ext: '' + ext: '', + codec: '' } } @@ -266,10 +270,9 @@ showCustomize = () => { ﹢按键 - - ﹢延时 ﹢动作

@@ -287,7 +290,8 @@ showCustomize = () => { - + +

@@ -418,6 +422,7 @@ $("#options").on('click', '.editBtn', function () { $('#custombin').show().val(data.customOptions.bin); $('#customarg').show().val(data.customOptions.argv); $('#customext').show().val(data.customOptions.ext); + $('#customcodec').show().val(data.customOptions.codec); } // mode == 'applescript' && (mode = 'shell'); // mode == 'cmd' && (mode = 'powershell'); @@ -479,6 +484,9 @@ $("#options").on('click', '#addAction', async function () { var a = $('#action').val(); var text; switch (a) { + case 'await sleep': + text = '要延时的毫秒'; + break; case 'open': text = '要打开的文件'; break; @@ -521,6 +529,8 @@ $("#options").on('click', '#addAction', async function () { if (content) { if (a == 'ubrowser') { window.editor.replaceSelection(`utools.ubrowser.goto("${content}")\n .run()\n`) + } else if (a == 'await sleep') { + window.editor.replaceSelection(`${a}(${content})\n`) } else { window.editor.replaceSelection(`${a}("${content.replace(/\\/g, '\\\\')}");\n`) } @@ -671,7 +681,8 @@ $("#options").on('click', '.saveBtn', function () { pushData.customOptions = { "bin": $('#custombin').val(), "argv": $('#customarg').val(), - "ext": $('#customext').val() + "ext": $('#customext').val(), + 'codec': $('#customcodec').val() } } if (program == 'simulation') { @@ -698,10 +709,13 @@ programCheck = () => { switch (mode) { case 'custom': $('.customscript').show(); + $('.simulation').hide(); + $('.varoutput').show(); break; case 'simulation': $('.varoutput').hide(); $('.simulation').show(); + $('.customscript').hide(); mode = 'javascript'; break; default: diff --git a/src/preload.js b/src/preload.js index 8b04056..41bea04 100644 --- a/src/preload.js +++ b/src/preload.js @@ -43,7 +43,7 @@ writeFile = fs.writeFileSync isWin = os.platform() == 'win32' ? true : false; -isDev = /unsafe-\w+\.asar/.test(__dirname) ? false : true +isDev = /[a-zA-Z0-9\-]+\.asar/.test(__dirname) ? false : true basename = path.basename; dirname = __dirname; @@ -267,11 +267,11 @@ run = (cmd, option, terminal, callback) => { var chunks = [], err_chunks = []; child.stdout.on('data', chunk => { - if (isWin) chunk = iconv.decode(chunk, 'GBK') + if (option.codec) chunk = iconv.decode(chunk, option.codec) chunks.push(chunk) }) child.stderr.on('data', err_chunk => { - if (isWin) err_chunk = iconv.decode(err_chunk, 'GBK') + if (option.codec) err_chunk = iconv.decode(err_chunk, option.codec) err_chunks.push(err_chunk) }) child.on('close', code => {