55 lines
1.3 KiB
JavaScript
Raw Normal View History

import options from "./options.js";
import Component from "../widgets/component.js";
2020-04-12 14:22:51 +02:00
import utils from "../services/utils.js";
2018-06-09 10:34:51 -04:00
const MIN_ZOOM = 0.5;
const MAX_ZOOM = 2.0;
class ZoomService extends Component {
2020-02-27 10:03:14 +01:00
constructor() {
super();
options.initializedPromise.then(() => {
this.setZoomFactor(options.getFloat('zoomFactor'));
});
2018-06-09 10:34:51 -04:00
}
setZoomFactor(zoomFactor) {
zoomFactor = parseFloat(zoomFactor);
2020-04-12 14:22:51 +02:00
const webFrame = utils.dynamicRequire('electron').webFrame;
webFrame.setZoomFactor(zoomFactor);
2018-06-09 10:34:51 -04:00
}
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() {
2020-04-12 14:22:51 +02:00
return utils.dynamicRequire('electron').webFrame.getZoomFactor();
2018-06-09 10:34:51 -04:00
}
2020-02-16 19:23:49 +01:00
zoomOutEvent() {
this.setZoomFactorAndSave(this.getCurrentZoom() - 0.1);
}
2020-02-16 19:23:49 +01:00
zoomInEvent() {
this.setZoomFactorAndSave(this.getCurrentZoom() + 0.1);
}
2020-02-16 19:23:49 +01:00
setZoomFactorAndSaveEvent({zoomFactor}) {
this.setZoomFactorAndSave(zoomFactor);
}
}
const zoomService = new ZoomService();
export default zoomService;