From 03a1f3bba540ba48444c311ec7bcaa15fdd27f2d Mon Sep 17 00:00:00 2001 From: fofolee Date: Sun, 5 Jul 2020 10:54:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/preload.js | 72 +++++++++++++++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 27 deletions(-) diff --git a/src/preload.js b/src/preload.js index 066bc5e..16669a3 100644 --- a/src/preload.js +++ b/src/preload.js @@ -49,17 +49,6 @@ const shortCodes = [ } ] -let getSleepCodeByShell = ms => { - var cmd, tempFilePath - if (utools.isWindows()) { - tempFilePath = getQuickCommandScriptFile('vbs') - cmd = `echo set ws=CreateObject("Wscript.Shell") > ${tempFilePath} && echo Wscript.sleep ${ms} >> ${tempFilePath} && cscript /nologo ${tempFilePath}` - } else { - cmd = `sleep ${ms / 1000}` - } - return cmd -} - quickcommand = { // 模拟复制操作 simulateCopy: function() { @@ -109,9 +98,14 @@ quickcommand = { } var result = [] var options = { + onBeforeOpen: () => { + document.getElementById(`inputBox0`).focus() + $(".output").is(":parent") && utools.setExpendHeight(600) || modWindowHeight($('.swal2-popup').outerHeight() + 20) + }, html: html, focusConfirm: false, - backdrop: utools.isDarkColors() ? '#464646' : '#bbb', + showCancelButton: true, + backdrop: utools.isDarkColors() ? '#fff0' : '#bbb', preConfirm: () => { for (let i = 0; i < inputBoxNumbers; i++) { result.push(document.getElementById(`inputBox${i}`).value) @@ -144,25 +138,28 @@ quickcommand = { callback({ index: i, text: buttons[i] }) swal.clickConfirm() } + $(".output").is(":parent") && utools.setExpendHeight(600) || modWindowHeight($('.swal2-popup').outerHeight() + 20) }, html: html, - backdrop: utools.isDarkColors() ? '#464646' : '#bbb', + backdrop: utools.isDarkColors() ? '#fff0' : '#bbb', showConfirmButton: false } swalOneByOne(options) }, // 显示自动消失的提示框 - showMessageBox: function (title, icon = "success") { + showMessageBox: function (title, icon = "success", time = 3000) { var options = { icon: icon, title: title, toast: true, position: 'top', - timer: 3000, - onOpen: (toast) => { - toast.addEventListener('mouseenter', Swal.stopTimer) - toast.addEventListener('mouseleave', Swal.resumeTimer) + // timer: time, + showConfirmButton: false, + onOpen: toast => { + // toast.addEventListener('mouseenter', Swal.stopTimer) + // toast.addEventListener('mouseleave', Swal.resumeTimer) + setTimeout(() => { Swal.clickConfirm() }, time); } } swalOneByOne(options) @@ -181,11 +178,6 @@ quickcommand = { opt.placeholder || (opt.placeholder = "搜索,支持拼音") opt.enableHTML || (opt.enableHTML = false) typeof opt.closeOnSelect == 'undefined' && (opt.closeOnSelect = true) - // 调整插件高度 - let modWindowHeight = () => { - var height = $('.select2-results').height() - if ($('#options').is(':hidden')) utools.setExpendHeight(height > 600 ? 600 : height); - } if ($('#quickselect').length) $('#quickselect').remove() $("body").append(`
`) var selectBoxNumbers = selects.length @@ -220,10 +212,11 @@ quickcommand = { $('#selectBox').val(null).trigger('change') $('#selectBox').select2('open') $('#quickselect .select2').hide() - modWindowHeight() + opt.enableHTML || $('.select2-results').css({'line-height': '50px'}) + modWindowHeight($('.select2-results').height()) utools.setSubInput(({text})=>{ $("#quickselect .select2-search__field").val(text).trigger('input') - modWindowHeight() + modWindowHeight($('.select2-results').height()) }, opt.placeholder) $('#selectBox').on('select2:select', function (e) { callback({ index: $(this).val(), text: $(`option[value="${$(this).val()}"]`).text() }) @@ -267,8 +260,8 @@ quickcommand = { }, // 关闭进程 - kill: function (pid) { - process.kill(pid) + kill: function (pid, signal = 'SIGTERM') { + process.kill(pid, signal) }, // dom 解析 @@ -301,6 +294,21 @@ swalOneByOne = options => { swal.getQueueStep() && Swal.insertQueueStep(options) || Swal.queue([options]) } +let getSleepCodeByShell = ms => { + var cmd, tempFilePath + if (utools.isWindows()) { + tempFilePath = getQuickCommandScriptFile('vbs') + cmd = `echo set ws=CreateObject("Wscript.Shell") > ${tempFilePath} && echo Wscript.sleep ${ms} >> ${tempFilePath} && cscript /nologo ${tempFilePath}` + } else { + cmd = `sleep ${ms / 1000}` + } + return cmd +} + +let modWindowHeight = height => { + $('#options').is(':hidden') && utools.setExpendHeight(height > 600 ? 600 : height); +} + // 屏蔽危险函数 var getuToolsLite = () => { var utoolsLite = Object.assign({}, utools) @@ -523,6 +531,16 @@ getFileInfo = options => { return information } +getCurrentFolderPathFix = () => { + let pwd = utools.getCurrentFolderPath() + if(typeof pwd == 'undefined'){ + pwd = path.join(utools.getPath('home'), 'desktop') + }else{ + pwd = pwd.replace(/\\/g, '\\\\') + } + return pwd +} + saveFile = (options, content) => { var filename = utools.showSaveDialog(options) filename && fs.writeFile(filename, content, 'utf8', err => {