mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
persisting zoom setting in electron, fixes #112
This commit is contained in:
parent
083cccea28
commit
0f8f707acd
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 treeService from "./tree.js";
|
||||||
import linkService from "./link.js";
|
import linkService from "./link.js";
|
||||||
import fileService from "./file.js";
|
import fileService from "./file.js";
|
||||||
|
import zoomService from "./zoom.js";
|
||||||
import noteRevisionsDialog from "../dialogs/note_revisions.js";
|
import noteRevisionsDialog from "../dialogs/note_revisions.js";
|
||||||
import optionsDialog from "../dialogs/options.js";
|
import optionsDialog from "../dialogs/options.js";
|
||||||
import addLinkDialog from "../dialogs/add_link.js";
|
import addLinkDialog from "../dialogs/add_link.js";
|
||||||
@ -109,27 +110,10 @@ function registerEntrypoints() {
|
|||||||
$("#note-detail-text").focus();
|
$("#note-detail-text").focus();
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).bind('keydown', 'ctrl+-', () => {
|
if (utils.isElectron()) {
|
||||||
if (utils.isElectron()) {
|
$(document).bind('keydown', 'ctrl+-', zoomService.decreaseZoomFactor);
|
||||||
const webFrame = require('electron').webFrame;
|
$(document).bind('keydown', 'ctrl+=', zoomService.increaseZoomFactor);
|
||||||
|
}
|
||||||
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;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#note-title").bind('keydown', 'return', () => $("#note-detail-text").focus());
|
$("#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 utils from "./utils.js";
|
||||||
import server from "./server.js";
|
import optionsInitService from './options_init.js';
|
||||||
|
|
||||||
let lastProtectedSessionOperationDate = null;
|
let lastProtectedSessionOperationDate = null;
|
||||||
let protectedSessionTimeout = null;
|
let protectedSessionTimeout = null;
|
||||||
let protectedSessionId = null;
|
let protectedSessionId = null;
|
||||||
|
|
||||||
$(document).ready(() => {
|
optionsInitService.optionsReady.then(options => protectedSessionTimeout = options.protectedSessionTimeout);
|
||||||
server.get('options').then(options => protectedSessionTimeout = options.protectedSessionTimeout);
|
|
||||||
});
|
|
||||||
|
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
if (lastProtectedSessionOperationDate !== null && new Date().getTime() - lastProtectedSessionOperationDate.getTime() > protectedSessionTimeout * 1000) {
|
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 sql = require('../../services/sql');
|
||||||
const optionService = require('../../services/options');
|
const optionService = require('../../services/options');
|
||||||
|
const log = require('../../services/log');
|
||||||
|
|
||||||
// options allowed to be updated directly in options dialog
|
// options allowed to be updated directly in options dialog
|
||||||
const ALLOWED_OPTIONS = ['protectedSessionTimeout', 'noteRevisionSnapshotTimeInterval'];
|
const ALLOWED_OPTIONS = ['protectedSessionTimeout', 'noteRevisionSnapshotTimeInterval', 'zoomFactor'];
|
||||||
|
|
||||||
async function getOptions() {
|
async function getOptions() {
|
||||||
const options = await sql.getMap("SELECT name, value FROM options WHERE name IN ("
|
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"];
|
return [400, "not allowed option to set"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.info(`Updating option ${name} to ${value}`);
|
||||||
|
|
||||||
await optionService.setOption(name, value);
|
await optionService.setOption(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
const build = require('./build');
|
const build = require('./build');
|
||||||
const packageJson = require('../../package');
|
const packageJson = require('../../package');
|
||||||
|
|
||||||
const APP_DB_VERSION = 96;
|
const APP_DB_VERSION = 97;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
appVersion: packageJson.version,
|
appVersion: packageJson.version,
|
||||||
|
@ -53,6 +53,8 @@ async function initOptions(startNotePath) {
|
|||||||
|
|
||||||
await createOption('lastSyncedPull', appInfo.dbVersion, false);
|
await createOption('lastSyncedPull', appInfo.dbVersion, false);
|
||||||
await createOption('lastSyncedPush', 0, false);
|
await createOption('lastSyncedPush', 0, false);
|
||||||
|
|
||||||
|
await createOption('zoomFactor', 1.0, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user