diff --git a/src/public/javascripts/desktop.js b/src/public/javascripts/desktop.js
index 18051199e..bcd977b7e 100644
--- a/src/public/javascripts/desktop.js
+++ b/src/public/javascripts/desktop.js
@@ -1,3 +1,4 @@
+import glob from './services/glob.js';
import contextMenu from './services/tree_context_menu.js';
import link from './services/link.js';
import ws from './services/ws.js';
@@ -66,66 +67,6 @@ import RelationMapTypeWidget from "./widgets/type_widgets/relation_map.js";
import ProtectedSessionTypeWidget from "./widgets/type_widgets/protected_session.js";
import BookTypeWidget from "./widgets/type_widgets/book.js";
-window.glob.PROFILING_LOG = false;
-
-window.glob.isDesktop = utils.isDesktop;
-window.glob.isMobile = utils.isMobile;
-
-window.glob.getComponentByEl = el => appContext.getComponentByEl(el);
-window.glob.getHeaders = server.getHeaders;
-
-// required for ESLint plugin and CKEditor
-window.glob.getActiveTabNote = () => appContext.tabManager.getActiveTabNote();
-window.glob.requireLibrary = libraryLoader.requireLibrary;
-window.glob.ESLINT = libraryLoader.ESLINT;
-window.glob.appContext = appContext; // for debugging
-
-protectedSessionHolder.setProtectedSessionId(null);
-
-window.onerror = function (msg, url, lineNo, columnNo, error) {
- const string = msg.toLowerCase();
-
- let message = "Uncaught error: ";
-
- if (string.includes("Cannot read property 'defaultView' of undefined")) {
- // ignore this specific error which is very common but we don't know where it comes from
- // and it seems to be harmless
- return true;
- }
- else if (string.includes("script error")) {
- message += 'No details available';
- }
- else {
- message += [
- 'Message: ' + msg,
- 'URL: ' + url,
- 'Line: ' + lineNo,
- 'Column: ' + columnNo,
- 'Error object: ' + JSON.stringify(error)
- ].join(' - ');
- }
-
- ws.logError(message);
-
- return false;
-};
-
-for (const appCssNoteId of window.appCssNoteIds) {
- libraryLoader.requireCss(`api/notes/download/${appCssNoteId}`);
-}
-
-const wikiBaseUrl = "https://github.com/zadam/trilium/wiki/";
-
-$(document).on("click", "button[data-help-page]", e => {
- const $button = $(e.target);
-
- window.open(wikiBaseUrl + $button.attr("data-help-page"), '_blank');
-});
-
-$("body").on("click", "a.external", function () {
- window.open($(this).attr("href"), '_blank');
-});
-
if (utils.isElectron()) {
require('electron').ipcRenderer.on('globalShortcut', async function(event, actionName) {
keyboardActionService.triggerAction(actionName);
@@ -136,28 +77,6 @@ $('[data-toggle="tooltip"]').tooltip({
html: true
});
-// for CKEditor integration (button on block toolbar)
-window.glob.importMarkdownInline = async () => {
- const dialog = await import("./dialogs/markdown_import.js");
-
- dialog.importMarkdownInline();
-};
-
-window.glob.SEARCH_HELP_TEXT = `
-Search tips - also see
-
-
- - Just enter any text for full text search
- @abc
- returns notes with label abc
- @year=2019
- matches notes with label year
having value 2019
- @rock @pop
- matches notes which have both rock
and pop
labels
- @rock or @pop
- only one of the labels must be present
- @year<=2000
- numerical comparison (also >, >=, <).
- @dateCreated>=MONTH-1
- notes created in the last month
- =handler
- will execute script defined in handler
relation to get results
-
-`;
-
macInit.init();
appContext.start();
diff --git a/src/public/javascripts/mobile.js b/src/public/javascripts/mobile.js
index 7e942a23b..a0ea7f9b4 100644
--- a/src/public/javascripts/mobile.js
+++ b/src/public/javascripts/mobile.js
@@ -6,27 +6,7 @@ import branchService from "./services/branches.js";
import utils from "./services/utils.js";
import appContext from "./services/app_context.js";
import noteCreateService from "./services/note_create.js";
-import treeUtils from "./services/tree_utils.js";
-import linkService from "./services/link.js";
-import noteContentRenderer from "./services/note_content_renderer.js";
-
-window.glob.isDesktop = utils.isDesktop;
-window.glob.isMobile = utils.isMobile;
-window.glob.showAddLinkDialog = () => import('./dialogs/add_link.js').then(d => d.showDialog());
-window.glob.showIncludeNoteDialog = cb => import('./dialogs/include_note.js').then(d => d.showDialog(cb));
-window.glob.loadIncludedNote = async (noteId, el) => {
- const note = await treeCache.getNote(noteId);
-
- if (note) {
- $(el).empty().append($("").append(await linkService.createNoteLink(note.noteId, {
- showTooltip: false
- })));
-
- const {renderedContent} = await noteContentRenderer.getRenderedContent(note);
-
- $(el).append(renderedContent);
- }
-};
+import glob from "./services/glob.js";
const $leftPane = $("#left-pane");
const $tree = $("#tree");
diff --git a/src/public/javascripts/services/app_context.js b/src/public/javascripts/services/app_context.js
index 6af674f39..803fbe53d 100644
--- a/src/public/javascripts/services/app_context.js
+++ b/src/public/javascripts/services/app_context.js
@@ -28,7 +28,7 @@ class AppContext extends Component {
this.tabManager.loadTabs();
- bundleService.executeStartupBundles();
+ setTimeout(() => bundleService.executeStartupBundles(), 2000);
}
showWidgets() {
diff --git a/src/public/javascripts/services/glob.js b/src/public/javascripts/services/glob.js
new file mode 100644
index 000000000..4567f1205
--- /dev/null
+++ b/src/public/javascripts/services/glob.js
@@ -0,0 +1,90 @@
+import utils from "./utils.js";
+import appContext from "./app_context.js";
+import server from "./server.js";
+import libraryLoader from "./library_loader.js";
+import ws from "./ws.js";
+import protectedSessionHolder from "./protected_session_holder.js";
+
+window.glob.PROFILING_LOG = false;
+
+window.glob.isDesktop = utils.isDesktop;
+window.glob.isMobile = utils.isMobile;
+
+window.glob.getComponentByEl = el => appContext.getComponentByEl(el);
+window.glob.getHeaders = server.getHeaders;
+
+// required for ESLint plugin and CKEditor
+window.glob.getActiveTabNote = () => appContext.tabManager.getActiveTabNote();
+window.glob.requireLibrary = libraryLoader.requireLibrary;
+window.glob.ESLINT = libraryLoader.ESLINT;
+window.glob.appContext = appContext; // for debugging
+
+// for CKEditor integration (button on block toolbar)
+window.glob.importMarkdownInline = async () => {
+ const dialog = await import("./dialogs/markdown_import.js");
+
+ dialog.importMarkdownInline();
+};
+
+window.glob.SEARCH_HELP_TEXT = `
+Search tips - also see
+
+
+ - Just enter any text for full text search
+ @abc
- returns notes with label abc
+ @year=2019
- matches notes with label year
having value 2019
+ @rock @pop
- matches notes which have both rock
and pop
labels
+ @rock or @pop
- only one of the labels must be present
+ @year<=2000
- numerical comparison (also >, >=, <).
+ @dateCreated>=MONTH-1
- notes created in the last month
+ =handler
- will execute script defined in handler
relation to get results
+
+`;
+
+window.onerror = function (msg, url, lineNo, columnNo, error) {
+ const string = msg.toLowerCase();
+
+ let message = "Uncaught error: ";
+
+ if (string.includes("Cannot read property 'defaultView' of undefined")) {
+ // ignore this specific error which is very common but we don't know where it comes from
+ // and it seems to be harmless
+ return true;
+ }
+ else if (string.includes("script error")) {
+ message += 'No details available';
+ }
+ else {
+ message += [
+ 'Message: ' + msg,
+ 'URL: ' + url,
+ 'Line: ' + lineNo,
+ 'Column: ' + columnNo,
+ 'Error object: ' + JSON.stringify(error)
+ ].join(' - ');
+ }
+
+ ws.logError(message);
+
+ return false;
+};
+
+protectedSessionHolder.setProtectedSessionId(null);
+
+for (const appCssNoteId of window.appCssNoteIds || []) {
+ libraryLoader.requireCss(`api/notes/download/${appCssNoteId}`);
+}
+
+const wikiBaseUrl = "https://github.com/zadam/trilium/wiki/";
+
+$(document).on("click", "button[data-help-page]", e => {
+ const $button = $(e.target);
+
+ window.open(wikiBaseUrl + $button.attr("data-help-page"), '_blank');
+});
+
+$("body").on("click", "a.external", function () {
+ window.open($(this).attr("href"), '_blank');
+});
+
+export default {}
\ No newline at end of file
diff --git a/src/public/javascripts/services/server.js b/src/public/javascripts/services/server.js
index 82b971358..07fd1ae81 100644
--- a/src/public/javascripts/services/server.js
+++ b/src/public/javascripts/services/server.js
@@ -1,5 +1,4 @@
import utils from './utils.js';
-import toastService from "./toast.js";
const REQUEST_LOGGING_ENABLED = false;
@@ -112,8 +111,9 @@ function ajax(url, method, data, headers) {
headers: respHeaders
});
},
- error: (jqXhr, textStatus, error) => {
+ error: async (jqXhr, textStatus, error) => {
const message = "Error when calling " + method + " " + url + ": " + textStatus + " - " + error;
+ const toastService = (await import("./toast.js")).default;
toastService.showError(message);
toastService.throwError(message);
diff --git a/src/views/desktop.ejs b/src/views/desktop.ejs
index 298d81a39..0700b6c04 100644
--- a/src/views/desktop.ejs
+++ b/src/views/desktop.ejs
@@ -46,9 +46,9 @@
maxSyncIdAtLoad: <%= maxSyncIdAtLoad %>,
instanceName: '<%= instanceName %>',
csrfToken: '<%= csrfToken %>',
- isDev: '<%= isDev %>'
+ isDev: '<%= isDev %>',
+ appCssNoteIds: <%- JSON.stringify(appCssNoteIds) %>
};
- window.appCssNoteIds = <%- JSON.stringify(appCssNoteIds) %>;
diff --git a/src/views/mobile.ejs b/src/views/mobile.ejs
index 76e1ba069..375f3b76b 100644
--- a/src/views/mobile.ejs
+++ b/src/views/mobile.ejs
@@ -98,7 +98,8 @@
maxSyncIdAtLoad: <%= maxSyncIdAtLoad %>,
instanceName: '<%= instanceName %>',
csrfToken: '<%= csrfToken %>',
- isDev: '<%= isDev %>'
+ isDev: '<%= isDev %>',
+ appCssNoteIds: <%- JSON.stringify(appCssNoteIds) %>
};