renamed "messagingService" to "ws"

This commit is contained in:
zadam 2019-08-26 20:21:43 +02:00
parent d039a5f24e
commit 36c87b7fa0
21 changed files with 52 additions and 52 deletions

View File

@ -2,7 +2,7 @@ import cloning from './services/cloning.js';
import contextMenu from './services/tree_context_menu.js'; import contextMenu from './services/tree_context_menu.js';
import dragAndDropSetup from './services/drag_and_drop.js'; import dragAndDropSetup from './services/drag_and_drop.js';
import link from './services/link.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 noteDetailService from './services/note_detail.js';
import noteType from './services/note_type.js'; import noteType from './services/note_type.js';
import protectedSessionService from './services/protected_session.js'; import protectedSessionService from './services/protected_session.js';
@ -71,7 +71,7 @@ window.onerror = function (msg, url, lineNo, columnNo, error) {
].join(' - '); ].join(' - ');
} }
messagingService.logError(message); ws.logError(message);
return false; return false;
}; };

View File

@ -1,6 +1,6 @@
import treeUtils from "../services/tree_utils.js"; import treeUtils from "../services/tree_utils.js";
import utils from "../services/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"; import infoService from "../services/info.js";
const $dialog = $("#export-dialog"); 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') { if (message.type === 'export-error') {
infoService.showError(message.message); infoService.showError(message.message);
$dialog.modal('hide'); $dialog.modal('hide');

View File

