修复php乱码,添加自定义输入编码

This commit is contained in:
fofolee 2020-05-16 11:13:03 +08:00
parent 7e853946f7
commit 01993476d6
2 changed files with 26 additions and 12 deletions

View File

@ -104,17 +104,20 @@ programs = {
cmd: { cmd: {
bin: '', bin: '',
argv: '', argv: '',
ext: 'bat' ext: 'bat',
codec: isWin ? 'gbk' : 'utf8'
}, },
powershell: { powershell: {
bin: 'powershell', bin: 'powershell',
argv: '-NoProfile -File', argv: '-NoProfile -File',
ext: 'ps1' ext: 'ps1',
codec: isWin ? 'gbk' : 'utf8'
}, },
python: { python: {
bin: 'python', bin: 'python',
argv: '-u', argv: '-u',
ext: 'py' ext: 'py',
codec: isWin ? 'gbk' : 'utf8'
}, },
javascript: { javascript: {
bin: 'node', bin: 'node',
@ -144,7 +147,8 @@ programs = {
custom: { custom: {
bin: '', bin: '',
argv: '', argv: '',
ext: '' ext: '',
codec: ''
} }
} }
@ -266,10 +270,9 @@ showCustomize = () => {
</select> </select>
<input type="text" id="presskey" class="robot keys" placeholder="模拟按键"> <input type="text" id="presskey" class="robot keys" placeholder="模拟按键">
<span id="addKey" class="robot footBtn">按键</span> <span id="addKey" class="robot footBtn">按键</span>
<input type="text" id="keydelay" class="robot keys" placeholder="等待时间">
<span id="addDelay" class="robot footBtn">延时</span>
<select id="action" class="robot keys"> <select id="action" class="robot keys">
<option value="" style="display:none">预设动作</option> <option value="" style="display:none">预设动作</option>
<option value="await sleep">添加延时</option>
<option value="open">打开文件</option> <option value="open">打开文件</option>
<option value="visit">打开网址</option> <option value="visit">打开网址</option>
<option value="locate">定位文件</option> <option value="locate">定位文件</option>
@ -278,7 +281,7 @@ showCustomize = () => {
<option value="message">系统消息</option> <option value="message">系统消息</option>
<option value="alert">弹窗显示</option> <option value="alert">弹窗显示</option>
<option value="send">发送文本</option> <option value="send">发送文本</option>
<option value="ubrowser">ubrowser</option> <option value="ubrowser">ubrowser打开</option>
</select> </select>
<span id="addAction" class="robot footBtn">动作</span> <span id="addAction" class="robot footBtn">动作</span>
</p> </p>
@ -287,7 +290,8 @@ showCustomize = () => {
<span> <span>
<input type="text" id="custombin" class="customscript" placeholder="解释器绝对路径"> <input type="text" id="custombin" class="customscript" placeholder="解释器绝对路径">
<input type="text" id="customarg" class="customscript" placeholder="参数"> <input type="text" id="customarg" class="customscript" placeholder="参数">
<input type="text" id="customext" class="customscript" placeholder="脚本后缀,不含."> <input type="text" id="customext" class="customscript" placeholder="后缀,不含.">
<input type="text" id="customcodec" class="customscript" placeholder="输出编码">
</span> </span>
</p> </p>
<p><textarea id="cmd" placeholder="可以直接拖放脚本文件至此处"></textarea></p> <p><textarea id="cmd" placeholder="可以直接拖放脚本文件至此处"></textarea></p>
@ -418,6 +422,7 @@ $("#options").on('click', '.editBtn', function () {
$('#custombin').show().val(data.customOptions.bin); $('#custombin').show().val(data.customOptions.bin);
$('#customarg').show().val(data.customOptions.argv); $('#customarg').show().val(data.customOptions.argv);
$('#customext').show().val(data.customOptions.ext); $('#customext').show().val(data.customOptions.ext);
$('#customcodec').show().val(data.customOptions.codec);
} }
// mode == 'applescript' && (mode = 'shell'); // mode == 'applescript' && (mode = 'shell');
// mode == 'cmd' && (mode = 'powershell'); // mode == 'cmd' && (mode = 'powershell');
@ -479,6 +484,9 @@ $("#options").on('click', '#addAction', async function () {
var a = $('#action').val(); var a = $('#action').val();
var text; var text;
switch (a) { switch (a) {
case 'await sleep':
text = '要延时的毫秒';
break;
case 'open': case 'open':
text = '要打开的文件'; text = '要打开的文件';
break; break;
@ -521,6 +529,8 @@ $("#options").on('click', '#addAction', async function () {
if (content) { if (content) {
if (a == 'ubrowser') { if (a == 'ubrowser') {
window.editor.replaceSelection(`utools.ubrowser.goto("${content}")\n .run()\n`) window.editor.replaceSelection(`utools.ubrowser.goto("${content}")\n .run()\n`)
} else if (a == 'await sleep') {
window.editor.replaceSelection(`${a}(${content})\n`)
} else { } else {
window.editor.replaceSelection(`${a}("${content.replace(/\\/g, '\\\\')}");\n`) window.editor.replaceSelection(`${a}("${content.replace(/\\/g, '\\\\')}");\n`)
} }
@ -671,7 +681,8 @@ $("#options").on('click', '.saveBtn', function () {
pushData.customOptions = { pushData.customOptions = {
"bin": $('#custombin').val(), "bin": $('#custombin').val(),
"argv": $('#customarg').val(), "argv": $('#customarg').val(),
"ext": $('#customext').val() "ext": $('#customext').val(),
'codec': $('#customcodec').val()
} }
} }
if (program == 'simulation') { if (program == 'simulation') {
@ -698,10 +709,13 @@ programCheck = () => {
switch (mode) { switch (mode) {
case 'custom': case 'custom':
$('.customscript').show(); $('.customscript').show();
$('.simulation').hide();
$('.varoutput').show();
break; break;
case 'simulation': case 'simulation':
$('.varoutput').hide(); $('.varoutput').hide();
$('.simulation').show(); $('.simulation').show();
$('.customscript').hide();
mode = 'javascript'; mode = 'javascript';
break; break;
default: default:

View File

@ -43,7 +43,7 @@ writeFile = fs.writeFileSync
isWin = os.platform() == 'win32' ? true : false; 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; basename = path.basename;
dirname = __dirname; dirname = __dirname;
@ -267,11 +267,11 @@ run = (cmd, option, terminal, callback) => {
var chunks = [], var chunks = [],
err_chunks = []; err_chunks = [];
child.stdout.on('data', chunk => { child.stdout.on('data', chunk => {
if (isWin) chunk = iconv.decode(chunk, 'GBK') if (option.codec) chunk = iconv.decode(chunk, option.codec)
chunks.push(chunk) chunks.push(chunk)
}) })
child.stderr.on('data', err_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) err_chunks.push(err_chunk)
}) })
child.on('close', code => { child.on('close', code => {