Fix changing zoom factor with keyboard shortcut in Settings
This commit is contained in:
parent
ca45a9cf74
commit
6c24d5be74
2 changed files with 33 additions and 10 deletions
35
app/main.ts
35
app/main.ts
|
@ -532,7 +532,7 @@ function handleCommonWindowEvents(
|
||||||
const focusInterval = setInterval(setWindowFocus, 10000);
|
const focusInterval = setInterval(setWindowFocus, 10000);
|
||||||
window.on('closed', () => clearInterval(focusInterval));
|
window.on('closed', () => clearInterval(focusInterval));
|
||||||
|
|
||||||
// Works only for mainWindow because it has `enablePreferredSizeMode`
|
// Works only for mainWindow and settings because they have `enablePreferredSizeMode`
|
||||||
let lastZoomFactor = window.webContents.getZoomFactor();
|
let lastZoomFactor = window.webContents.getZoomFactor();
|
||||||
const onZoomChanged = () => {
|
const onZoomChanged = () => {
|
||||||
if (
|
if (
|
||||||
|
@ -548,15 +548,33 @@ function handleCommonWindowEvents(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
drop(
|
|
||||||
settingsChannel?.invokeCallbackInMainWindow('persistZoomFactor', [
|
|
||||||
zoomFactor,
|
|
||||||
])
|
|
||||||
);
|
|
||||||
|
|
||||||
lastZoomFactor = zoomFactor;
|
lastZoomFactor = zoomFactor;
|
||||||
|
if (!mainWindow) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (window === mainWindow) {
|
||||||
|
drop(
|
||||||
|
settingsChannel?.invokeCallbackInMainWindow('persistZoomFactor', [
|
||||||
|
zoomFactor,
|
||||||
|
])
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
mainWindow.webContents.setZoomFactor(zoomFactor);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
window.webContents.on('preferred-size-changed', onZoomChanged);
|
window.once('ready-to-show', async () => {
|
||||||
|
// Workaround to apply zoomFactor because webPreferences does not handle it correctly
|
||||||
|
// https://github.com/electron/electron/issues/10572
|
||||||
|
const zoomFactor =
|
||||||
|
(await settingsChannel?.getSettingFromMainWindow('zoomFactor')) ?? 1;
|
||||||
|
window.webContents.setZoomFactor(zoomFactor);
|
||||||
|
});
|
||||||
|
window.on('show', () => {
|
||||||
|
// Install handler here after we init zoomFactor otherwise an initial
|
||||||
|
// preferred-size-changed event emits with an undesired zoomFactor.
|
||||||
|
window.webContents.on('preferred-size-changed', onZoomChanged);
|
||||||
|
});
|
||||||
|
|
||||||
nativeThemeNotifier.addWindow(window);
|
nativeThemeNotifier.addWindow(window);
|
||||||
|
|
||||||
|
@ -1323,6 +1341,7 @@ async function showSettingsWindow() {
|
||||||
contextIsolation: true,
|
contextIsolation: true,
|
||||||
preload: join(__dirname, '../bundles/settings/preload.js'),
|
preload: join(__dirname, '../bundles/settings/preload.js'),
|
||||||
nativeWindowOpen: true,
|
nativeWindowOpen: true,
|
||||||
|
enablePreferredSizeMode: true,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Copyright 2021 Signal Messenger, LLC
|
// Copyright 2021 Signal Messenger, LLC
|
||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
import { contextBridge, ipcRenderer } from 'electron';
|
import { contextBridge, ipcRenderer, webFrame } from 'electron';
|
||||||
import { MinimalSignalContext } from '../minimalContext';
|
import { MinimalSignalContext } from '../minimalContext';
|
||||||
|
|
||||||
import type { PropsPreloadType } from '../../components/Preferences';
|
import type { PropsPreloadType } from '../../components/Preferences';
|
||||||
|
@ -418,7 +418,11 @@ async function renderPreferences() {
|
||||||
// 2. Trigger `preferred-size-changed` in the main process
|
// 2. Trigger `preferred-size-changed` in the main process
|
||||||
// 3. Finally result in `window.storage` update which will cause the
|
// 3. Finally result in `window.storage` update which will cause the
|
||||||
// rerender.
|
// rerender.
|
||||||
onZoomFactorChange: settingZoomFactor.setValue,
|
onZoomFactorChange: (value: number) => {
|
||||||
|
// Update Settings window zoom factor to match the selected value.
|
||||||
|
webFrame.setZoomFactor(value);
|
||||||
|
return settingZoomFactor.setValue(value);
|
||||||
|
},
|
||||||
|
|
||||||
hasCustomTitleBar: MinimalSignalContext.OS.hasCustomTitleBar(),
|
hasCustomTitleBar: MinimalSignalContext.OS.hasCustomTitleBar(),
|
||||||
executeMenuRole: MinimalSignalContext.executeMenuRole,
|
executeMenuRole: MinimalSignalContext.executeMenuRole,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue