mirror of
https://github.com/zadam/trilium.git
synced 2025-01-29 02:18:18 +08:00
persisting zoom setting in electron, fixes #112
This commit is contained in:
parent
083cccea28
commit
0f8f707acd
8 changed files with 67 additions and 27 deletions
2
db/migrations/0097__add_zoomFactor.sql
Normal file
2
db/migrations/0097__add_zoomFactor.sql
Normal 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);
|
|
@ -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());
|
||||
|
||||
|
|
9
src/public/javascripts/services/options_init.js
Normal file
9
src/public/javascripts/services/options_init.js
Normal 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
|
||||
}
|
|
@ -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) {
|
||||
|
|
42
src/public/javascripts/services/zoom.js
Normal file
42
src/public/javascripts/services/zoom.js
Normal 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
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 = {
|
||||
|
|
Loading…
Reference in a new issue