mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-09 23:16:18 +08:00
feat: 封装 enterData, 命令图标改进
This commit is contained in:
parent
60968ac334
commit
9e8e0287b0
@ -88,7 +88,7 @@
|
|||||||
if (db.program == "custom") {
|
if (db.program == "custom") {
|
||||||
option = db.customOptions;
|
option = db.customOptions;
|
||||||
} else if(db.program == "quickcommand"){
|
} else if(db.program == "quickcommand"){
|
||||||
option = { mode: "quickcommand", payload: payload };
|
option = { mode: "quickcommand", enterData: { code, type, payload } };
|
||||||
}else{
|
}else{
|
||||||
option = programs[db.program];
|
option = programs[db.program];
|
||||||
}
|
}
|
||||||
@ -174,7 +174,7 @@
|
|||||||
runCodeInVm(cmd, (stdout, stderr) => {
|
runCodeInVm(cmd, (stdout, stderr) => {
|
||||||
if (cmd.includes("utools.setExpendHeight")) outputOpts.autoHeight = false
|
if (cmd.includes("utools.setExpendHeight")) outputOpts.autoHeight = false
|
||||||
switchQuickCommandResult(stdout, stderr, outputOpts)
|
switchQuickCommandResult(stdout, stderr, outputOpts)
|
||||||
}, option.payload)
|
}, option.enterData)
|
||||||
} else {
|
} else {
|
||||||
var terminal = output == 'terminal' ? true : false
|
var terminal = output == 'terminal' ? true : false
|
||||||
outputOpts.scriptPath = getQuickCommandScriptFile(option.ext)
|
outputOpts.scriptPath = getQuickCommandScriptFile(option.ext)
|
||||||
@ -871,6 +871,8 @@
|
|||||||
$("#ruleWord").html("配 置");
|
$("#ruleWord").html("配 置");
|
||||||
$(".var.regex, .var.window, .var.files").prop("disabled", false)
|
$(".var.regex, .var.window, .var.files").prop("disabled", false)
|
||||||
$("#rule").prop("placeholder", '等效于 features.cmds');
|
$("#rule").prop("placeholder", '等效于 features.cmds');
|
||||||
|
let sample = `["关键词",{"type":"img","label":"图片匹配"},{"type":"files","label":"文件匹配","fileType":"file","match":"/aaa/","minLength":1,"maxLength":99},{"type":"regex","label":"文本正则匹配","match":"/bbb/i","minLength":1,"maxLength":99},{"type":"over","label":"无匹配时","exclude":"/ccc/i","minLength":1,"maxLength":99},{"type":"window","label":"窗口动作","match":{"app":["ddd.app","eee.exe"],"title":"/fff/","class":["ggg"]}}]`
|
||||||
|
!$('#rule').val() && $('#rule').val(sample)
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -886,7 +888,7 @@
|
|||||||
let hasCustomIcon = () => {
|
let hasCustomIcon = () => {
|
||||||
var src = $("#icon").attr('src');
|
var src = $("#icon").attr('src');
|
||||||
var iconame = $("#iconame").val();
|
var iconame = $("#iconame").val();
|
||||||
return /data:image\/png;base64,/.test(src) || iconame
|
return /data:image\/\w+;base64,/.test(src) || iconame
|
||||||
}
|
}
|
||||||
|
|
||||||
let programCheck = () => {
|
let programCheck = () => {
|
||||||
@ -1339,18 +1341,16 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
// 选择图标
|
// 选择图标
|
||||||
$("#options").on('click', '#icon', function () {
|
$("#options").on('click', '#icon', async function () {
|
||||||
var options = {
|
var options = {
|
||||||
buttonLabel: '选择',
|
buttonLabel: '选择',
|
||||||
filters: [{
|
properties: ['openFile']
|
||||||
name: 'Images',
|
|
||||||
extensions: ['png']
|
|
||||||
}, ]
|
|
||||||
}
|
}
|
||||||
var file = getFileInfo({ type: 'dialog', argvs: options, readfile: false })
|
var file = getFileInfo({ type: 'dialog', argvs: options, readfile: false })
|
||||||
if (file) {
|
if (file) {
|
||||||
$("#iconame").val(file.name);
|
$("#iconame").val(file.name);
|
||||||
$("#icon").attr('src', file.path);
|
let src = await getBase64Ico(file.path);
|
||||||
|
$("#icon").attr('src', src);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -1373,18 +1373,9 @@
|
|||||||
scptarg = $('#scptarg').val(),
|
scptarg = $('#scptarg').val(),
|
||||||
program = $('#program').val(),
|
program = $('#program').val(),
|
||||||
desc = $('#desc').val(),
|
desc = $('#desc').val(),
|
||||||
iconame = $("#iconame").val(),
|
icon = $("#icon").attr('src'),
|
||||||
iconpath = $("#icon").attr('src'),
|
|
||||||
icon,
|
|
||||||
hasSubInput;
|
hasSubInput;
|
||||||
if (!desc) desc = ' ';
|
if (!desc) desc = ' ';
|
||||||
// 选择了图标的情况下
|
|
||||||
if (iconame) {
|
|
||||||
icon = await window.getBase64Ico(iconpath);
|
|
||||||
// 未自定义使用默认
|
|
||||||
} else {
|
|
||||||
icon = iconpath;
|
|
||||||
}
|
|
||||||
if (type == 'key') {
|
if (type == 'key') {
|
||||||
cmds = rule.split(",").map(x => x.trim())
|
cmds = rule.split(",").map(x => x.trim())
|
||||||
} else if (type == 'regex') {
|
} else if (type == 'regex') {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
"main": "index.html",
|
"main": "index.html",
|
||||||
"homepage": "https://github.com/fofolee/uTools-QuickerCommand",
|
"homepage": "https://github.com/fofolee/uTools-QuickerCommand",
|
||||||
"publishPage": "https://yuanliao.info/d/424",
|
"publishPage": "https://yuanliao.info/d/424",
|
||||||
"version": "2.1.0",
|
"version": "2.1.1",
|
||||||
"author": "云之轩",
|
"author": "云之轩",
|
||||||
"unpack":"autopep8.py",
|
"unpack":"autopep8.py",
|
||||||
"logo": "logo.png",
|
"logo": "logo.png",
|
||||||
|
@ -440,9 +440,10 @@ let getSandboxFuns = () => {
|
|||||||
return sandbox
|
return sandbox
|
||||||
}
|
}
|
||||||
|
|
||||||
let createNodeVM = (payload = "") => {
|
let createNodeVM = (enterData = {}) => {
|
||||||
var sandbox = getSandboxFuns()
|
var sandbox = getSandboxFuns()
|
||||||
sandbox.quickcommand.payload = payload
|
sandbox.quickcommand.enterData = enterData
|
||||||
|
sandbox.quickcommand.payload = enterData.payload
|
||||||
const vm = new NodeVM({
|
const vm = new NodeVM({
|
||||||
require: {
|
require: {
|
||||||
external: true,
|
external: true,
|
||||||
@ -488,8 +489,8 @@ let parseItem = item => {
|
|||||||
return item.toString()
|
return item.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
runCodeInVm = (cmd, cb, payload = "") => {
|
runCodeInVm = (cmd, cb, enterData = {}) => {
|
||||||
const vm = createNodeVM(payload)
|
const vm = createNodeVM(enterData)
|
||||||
//重定向 console
|
//重定向 console
|
||||||
vm.on('console.log', stdout => {
|
vm.on('console.log', stdout => {
|
||||||
console.log(stdout);
|
console.log(stdout);
|
||||||
@ -596,7 +597,7 @@ dirPythonMod = (mod, cb) => {
|
|||||||
getNodeJsCommand = () => {
|
getNodeJsCommand = () => {
|
||||||
var obj = getSandboxFuns()
|
var obj = getSandboxFuns()
|
||||||
obj.Buffer = Buffer
|
obj.Buffer = Buffer
|
||||||
obj.quickcommand.payload = ''
|
obj.quickcommand.enterData = {code: '', type: '', payload: ''}
|
||||||
return obj
|
return obj
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -621,9 +622,14 @@ getQuickCommandScriptFile = ext => {
|
|||||||
return path.join(os.tmpdir(), `QuickCommandTempScript.${ext}`)
|
return path.join(os.tmpdir(), `QuickCommandTempScript.${ext}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
getBase64Ico = async path => {
|
getBase64Ico = async filepath => {
|
||||||
let sourceImage = 'data:image/png;base64,' + fs.readFileSync(path, 'base64')
|
let sourceImage, ext = path.extname(filepath).slice(1)
|
||||||
let compressedImage = await getCompressedIco(path)
|
if (ext == 'png' || ext == 'jpg' || ext == 'jpeg' || ext == 'bmp' || ext == 'ico') {
|
||||||
|
sourceImage = `data:image/${ext};base64,` + fs.readFileSync(filepath, 'base64')
|
||||||
|
} else {
|
||||||
|
sourceImage = utools.getFileIcon(filepath)
|
||||||
|
}
|
||||||
|
let compressedImage = await getCompressedIco(sourceImage)
|
||||||
return compressedImage.length > sourceImage.length ? sourceImage : compressedImage
|
return compressedImage.length > sourceImage.length ? sourceImage : compressedImage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user