2018-06-03 01:02:20 +08:00
|
|
|
import server from "./server.js";
|
|
|
|
import utils from "./utils.js";
|
2019-08-25 23:36:13 +08:00
|
|
|
import optionsService from "./options.js";
|
2018-06-03 01:02:20 +08:00
|
|
|
|
2018-06-09 22:34:51 +08:00
|
|
|
const MIN_ZOOM = 0.5;
|
|
|
|
const MAX_ZOOM = 2.0;
|
2018-06-03 01:02:20 +08:00
|
|
|
|
2018-06-09 22:34:51 +08:00
|
|
|
async function decreaseZoomFactor() {
|
|
|
|
await setZoomFactorAndSave(getCurrentZoom() - 0.1);
|
2018-06-03 01:02:20 +08:00
|
|
|
}
|
|
|
|
|
2018-06-09 22:34:51 +08:00
|
|
|
async function increaseZoomFactor() {
|
|
|
|
await setZoomFactorAndSave(getCurrentZoom() + 0.1);
|
2018-06-03 01:02:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function setZoomFactor(zoomFactor) {
|
|
|
|
zoomFactor = parseFloat(zoomFactor);
|
|
|
|
|
|
|
|
const webFrame = require('electron').webFrame;
|
|
|
|
webFrame.setZoomFactor(zoomFactor);
|
|
|
|
}
|
|
|
|
|
2018-06-09 11:18:53 +08:00
|
|
|
async function setZoomFactorAndSave(zoomFactor) {
|
2018-06-09 22:34:51 +08:00
|
|
|
if (!utils.isElectron()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (zoomFactor >= MIN_ZOOM && zoomFactor <= MAX_ZOOM) {
|
|
|
|
setZoomFactor(zoomFactor);
|
|
|
|
|
|
|
|
await server.put('options/zoomFactor/' + zoomFactor);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
console.log(`Zoom factor ${zoomFactor} outside of the range, ignored.`);
|
|
|
|
}
|
|
|
|
}
|
2018-06-09 11:18:53 +08:00
|
|
|
|
2018-06-09 22:34:51 +08:00
|
|
|
function getCurrentZoom() {
|
|
|
|
return require('electron').webFrame.getZoomFactor();
|
2018-06-09 11:18:53 +08:00
|
|
|
}
|
|
|
|
|
2018-06-03 01:02:20 +08:00
|
|
|
if (utils.isElectron()) {
|
2019-08-25 23:36:13 +08:00
|
|
|
optionsService.addLoadListener(options => setZoomFactor(options.getFloat('zoomFactor')))
|
2018-06-03 01:02:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
decreaseZoomFactor,
|
|
|
|
increaseZoomFactor,
|
2018-06-09 11:18:53 +08:00
|
|
|
setZoomFactor,
|
|
|
|
setZoomFactorAndSave
|
2018-06-03 01:02:20 +08:00
|
|
|
}
|