From a2bb06eea2abe10faa8c810b3e0a218627b61573 Mon Sep 17 00:00:00 2001 From: fofolee Date: Tue, 11 Jun 2019 17:04:16 +0800 Subject: [PATCH] =?UTF-8?q?jschardet=E5=88=A4=E6=96=AD=E7=BC=96=E7=A0=81?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=8A=A0=20hostname=20=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- preload.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/preload.js b/preload.js index cae3054..5799cdd 100644 --- a/preload.js +++ b/preload.js @@ -4,6 +4,7 @@ const { spawn, exec } = require("child_process") const iconv = require('iconv-lite') const { clipboard } = require('electron') const robot = require('./robotjs') +const jschardet = require("jschardet") //-------checkUpdate------ const path = require("path") @@ -144,6 +145,12 @@ special = async cmd => { cmd = cmd.replace(/\{\{isWin\}\}/mg, repl) } + // 获取电脑名 + if (cmd.includes('{{HostName}}')) { + let repl = os.hostname(); + cmd = cmd.replace(/\{\{HostName\}\}/mg, repl) + } + // 获取资源管理器或访达当前目录 if (cmd.includes('{{pwd}}')) { let repl = await pwd(); @@ -193,12 +200,11 @@ run = async (cmd, option, codec, callback) => { } var chunks = [], err_chunks = []; - codec = isWin ? codec : 'utf8'; child.stdout.on('data', chunk => { - chunks.push(iconv.decode(chunk, codec)) + chunks.push(iconv.decode(chunk, jschardet.detect(chunk).encoding)) }) child.stderr.on('data', err_chunk => { - err_chunks.push(iconv.decode(err_chunk, codec)) + err_chunks.push(iconv.decode(err_chunk, jschardet.detect(err_chunk).encoding)) }) child.on('close', code => { let stdout = chunks.join("");