@ -3,7 +3,7 @@ import utils from '../services/utils.js';
import treeUtils from "../services/tree_utils.js"; import treeUtils from "../services/tree_utils.js";
import server from "../services/server.js"; import server from "../services/server.js";
import infoService from "../services/info.js"; import infoService from "../services/info.js";
import messagingService from "../services/messaging.js"; import ws from "../services/ws.js";
const $dialog = $("#import-dialog"); const $dialog = $("#import-dialog");
const $form = $("#import-form"); const $form = $("#import-form");
@ -117,7 +117,7 @@ function boolToString($el) {
return $el.is(":checked") ? "true" : "false"; return $el.is(":checked") ? "true" : "false";
} }
messagingService.subscribeToMessages(async message => { ws.subscribeToMessages(async message => {
if (message.type === 'import-error') { if (message.type === 'import-error') {
infoService.showError(message.message); infoService.showError(message.message);
$dialog.modal('hide'); $dialog.modal('hide');

View File

@ -1,6 +1,6 @@
import server from "./server.js"; import server from "./server.js";
import utils from "./utils.js"; import utils from "./utils.js";
import messagingService from "./messaging.js"; import ws from "./ws.js";
import treeUtils from "./tree_utils.js"; import treeUtils from "./tree_utils.js";
import noteAutocompleteService from "./note_autocomplete.js"; import noteAutocompleteService from "./note_autocomplete.js";
import linkService from "./link.js"; import linkService from "./link.js";
@ -179,7 +179,7 @@ class Attributes {
.append($openButton)); .append($openButton));
} }
else { else {
messagingService.logError("Unknown labelType=" + definitionAttr.labelType); ws.logError("Unknown labelType=" + definitionAttr.labelType);
} }
} }
else if (valueAttr.type === 'relation') { else if (valueAttr.type === 'relation') {
@ -197,7 +197,7 @@ class Attributes {
$input.setSelectedPath(valueAttr.value); $input.setSelectedPath(valueAttr.value);
} }
else { else {
messagingService.logError("Unknown attribute type=" + valueAttr.type); ws.logError("Unknown attribute type=" + valueAttr.type);
return; return;
} }

View File

@ -1,4 +1,4 @@
import messagingService from "./messaging.js"; import ws from "./ws.js";
import utils from "./utils.js"; import utils from "./utils.js";
function showMessage(message) { function showMessage(message) {
@ -13,7 +13,7 @@ function showMessage(message) {
function showAndLogError(message, delay = 10000) { function showAndLogError(message, delay = 10000) {
showError(message, delay); showError(message, delay);
messagingService.logError(message); ws.logError(message);
} }
function showError(message, delay = 10000) { function showError(message, delay = 10000) {
@ -44,7 +44,7 @@ function getNotifySettings(type, delay) {
} }
function throwError(message) { function throwError(message) {
messagingService.logError(message); ws.logError(message);
throw new Error(message); throw new Error(message);
} }

View File

@ -1,7 +1,7 @@
import treeService from './tree.js'; import treeService from './tree.js';
import TabContext from './tab_context.js'; import TabContext from './tab_context.js';
import server from './server.js'; import server from './server.js';
import messagingService from "./messaging.js"; import ws from "./ws.js";
import treeCache from "./tree_cache.js"; import treeCache from "./tree_cache.js";
import NoteFull from "../entities/note_full.js"; import NoteFull from "../entities/note_full.js";
import bundleService from "./bundle.js"; import bundleService from "./bundle.js";
@ -353,7 +353,7 @@ function fireDetailLoaded() {
detailLoadedListeners = []; detailLoadedListeners = [];
} }
messagingService.subscribeToOutsideSyncMessages(syncData => { ws.subscribeToOutsideSyncMessages(syncData => {
const noteIdsToRefresh = new Set(); const noteIdsToRefresh = new Set();
syncData syncData
@ -370,7 +370,7 @@ messagingService.subscribeToOutsideSyncMessages(syncData => {
} }
}); });
messagingService.subscribeToAllSyncMessages(syncData => { ws.subscribeToAllSyncMessages(syncData => {
for (const tc of tabContexts) { for (const tc of tabContexts) {
tc.syncDataReceived(syncData); tc.syncDataReceived(syncData);
} }

View File

@ -1,5 +1,5 @@
import bundleService from "./bundle.js"; import bundleService from "./bundle.js";
import messagingService from "./messaging.js"; import ws from "./ws.js";
import optionsService from "./options.js"; import optionsService from "./options.js";
class Sidebar { class Sidebar {
@ -83,7 +83,7 @@ class Sidebar {
} }
} }
catch (e) { 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); this.$widgetContainer.append($el);
} }
catch (e) { catch (e) {
messagingService.logError(`Error while loading widget ${widget.widgetName}: ${e.message}`); ws.logError(`Error while loading widget ${widget.widgetName}: ${e.message}`);
} }
} }
} }

View File

@ -1,6 +1,6 @@
import contextMenuWidget from './context_menu.js'; import contextMenuWidget from './context_menu.js';
import dragAndDropSetup from './drag_and_drop.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 noteDetailService from './note_detail.js';
import protectedSessionHolder from './protected_session_holder.js'; import protectedSessionHolder from './protected_session_holder.js';
import treeUtils from './tree_utils.js'; import treeUtils from './tree_utils.js';
@ -126,7 +126,7 @@ async function getNodeFromPath(notePath, expand = false, expandOpts = {}) {
foundChildNode = findChildNode(parentNode, childNoteId); foundChildNode = findChildNode(parentNode, childNoteId);
if (!foundChildNode) { 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; return;
} }
} }
@ -233,7 +233,7 @@ async function getRunPath(notePath) {
const parents = await child.getParentNotes(); const parents = await child.getParentNotes();
if (!parents) { if (!parents) {
messagingService.logError("No parents found for " + childNoteId); ws.logError("No parents found for " + childNoteId);
return; return;
} }
@ -258,7 +258,7 @@ async function getRunPath(notePath) {
break; break;
} }
else { else {
messagingService.logError("No parents, can't activate node."); ws.logError("No parents, can't activate node.");
return; return;
} }
} }
@ -738,7 +738,7 @@ async function showTree() {
initFancyTree(tree); initFancyTree(tree);
} }
messagingService.subscribeToMessages(message => { ws.subscribeToMessages(message => {
if (message.type === 'refresh-tree') { if (message.type === 'refresh-tree') {
reload(); reload();
} }
@ -753,7 +753,7 @@ messagingService.subscribeToMessages(message => {
} }
}); });
messagingService.subscribeToOutsideSyncMessages(syncData => { ws.subscribeToOutsideSyncMessages(syncData => {
if (syncData.some(sync => sync.entityName === 'branches') if (syncData.some(sync => sync.entityName === 'branches')
|| syncData.some(sync => sync.entityName === 'notes')) { || syncData.some(sync => sync.entityName === 'notes')) {

View File

@ -3,7 +3,7 @@ import utils from "./utils.js";
import Branch from "../entities/branch.js"; import Branch from "../entities/branch.js";
import server from "./server.js"; import server from "./server.js";
import treeCache from "./tree_cache.js"; import treeCache from "./tree_cache.js";
import messagingService from "./messaging.js"; import ws from "./ws.js";
import hoistedNoteService from "./hoisted_note.js"; import hoistedNoteService from "./hoisted_note.js";
async function prepareTree() { async function prepareTree() {
@ -100,7 +100,7 @@ async function prepareRealBranch(parentNote) {
const childBranches = await parentNote.getChildBranches(); const childBranches = await parentNote.getChildBranches();
if (!childBranches) { if (!childBranches) {
messagingService.logError(`No children for ${parentNote}. This shouldn't happen.`); ws.logError(`No children for ${parentNote}. This shouldn't happen.`);
return; return;
} }

View File

@ -2,7 +2,7 @@ import utils from "./utils.js";
import Branch from "../entities/branch.js"; import Branch from "../entities/branch.js";
import NoteShort from "../entities/note_short.js"; import NoteShort from "../entities/note_short.js";
import infoService from "./info.js"; import infoService from "./info.js";
import messagingService from "./messaging.js"; import ws from "./ws.js";
import server from "./server.js"; import server from "./server.js";
/** /**
@ -107,7 +107,7 @@ class TreeCache {
return noteIds.map(noteId => { return noteIds.map(noteId => {
if (!this.notes[noteId] && !silentNotFoundError) { if (!this.notes[noteId] && !silentNotFoundError) {
messagingService.logError(`Can't find note "${noteId}"`); ws.logError(`Can't find note "${noteId}"`);
return null; return null;
} }

View File

@ -1,5 +1,5 @@
import treeService from './tree.js'; import treeService from './tree.js';
import messagingService from './messaging.js'; import ws from './ws.js';
import protectedSessionService from './protected_session.js'; import protectedSessionService from './protected_session.js';
import treeChangesService from './branches.js'; import treeChangesService from './branches.js';
import treeUtils from './tree_utils.js'; import treeUtils from './tree_utils.js';
@ -153,7 +153,7 @@ class TreeContextMenu {
hoistedNoteService.unhoist(); hoistedNoteService.unhoist();
} }
else { else {
messagingService.logError("Unknown command: " + cmd); ws.logError("Unknown command: " + cmd);
} }
} }
} }

View File

@ -1,6 +1,6 @@
import utils from "../services/utils.js"; import utils from "../services/utils.js";
import linkService from "../services/link.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"; import StandardWidget from "./standard_widget.js";
class AttributesWidget extends StandardWidget { class AttributesWidget extends StandardWidget {
@ -71,12 +71,12 @@ class AttributesWidget extends StandardWidget {
$container.append(await linkService.createNoteLink(attribute.value)); $container.append(await linkService.createNoteLink(attribute.value));
$container.append(" "); $container.append(" ");
} else { } 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') { } else if (attribute.type === 'label-definition' || attribute.type === 'relation-definition') {
$container.append(attribute.name + " definition "); $container.append(attribute.name + " definition ");
} else { } else {
messagingService.logError("Unknown attr type: " + attribute.type); ws.logError("Unknown attr type: " + attribute.type);
} }
} }
} }

View File

@ -5,7 +5,7 @@ const dateNoteService = require('../../services/date_notes');
const dateUtils = require('../../services/date_utils'); const dateUtils = require('../../services/date_utils');
const imageService = require('../../services/image'); const imageService = require('../../services/image');
const appInfo = require('../../services/app_info'); const appInfo = require('../../services/app_info');
const messagingService = require('../../services/messaging'); const ws = require('../../services/ws.js');
const log = require('../../services/log'); const log = require('../../services/log');
const utils = require('../../services/utils'); const utils = require('../../services/utils');
const path = require('path'); const path = require('path');
@ -102,7 +102,7 @@ async function addImagesToNote(images, note, content) {
async function openNote(req) { async function openNote(req) {
if (utils.isElectron()) { if (utils.isElectron()) {
messagingService.sendMessageToAllClients({ ws.sendMessageToAllClients({
type: 'open-note', type: 'open-note',
noteId: req.params.noteId noteId: req.params.noteId
}); });

View File

@ -4,7 +4,7 @@ const tarExportService = require('../../services/export/tar');
const singleExportService = require('../../services/export/single'); const singleExportService = require('../../services/export/single');
const opmlExportService = require('../../services/export/opml'); const opmlExportService = require('../../services/export/opml');
const repository = require("../../services/repository"); const repository = require("../../services/repository");
const messagingService = require("../../services/messaging"); const ws = require("../../services/ws.js");
const log = require("../../services/log"); const log = require("../../services/log");
class ExportContext { class ExportContext {
@ -23,7 +23,7 @@ class ExportContext {
if (Date.now() - this.lastSentCountTs >= 500) { if (Date.now() - this.lastSentCountTs >= 500) {
this.lastSentCountTs = Date.now(); this.lastSentCountTs = Date.now();
await messagingService.sendMessageToAllClients({ await ws.sendMessageToAllClients({
exportId: this.exportId, exportId: this.exportId,
type: 'export-progress-count', type: 'export-progress-count',
progressCount: this.progressCount progressCount: this.progressCount
@ -32,7 +32,7 @@ class ExportContext {
} }
async exportFinished() { async exportFinished() {
await messagingService.sendMessageToAllClients({ await ws.sendMessageToAllClients({
exportId: this.exportId, exportId: this.exportId,
type: 'export-finished' type: 'export-finished'
}); });
@ -40,7 +40,7 @@ class ExportContext {
// must remaing non-static // must remaing non-static
async reportError(message) { async reportError(message) {
await messagingService.sendMessageToAllClients({ await ws.sendMessageToAllClients({
type: 'export-error', type: 'export-error',
message: message message: message
}); });

View File

@ -10,7 +10,7 @@ const repository = require('./repository');
const axios = require('axios'); const axios = require('axios');
const dayjs = require('dayjs'); const dayjs = require('dayjs');
const cloningService = require('./cloning'); const cloningService = require('./cloning');
const messagingService = require('./messaging'); const ws = require('./ws.js');
const appInfo = require('./app_info'); const appInfo = require('./app_info');
const searchService = require('./search'); const searchService = require('./search');
@ -211,7 +211,7 @@ function BackendScriptApi(currentNote, apiParams) {
this.createNoteAndRefresh = async function(parentNoteId, title, content, extraOptions) { this.createNoteAndRefresh = async function(parentNoteId, title, content, extraOptions) {
await noteService.createNote(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>} * @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 version * @return {{syncVersion, appVersion, buildRevision, dbVersion, dataDirectory, buildDate}|*} - object representing basic info about running Trilium version

View File

@ -3,7 +3,7 @@
const sql = require('./sql'); const sql = require('./sql');
const sqlInit = require('./sql_init'); const sqlInit = require('./sql_init');
const log = require('./log'); const log = require('./log');
const messagingService = require('./messaging'); const ws = require('./ws.js');
const syncMutexService = require('./sync_mutex'); const syncMutexService = require('./sync_mutex');
const repository = require('./repository'); const repository = require('./repository');
const cls = require('./cls'); const cls = require('./cls');
@ -381,13 +381,13 @@ async function runChecks() {
}); });
if (fixedIssues) { if (fixedIssues) {
messagingService.refreshTree(); ws.refreshTree();
} }
if (unrecoverableConsistencyErrors) { if (unrecoverableConsistencyErrors) {
log.info(`Consistency checks failed (took ${elapsedTimeMs}ms)`); log.info(`Consistency checks failed (took ${elapsedTimeMs}ms)`);
messagingService.sendMessageToAllClients({type: 'consistency-checks-failed'}); ws.sendMessageToAllClients({type: 'consistency-checks-failed'});
} }
else { else {
log.info(`All consistency checks passed (took ${elapsedTimeMs}ms)`); log.info(`All consistency checks passed (took ${elapsedTimeMs}ms)`);

View File

@ -4,7 +4,7 @@ const sql = require('./sql');
const utils = require('./utils'); const utils = require('./utils');
const log = require('./log'); const log = require('./log');
const eventLogService = require('./event_log'); const eventLogService = require('./event_log');
const messagingService = require('./messaging'); const ws = require('./ws.js');
const ApiToken = require('../entities/api_token'); const ApiToken = require('../entities/api_token');
const Branch = require('../entities/branch'); const Branch = require('../entities/branch');
const Note = require('../entities/note'); const Note = require('../entities/note');
@ -60,7 +60,7 @@ async function checkContentHashes(otherHashes) {
if (key !== 'recent_notes') { if (key !== 'recent_notes') {
// let's not get alarmed about recent notes which get updated often and can cause failures in race conditions // 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'});
} }
} }
} }

View File

@ -1,6 +1,6 @@
"use strict"; "use strict";
const messagingService = require('./messaging'); const ws = require('./ws.js');
// importId => ImportContext // importId => ImportContext
const importContexts = {}; const importContexts = {};
@ -36,7 +36,7 @@ class ImportContext {
if (Date.now() - this.lastSentCountTs >= 500) { if (Date.now() - this.lastSentCountTs >= 500) {
this.lastSentCountTs = Date.now(); this.lastSentCountTs = Date.now();
await messagingService.sendMessageToAllClients({ await ws.sendMessageToAllClients({
importId: this.importId, importId: this.importId,
type: 'import-progress-count', type: 'import-progress-count',
progressCount: this.progressCount progressCount: this.progressCount
@ -46,7 +46,7 @@ class ImportContext {
// must remaing non-static // must remaing non-static
async reportError(message) { async reportError(message) {
await messagingService.sendMessageToAllClients({ await ws.sendMessageToAllClients({
type: 'import-error', type: 'import-error',
message: message message: message
}); });

View File

@ -21,7 +21,7 @@ const https = require('https');
const config = require('./services/config'); const config = require('./services/config');
const log = require('./services/log'); const log = require('./services/log');
const appInfo = require('./services/app_info'); const appInfo = require('./services/app_info');
const messagingService = require('./services/messaging'); const ws = require('./services/ws.js');
const utils = require('./services/utils'); const utils = require('./services/utils');
const sqlInit = require('./services/sql_init'); const sqlInit = require('./services/sql_init');
const port = require('./services/port'); const port = require('./services/port');
@ -77,7 +77,7 @@ async function startTrilium() {
httpServer.on('error', onError); httpServer.on('error', onError);
httpServer.on('listening', () => debug('Listening on port' + httpServer.address().port)); 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()) { if (utils.isElectron()) {
const electronRouting = require('./routes/electron'); const electronRouting = require('./routes/electron');