Skip to content

Commit

Permalink
Reorder IPC callbacks for settings window
Browse files Browse the repository at this point in the history
Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com>
  • Loading branch information
automated-signal and indutny-signal committed Sep 7, 2021
1 parent 30000ed commit b059eac
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 15 deletions.
7 changes: 1 addition & 6 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions ts/shims/dispatchItemsMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' ||
Expand All @@ -20,6 +21,5 @@ export const dispatchItemsMiddleware: Middleware = ({
) {
ipcRenderer.send('preferences-changed', getState().items);
}

return next(action);
return result;
};
4 changes: 2 additions & 2 deletions ts/util/createIPCEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down Expand Up @@ -507,7 +507,7 @@ export function createIPCEvents(
getMediaPermissions: window.getMediaPermissions,
getMediaCameraPermissions: window.getMediaCameraPermissions,

setPassiveZoomFactor: zoomFactor =>
persistZoomFactor: zoomFactor =>
window.storage.put('zoomFactor', zoomFactor),

...overrideEvents,
Expand Down
2 changes: 1 addition & 1 deletion ts/util/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
Expand Down
2 changes: 1 addition & 1 deletion ts/windows/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
15 changes: 12 additions & 3 deletions ts/windows/settings/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function getSystemTraySettingValues(
};
}

window.renderPreferences = async () => {
const renderPreferences = async () => {
if (!renderComponent) {
setTimeout(window.renderPreferences, 100);
return;
Expand Down Expand Up @@ -373,19 +373,28 @@ 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,
};

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());

0 comments on commit b059eac

Please sign in to comment.