Skip to content

Commit

Permalink
optim custom dialog
Browse files Browse the repository at this point in the history
press "enter" and go for simpler dialogs
  • Loading branch information
RoderickQiu committed Aug 2, 2023
1 parent bf1015b commit affbeed
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
14 changes: 13 additions & 1 deletion custom-dialog.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@
$("#dialog-msg").text(message.msg);
executeAfter = message.executeAfter;
ipc.send("custom-dialog-fit", Math.round(msgNode.height() / parseFloat(msgNode.css('line-height'))));
if (message.type === 1 || message.type === 2) $("#dialog-cancel").removeClass("d-none"); //select_on
document.onkeydown = function () {
};
if (message.type === 1 || message.type === 2) $("#dialog-cancel").removeClass("d-none");
else $("#dialog-cancel").addClass("d-none");

if (message.type === 2) { //update_on
$("#dialog-cancel").text(i18n.__('update-refuse'));
$("#dialog-button-3").removeClass("d-none");
Expand All @@ -77,6 +80,15 @@
$("#timer").css("width", "210px");
$("#dialog-buttons").css("width", "210px");
}

if (message.type === 0) {//on
document.onkeydown = function (event1) {
let ev = document.all ? window.event : event1;
if ((ev.keyCode || ev.which) === 13) {
ok();
}
}
}
})
</script>
<script src="renderer.js"></script>
Expand Down
37 changes: 20 additions & 17 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -739,33 +739,36 @@ function customDialog(mode, title, msg, executeAfter) {
}
if (executeAfter == null) executeAfter = "";
if (mode === "on" || mode === "select_on" || mode === "update_on") {
customDialogWin.webContents.send("dialog-init", {
title: title,
msg: msg,
executeAfter: executeAfter,
type: getCustomDialogModeType(mode)
});
customDialogWin.show();
customDialogWin.setAlwaysOnTop(true, "pop-up-menu");
customDialogWin.focus();
if (mode === "update_on") {
customDialogWin.setSize(Math.floor(240 * ratio) * 2, customDialogWin.getSize()[1]);
} else {
customDialogWin.setSize(Math.floor(240 * ratio), customDialogWin.getSize()[1]);
if (customDialogWin != null) {
customDialogWin.webContents.send("dialog-init", {
title: title,
msg: msg,
executeAfter: executeAfter,
type: getCustomDialogModeType(mode)
});
customDialogWin.show();
customDialogWin.setAlwaysOnTop(true, "pop-up-menu");
customDialogWin.focus();
if (mode === "update_on") {
customDialogWin.setSize(Math.floor(240 * ratio) * 2, customDialogWin.getSize()[1]);
} else {
customDialogWin.setSize(Math.floor(240 * ratio), customDialogWin.getSize()[1]);
}
customDialogWin.center();
}
customDialogWin.center();
} else if (mode === "off") {
customDialogWin.hide();
if (customDialogWin != null) customDialogWin.hide();
try {
eval(executeAfter);
} catch (e) {
console.log(e);
}
} else if (mode === "cancel") {
customDialogWin.hide();
if (customDialogWin != null) customDialogWin.hide();
} else if (mode === "button3_update") {
shell.openExternal("https://github.com/RoderickQiu/wnr/releases/latest");
customDialogWin.hide();

if (customDialogWin != null) customDialogWin.hide();
}
}

Expand Down

0 comments on commit affbeed

Please sign in to comment.