From bb8b563ecec8e4d0dd1327de3e1a115a326008ea Mon Sep 17 00:00:00 2001 From: zadam Date: Sat, 28 Dec 2019 12:55:53 +0100 Subject: [PATCH] relaunch app after successful sync --- .../javascripts/services/frontend_script_api.js | 10 ++++++++-- src/public/javascripts/setup.js | 11 +++++++---- src/services/auth.js | 2 +- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/public/javascripts/services/frontend_script_api.js b/src/public/javascripts/services/frontend_script_api.js index d17ad38d3..06bc5e839 100644 --- a/src/public/javascripts/services/frontend_script_api.js +++ b/src/public/javascripts/services/frontend_script_api.js @@ -125,14 +125,14 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, tabConte } /** - * Executes given anonymous function on the server. + * Executes given anonymous function on the backend. * Internally this serializes the anonymous function into string and sends it to backend via AJAX. * * @param {string} script - script to be executed on the backend * @param {Array.} params - list of parameters to the anonymous function to be send to backend * @return {Promise<*>} return value of the executed function on the backend */ - this.runOnServer = async (script, params = []) => { + this.runOnBackend = async (script, params = []) => { if (typeof script === "function") { script = script.toString(); } @@ -159,6 +159,12 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, tabConte } }; + /** + * @deprecated new name of this API call is runOnBackend so use that + * @method + */ + this.runOnServer = this.runOnBackend; + /** * This is a powerful search method - you can search by attributes and their values, e.g.: * "@dateModified =* MONTH AND @log". See full documentation for all options at: https://github.com/zadam/trilium/wiki/Search diff --git a/src/public/javascripts/setup.js b/src/public/javascripts/setup.js index 4511679b1..65542cc47 100644 --- a/src/public/javascripts/setup.js +++ b/src/public/javascripts/setup.js @@ -131,12 +131,15 @@ async function checkOutstandingSyncs() { const { stats, initialized } = await $.get('api/sync/stats'); if (initialized) { - window.location.replace("./"); + const remote = require('electron').remote; + remote.app.relaunch(); + remote.app.exit(0); } + else { + const totalOutstandingSyncs = stats.outstandingPushes + stats.outstandingPulls; - const totalOutstandingSyncs = stats.outstandingPushes + stats.outstandingPulls; - - $("#outstanding-syncs").html(totalOutstandingSyncs); + $("#outstanding-syncs").html(totalOutstandingSyncs); + } } function showAlert(message) { diff --git a/src/services/auth.js b/src/services/auth.js index bb19b9ca1..f1192fa5f 100644 --- a/src/services/auth.js +++ b/src/services/auth.js @@ -83,7 +83,7 @@ async function checkBasicAuth(req, res, next) { const dbUsername = await optionService.getOption('username'); if (dbUsername !== username || !await passwordEncryptionService.verifyPassword(password)) { - res.status(401).send("Not authorized"); + res.status(401).send('Incorrect username and/or password'); } else { next();