Make zoom level persistent on Desktop

- uses local storage.
- for 'web', the browser is already handling that.
This commit is contained in:
infiinte-persistence 2021-01-26 13:17:42 +08:00 committed by Sean Yesmunt
parent 5573374aa9
commit 912489cce0
4 changed files with 22 additions and 4 deletions

View file

@ -24,3 +24,4 @@ export const DARK_MODE_TIMES = 'dark_mode_times';
export const ENABLE_SYNC = 'enable_sync'; export const ENABLE_SYNC = 'enable_sync';
export const TO_TRAY_WHEN_CLOSED = 'to_tray_when_closed'; export const TO_TRAY_WHEN_CLOSED = 'to_tray_when_closed';
export const ENABLE_PUBLISH_PREVIEW = 'enable-publish-preview'; export const ENABLE_PUBLISH_PREVIEW = 'enable-publish-preview';
export const DESKTOP_WINDOW_ZOOM = 'desktop_window_zoom';

View file

@ -44,4 +44,8 @@ export default function useHover(ref) {
window.addEventListener('wheel', handleWheel); window.addEventListener('wheel', handleWheel);
return () => window.removeEventListener('wheel', handleWheel); return () => window.removeEventListener('wheel', handleWheel);
}, []); }, []);
useEffect(() => {
changeZoomFactor(ZOOM.LOAD_FROM_LOCAL_STORAGE);
}, []);
} }

View file

@ -49,6 +49,7 @@ const defaultState = {
[SETTINGS.TILE_LAYOUT]: true, [SETTINGS.TILE_LAYOUT]: true,
[SETTINGS.VIDEO_THEATER_MODE]: false, [SETTINGS.VIDEO_THEATER_MODE]: false,
[SETTINGS.VIDEO_PLAYBACK_RATE]: 1, [SETTINGS.VIDEO_PLAYBACK_RATE]: 1,
[SETTINGS.DESKTOP_WINDOW_ZOOM]: 1,
[SETTINGS.DARK_MODE_TIMES]: { [SETTINGS.DARK_MODE_TIMES]: {
from: { hour: '21', min: '00', formattedTime: '21:00' }, from: { hour: '21', min: '00', formattedTime: '21:00' },

View file

@ -1,10 +1,12 @@
import { webFrame } from 'electron'; import { webFrame } from 'electron';
import { SETTINGS } from 'lbry-redux';
const isDev = process.env.NODE_ENV !== 'production'; const isDev = process.env.NODE_ENV !== 'production';
export const ZOOM = { export const ZOOM = {
INCREMENT: 'INCREMENT', INCREMENT: 'INCREMENT',
DECREMENT: 'DECREMENT', DECREMENT: 'DECREMENT',
RESET: 'RESET', RESET: 'RESET',
LOAD_FROM_LOCAL_STORAGE: 'LOAD_FROM_LOCAL_STORAGE',
}; };
function getNextZoomFactor(curFactor, isIncreasing) { function getNextZoomFactor(curFactor, isIncreasing) {
@ -24,19 +26,29 @@ function getNextZoomFactor(curFactor, isIncreasing) {
export function changeZoomFactor(action) { export function changeZoomFactor(action) {
const ZOOM_DFLT_FACTOR = 1.0; const ZOOM_DFLT_FACTOR = 1.0;
const curFactor = webFrame.getZoomFactor(); const curFactor = webFrame.getZoomFactor();
let newFactor = null;
switch (action) { switch (action) {
case ZOOM.INCREMENT: case ZOOM.INCREMENT:
webFrame.setZoomFactor(getNextZoomFactor(curFactor, true)); newFactor = getNextZoomFactor(curFactor, true);
break; break;
case ZOOM.DECREMENT: case ZOOM.DECREMENT:
webFrame.setZoomFactor(getNextZoomFactor(curFactor, false)); newFactor = getNextZoomFactor(curFactor, false);
break; break;
case ZOOM.RESET: case ZOOM.RESET:
webFrame.setZoomFactor(ZOOM_DFLT_FACTOR); newFactor = ZOOM_DFLT_FACTOR;
break;
case ZOOM.LOAD_FROM_LOCAL_STORAGE:
newFactor = parseFloat(window.localStorage.getItem(SETTINGS.DESKTOP_WINDOW_ZOOM));
if (isNaN(newFactor)) {
newFactor = ZOOM_DFLT_FACTOR;
}
break; break;
default: default:
if (isDev) throw new Error('changeZoomFactor: unexpected action'); if (isDev) throw new Error('changeZoomFactor: unexpected action');
break; return;
} }
webFrame.setZoomFactor(newFactor);
window.localStorage.setItem(SETTINGS.DESKTOP_WINDOW_ZOOM, newFactor);
} }