persisting zoom setting in electron, fixes #112

This commit is contained in:
azivner 2018-06-02 13:02:20 -04:00
parent 083cccea28
commit 0f8f707acd
8 changed files with 67 additions and 27 deletions

View file

@ -0,0 +1,2 @@
INSERT INTO options (optionId, name, value, dateCreated, dateModified, isSynced)
VALUES ('zoomFactor_key', 'zoomFactor', '1.0', '2018-06-01T03:35:55.041Z', '2018-06-01T03:35:55.041Z', 0);

View file

@ -2,6 +2,7 @@ import utils from "./utils.js";
import treeService from "./tree.js";
import linkService from "./link.js";
import fileService from "./file.js";
import zoomService from "./zoom.js";
import noteRevisionsDialog from "../dialogs/note_revisions.js";
import optionsDialog from "../dialogs/options.js";
import addLinkDialog from "../dialogs/add_link.js";
@ -109,27 +110,10 @@ function registerEntrypoints() {
$("#note-detail-text").focus();
});
$(document).bind('keydown', 'ctrl+-', () => {
if (utils.isElectron()) {
const webFrame = require('electron').webFrame;
if (webFrame.getZoomFactor() > 0.2) {
webFrame.setZoomFactor(webFrame.getZoomFactor() - 0.1);
}
return false;
}
});
$(document).bind('keydown', 'ctrl+=', () => {
if (utils.isElectron()) {
const webFrame = require('electron').webFrame;
webFrame.setZoomFactor(webFrame.getZoomFactor() + 0.1);
return false;
}
});
if (utils.isElectron()) {
$(document).bind('keydown', 'ctrl+-', zoomService.decreaseZoomFactor);
$(document).bind('keydown', 'ctrl+=', zoomService.increaseZoomFactor);
}
$("#note-title").bind('keydown', 'return', () => $("#note-detail-text").focus());

View file

@ -0,0 +1,9 @@
import server from "./server.js";
const optionsReady = new Promise((resolve, reject) => {
$(document).ready(() => server.get('options').then(resolve));
});
export default {
optionsReady
}

View file

@ -1,13 +1,11 @@
import utils from "./utils.js";
import server from "./server.js";
import optionsInitService from './options_init.js';
let lastProtectedSessionOperationDate = null;
let protectedSessionTimeout = null;
let protectedSessionId = null;
$(document).ready(() => {
server.get('options').then(options => protectedSessionTimeout = options.protectedSessionTimeout);
});
optionsInitService.optionsReady.then(options => protectedSessionTimeout = options.protectedSessionTimeout);
setInterval(() => {
if (lastProtectedSessionOperationDate !== null && new Date().getTime() - lastProtectedSessionOperationDate.getTime() > protectedSessionTimeout * 1000) {

View file

@ -0,0 +1,42 @@
import server from "./server.js";
import utils from "./utils.js";
import optionsInitService from "./options_init.js";
function decreaseZoomFactor() {
const webFrame = require('electron').webFrame;
if (webFrame.getZoomFactor() > 0.2) {
const webFrame = require('electron').webFrame;
const newZoomFactor = webFrame.getZoomFactor() - 0.1;
webFrame.setZoomFactor(newZoomFactor);
server.put('options/zoomFactor/' + newZoomFactor);
}
}
function increaseZoomFactor() {
const webFrame = require('electron').webFrame;
const newZoomFactor = webFrame.getZoomFactor() + 0.1;
webFrame.setZoomFactor(newZoomFactor);
server.put('options/zoomFactor/' + newZoomFactor);
}
function setZoomFactor(zoomFactor) {
zoomFactor = parseFloat(zoomFactor);
const webFrame = require('electron').webFrame;
webFrame.setZoomFactor(zoomFactor);
}
if (utils.isElectron()) {
optionsInitService.optionsReady.then(options => setZoomFactor(options.zoomFactor))
}
export default {
decreaseZoomFactor,
increaseZoomFactor,
setZoomFactor
}

View file

@ -2,9 +2,10 @@
const sql = require('../../services/sql');
const optionService = require('../../services/options');
const log = require('../../services/log');
// options allowed to be updated directly in options dialog
const ALLOWED_OPTIONS = ['protectedSessionTimeout', 'noteRevisionSnapshotTimeInterval'];
const ALLOWED_OPTIONS = ['protectedSessionTimeout', 'noteRevisionSnapshotTimeInterval', 'zoomFactor'];
async function getOptions() {
const options = await sql.getMap("SELECT name, value FROM options WHERE name IN ("
@ -20,6 +21,8 @@ async function updateOption(req) {
return [400, "not allowed option to set"];
}
log.info(`Updating option ${name} to ${value}`);
await optionService.setOption(name, value);
}

View file

@ -3,7 +3,7 @@
const build = require('./build');
const packageJson = require('../../package');
const APP_DB_VERSION = 96;
const APP_DB_VERSION = 97;
module.exports = {
appVersion: packageJson.version,

View file

@ -53,6 +53,8 @@ async function initOptions(startNotePath) {
await createOption('lastSyncedPull', appInfo.dbVersion, false);
await createOption('lastSyncedPush', 0, false);
await createOption('zoomFactor', 1.0, false);
}
module.exports = {