Reorder IPC callbacks for settings window

This commit is contained in:
Fedor Indutny 2021-09-07 12:42:17 -07:00 committed by GitHub
parent 5c7972893c
commit 4bed918cf8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 19 additions and 15 deletions

View File

@ -319,12 +319,7 @@ function handleCommonWindowEvents(window) {
}
if (window.webContents) {
window.webContents.send('callbacks:call:setPassiveZoomFactor', [
zoomFactor,
]);
if (settingsWindow && settingsWindow.webContents) {
settingsWindow.webContents.send('render');
}
window.webContents.send('callbacks:call:persistZoomFactor', [zoomFactor]);
}
lastZoomFactor = zoomFactor;

View File

@ -9,6 +9,7 @@ import { COLORS_CHANGED, COLOR_SELECTED } from '../state/ducks/conversations';
export const dispatchItemsMiddleware: Middleware = ({
getState,
}) => next => action => {
const result = next(action);
if (
action.type === 'items/PUT' ||
action.type === 'items/PUT_EXTERNAL' ||
@ -20,6 +21,5 @@ export const dispatchItemsMiddleware: Middleware = ({
) {
ipcRenderer.send('preferences-changed', getState().items);
}
return next(action);
return result;
};

View File

@ -107,7 +107,7 @@ export type IPCEventsCallbacksType = {
customColor?: { id: string; value: CustomColorType }
) => void;
getDefaultConversationColor: () => DefaultConversationColorType;
setPassiveZoomFactor: (factor: number) => Promise<void>;
persistZoomFactor: (factor: number) => Promise<void>;
};
type ValuesWithGetters = Omit<
@ -507,7 +507,7 @@ export function createIPCEvents(
getMediaPermissions: window.getMediaPermissions,
getMediaCameraPermissions: window.getMediaCameraPermissions,
setPassiveZoomFactor: zoomFactor =>
persistZoomFactor: zoomFactor =>
window.storage.put('zoomFactor', zoomFactor),
...overrideEvents,

View File

@ -181,7 +181,7 @@ export function installCallback<Name extends keyof IPCEventsCallbacksType>(
);
} catch (error) {
ipcRenderer.send(
`callbacks:call-success;${name}`,
`callbacks:call-success:${name}`,
error && error.stack ? error.stack : error
);
}

View File

@ -16,7 +16,7 @@ installCallback('resetAllChatColors');
installCallback('resetDefaultChatColor');
installCallback('setGlobalDefaultConversationColor');
installCallback('getDefaultConversationColor');
installCallback('setPassiveZoomFactor');
installCallback('persistZoomFactor');
// Getters only. These are set by the primary device
installSetting('blockedCount', {

View File

@ -160,7 +160,7 @@ function getSystemTraySettingValues(
};
}
window.renderPreferences = async () => {
const renderPreferences = async () => {
if (!renderComponent) {
setTimeout(window.renderPreferences, 100);
return;
@ -373,7 +373,13 @@ window.renderPreferences = async () => {
onUniversalExpireTimerChange: reRender(
settingUniversalExpireTimer.setValue
),
onZoomFactorChange: reRender(settingZoomFactor.setValue),
// Zoom factor change doesn't require immediate rerender since it will:
// 1. Update the zoom factor in the main window
// 2. Trigger `preferred-size-changed` in the main process
// 3. Finally result in `window.storage` update which will cause the
// rerender.
onZoomFactorChange: settingZoomFactor.setValue,
i18n: window.i18n,
};
@ -381,11 +387,14 @@ window.renderPreferences = async () => {
function reRender<Value>(f: (value: Value) => Promise<Value>) {
return async (value: Value) => {
await f(value);
window.renderPreferences();
renderPreferences();
};
}
renderComponent(Preferences, props);
};
window.renderPreferences = renderPreferences;
initializeLogging();
ipcRenderer.on('render', () => renderPreferences());