import options from "./options.js"; import Component from "../widgets/component.js"; const MIN_ZOOM = 0.5; const MAX_ZOOM = 2.0; export default class ZoomService extends Component { constructor(appContext, parent) { super(appContext, parent); this.setZoomFactor(options.getFloat('zoomFactor')); } setZoomFactor(zoomFactor) { zoomFactor = parseFloat(zoomFactor); const webFrame = require('electron').webFrame; webFrame.setZoomFactor(zoomFactor); } async setZoomFactorAndSave(zoomFactor) { if (zoomFactor >= MIN_ZOOM && zoomFactor <= MAX_ZOOM) { this.setZoomFactor(zoomFactor); await options.save('zoomFactor', zoomFactor); } else { console.log(`Zoom factor ${zoomFactor} outside of the range, ignored.`); } } getCurrentZoom() { return require('electron').webFrame.getZoomFactor(); } zoomOutEvent() { this.setZoomFactorAndSave(this.getCurrentZoom() - 0.1); } zoomInEvent() { this.setZoomFactorAndSave(this.getCurrentZoom() + 0.1); } setZoomFactorAndSaveEvent({zoomFactor}) { this.setZoomFactorAndSave(zoomFactor); } }