From aff742828649eb2d06f368833a9892cc8216ef0d Mon Sep 17 00:00:00 2001 From: Manoj Vivek Date: Fri, 24 Feb 2023 15:27:47 +0530 Subject: [PATCH] Zoom level persisted across restarts --- .../src/renderer/store/features/renderer/index.ts | 10 +++++++--- desktop-app/src/store/index.ts | 10 ++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/desktop-app/src/renderer/store/features/renderer/index.ts b/desktop-app/src/renderer/store/features/renderer/index.ts index 43cbee7e..b05884fe 100644 --- a/desktop-app/src/renderer/store/features/renderer/index.ts +++ b/desktop-app/src/renderer/store/features/renderer/index.ts @@ -17,7 +17,7 @@ const zoomSteps = [ const initialState: RendererState = { address: window.electron.store.get('homepage'), - zoomFactor: zoomSteps[3], + zoomFactor: zoomSteps[window.electron.store.get('renderer.zoomStepIndex')], rotate: false, isInspecting: undefined, layout: window.electron.store.get('ui.previewLayout'), @@ -35,13 +35,17 @@ export const rendererSlice = createSlice({ zoomIn: (state) => { const index = zoomSteps.indexOf(state.zoomFactor); if (index < zoomSteps.length - 1) { - state.zoomFactor = zoomSteps[index + 1]; + const newIndex = index + 1; + state.zoomFactor = zoomSteps[newIndex]; + window.electron.store.set('renderer.zoomStepIndex', newIndex); } }, zoomOut: (state) => { const index = zoomSteps.indexOf(state.zoomFactor); if (index > 0) { - state.zoomFactor = zoomSteps[index - 1]; + const newIndex = index - 1; + state.zoomFactor = zoomSteps[newIndex]; + window.electron.store.set('renderer.zoomStepIndex', newIndex); } }, setRotate: (state, action: PayloadAction) => { diff --git a/desktop-app/src/store/index.ts b/desktop-app/src/store/index.ts index 57f4e99a..184ad0cd 100644 --- a/desktop-app/src/store/index.ts +++ b/desktop-app/src/store/index.ts @@ -16,6 +16,16 @@ const schema = { }, }, }, + renderer: { + type: 'object', + properties: { + zoomStepIndex: { + type: 'number', + default: 3, + }, + }, + default: {}, + }, devtools: { type: 'object', properties: {