mirror of
https://github.com/zulip/zulip-desktop.git
synced 2025-11-11 01:16:09 +00:00
WebView: Get event parameters via WebContents rather than WebviewTag.
Works around https://github.com/electron/electron/issues/31924. Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
@@ -10,11 +10,9 @@ const dingSound = new Audio("../resources/sounds/ding.ogg");
|
|||||||
|
|
||||||
export default function handleExternalLink(
|
export default function handleExternalLink(
|
||||||
this: WebView,
|
this: WebView,
|
||||||
event: Electron.NewWindowEvent,
|
details: Electron.HandlerDetails,
|
||||||
): void {
|
): void {
|
||||||
event.preventDefault();
|
const url = new URL(details.url);
|
||||||
|
|
||||||
const url = new URL(event.url);
|
|
||||||
const downloadPath = ConfigUtil.getConfigItem(
|
const downloadPath = ConfigUtil.getConfigItem(
|
||||||
"downloadsPath",
|
"downloadsPath",
|
||||||
`${app.getPath("downloads")}`,
|
`${app.getPath("downloads")}`,
|
||||||
|
|||||||
@@ -130,16 +130,18 @@ export default class WebView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
registerListeners(): void {
|
registerListeners(): void {
|
||||||
this.$el.addEventListener("new-window", (event) => {
|
const webContents = this.getWebContents();
|
||||||
handleExternalLink.call(this, event);
|
|
||||||
|
webContents.setWindowOpenHandler((details) => {
|
||||||
|
handleExternalLink.call(this, details);
|
||||||
|
return {action: "deny"};
|
||||||
});
|
});
|
||||||
|
|
||||||
if (shouldSilentWebview) {
|
if (shouldSilentWebview) {
|
||||||
this.getWebContents().setAudioMuted(true);
|
webContents.setAudioMuted(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.$el.addEventListener("page-title-updated", (event) => {
|
webContents.on("page-title-updated", (_event, title) => {
|
||||||
const {title} = event;
|
|
||||||
this.badgeCount = this.getBadgeCount(title);
|
this.badgeCount = this.getBadgeCount(title);
|
||||||
this.props.onTitleChange();
|
this.props.onTitleChange();
|
||||||
});
|
});
|
||||||
@@ -152,9 +154,7 @@ export default class WebView {
|
|||||||
this.canGoBackButton();
|
this.canGoBackButton();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.$el.addEventListener("page-favicon-updated", (event) => {
|
webContents.on("page-favicon-updated", (_event, favicons) => {
|
||||||
const {favicons} = event;
|
|
||||||
|
|
||||||
// This returns a string of favicons URL. If there is a PM counts in unread messages then the URL would be like
|
// This returns a string of favicons URL. If there is a PM counts in unread messages then the URL would be like
|
||||||
// https://chat.zulip.org/static/images/favicon/favicon-pms.png
|
// https://chat.zulip.org/static/images/favicon/favicon-pms.png
|
||||||
if (
|
if (
|
||||||
@@ -170,7 +170,6 @@ export default class WebView {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const webContents = this.getWebContents();
|
|
||||||
webContents.addListener("context-menu", (event, menuParameters) => {
|
webContents.addListener("context-menu", (event, menuParameters) => {
|
||||||
contextMenu(webContents, event, menuParameters);
|
contextMenu(webContents, event, menuParameters);
|
||||||
});
|
});
|
||||||
@@ -181,8 +180,7 @@ export default class WebView {
|
|||||||
this.show();
|
this.show();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.$el.addEventListener("did-fail-load", (event) => {
|
webContents.on("did-fail-load", (_event, _errorCode, errorDescription) => {
|
||||||
const {errorDescription} = event;
|
|
||||||
const hasConnectivityError =
|
const hasConnectivityError =
|
||||||
SystemUtil.connectivityERR.includes(errorDescription);
|
SystemUtil.connectivityERR.includes(errorDescription);
|
||||||
if (hasConnectivityError) {
|
if (hasConnectivityError) {
|
||||||
|
|||||||
Reference in New Issue
Block a user