mirror of
https://github.com/zadam/trilium.git
synced 2024-11-10 17:13:45 +08:00
some tweaks mainly for electron support
This commit is contained in:
parent
0481b1b79c
commit
b890c9982b
7 changed files with 101 additions and 13 deletions
16
app.js
16
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();
|
||||
|
||||
|
|
5
build.sh
Executable file
5
build.sh
Executable file
|
@ -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
|
56
package.json
56
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": [
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -170,4 +170,4 @@ module.exports = {
|
|||
updateNote,
|
||||
addNoteAudits,
|
||||
deleteNote
|
||||
}
|
||||
};
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
};
|
Loading…
Reference in a new issue