更改命令图标储存方式

This commit is contained in:
fofolee 2020-04-10 19:31:44 +08:00
parent 6ea282b6f0
commit f42e59ea82
2 changed files with 12 additions and 27 deletions

View File

@ -159,12 +159,7 @@ showOptions = () => {
break;
}
}
try {
var iconpath = cacheIco(customFts[fts].base64Ico, features.icon);
} 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="${features.icon}"></td>
<td>${cmds}</td><td>${features.explain}</td><td>
<label class="switch-btn">
<input class="checked-switch" id="${features.code}" type="checkbox" ${isChecked}>
@ -370,8 +365,6 @@ $("#options").on('click', '.editBtn', function () {
$('#codec').val(data.codec);
$("#icon").attr('src', data.features.icon);
let mode = data.program;
let iconame = basename(data.features.icon);
if (iconame != `${mode}.png`) $('#iconame').val(iconame);
if (mode == 'custom') {
$('#custombin').show().val(data.customOptions.bin);
$('#customarg').show().val(data.customOptions.argv);
@ -416,7 +409,7 @@ $("#options").on('click', '#icon, #iconame', function () {
buttonLabel: '选择',
filters: [{
name: 'Images',
extensions: ['jpg', 'jpeg', 'png']
extensions: ['png']
}, ]
}
let iconpath = window.openFolder(options)[0];
@ -476,18 +469,13 @@ $("#options").on('click', '.saveBtn', function () {
base64ico,
hasSubInput;
if (!desc) desc = ' ';
// 自定义了图标的情况下
// 选择了图标的情况下
if (iconame) {
icon = `../QuickCommandIcons/${iconame}`;
if (iconpath == icon) {
base64ico = window.getBase64Ico(resolve(dirname, iconpath));
} else {
base64ico = window.getBase64Ico(iconpath);
}
base64ico = window.getBase64Ico(iconpath);
icon = "data:image/png;base64," + base64ico;
// 未自定义使用默认
} else {
icon = iconpath;
base64ico = '';
}
var noKeyword;
var rule = $('#rule').val();
@ -533,7 +521,6 @@ $("#options").on('click', '.saveBtn', function () {
cmd: cmd,
output: output,
codec: codec,
base64Ico: base64ico,
noKeyword: noKeyword,
hasSubInput: hasSubInput
}
@ -553,10 +540,16 @@ $("#options").on('click', '.saveBtn', function () {
}
})
hasCustomIcon = () => {
var src = $("#icon").attr('src');
var iconame = $("#iconame").val();
return /data:image\/png;base64,/.test(src) || iconame
}
// 语言选项改变时
$("#options").on('change', '#program', function () {
let mode = $(this).val();
if (!$("#iconame").val()) $("#icon").attr('src', `logo/${mode}.png`);
if (!hasCustomIcon()) $("#icon").attr('src', `logo/${mode}.png`);
if (mode == 'custom') {
$('#custombin').show();
$('#customarg').show();

View File

@ -44,14 +44,6 @@ getBase64Ico = path => {
return fs.readFileSync(path, 'base64');
}
cacheIco = (b64, icon) => {
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 = options => {
return dialog.showOpenDialogSync(BrowserWindow.getFocusedWindow(), options);
}