引入一些新模块

This commit is contained in:
fofolee 2020-04-22 01:19:55 +08:00
parent ebba2cea10
commit bced863572

View File

@ -2,12 +2,11 @@ const fs = require('fs');
const os = require('os'); const os = require('os');
const { spawn, exec } = require("child_process") const { spawn, exec } = require("child_process")
const iconv = require('iconv-lite') const iconv = require('iconv-lite')
const { clipboard } = require('electron') const { clipboard, shell} = require('electron')
const robot = utools.robot const robot = utools.robot
const path = require("path") const path = require("path")
const { dialog, BrowserWindow, nativeImage } = require('electron').remote const { dialog, BrowserWindow, nativeImage } = require('electron').remote
const { shell } = require('electron');
pluginInfo = JSON.parse(fs.readFileSync(path.join(__dirname, 'plugin.json'))); pluginInfo = JSON.parse(fs.readFileSync(path.join(__dirname, 'plugin.json')));
logo = nativeImage.createFromPath(path.join(__dirname, 'logo.png')); logo = nativeImage.createFromPath(path.join(__dirname, 'logo.png'));
@ -15,14 +14,11 @@ logo = nativeImage.createFromPath(path.join(__dirname, 'logo.png'));
// fix PATH // fix PATH
process.env.PATH += ':/usr/local/bin:/usr/local/sbin' process.env.PATH += ':/usr/local/bin:/usr/local/sbin'
messageBox = (options, callback) => { open = path => {
dialog.showMessageBox(BrowserWindow.getFocusedWindow(), options, index => { shell.showItemInFolder(path);
utools.showMainWindow()
callback(index)
})
} }
open = url => { visit = url => {
shell.openExternal(url); shell.openExternal(url);
} }
// ------------------------ // ------------------------
@ -32,12 +28,10 @@ isWin = os.platform() == 'win32' ? true : false;
isDev = /unsafe-\w+\.asar/.test(__dirname) ? false : true isDev = /unsafe-\w+\.asar/.test(__dirname) ? false : true
basename = path.basename; basename = path.basename;
dirname = __dirname; dirname = __dirname;
resolve = path.resolve; resolve = path.resolve;
exists = fs.existsSync; exists = fs.existsSync;
tmpdir = os.tmpdir(),
getBase64Ico = path => { getBase64Ico = path => {
return fs.readFileSync(path, 'base64'); return fs.readFileSync(path, 'base64');
@ -143,22 +137,7 @@ getSelectFile = hwnd =>
reslove(stdout.trim()); reslove(stdout.trim());
}); });
} }
}) })
// GetBinPath = () => {
// if (isDev) {
// return path.join(__dirname.replace(/(unsafe-\w+\.asar)/,'$1.unpacked'), 'bin', 'GetForegroundWindow.exe')
// } else {
// return path.join(__dirname, 'bin', 'GetForegroundWindow.exe')
// }
// }
// 获取前台窗口句柄
// GetForegroundWindow = callback =>
// exec(`"${GetBinPath()}"`, (error, stdout, stderr) => {
// callback(stdout);
// });
pwd = hwnd => pwd = hwnd =>
new Promise((reslove, reject) => { new Promise((reslove, reject) => {
@ -215,12 +194,11 @@ special = async cmd => {
} }
run = async (cmd, option, codec, terminal, callback) => { run = async (cmd, option, codec, terminal, callback) => {
var tmp = os.tmpdir(), var bin = option.bin,
bin = option.bin,
argv = option.argv, argv = option.argv,
ext = option.ext; ext = option.ext;
cmd = await special(cmd); cmd = await special(cmd);
let script = path.join(tmp, `QuickCommandTempScript.${ext}`) let script = path.join(tmpdir, `QuickCommandTempScript.${ext}`)
// 批处理和 powershell 默认编码为 GBK, 解决批处理的换行问题 // 批处理和 powershell 默认编码为 GBK, 解决批处理的换行问题
if (ext == 'bat' || ext == 'ps1') cmd = iconv.encode(cmd.replace(/\n/g, '\r\n'), 'GBK'); if (ext == 'bat' || ext == 'ps1') cmd = iconv.encode(cmd.replace(/\n/g, '\r\n'), 'GBK');
fs.writeFileSync(script, cmd); fs.writeFileSync(script, cmd);