Rocket.chat.electron: Stop grabbing focus and don't set position when app started.

Created on 31 Dec 2020  路  4Comments  路  Source: RocketChat/Rocket.Chat.Electron

My Setup

  • Operating System: Arch Linux
  • App Version: 3.1.1
  • Installation type: AUR

  • [X] I have tested with the latest version
  • [X] I can simulate the issue easily

Description

Every time Rocket Chat starts, it will grabbing focus and set itself to screen center, which is very annoying. Because I typically set it to some special position on screen, window manager will remember it and set it there next time, but now I have to set it every time manually because Rocket Chat set itself to screen center.

And it looks like it will pop up and grab focus on server loaded, but I may doing other thing and suddenly Rocket Chat pops up and grabs focus, which breaks my work. And if it failed to load the server, it will pop up some times because it is trying to reload.

Current Behavior

Starting in screen center, and poping up and grabbing while loading server.

Expected Behavior

When I was using an old version of Rocket Chat, those problems does not exist. It just allows window manager to put it and never grabs focus on loaded.

All 4 comments

Today my connection to server is not so good and I got near 10 times focus grabbing while I am typing in other programs just because Rocket.Chat's trying to re-connect...

It's very annoying :'( I cannot focus my working while rocket app auto focus randomly.

OK, finally, I find where the annoying problem exists, it took half day:

diff --git a/src/ui/main/serverView/index.ts b/src/ui/main/serverView/index.ts
index 5720c300d..51ee70c6d 100644
--- a/src/ui/main/serverView/index.ts
+++ b/src/ui/main/serverView/index.ts
@@ -93,7 +93,7 @@ const initializeServerWebContents = (serverUrl: string, guestWebContents: WebCon
   };

   const handleDomReady = (): void => {
-    guestWebContents.focus();
+    // guestWebContents.focus();
   };

   const handleDidNavigateInPage = (

Just prevent it grabbing focus when DOM is ready, this typically happens when the webpage refreshed.

It was added in a big commit https://github.com/RocketChat/Rocket.Chat.Electron/commit/00435e1930d7f032c58334877f3af1b0b47f74fa by @tassoevan , with a long message showing a lot of enhancement. I am not sure why he added this, it might be negligence when working with a lot of code.

I suggest to stop grabbing focus when page if refreshed, because when user puts rocketchat in background he/she may have other works to do, and don't want to be bothered with a page reloading. But it is better if the original writer of this line give some advise.

Anyway I will make a PR to comment out this line, it's toooooooooooooo annoying for me.

I found another fix for not remembering last position. This can be reproduced when the window's x or y position is 0.

for example I usually set rocket chat to left half of my monitor and then the x position is 0, and if I close rocket chat, re-launch it, it cannot use 0 as x position and then go to screen center.

Fix is like this:

diff --git a/src/ui/main/rootWindow.ts b/src/ui/main/rootWindow.ts
index 0f052cf91..ee623ed9b 100644
--- a/src/ui/main/rootWindow.ts
+++ b/src/ui/main/rootWindow.ts
@@ -102,7 +102,7 @@ export const applyRootWindowState = (browserWindow: BrowserWindow): void => {
     return;
   }

-  if (!x || !y) {
+  if (x == null || y == null) {
     browserWindow.setBounds({ width, height });
   } else {
     browserWindow.setBounds({ x, y, width, height });

I guess (!x || !y) here means that when x or y is undefined, don't set position, however in JavaScript !0 is also true. I am a JavaScript programmer instead of TypeScript programmer, so I am not sure how to determine x is undefined in TypeScript, but in JavaScript it should be x != null instead of !x.

I'll send another PR.

Was this page helpful?
0 / 5 - 0 ratings