mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-08 06:16:27 +08:00
增加导入导出功能
This commit is contained in:
parent
821413e775
commit
67964c177f
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
可以配置一些常用的命令,比如`回收站` `查看网络连接`之类
|
可以配置一些常用的命令,比如`回收站` `查看网络连接`之类
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
@ -62,6 +62,10 @@
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
#### 导入导出
|
||||||
|
|
||||||
|
支持命令的导入或者导出
|
||||||
|
|
||||||
## 下载
|
## 下载
|
||||||
|
|
||||||
[百度网盘](https://pan.baidu.com/s/1kEEQcQ1p3Rjli2sTtmCcTg) 提取码: `rbek`
|
[百度网盘](https://pan.baidu.com/s/1kEEQcQ1p3Rjli2sTtmCcTg) 提取码: `rbek`
|
||||||
|
@ -203,15 +203,20 @@
|
|||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options span.editBtn {
|
#options span.Btn{
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
#options span.editBtn {
|
||||||
color: #00af2c;
|
color: #00af2c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#options span.exportBtn {
|
||||||
|
color: #407abf;
|
||||||
|
}
|
||||||
|
|
||||||
#options span.delBtn {
|
#options span.delBtn {
|
||||||
font-size: 16px;
|
|
||||||
cursor: pointer;
|
|
||||||
color: #ed5b49
|
color: #ed5b49
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,6 +224,10 @@
|
|||||||
color: #057205;
|
color: #057205;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#options span.exportBtn:hover {
|
||||||
|
color: #2d5586;
|
||||||
|
}
|
||||||
|
|
||||||
#options span.delBtn:hover {
|
#options span.delBtn:hover {
|
||||||
color: #bd3523;
|
color: #bd3523;
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,38 @@ getCustomFts = () => {
|
|||||||
return customFts;
|
return customFts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
putCustomFts = (code, pushData) => {
|
||||||
|
var db = utools.db.get("customFts");
|
||||||
|
if (db) {
|
||||||
|
var rev = db._rev
|
||||||
|
var data = db.data
|
||||||
|
data[code] = pushData;
|
||||||
|
utools.db.put({ _id: "customFts", data: data, _rev: rev });
|
||||||
|
} else {
|
||||||
|
var data = {};
|
||||||
|
data[code] = pushData;
|
||||||
|
utools.db.put({ _id: "customFts", data: data });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
importCommand = () => {
|
||||||
|
var options = {
|
||||||
|
filters: [{ name: 'json', extensions: ['json'] }, ]
|
||||||
|
}
|
||||||
|
let file = window.openFolder(options)[0];
|
||||||
|
$.get(file, data => {
|
||||||
|
var pushData = JSON.parse(data),
|
||||||
|
code = basename(file, '.json'),
|
||||||
|
customFts = getCustomFts();
|
||||||
|
if (code in customFts) {
|
||||||
|
window.messageBox({ type: 'error', icon: window.logo, message: "命令名称重复, 请先修改文件名再导入!", buttons: ['朕知道了'] })
|
||||||
|
} else {
|
||||||
|
putCustomFts(code, pushData);
|
||||||
|
showOptions();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
programs = {
|
programs = {
|
||||||
shell: {
|
shell: {
|
||||||
bin: 'bash',
|
bin: 'bash',
|
||||||
@ -78,9 +110,11 @@ showOptions = () => {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var iconpath = pjoin(dirname, features.icon),
|
try {
|
||||||
base64Ico = customFts[fts].base64Ico;
|
var iconpath = cacheIco(customFts[fts].base64Ico, features.icon);
|
||||||
if (!exists(iconpath) && base64Ico) saveBase64Ico(iconpath, base64Ico);
|
} catch (e) {
|
||||||
|
window.messageBox({ type: 'error', icon: window.logo, message: e.toString(), buttons: ['纳尼?!'] })
|
||||||
|
}
|
||||||
featureList += `<tr><td><img class="logo" src="${iconpath}"></td>
|
featureList += `<tr><td><img class="logo" src="${iconpath}"></td>
|
||||||
<td>${cmds}</td><td width="300px">${features.explain}</td><td>
|
<td>${cmds}</td><td width="300px">${features.explain}</td><td>
|
||||||
<label class="switch-btn">
|
<label class="switch-btn">
|
||||||
@ -88,12 +122,14 @@ showOptions = () => {
|
|||||||
<span class="text-switch"></span>
|
<span class="text-switch"></span>
|
||||||
<span class="toggle-btn"></span>
|
<span class="toggle-btn"></span>
|
||||||
</label>
|
</label>
|
||||||
<span class="editBtn" code="${features.code}">✎</span>
|
<span class="Btn editBtn" code="${features.code}"><i class="fa fa-pencil-square fa-fw"></i></span>
|
||||||
<span class="delBtn" code="${features.code}">✘</span>
|
<span class="Btn exportBtn" code="${features.code}"><i class="fa fa-share-square fa-fw"></i></span>
|
||||||
|
<span class="Btn delBtn" code="${features.code}"><i class="fa fa-trash fa-fw"></i></span>
|
||||||
</td>`
|
</td>`
|
||||||
};
|
};
|
||||||
featureList += `</tr></table><div class="foot">
|
featureList += `</tr></table><div class="foot">
|
||||||
<div id="add" class="footBtn">添加命令</div>
|
<div id="add" class="footBtn">添加命令</div>
|
||||||
|
<div id="import" class="footBtn">导入命令</div>
|
||||||
<div id="disableAll" class="footBtn">全部禁用</div>
|
<div id="disableAll" class="footBtn">全部禁用</div>
|
||||||
<div id="enableAll" class="footBtn">全部启用</div>
|
<div id="enableAll" class="footBtn">全部启用</div>
|
||||||
</div>`
|
</div>`
|
||||||
@ -180,6 +216,8 @@ $("#options").on('click', '.footBtn', function () {
|
|||||||
switch ($(this).attr('id')) {
|
switch ($(this).attr('id')) {
|
||||||
case 'add': showCustomize();
|
case 'add': showCustomize();
|
||||||
break;
|
break;
|
||||||
|
case 'import': importCommand();
|
||||||
|
break;
|
||||||
case 'enableAll': $(".checked-switch:not(:checked)").click();
|
case 'enableAll': $(".checked-switch:not(:checked)").click();
|
||||||
break;
|
break;
|
||||||
case 'disableAll': $(".checked-switch:checked").click();
|
case 'disableAll': $(".checked-switch:checked").click();
|
||||||
@ -219,6 +257,20 @@ $("#options").on('click', '.editBtn', function () {
|
|||||||
window.editor.setValue(data.cmd);
|
window.editor.setValue(data.cmd);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 导出
|
||||||
|
$("#options").on('click', '.exportBtn', function () {
|
||||||
|
var code = $(this).attr('code'),
|
||||||
|
json = getCustomFts()[code],
|
||||||
|
options = {
|
||||||
|
title: '选择保存位置',
|
||||||
|
defaultPath: code,
|
||||||
|
filters: [
|
||||||
|
{ name: 'json', extensions: ['json'] },
|
||||||
|
]
|
||||||
|
};
|
||||||
|
window.saveFile(options, JSON.stringify(json));
|
||||||
|
})
|
||||||
|
|
||||||
// 删除
|
// 删除
|
||||||
$("#options").on('click', '.delBtn', function () {
|
$("#options").on('click', '.delBtn', function () {
|
||||||
var code = $(this).attr('code'),
|
var code = $(this).attr('code'),
|
||||||
@ -232,7 +284,14 @@ $("#options").on('click', '.delBtn', function () {
|
|||||||
|
|
||||||
// 选择图标
|
// 选择图标
|
||||||
$("#options").on('click', '#icon, #iconame', function () {
|
$("#options").on('click', '#icon, #iconame', function () {
|
||||||
let iconpath = window.openFolder()[0];
|
var options = {
|
||||||
|
buttonLabel: '选择',
|
||||||
|
filters: [{
|
||||||
|
name: 'Images',
|
||||||
|
extensions: ['jpg', 'jpeg', 'png']
|
||||||
|
}, ]
|
||||||
|
}
|
||||||
|
let iconpath = window.openFolder(options)[0];
|
||||||
$("#iconame").val(basename(iconpath));
|
$("#iconame").val(basename(iconpath));
|
||||||
$("#icon").attr('src', iconpath);
|
$("#icon").attr('src', iconpath);
|
||||||
})
|
})
|
||||||
@ -244,7 +303,7 @@ $("#options").on('click', '.saveBtn', function () {
|
|||||||
// 如果 code 重复, 编辑状态下不检测
|
// 如果 code 重复, 编辑状态下不检测
|
||||||
if (code in customFts && !$('#kw').attr('edit')) {
|
if (code in customFts && !$('#kw').attr('edit')) {
|
||||||
$('#kw').css({ 'border-bottom-color': '#ec1212' })
|
$('#kw').css({ 'border-bottom-color': '#ec1212' })
|
||||||
window.messageBox({ type: 'error', icon: window.logo, message: "命令名称与现有的重复!", buttons: ['朕知道了'] })
|
window.messageBox({ type: 'error', icon: window.logo, message: "命令名称重复!", buttons: ['朕知道了'] })
|
||||||
} else {
|
} else {
|
||||||
var kw = $('#kw').val().split(','),
|
var kw = $('#kw').val().split(','),
|
||||||
program = $('#program').val(),
|
program = $('#program').val(),
|
||||||
@ -258,9 +317,9 @@ $("#options").on('click', '.saveBtn', function () {
|
|||||||
base64ico;
|
base64ico;
|
||||||
// 自定义了图标的情况下
|
// 自定义了图标的情况下
|
||||||
if (iconame) {
|
if (iconame) {
|
||||||
icon = window.getIconPath(iconame);
|
icon = `../QuickCommandIcons/${iconame}`;
|
||||||
if (iconpath == icon) {
|
if (iconpath == icon) {
|
||||||
base64ico = window.getBase64Ico(pjoin(dirname, iconpath));
|
base64ico = window.getBase64Ico(resolve(dirname, iconpath));
|
||||||
} else {
|
} else {
|
||||||
base64ico = window.getBase64Ico(iconpath);
|
base64ico = window.getBase64Ico(iconpath);
|
||||||
}
|
}
|
||||||
@ -281,9 +340,8 @@ $("#options").on('click', '.saveBtn', function () {
|
|||||||
noKeyword = false;
|
noKeyword = false;
|
||||||
}
|
}
|
||||||
$("#customize").animate({ top: '100%' });
|
$("#customize").animate({ top: '100%' });
|
||||||
var pushData = {};
|
|
||||||
// 添加特性
|
// 添加特性
|
||||||
pushData[code] = {
|
pushData = {
|
||||||
features: {
|
features: {
|
||||||
"code": code,
|
"code": code,
|
||||||
"explain": desc,
|
"explain": desc,
|
||||||
@ -297,15 +355,7 @@ $("#options").on('click', '.saveBtn', function () {
|
|||||||
base64Ico: base64ico,
|
base64Ico: base64ico,
|
||||||
noKeyword: noKeyword
|
noKeyword: noKeyword
|
||||||
}
|
}
|
||||||
var db = utools.db.get("customFts");
|
putCustomFts(code, pushData);
|
||||||
if (db) {
|
|
||||||
var rev = db._rev
|
|
||||||
var data = db.data
|
|
||||||
data[code] = pushData[code];
|
|
||||||
utools.db.put({ _id: "customFts", data: data, _rev: rev });
|
|
||||||
} else {
|
|
||||||
utools.db.put({ _id: "customFts", data: pushData });
|
|
||||||
}
|
|
||||||
showOptions();
|
showOptions();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||||
<link rel="stylesheet" href="assets/options.css">
|
<link rel="stylesheet" href="assets/options.css">
|
||||||
<link rel="stylesheet" href="codemirror/lib/codemirror.css">
|
<link rel="stylesheet" href="codemirror/lib/codemirror.css">
|
||||||
|
<link rel="stylesheet" href="font-awesome-4.7.0/css/font-awesome.min.css">
|
||||||
<script src="assets/jquery-3.3.1.min.js"></script>
|
<script src="assets/jquery-3.3.1.min.js"></script>
|
||||||
<script src="codemirror/lib/codemirror.js"></script>
|
<script src="codemirror/lib/codemirror.js"></script>
|
||||||
<script src="codemirror/addon/display/placeholder.js"></script>
|
<script src="codemirror/addon/display/placeholder.js"></script>
|
||||||
|
33
preload.js
33
preload.js
@ -32,31 +32,32 @@ basename = path.basename;
|
|||||||
|
|
||||||
dirname = __dirname;
|
dirname = __dirname;
|
||||||
|
|
||||||
pjoin = path.join;
|
resolve = path.resolve;
|
||||||
|
|
||||||
exists = fs.existsSync;
|
exists = fs.existsSync;
|
||||||
|
|
||||||
getIconPath = name => {
|
|
||||||
let dir = path.resolve(__dirname, '..', 'QuickCommandIcons')
|
|
||||||
if (!exists(dir)) fs.mkdirSync(dir);
|
|
||||||
return `../QuickCommandIcons/${name}`
|
|
||||||
}
|
|
||||||
|
|
||||||
getBase64Ico = path => {
|
getBase64Ico = path => {
|
||||||
return fs.readFileSync(path, 'base64');
|
return fs.readFileSync(path, 'base64');
|
||||||
}
|
}
|
||||||
|
|
||||||
saveBase64Ico = (path, b64) => {
|
cacheIco = (b64, icon) => {
|
||||||
fs.writeFileSync(path, b64, 'base64');
|
var file = path.resolve(__dirname, icon),
|
||||||
|
dir = path.dirname(file);
|
||||||
|
!exists(dir) && fs.mkdirSync(dir);
|
||||||
|
b64 && !exists(file) && fs.writeFileSync(file, b64, 'base64');
|
||||||
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
openFolder = () => {
|
openFolder = options => {
|
||||||
return dialog.showOpenDialog(BrowserWindow.getFocusedWindow(), {
|
return dialog.showOpenDialog(BrowserWindow.getFocusedWindow(), options);
|
||||||
buttonLabel: '选择',
|
}
|
||||||
filters: [
|
|
||||||
{name: 'Images', extensions: ['jpg', 'jpeg', 'png']},
|
saveFile = (options, content) => {
|
||||||
]
|
dialog.showSaveDialog(BrowserWindow.getFocusedWindow(), options, filename => {
|
||||||
});
|
filename && fs.writeFile(filename, content, 'utf8', err => {
|
||||||
|
err && console.log(err)
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
copy = () => {
|
copy = () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user