Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Update Custom Window Options #38

Merged
merged 2 commits into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ let rl;
let callbacks = {};
let counters = {};
let elements = {};
let windowOptions = {};
let menus = {};
let quittingApp = false;

Expand Down Expand Up @@ -275,6 +276,9 @@ function onReady () {
case consts.eventNames.windowCmdUnmaximize:
elements[json.targetID].unmaximize()
break;
case consts.eventNames.windowCmdUpdateCustomOptions:
windowOptions[json.targetID] = json.windowOptions
break;
case consts.eventNames.windowCmdWebContentsExecuteJavascript:
elements[json.targetID].webContents.executeJavaScript(json.code).then(() => client.write(json.targetID, consts.eventNames.windowEventWebContentsExecutedJavaScript));
break;
Expand Down Expand Up @@ -392,6 +396,7 @@ function windowCreate(json) {
}
json.windowOptions.webPreferences.nodeIntegration = true
elements[json.targetID] = new BrowserWindow(json.windowOptions)
windowOptions[json.targetID] = json.windowOptions
if (typeof json.windowOptions.proxy !== "undefined") {
elements[json.targetID].webContents.session.setProxy(json.windowOptions.proxy)
.then(() => windowCreateFinish(json))
Expand All @@ -406,19 +411,19 @@ function windowCreateFinish(json) {
elements[json.targetID].loadURL(json.url, (typeof json.windowOptions.load !== "undefined" ? json.windowOptions.load : {}));
elements[json.targetID].on('blur', () => { client.write(json.targetID, consts.eventNames.windowEventBlur) })
elements[json.targetID].on('close', (e) => {
if (typeof json.windowOptions.custom !== "undefined") {
if (typeof json.windowOptions.custom.messageBoxOnClose !== "undefined") {
let buttonId = dialog.showMessageBoxSync(null, json.windowOptions.custom.messageBoxOnClose)
if (typeof json.windowOptions.custom.messageBoxOnClose.confirmId !== "undefined" && json.windowOptions.custom.messageBoxOnClose.confirmId !== buttonId) {
if (typeof windowOptions[json.targetID] !== "undefined" && typeof windowOptions[json.targetID].custom !== "undefined") {
if (typeof windowOptions[json.targetID].custom.messageBoxOnClose !== "undefined") {
let buttonId = dialog.showMessageBoxSync(null, windowOptions[json.targetID].custom.messageBoxOnClose)
if (typeof windowOptions[json.targetID].custom.messageBoxOnClose.confirmId !== "undefined" && windowOptions[json.targetID].custom.messageBoxOnClose.confirmId !== buttonId) {
e.preventDefault()
return
}
}
if (!quittingApp) {
if (json.windowOptions.custom.minimizeOnClose) {
if (windowOptions[json.targetID].custom.minimizeOnClose) {
e.preventDefault();
elements[json.targetID].minimize();
} else if (json.windowOptions.custom.hideOnClose) {
} else if (windowOptions[json.targetID].custom.hideOnClose) {
e.preventDefault();
elements[json.targetID].hide();
}
Expand Down
1 change: 1 addition & 0 deletions src/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ module.exports = {
windowCmdRestore: "window.cmd.restore",
windowCmdShow: "window.cmd.show",
windowCmdUnmaximize: "window.cmd.unmaximize",
windowCmdUpdateCustomOptions: "window.cmd.update.custom.options",
windowCmdWebContentsCloseDevTools: "window.cmd.web.contents.close.dev.tools",
windowCmdWebContentsOpenDevTools: "window.cmd.web.contents.open.dev.tools",
windowCmdWebContentsExecuteJavascript: "window.cmd.web.contents.execute.javascript",
Expand Down