Skip to content

Commit

Permalink
Merge pull request #1859 from holium/RE-294-system-cursor-bug
Browse files Browse the repository at this point in the history
Fix "Disable system cursor" not immediately applied to webviews bug
  • Loading branch information
gdbroman authored Jul 3, 2023
2 parents 9e9d63f + 734309b commit ff9a967
Showing 1 changed file with 14 additions and 24 deletions.
38 changes: 14 additions & 24 deletions app/src/main/helpers/cursorSettings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BrowserWindow, ipcMain } from 'electron';
import { BrowserWindow, ipcMain, webContents } from 'electron';
import Store from 'electron-store';

import { isMac, isWindows } from './env';
Expand Down Expand Up @@ -179,32 +179,22 @@ const showSystemCursor = (webContents: Electron.WebContents) => {
webContents.insertCSS(showSystemCursorCss);
};

const enableRealmCursor = (
mainWindow: BrowserWindow,
mouseOverlayWindow: BrowserWindow
) => {
if (isMac) {
hideSystemCursor(mouseOverlayWindow.webContents);
hideSystemCursor(mainWindow.webContents);
} else if (isWindows) {
hideSystemCursor(mouseOverlayWindow.webContents);
hideSystemCursor(mainWindow.webContents);
}
};
const enableRealmCursor = () => {
// Get all windows and potentially nested webviews.
const webviews = webContents.getAllWebContents();

export const disableRealmCursor = (
mainWindow: BrowserWindow,
mouseOverlayWindow: BrowserWindow
) => {
if (mainWindow.isDestroyed()) return;
webviews.forEach(hideSystemCursor);
};

export const disableRealmCursor = (mouseOverlayWindow: BrowserWindow) => {
const isStandaloneChat = store.get('isStandaloneChat');

// In Realm you can toggle the cursor in settings,
// but in standalone we don't need to override the `cursor: none` since it's never applied.
if (!isStandaloneChat) {
showSystemCursor(mouseOverlayWindow.webContents);
showSystemCursor(mainWindow.webContents);
// Get all windows and potentially nested webviews.
const webviews = webContents.getAllWebContents();
webviews.forEach(showSystemCursor);
}

mouseOverlayWindow.webContents.send('disable-realm-cursor');
Expand Down Expand Up @@ -237,9 +227,9 @@ const registerListeners = (
if (mainWindow.isDestroyed()) return;

if (realmCursorEnabled) {
enableRealmCursor(mainWindow, mouseOverlayWindow);
enableRealmCursor();
} else {
disableRealmCursor(mainWindow, mouseOverlayWindow);
disableRealmCursor(mouseOverlayWindow);
}
});

Expand All @@ -251,7 +241,7 @@ const registerListeners = (
const enabled = setRealmCursor(true);
if (!enabled) return;

enableRealmCursor(mainWindow, mouseOverlayWindow);
enableRealmCursor();

if (reloadMouseWindow) {
mouseOverlayWindow.reload();
Expand All @@ -261,7 +251,7 @@ const registerListeners = (
ipcMain.handle('disable-realm-cursor', (_, reloadMouseWindow?: boolean) => {
setRealmCursor(false);

disableRealmCursor(mainWindow, mouseOverlayWindow);
disableRealmCursor(mouseOverlayWindow);

if (reloadMouseWindow) {
mouseOverlayWindow.reload();
Expand Down

0 comments on commit ff9a967

Please sign in to comment.