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
some tweaks mainly for electron support
azivnerb890c9982b92
diff --git a/app.js b/app.jsindex fc95b4b704..230ff9a96e 100644--- a/app.js+++ b/app.js@@ -10,6 +10,7 @@ const os = require('os');const options = require('./services/options');const log = require('./services/log');const utils = require('./services/utils');+const sql = require('./services/sql');const dataDir = require('./services/data_dir');const sessionSecret = require('./services/session_secret');@@ -17,6 +18,15 @@ const sessionSecret = require('./services/session_secret');const db = require('sqlite');db.open(dataDir.DOCUMENT_PATH, { Promise }).then(async () => {+ const tableResults = await sql.getResults("SELECT name FROM sqlite_master WHERE type='table' AND name='notes'");++ console.log(tableResults);++ if (tableResults.length !== 1) {+ console.log("No connection to initialized DB.");+ process.exit(1);+ }+if (!await options.getOption('document_id')) {await options.setOption('document_id', utils.randomString(32));}@@ -24,7 +34,11 @@ db.open(dataDir.DOCUMENT_PATH, { Promise }).then(async () => {if (!await options.getOption('document_secret')) {await options.setOption('document_secret', utils.randomSecureToken(32));}-});+})+ .catch(e => {+ console.log("Error connecting to DB.", e);+ process.exit(1);+ });const app = express();diff --git a/build.sh b/build.shnew file mode 100755index 0000000000..3c1f9d7aa7--- /dev/null+++ b/build.sh@@ -0,0 +1,5 @@+#!/bin/bash++./node_modules/.bin/electron-packager . --out=dist --platform=linux,win32 --overwrite++#./node_modules/.bin/electron-installer-debian --src dist/trilium-linux-x64/ --dest dist/installers/ --arch amd64\ No newline at end of filediff --git a/package.json b/package.jsonindex cf720c68b6..cf4223bb46 100644--- a/package.json+++ b/package.json@@ -1,20 +1,28 @@{"name": "trilium",+ "description": "Trilium","version": "0.0.1","private": true,"scripts": {"start": "node ./bin/www","test-electron": "xo","start-electron": "electron .",- "build-electron": "electron-packager . --out=dist --asar --overwrite --all"+ "build-electron": "electron-packager . --out=dist --asar --overwrite --all",+ "start-forge": "electron-forge start",+ "package-forge": "electron-forge package",+ "make-forge": "electron-forge make",+ "publish-forge": "electron-forge publish"},"dependencies": {+ "electron-compile": "^6.4.2",+ "electron-squirrel-startup": "^1.0.0","body-parser": "~1.18.2","cookie-parser": "~1.4.3","debug": "~3.1.0","ejs": "~2.5.7",- "electron": "^1.7.9",+ "electron": "^1.8.2-beta.1","electron-debug": "^1.0.0",+ "electron-forge": "^4.1.2","electron-rebuild": "^1.6.0","express": "~4.16.2","express-session": "^1.15.6",@@ -34,7 +42,49 @@"devtron": "^1.1.0","electron-packager": "^8.0.0","electron": "^1.6.6",- "xo": "^0.18.0"+ "xo": "^0.18.0",+ "babel-plugin-transform-async-to-generator": "^6.24.1",+ "babel-preset-env": "^1.6.1",+ "babel-preset-react": "^6.24.1",+ "electron-forge": "^4.1.2",+ "electron-prebuilt-compile": "1.7.9",+ "eslint": "^3.19.0",+ "eslint-config-airbnb": "^15.1.0",+ "eslint-plugin-import": "^2.8.0",+ "eslint-plugin-jsx-a11y": "^5.1.1",+ "eslint-plugin-react": "^7.4.0"+ },+ "config": {+ "forge": {+ "make_targets": {+ "win32": [+ "squirrel"+ ],+ "darwin": [+ "zip"+ ],+ "linux": [+ "deb",+ "rpm"+ ]+ },+ "electronPackagerConfig": {+ "packageManager": "npm"+ },+ "electronWinstallerConfig": {+ "name": "trilium"+ },+ "electronInstallerDebian": {},+ "electronInstallerRedhat": {},+ "github_repository": {+ "owner": "",+ "name": ""+ },+ "windowsStoreConfig": {+ "packageName": "",+ "name": "trilium"+ }+ }},"xo": {"envs": [diff --git a/services/auth.js b/services/auth.jsindex 2d5404acdc..722ee243d7 100644--- a/services/auth.js+++ b/services/auth.js@@ -1,9 +1,10 @@"use strict";const migration = require('./migration');+const utils = require('./utils');async function checkAuth(req, res, next) {- if (!req.session.loggedIn) {+ if (!req.session.loggedIn && !utils.isElectron()) {res.redirect("login");}else if (await migration.isDbUpToDate()) {@@ -15,7 +16,7 @@ async function checkAuth(req, res, next) {}async function checkAuthWithoutMigration(req, res, next) {- if (!req.session.loggedIn) {+ if (!req.session.loggedIn && !utils.isElectron()) {res.redirect("login");}else {@@ -24,7 +25,7 @@ async function checkAuthWithoutMigration(req, res, next) {}async function checkApiAuth(req, res, next) {- if (!req.session.loggedIn) {+ if (!req.session.loggedIn && !utils.isElectron()) {res.status(401).send("Not authorized");}else if (await migration.isDbUpToDate()) {@@ -36,7 +37,7 @@ async function checkApiAuth(req, res, next) {}async function checkApiAuthWithoutMigration(req, res, next) {- if (!req.session.loggedIn) {+ if (!req.session.loggedIn && !utils.isElectron()) {res.status(401).send("Not authorized");}else {diff --git a/services/notes.js b/services/notes.jsindex 023de3d016..8805f931f8 100644--- a/services/notes.js+++ b/services/notes.js@@ -170,4 +170,4 @@ module.exports = {updateNote,addNoteAudits,deleteNote-}\ No newline at end of file+};\ No newline at end of filediff --git a/services/sync.js b/services/sync.jsindex 314fed997a..77c9ce75a9 100644--- a/services/sync.js+++ b/services/sync.js@@ -225,7 +225,22 @@ async function sync() {};}- const syncContext = await login();+ try {+ const syncContext = await login();+ }+ catch (e) {+ if (e.message.indexOf('ECONNREFUSED') !== -1) {+ logSync("No connection to sync server.");++ return {+ success: false,+ message: "No connection to sync server."+ };+ }+ else {+ throw e;+ }+ }await pushSync(syncContext);@@ -261,8 +276,6 @@ function logSyncError(message, e) {completeMessage += ", inner exception: " + e.stack;}- log.info(completeMessage);-throw new Error(completeMessage);}diff --git a/services/utils.js b/services/utils.jsindex 58a3d951d6..367897fbf0 100644--- a/services/utils.js+++ b/services/utils.js@@ -44,6 +44,10 @@ function browserId(req) {return req.get('x-browser-id');}+function isElectron() {+ return !!process.versions['electron'];+}+module.exports = {randomSecureToken,randomString,@@ -52,5 +56,6 @@ module.exports = {toBase64,fromBase64,hmac,- browserId+ browserId,+ isElectron};\ No newline at end of file