Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
renamed "messagingService" to "ws"
zadam36c87b7fa014
diff --git a/src/public/javascripts/desktop.js b/src/public/javascripts/desktop.jsindex f17740ca91..02fd9a7ba5 100644--- a/src/public/javascripts/desktop.js+++ b/src/public/javascripts/desktop.js@@ -2,7 +2,7 @@ import cloning from './services/cloning.js';import contextMenu from './services/tree_context_menu.js';import dragAndDropSetup from './services/drag_and_drop.js';import link from './services/link.js';-import messagingService from './services/messaging.js';+import ws from './services/ws.js';import noteDetailService from './services/note_detail.js';import noteType from './services/note_type.js';import protectedSessionService from './services/protected_session.js';@@ -71,7 +71,7 @@ window.onerror = function (msg, url, lineNo, columnNo, error) {].join(' - ');}- messagingService.logError(message);+ ws.logError(message);return false;};diff --git a/src/public/javascripts/dialogs/export.js b/src/public/javascripts/dialogs/export.jsindex 749614dfdd..65929e3fe9 100644--- a/src/public/javascripts/dialogs/export.js+++ b/src/public/javascripts/dialogs/export.js@@ -1,6 +1,6 @@import treeUtils from "../services/tree_utils.js";import utils from "../services/utils.js";-import messagingService from "../services/messaging.js";+import ws from "../services/ws.js";import infoService from "../services/info.js";const $dialog = $("#export-dialog");@@ -112,7 +112,7 @@ $('input[name=export-subtree-format]').change(function () {}});-messagingService.subscribeToMessages(async message => {+ws.subscribeToMessages(async message => {if (message.type === 'export-error') {infoService.showError(message.message);$dialog.modal('hide');diff --git a/src/public/javascripts/dialogs/import.js b/src/public/javascripts/dialogs/import.jsindex 47e39821ae..d7d6edd4a9 100644--- a/src/public/javascripts/dialogs/import.js+++ b/src/public/javascripts/dialogs/import.js@@ -3,7 +3,7 @@ import utils from '../services/utils.js';import treeUtils from "../services/tree_utils.js";import server from "../services/server.js";import infoService from "../services/info.js";-import messagingService from "../services/messaging.js";+import ws from "../services/ws.js";const $dialog = $("#import-dialog");const $form = $("#import-form");@@ -117,7 +117,7 @@ function boolToString($el) {return $el.is(":checked") ? "true" : "false";}-messagingService.subscribeToMessages(async message => {+ws.subscribeToMessages(async message => {if (message.type === 'import-error') {infoService.showError(message.message);$dialog.modal('hide');diff --git a/src/public/javascripts/services/attributes.js b/src/public/javascripts/services/attributes.jsindex 3bbd947f6a..5a62e60f9e 100644--- a/src/public/javascripts/services/attributes.js+++ b/src/public/javascripts/services/attributes.js@@ -1,6 +1,6 @@import server from "./server.js";import utils from "./utils.js";-import messagingService from "./messaging.js";+import ws from "./ws.js";import treeUtils from "./tree_utils.js";import noteAutocompleteService from "./note_autocomplete.js";import linkService from "./link.js";@@ -179,7 +179,7 @@ class Attributes {.append($openButton));}else {- messagingService.logError("Unknown labelType=" + definitionAttr.labelType);+ ws.logError("Unknown labelType=" + definitionAttr.labelType);}}else if (valueAttr.type === 'relation') {@@ -197,7 +197,7 @@ class Attributes {$input.setSelectedPath(valueAttr.value);}else {- messagingService.logError("Unknown attribute type=" + valueAttr.type);+ ws.logError("Unknown attribute type=" + valueAttr.type);return;}diff --git a/src/public/javascripts/services/info.js b/src/public/javascripts/services/info.jsindex c3eb76f8fd..2df8ed6008 100644--- a/src/public/javascripts/services/info.js+++ b/src/public/javascripts/services/info.js@@ -1,4 +1,4 @@-import messagingService from "./messaging.js";+import ws from "./ws.js";import utils from "./utils.js";function showMessage(message) {@@ -13,7 +13,7 @@ function showMessage(message) {function showAndLogError(message, delay = 10000) {showError(message, delay);- messagingService.logError(message);+ ws.logError(message);}function showError(message, delay = 10000) {@@ -44,7 +44,7 @@ function getNotifySettings(type, delay) {}function throwError(message) {- messagingService.logError(message);+ ws.logError(message);throw new Error(message);}diff --git a/src/public/javascripts/services/note_detail.js b/src/public/javascripts/services/note_detail.jsindex f374fbc35a..c53d7446ae 100644--- a/src/public/javascripts/services/note_detail.js+++ b/src/public/javascripts/services/note_detail.js@@ -1,7 +1,7 @@import treeService from './tree.js';import TabContext from './tab_context.js';import server from './server.js';-import messagingService from "./messaging.js";+import ws from "./ws.js";import treeCache from "./tree_cache.js";import NoteFull from "../entities/note_full.js";import bundleService from "./bundle.js";@@ -353,7 +353,7 @@ function fireDetailLoaded() {detailLoadedListeners = [];}-messagingService.subscribeToOutsideSyncMessages(syncData => {+ws.subscribeToOutsideSyncMessages(syncData => {const noteIdsToRefresh = new Set();syncData@@ -370,7 +370,7 @@ messagingService.subscribeToOutsideSyncMessages(syncData => {}});-messagingService.subscribeToAllSyncMessages(syncData => {+ws.subscribeToAllSyncMessages(syncData => {for (const tc of tabContexts) {tc.syncDataReceived(syncData);}diff --git a/src/public/javascripts/services/sidebar.js b/src/public/javascripts/services/sidebar.jsindex 4a8b8dbe7a..17155b5f45 100644--- a/src/public/javascripts/services/sidebar.js+++ b/src/public/javascripts/services/sidebar.js@@ -1,5 +1,5 @@import bundleService from "./bundle.js";-import messagingService from "./messaging.js";+import ws from "./ws.js";import optionsService from "./options.js";class Sidebar {@@ -83,7 +83,7 @@ class Sidebar {}}catch (e) {- messagingService.logError(`Error while creating widget ${widgetClass.name}: ${e.message}`);+ ws.logError(`Error while creating widget ${widgetClass.name}: ${e.message}`);}}@@ -95,7 +95,7 @@ class Sidebar {this.$widgetContainer.append($el);}catch (e) {- messagingService.logError(`Error while loading widget ${widget.widgetName}: ${e.message}`);+ ws.logError(`Error while loading widget ${widget.widgetName}: ${e.message}`);}}}diff --git a/src/public/javascripts/services/tree.js b/src/public/javascripts/services/tree.jsindex ae721f867e..5ffd5241d8 100644--- a/src/public/javascripts/services/tree.js+++ b/src/public/javascripts/services/tree.js@@ -1,6 +1,6 @@import contextMenuWidget from './context_menu.js';import dragAndDropSetup from './drag_and_drop.js';-import messagingService from './messaging.js';+import ws from './ws.js';import noteDetailService from './note_detail.js';import protectedSessionHolder from './protected_session_holder.js';import treeUtils from './tree_utils.js';@@ -126,7 +126,7 @@ async function getNodeFromPath(notePath, expand = false, expandOpts = {}) {foundChildNode = findChildNode(parentNode, childNoteId);if (!foundChildNode) {- messagingService.logError(`Can't find node for child node of noteId=${childNoteId} for parent of noteId=${parentNode.data.noteId} and hoistedNoteId=${hoistedNoteId}, requested path is ${notePath}`);+ ws.logError(`Can't find node for child node of noteId=${childNoteId} for parent of noteId=${parentNode.data.noteId} and hoistedNoteId=${hoistedNoteId}, requested path is ${notePath}`);return;}}@@ -233,7 +233,7 @@ async function getRunPath(notePath) {const parents = await child.getParentNotes();if (!parents) {- messagingService.logError("No parents found for " + childNoteId);+ ws.logError("No parents found for " + childNoteId);return;}@@ -258,7 +258,7 @@ async function getRunPath(notePath) {break;}else {- messagingService.logError("No parents, can't activate node.");+ ws.logError("No parents, can't activate node.");return;}}@@ -738,7 +738,7 @@ async function showTree() {initFancyTree(tree);}-messagingService.subscribeToMessages(message => {+ws.subscribeToMessages(message => {if (message.type === 'refresh-tree') {reload();}@@ -753,7 +753,7 @@ messagingService.subscribeToMessages(message => {}});-messagingService.subscribeToOutsideSyncMessages(syncData => {+ws.subscribeToOutsideSyncMessages(syncData => {if (syncData.some(sync => sync.entityName === 'branches')|| syncData.some(sync => sync.entityName === 'notes')) {diff --git a/src/public/javascripts/services/tree_builder.js b/src/public/javascripts/services/tree_builder.jsindex 16a1c47087..2f8c8ef244 100644--- a/src/public/javascripts/services/tree_builder.js+++ b/src/public/javascripts/services/tree_builder.js@@ -3,7 +3,7 @@ import utils from "./utils.js";import Branch from "../entities/branch.js";import server from "./server.js";import treeCache from "./tree_cache.js";-import messagingService from "./messaging.js";+import ws from "./ws.js";import hoistedNoteService from "./hoisted_note.js";async function prepareTree() {@@ -100,7 +100,7 @@ async function prepareRealBranch(parentNote) {const childBranches = await parentNote.getChildBranches();if (!childBranches) {- messagingService.logError(`No children for ${parentNote}. This shouldn't happen.`);+ ws.logError(`No children for ${parentNote}. This shouldn't happen.`);return;}diff --git a/src/public/javascripts/services/tree_cache.js b/src/public/javascripts/services/tree_cache.jsindex 33497180e8..a3fdf203c4 100644--- a/src/public/javascripts/services/tree_cache.js+++ b/src/public/javascripts/services/tree_cache.js@@ -2,7 +2,7 @@ import utils from "./utils.js";import Branch from "../entities/branch.js";import NoteShort from "../entities/note_short.js";import infoService from "./info.js";-import messagingService from "./messaging.js";+import ws from "./ws.js";import server from "./server.js";/**@@ -107,7 +107,7 @@ class TreeCache {return noteIds.map(noteId => {if (!this.notes[noteId] && !silentNotFoundError) {- messagingService.logError(`Can't find note "${noteId}"`);+ ws.logError(`Can't find note "${noteId}"`);return null;}diff --git a/src/public/javascripts/services/tree_context_menu.js b/src/public/javascripts/services/tree_context_menu.jsindex b407f476a7..aa636882bd 100644--- a/src/public/javascripts/services/tree_context_menu.js+++ b/src/public/javascripts/services/tree_context_menu.js@@ -1,5 +1,5 @@import treeService from './tree.js';-import messagingService from './messaging.js';+import ws from './ws.js';import protectedSessionService from './protected_session.js';import treeChangesService from './branches.js';import treeUtils from './tree_utils.js';@@ -153,7 +153,7 @@ class TreeContextMenu {hoistedNoteService.unhoist();}else {- messagingService.logError("Unknown command: " + cmd);+ ws.logError("Unknown command: " + cmd);}}}diff --git a/src/public/javascripts/services/messaging.js b/src/public/javascripts/services/ws.jssimilarity index 100%rename from src/public/javascripts/services/messaging.jsrename to src/public/javascripts/services/ws.jsdiff --git a/src/public/javascripts/widgets/attributes.js b/src/public/javascripts/widgets/attributes.jsindex eda7c1db36..3f800b19ae 100644--- a/src/public/javascripts/widgets/attributes.js+++ b/src/public/javascripts/widgets/attributes.js@@ -1,6 +1,6 @@import utils from "../services/utils.js";import linkService from "../services/link.js";-import messagingService from "../services/messaging.js";+import ws from "../services/ws.js";import StandardWidget from "./standard_widget.js";class AttributesWidget extends StandardWidget {@@ -71,12 +71,12 @@ class AttributesWidget extends StandardWidget {$container.append(await linkService.createNoteLink(attribute.value));$container.append(" ");} else {- messagingService.logError(`Relation ${attribute.attributeId} has empty target`);+ ws.logError(`Relation ${attribute.attributeId} has empty target`);}} else if (attribute.type === 'label-definition' || attribute.type === 'relation-definition') {$container.append(attribute.name + " definition ");} else {- messagingService.logError("Unknown attr type: " + attribute.type);+ ws.logError("Unknown attr type: " + attribute.type);}}}diff --git a/src/routes/api/clipper.js b/src/routes/api/clipper.jsindex 4a3904c2c6..5be97ea455 100644--- a/src/routes/api/clipper.js+++ b/src/routes/api/clipper.js@@ -5,7 +5,7 @@ const dateNoteService = require('../../services/date_notes');const dateUtils = require('../../services/date_utils');const imageService = require('../../services/image');const appInfo = require('../../services/app_info');-const messagingService = require('../../services/messaging');+const ws = require('../../services/ws.js');const log = require('../../services/log');const utils = require('../../services/utils');const path = require('path');@@ -102,7 +102,7 @@ async function addImagesToNote(images, note, content) {async function openNote(req) {if (utils.isElectron()) {- messagingService.sendMessageToAllClients({+ ws.sendMessageToAllClients({type: 'open-note',noteId: req.params.noteId});diff --git a/src/routes/api/export.js b/src/routes/api/export.jsindex 59d6a20d3c..4117800c14 100644--- a/src/routes/api/export.js+++ b/src/routes/api/export.js@@ -4,7 +4,7 @@ const tarExportService = require('../../services/export/tar');const singleExportService = require('../../services/export/single');const opmlExportService = require('../../services/export/opml');const repository = require("../../services/repository");-const messagingService = require("../../services/messaging");+const ws = require("../../services/ws.js");const log = require("../../services/log");class ExportContext {@@ -23,7 +23,7 @@ class ExportContext {if (Date.now() - this.lastSentCountTs >= 500) {this.lastSentCountTs = Date.now();- await messagingService.sendMessageToAllClients({+ await ws.sendMessageToAllClients({exportId: this.exportId,type: 'export-progress-count',progressCount: this.progressCount@@ -32,7 +32,7 @@ class ExportContext {}async exportFinished() {- await messagingService.sendMessageToAllClients({+ await ws.sendMessageToAllClients({exportId: this.exportId,type: 'export-finished'});@@ -40,7 +40,7 @@ class ExportContext {// must remaing non-staticasync reportError(message) {- await messagingService.sendMessageToAllClients({+ await ws.sendMessageToAllClients({type: 'export-error',message: message});diff --git a/src/services/backend_script_api.js b/src/services/backend_script_api.jsindex 9de17d977d..377b58d4da 100644--- a/src/services/backend_script_api.js+++ b/src/services/backend_script_api.js@@ -10,7 +10,7 @@ const repository = require('./repository');const axios = require('axios');const dayjs = require('dayjs');const cloningService = require('./cloning');-const messagingService = require('./messaging');+const ws = require('./ws.js');const appInfo = require('./app_info');const searchService = require('./search');@@ -211,7 +211,7 @@ function BackendScriptApi(currentNote, apiParams) {this.createNoteAndRefresh = async function(parentNoteId, title, content, extraOptions) {await noteService.createNote(parentNoteId, title, content, extraOptions);- messagingService.refreshTree();+ ws.refreshTree();};/**@@ -307,7 +307,7 @@ function BackendScriptApi(currentNote, apiParams) {** @returns {Promise<void>}*/- this.refreshTree = messagingService.refreshTree;+ this.refreshTree = ws.refreshTree;/*** @return {{syncVersion, appVersion, buildRevision, dbVersion, dataDirectory, buildDate}|*} - object representing basic info about running Trilium versiondiff --git a/src/services/consistency_checks.js b/src/services/consistency_checks.jsindex cd8b6a8f9e..ed2e558154 100644--- a/src/services/consistency_checks.js+++ b/src/services/consistency_checks.js@@ -3,7 +3,7 @@const sql = require('./sql');const sqlInit = require('./sql_init');const log = require('./log');-const messagingService = require('./messaging');+const ws = require('./ws.js');const syncMutexService = require('./sync_mutex');const repository = require('./repository');const cls = require('./cls');@@ -381,13 +381,13 @@ async function runChecks() {});if (fixedIssues) {- messagingService.refreshTree();+ ws.refreshTree();}if (unrecoverableConsistencyErrors) {log.info(`Consistency checks failed (took ${elapsedTimeMs}ms)`);- messagingService.sendMessageToAllClients({type: 'consistency-checks-failed'});+ ws.sendMessageToAllClients({type: 'consistency-checks-failed'});}else {log.info(`All consistency checks passed (took ${elapsedTimeMs}ms)`);diff --git a/src/services/content_hash.js b/src/services/content_hash.jsindex c893228178..e1ffc29ce3 100644--- a/src/services/content_hash.js+++ b/src/services/content_hash.js@@ -4,7 +4,7 @@ const sql = require('./sql');const utils = require('./utils');const log = require('./log');const eventLogService = require('./event_log');-const messagingService = require('./messaging');+const ws = require('./ws.js');const ApiToken = require('../entities/api_token');const Branch = require('../entities/branch');const Note = require('../entities/note');@@ -60,7 +60,7 @@ async function checkContentHashes(otherHashes) {if (key !== 'recent_notes') {// let's not get alarmed about recent notes which get updated often and can cause failures in race conditions- await messagingService.sendMessageToAllClients({type: 'sync-hash-check-failed'});+ await ws.sendMessageToAllClients({type: 'sync-hash-check-failed'});}}}diff --git a/src/services/import_context.js b/src/services/import_context.jsindex 5d2935ddd9..ea29f5c752 100644--- a/src/services/import_context.js+++ b/src/services/import_context.js@@ -1,6 +1,6 @@"use strict";-const messagingService = require('./messaging');+const ws = require('./ws.js');// importId => ImportContextconst importContexts = {};@@ -36,7 +36,7 @@ class ImportContext {if (Date.now() - this.lastSentCountTs >= 500) {this.lastSentCountTs = Date.now();- await messagingService.sendMessageToAllClients({+ await ws.sendMessageToAllClients({importId: this.importId,type: 'import-progress-count',progressCount: this.progressCount@@ -46,7 +46,7 @@ class ImportContext {// must remaing non-staticasync reportError(message) {- await messagingService.sendMessageToAllClients({+ await ws.sendMessageToAllClients({type: 'import-error',message: message});diff --git a/src/services/messaging.js b/src/services/ws.jssimilarity index 100%rename from src/services/messaging.jsrename to src/services/ws.jsdiff --git a/src/www b/src/wwwindex d775fce358..26375f40af 100755--- a/src/www+++ b/src/www@@ -21,7 +21,7 @@ const https = require('https');const config = require('./services/config');const log = require('./services/log');const appInfo = require('./services/app_info');-const messagingService = require('./services/messaging');+const ws = require('./services/ws.js');const utils = require('./services/utils');const sqlInit = require('./services/sql_init');const port = require('./services/port');@@ -77,7 +77,7 @@ async function startTrilium() {httpServer.on('error', onError);httpServer.on('listening', () => debug('Listening on port' + httpServer.address().port));- sqlInit.dbReady.then(() => messagingService.init(httpServer, sessionParser));+ sqlInit.dbReady.then(() => ws.init(httpServer, sessionParser));if (utils.isElectron()) {const electronRouting = require('./routes/electron');