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) { if (window.webContents) {
window.webContents.send('callbacks:call:setPassiveZoomFactor', [ window.webContents.send('callbacks:call:persistZoomFactor', [zoomFactor]);
zoomFactor,
]);
if (settingsWindow && settingsWindow.webContents) {
settingsWindow.webContents.send('render');
}
} }
lastZoomFactor = zoomFactor; lastZoomFactor = zoomFactor;

View File

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

View File

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

View File

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

View File

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

View File

@ -160,7 +160,7 @@ function getSystemTraySettingValues(
}; };
} }
window.renderPreferences = async () => { const renderPreferences = async () => {
if (!renderComponent) { if (!renderComponent) {
setTimeout(window.renderPreferences, 100); setTimeout(window.renderPreferences, 100);
return; return;
@ -373,7 +373,13 @@ window.renderPreferences = async () => {
onUniversalExpireTimerChange: reRender( onUniversalExpireTimerChange: reRender(
settingUniversalExpireTimer.setValue 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, i18n: window.i18n,
}; };
@ -381,11 +387,14 @@ window.renderPreferences = async () => {
function reRender<Value>(f: (value: Value) => Promise<Value>) { function reRender<Value>(f: (value: Value) => Promise<Value>) {
return async (value: Value) => { return async (value: Value) => {
await f(value); await f(value);
window.renderPreferences(); renderPreferences();
}; };
} }
renderComponent(Preferences, props); renderComponent(Preferences, props);
}; };
window.renderPreferences = renderPreferences;
initializeLogging(); initializeLogging();
ipcRenderer.on('render', () => renderPreferences());