mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-30 04:42:45 +08:00
添加显示选择框、输入框、按钮三个api
This commit is contained in:
parent
2f07a2843c
commit
8503848e8a
105
src/preload.js
105
src/preload.js
@ -13,7 +13,7 @@ if (!utools.isWindows()) process.env.PATH += ':/usr/local/bin:/usr/local/sbin'
|
|||||||
|
|
||||||
// window.startTime = new Date().getTime()
|
// window.startTime = new Date().getTime()
|
||||||
|
|
||||||
const QuickCommandActions = [
|
const shortCodes = [
|
||||||
|
|
||||||
open = path => {
|
open = path => {
|
||||||
utools.shellOpenItem(path)
|
utools.shellOpenItem(path)
|
||||||
@ -37,27 +37,29 @@ const QuickCommandActions = [
|
|||||||
|
|
||||||
keyTap = (key, ...modifier) => utools.simulateKeyboardTap(key, ...modifier),
|
keyTap = (key, ...modifier) => utools.simulateKeyboardTap(key, ...modifier),
|
||||||
|
|
||||||
simulateCopy = () => {
|
|
||||||
var ctlKey = utools.isMacOs() ? 'command' : 'control';
|
|
||||||
utools.simulateKeyboardTap('c', ctlKey);
|
|
||||||
},
|
|
||||||
|
|
||||||
copyTo = text => {
|
copyTo = text => {
|
||||||
electron.clipboard.writeText(text)
|
electron.clipboard.writeText(text)
|
||||||
},
|
},
|
||||||
|
|
||||||
simulatePaste = () => {
|
send = text => {
|
||||||
|
copyTo(text);
|
||||||
|
quickcommand.simulatePaste();
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
const quickcommand = {
|
||||||
|
simulateCopy: function() {
|
||||||
|
var ctlKey = utools.isMacOs() ? 'command' : 'control';
|
||||||
|
utools.simulateKeyboardTap('c', ctlKey);
|
||||||
|
},
|
||||||
|
|
||||||
|
simulatePaste: function() {
|
||||||
var ctlKey = utools.isMacOs() ? 'command' : 'control';
|
var ctlKey = utools.isMacOs() ? 'command' : 'control';
|
||||||
utools.simulateKeyboardTap('v', ctlKey);
|
utools.simulateKeyboardTap('v', ctlKey);
|
||||||
},
|
},
|
||||||
|
|
||||||
send = text => {
|
|
||||||
copyTo(text);
|
|
||||||
simulatePaste();
|
|
||||||
},
|
|
||||||
|
|
||||||
// setTimout 不能在 vm2 中使用,同时在 electron 中有 bug
|
// setTimout 不能在 vm2 中使用,同时在 electron 中有 bug
|
||||||
sleep = ms => {
|
sleep: function(ms) {
|
||||||
var start = new Date().getTime()
|
var start = new Date().getTime()
|
||||||
var cmd, tempFilePath
|
var cmd, tempFilePath
|
||||||
if (utools.isWindows()) {
|
if (utools.isWindows()) {
|
||||||
@ -75,12 +77,77 @@ const QuickCommandActions = [
|
|||||||
}
|
}
|
||||||
var end = new Date().getTime()
|
var end = new Date().getTime()
|
||||||
return (end - start)
|
return (end - start)
|
||||||
|
},
|
||||||
|
|
||||||
|
showInputBox: function (callback = () => { }, placeHolders = [""]) {
|
||||||
|
if(typeof callback != 'function') return
|
||||||
|
var html = ""
|
||||||
|
var inputBoxNumbers = placeHolders.length
|
||||||
|
for (let i = 0; i < inputBoxNumbers; i++) {
|
||||||
|
html += `<input class="swal2-input" id="inputBox${i}" placeholder="${placeHolders[i]}">`
|
||||||
|
}
|
||||||
|
var result = []
|
||||||
|
var options = {
|
||||||
|
html: html,
|
||||||
|
focusConfirm: false,
|
||||||
|
preConfirm: () => {
|
||||||
|
for (let i = 0; i < inputBoxNumbers; i++) {
|
||||||
|
result.push(document.getElementById(`inputBox${i}`).value)
|
||||||
|
}
|
||||||
|
callback(result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
swalOneByOne(options)
|
||||||
|
},
|
||||||
|
|
||||||
|
showSelectBox: function (callback = () => { }, selects = [""]) {
|
||||||
|
if(typeof callback != 'function') return
|
||||||
|
var html = `<select id="selectBox" class="swal2-select">`
|
||||||
|
var selectBoxNumbers = selects.length
|
||||||
|
for (let i = 0; i < selectBoxNumbers; i++) {
|
||||||
|
html += `<option>${selects[i]}</option>`
|
||||||
|
}
|
||||||
|
html += `</select>`
|
||||||
|
var options = {
|
||||||
|
html: html,
|
||||||
|
focusConfirm: false,
|
||||||
|
preConfirm: () => {
|
||||||
|
callback(document.getElementById('selectBox').value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
swalOneByOne(options)
|
||||||
|
},
|
||||||
|
|
||||||
|
showButtonBox: function (callback = () => { }, buttons = [""]) {
|
||||||
|
if(typeof callback != 'function') return
|
||||||
|
var html = ``
|
||||||
|
var buttonBoxNumbers = buttons.length
|
||||||
|
for (let i = 0; i < buttonBoxNumbers; i++) {
|
||||||
|
html += `<button class="swal2-confirm swal2-styled" style="width: 80%" onclick="clickButton(${i})">${buttons[i]}</button>`
|
||||||
|
}
|
||||||
|
var options = {
|
||||||
|
onBeforeOpen: () => {
|
||||||
|
clickButton = i => {
|
||||||
|
callback({ index: i, text: buttons[i] })
|
||||||
|
swal.clickConfirm()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
html: html,
|
||||||
|
showConfirmButton: false
|
||||||
|
}
|
||||||
|
swalOneByOne(options)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
swalOneByOne = options => {
|
||||||
|
swal.getQueueStep() && Swal.insertQueueStep(options) || Swal.queue([options])
|
||||||
}
|
}
|
||||||
]
|
|
||||||
|
|
||||||
var getSandboxFuns = () => {
|
var getSandboxFuns = () => {
|
||||||
var sandbox = {
|
var sandbox = {
|
||||||
utools: utools,
|
utools: utools,
|
||||||
|
quickcommand: quickcommand,
|
||||||
// process: process,
|
// process: process,
|
||||||
electron: electron,
|
electron: electron,
|
||||||
fs: fs,
|
fs: fs,
|
||||||
@ -89,14 +156,13 @@ var getSandboxFuns = () => {
|
|||||||
child_process: child_process,
|
child_process: child_process,
|
||||||
util: util,
|
util: util,
|
||||||
alert: alert,
|
alert: alert,
|
||||||
// Swal: Swal,
|
|
||||||
$: {
|
$: {
|
||||||
get: $.get,
|
get: $.get,
|
||||||
post: $.post,
|
post: $.post,
|
||||||
ajax: $.ajax
|
ajax: $.ajax
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QuickCommandActions.forEach(f => {
|
shortCodes.forEach(f => {
|
||||||
sandbox[f.name] = f
|
sandbox[f.name] = f
|
||||||
})
|
})
|
||||||
return sandbox
|
return sandbox
|
||||||
@ -214,8 +280,9 @@ getBase64Ico = path => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
openFileInDialog = (options, readfile) => {
|
openFileInDialog = (options, readfile) => {
|
||||||
var file = utools.showOpenDialog(options)[0];
|
var dialog = utools.showOpenDialog(options);
|
||||||
if (!file) return false
|
if (!dialog) return false
|
||||||
|
var file = dialog[0]
|
||||||
var information = {
|
var information = {
|
||||||
name: path.basename(file),
|
name: path.basename(file),
|
||||||
path: file
|
path: file
|
||||||
@ -273,7 +340,7 @@ restoreClip = historyData => {
|
|||||||
getSelectText = () => {
|
getSelectText = () => {
|
||||||
var historyData = storeClip();
|
var historyData = storeClip();
|
||||||
electron.clipboard.writeText('');
|
electron.clipboard.writeText('');
|
||||||
simulateCopy();
|
quickcommand.simulateCopy();
|
||||||
var selectText = electron.clipboard.readText()
|
var selectText = electron.clipboard.readText()
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
restoreClip(historyData)
|
restoreClip(historyData)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user