mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
47 lines
1.2 KiB
JavaScript
47 lines
1.2 KiB
JavaScript
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(parent) {
|
|
super(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);
|
|
}
|
|
} |