Skip to content
This repository was archived by the owner on Feb 16, 2024. It is now read-only.
Open
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
18 changes: 15 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

// @ts-check
'use strict'

Expand Down Expand Up @@ -267,6 +268,11 @@ function onReady () {
case consts.eventNames.windowCmdShow:
elements[json.targetID].show()
break;
case consts.eventNames.windowCmdLoadUrl:
elements[json.targetID].loadURL(json.url, {}).then(() => {
client.write(json.targetID, consts.eventNames.windowEventLoadedUrl);
});
break;
case consts.eventNames.windowCmdWebContentsCloseDevTools:
elements[json.targetID].webContents.closeDevTools()
break;
Expand All @@ -277,11 +283,17 @@ function onReady () {
elements[json.targetID].unmaximize()
break;
case consts.eventNames.windowCmdUpdateCustomOptions:
windowOptions[json.targetID] = json.windowOptions
client.write(json.targetID, consts.eventNames.windowEventUpdatedCustomOptions, json.windowOptions)
client.write(json.targetID, consts.eventNames.windowEventUpdatedCustomOptions, json.windowOptions);
break;
case consts.eventNames.windowCmdWebContentsExecuteJavascript:
elements[json.targetID].webContents.executeJavaScript(json.code).then(() => client.write(json.targetID, consts.eventNames.windowEventWebContentsExecutedJavaScript));
elements[json.targetID].webContents.executeJavaScript(json.code)
.then(() => client.write(json.targetID, consts.eventNames.windowEventWebContentsExecutedJavaScript));
break;
case consts.eventNames.windowCmdWebContentsSetProxy:
elements[json.targetID].webContents.session.clearAuthCache().then(() => {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really like the fact of clearing the Session Auth Cache here.

It should be split into 2 different events, one for clearing the auth cache and another one to set the proxy.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree since when you re-set the proxy you don't want it to try use the same credentials (for instance, when using a rotating proxy IP), the behaviour in Electron is what is strange.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thing is, it makes sense in your case, but not in others. Clearing auth cache shouldn't be binded to setting the proxy simply to allow developers to do one without the other.

elements[json.targetID].webContents.session.setProxy(json.proxy)
.then(() => client.write(json.targetID, consts.eventNames.windowEventWebContentsSetProxy));
});
break;
}
});
Expand Down
4 changes: 4 additions & 0 deletions src/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,13 @@ module.exports = {
windowCmdSetBounds: "window.cmd.set.bounds",
windowCmdRestore: "window.cmd.restore",
windowCmdShow: "window.cmd.show",
windowCmdLoadUrl: "window.cmd.load.url",
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",
windowCmdWebContentsSetProxy: "window.cmd.web.contents.set.proxy",
windowEventBlur: "window.event.blur",
windowEventClosed: "window.event.closed",
windowEventDidFinishLoad: "window.event.did.finish.load",
Expand All @@ -116,7 +118,9 @@ module.exports = {
windowEventShow: "window.event.show",
windowEventUnmaximize: "window.event.unmaximize",
windowEventUnresponsive: "window.event.unresponsive",
windowEventLoadedUrl: "window.event.loaded.url",
windowEventWebContentsExecutedJavaScript: "window.event.web.contents.executed.javascript",
windowEventWebContentsSetProxy: "window.event.web.contents.set.proxy",
windowEventUpdatedCustomOptions: "window.event.updated.custom.options"
},
targetIds: {
Expand Down