mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-10 15:34:05 +08:00
版本兼容处理,暗黑模式
This commit is contained in:
parent
cb0f6bb1a7
commit
535c06efed
@ -1,6 +1,10 @@
|
|||||||
utools.onPluginEnter(async ({ code, type, payload }) => {
|
!function () {
|
||||||
|
utools.onPluginEnter(async ({ code, type, payload }) => {
|
||||||
|
adaptDarkMode()
|
||||||
|
// oldVersionFix()
|
||||||
var handleEnter
|
var handleEnter
|
||||||
utools.onPluginOut(() => {
|
utools.onPluginOut(() => {
|
||||||
|
// 暂存 codeRunner 的内容
|
||||||
if (code == "code") {
|
if (code == "code") {
|
||||||
var cmd = window.editor.getValue();
|
var cmd = window.editor.getValue();
|
||||||
var program = $('#program').val(),
|
var program = $('#program').val(),
|
||||||
@ -18,8 +22,9 @@ utools.onPluginEnter(async ({ code, type, payload }) => {
|
|||||||
$("#options").empty()
|
$("#options").empty()
|
||||||
$("#out").empty()
|
$("#out").empty()
|
||||||
$("[id^=quick").remove()
|
$("[id^=quick").remove()
|
||||||
|
$('body').css({overflow: 'hidden'})
|
||||||
swal.close()
|
swal.close()
|
||||||
if(handleEnter) document.removeEventListener('keydown', handleEnter)
|
if (handleEnter) document.removeEventListener('keydown', handleEnter)
|
||||||
})
|
})
|
||||||
// 配置页面
|
// 配置页面
|
||||||
if (code == 'options') {
|
if (code == 'options') {
|
||||||
@ -33,14 +38,15 @@ utools.onPluginEnter(async ({ code, type, payload }) => {
|
|||||||
showCodeEditor(file)
|
showCodeEditor(file)
|
||||||
} else {
|
} else {
|
||||||
// console.log(new Date().getTime() - window.startTime);
|
// console.log(new Date().getTime() - window.startTime);
|
||||||
|
$('body').css({overflow: 'auto'})
|
||||||
utools.setExpendHeight(0);
|
utools.setExpendHeight(0);
|
||||||
$("#options").hide();
|
$("#options").hide();
|
||||||
var db = utools.db.get('customFts').data[code],
|
var db = utools.db.get('customFts').data[code],
|
||||||
cmd = db.cmd;
|
cmd = db.cmd;
|
||||||
if (db.program == "custom") {
|
if (db.program == "custom") {
|
||||||
option = db.customOptions;
|
option = db.customOptions;
|
||||||
} else if(db.program == "simulation"){
|
} else if(db.program == "quickcommand"){
|
||||||
option = "simulation";
|
option = "quickcommand";
|
||||||
}else{
|
}else{
|
||||||
option = programs[db.program];
|
option = programs[db.program];
|
||||||
}
|
}
|
||||||
@ -78,11 +84,11 @@ utools.onPluginEnter(async ({ code, type, payload }) => {
|
|||||||
var setSubInput = () => {
|
var setSubInput = () => {
|
||||||
utools.setSubInput(({text}) => {
|
utools.setSubInput(({text}) => {
|
||||||
subinput = text;
|
subinput = text;
|
||||||
}, '');
|
}, '请输入');
|
||||||
}
|
}
|
||||||
handleEnter = (event) => {
|
handleEnter = (event) => {
|
||||||
if (event.keyCode == 13) {
|
if (event.keyCode == 13) {
|
||||||
$("#out").append('\n-------------------------------------\n\n');
|
$("#out").append(`<p style="color: #438eff">>> ${new Date()}</p>`);
|
||||||
var execmd = cmd.replace(/\{\{subinput\}\}/mg, subinput);
|
var execmd = cmd.replace(/\{\{subinput\}\}/mg, subinput);
|
||||||
runQuickCommand(execmd, option, db.output, true);
|
runQuickCommand(execmd, option, db.output, true);
|
||||||
}
|
}
|
||||||
@ -93,17 +99,17 @@ utools.onPluginEnter(async ({ code, type, payload }) => {
|
|||||||
runQuickCommand(cmd, option, db.output, false);
|
runQuickCommand(cmd, option, db.output, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
let runQuickCommand = (cmd, option, output, autoScroll = false, autoHeight = true) => {
|
let runQuickCommand = (cmd, option, output, autoScroll = false, autoHeight = true) => {
|
||||||
// 不需要输出的,提前关闭窗口
|
// 不需要输出的,提前关闭窗口
|
||||||
if (['ignore', 'clip', 'send', 'notice', 'terminal'].indexOf(output) !== -1) {
|
if (['ignore', 'clip', 'send', 'notice', 'terminal'].indexOf(output) !== -1) {
|
||||||
utools.hideMainWindow();
|
utools.hideMainWindow();
|
||||||
setTimeout(() => { utools.outPlugin(); }, 500);
|
setTimeout(() => { utools.outPlugin(); }, 500);
|
||||||
}
|
}
|
||||||
var outputOpts = { type: output, autoScroll: autoScroll, autoHeight: autoHeight }
|
var outputOpts = { type: output, autoScroll: autoScroll, autoHeight: autoHeight }
|
||||||
if (option == "simulation") {
|
if (option == "quickcommand") {
|
||||||
// 内置环境
|
// 内置环境
|
||||||
runCodeInVm(cmd, (stdout, stderr) => {
|
runCodeInVm(cmd, (stdout, stderr) => {
|
||||||
if (cmd.includes("utools.setExpendHeight")) outputOpts.autoHeight = false
|
if (cmd.includes("utools.setExpendHeight")) outputOpts.autoHeight = false
|
||||||
@ -117,10 +123,10 @@ let runQuickCommand = (cmd, option, output, autoScroll = false, autoHeight = tru
|
|||||||
switchQuickCommandResult(stdout, stderr, outputOpts)
|
switchQuickCommandResult(stdout, stderr, outputOpts)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switchQuickCommandResult = (stdout, stderr, outputOpts) => {
|
let switchQuickCommandResult = (stdout, stderr, outputOpts) => {
|
||||||
var output = outputOpts.output, autoScroll = outputOpts.autoScroll, autoHeight = outputOpts.autoHeight;
|
var output = outputOpts.type, autoScroll = outputOpts.autoScroll, autoHeight = outputOpts.autoHeight;
|
||||||
var outputAutoFix = (autoScroll, autoHeight) => {
|
var outputAutoFix = (autoScroll, autoHeight) => {
|
||||||
var outputHeight = $("#out").height() + 26
|
var outputHeight = $("#out").height() + 26
|
||||||
if (outputHeight > 600) outputHeight = 600
|
if (outputHeight > 600) outputHeight = 600
|
||||||
@ -179,4 +185,24 @@ switchQuickCommandResult = (stdout, stderr, outputOpts) => {
|
|||||||
// 无输出
|
// 无输出
|
||||||
utools.outPlugin()
|
utools.outPlugin()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 替换上个版本弃用的功能
|
||||||
|
let oldVersionFix = () => {
|
||||||
|
var customFts = getDB('customFts');
|
||||||
|
Object.keys(customFts).forEach(x => {
|
||||||
|
if (customFts[x].program == 'simulation') customFts[x].program = 'quickcommand';
|
||||||
|
if (customFts[x].cmd.includes('await sleep')) customFts[x].cmd = customFts[x].cmd.replace(/await sleep/g, 'quickcommand.sleep')
|
||||||
|
putDB(x, customFts[x], 'customFts');
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 兼容暗黑模式
|
||||||
|
let adaptDarkMode = () => {
|
||||||
|
if (utools.isDarkColors()) {
|
||||||
|
!$('#darkmode').length && $('head').append('<link id="darkmode" rel="stylesheet" href="assets/style/darkmode.css">')
|
||||||
|
} else {
|
||||||
|
$('#darkmode').length && $('#darkmode').remove()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
Loading…
x
Reference in New Issue
Block a user