trilium/src/public/javascripts/services/zoom.js

47 lines
1.2 KiB
JavaScript
Raw Normal View History

import options from "./options.js";
import Component from "../widgets/component.js";
2018-06-09 22:34:51 +08:00
const MIN_ZOOM = 0.5;
const MAX_ZOOM = 2.0;
export default class ZoomService extends Component {
2020-02-15 16:43:47 +08:00
constructor(appContext, parent) {
super(appContext, parent);
this.setZoomFactor(options.getFloat('zoomFactor'));
2018-06-09 22:34:51 +08:00
}
setZoomFactor(zoomFactor) {
zoomFactor = parseFloat(zoomFactor);
const webFrame = require('electron').webFrame;
webFrame.setZoomFactor(zoomFactor);
2018-06-09 22:34:51 +08: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() {
return require('electron').webFrame.getZoomFactor();
2018-06-09 22:34:51 +08:00
}
2020-02-17 02:23:49 +08:00
zoomOutEvent() {
this.setZoomFactorAndSave(this.getCurrentZoom() - 0.1);
}
2020-02-17 02:23:49 +08:00
zoomInEvent() {
this.setZoomFactorAndSave(this.getCurrentZoom() + 0.1);
}
2020-02-17 02:23:49 +08:00
setZoomFactorAndSaveEvent({zoomFactor}) {
this.setZoomFactorAndSave(zoomFactor);
}
}