From 6c17001e76d1f7448ed7e59f2768f28253bfa4c7 Mon Sep 17 00:00:00 2001 From: Devin Binnie <52460000+devinbinnie@users.noreply.github.com> Date: Fri, 31 Jan 2025 10:31:47 -0500 Subject: [PATCH] [MM-62581] Prevent URL view from ever taking focus by always returning focus to the current server view (#3303) --- src/main/views/viewManager.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/views/viewManager.ts b/src/main/views/viewManager.ts index d7bb9571..d6b539e8 100644 --- a/src/main/views/viewManager.ts +++ b/src/main/views/viewManager.ts @@ -362,6 +362,14 @@ export class ViewManager { const localURL = `mattermost-desktop://renderer/urlView.html?url=${encodeURIComponent(urlString)}`; performanceMonitor.registerView('URLView', urlView.webContents); urlView.webContents.loadURL(localURL); + + // This is a workaround for an issue where the URL view would steal focus from the main window + // See: https://github.com/electron/electron/issues/42339 + urlView.webContents.on('focus', () => { + log.debug('URL view focus prevented'); + this.getCurrentView()?.focus(); + }); + MainWindow.get()?.contentView.addChildView(urlView); const boundaries = this.views.get(this.currentView || '')?.getBounds() ?? MainWindow.getBounds();