mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
Merge pull request #60 from TriliumNext/fix/start-electron
fix: start-electron script
This commit is contained in:
commit
045f318612
72
bin/copy-dist.ts
Normal file
72
bin/copy-dist.ts
Normal file
@ -0,0 +1,72 @@
|
||||
const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
|
||||
const DEST_DIR = "./dist";
|
||||
const DEST_DIR_SRC = path.join(DEST_DIR, "src");
|
||||
const DEST_DIR_NODE_MODULES = path.join(DEST_DIR, "node_modules");
|
||||
|
||||
async function copyNodeModuleFileOrFolder(source: string) {
|
||||
const adjustedSource = source.substring(13);
|
||||
const destination = path.join(DEST_DIR_NODE_MODULES, adjustedSource);
|
||||
|
||||
console.log(`Copying ${source} to ${destination}`);
|
||||
await fs.ensureDir(path.dirname(destination));
|
||||
await fs.copy(source, destination);
|
||||
}
|
||||
|
||||
const copy = async () => {
|
||||
const filesToCopy = ["config-sample.ini"];
|
||||
for (const file of filesToCopy) {
|
||||
console.log(`Copying ${file}`);
|
||||
await fs.copy(file, path.join(DEST_DIR, file));
|
||||
}
|
||||
|
||||
const dirsToCopy = ["images", "libraries", "db"];
|
||||
for (const dir of dirsToCopy) {
|
||||
console.log(`Copying ${dir}`);
|
||||
await fs.copy(dir, path.join(DEST_DIR, dir));
|
||||
}
|
||||
|
||||
const srcDirsToCopy = ["./src/public", "./src/views"];
|
||||
for (const dir of srcDirsToCopy) {
|
||||
console.log(`Copying ${dir}`);
|
||||
await fs.copy(dir, path.join(DEST_DIR_SRC, path.basename(dir)));
|
||||
}
|
||||
|
||||
const nodeModulesFile = [
|
||||
"node_modules/react/umd/react.production.min.js",
|
||||
"node_modules/react/umd/react.development.js",
|
||||
"node_modules/react-dom/umd/react-dom.production.min.js",
|
||||
"node_modules/react-dom/umd/react-dom.development.js",
|
||||
"node_modules/katex/dist/katex.min.js",
|
||||
"node_modules/katex/dist/contrib/mhchem.min.js",
|
||||
"node_modules/katex/dist/contrib/auto-render.min.js",
|
||||
];
|
||||
|
||||
for (const file of nodeModulesFile) {
|
||||
await copyNodeModuleFileOrFolder(file);
|
||||
}
|
||||
|
||||
const nodeModulesFolder = [
|
||||
"node_modules/@excalidraw/excalidraw/dist/",
|
||||
"node_modules/katex/dist/",
|
||||
"node_modules/dayjs/",
|
||||
"node_modules/force-graph/dist/",
|
||||
"node_modules/boxicons/css/",
|
||||
"node_modules/boxicons/fonts/",
|
||||
"node_modules/mermaid/dist/",
|
||||
"node_modules/jquery/dist/",
|
||||
"node_modules/jquery-hotkeys/",
|
||||
"node_modules/print-this/",
|
||||
"node_modules/split.js/dist/",
|
||||
"node_modules/panzoom/dist/",
|
||||
];
|
||||
|
||||
for (const folder of nodeModulesFolder) {
|
||||
await copyNodeModuleFileOrFolder(folder);
|
||||
}
|
||||
};
|
||||
|
||||
copy()
|
||||
.then(() => console.log("Copying complete!"))
|
||||
.catch((err) => console.error("Error during copy:", err));
|
62
electron.js
62
electron.js
@ -1,62 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const {app, globalShortcut, BrowserWindow} = require('electron');
|
||||
const sqlInit = require('./src/services/sql_init');
|
||||
const appIconService = require('./src/services/app_icon.js');
|
||||
const windowService = require('./src/services/window');
|
||||
const tray = require('./src/services/tray');
|
||||
|
||||
// Adds debug features like hotkeys for triggering dev tools and reload
|
||||
require('electron-debug')();
|
||||
|
||||
appIconService.installLocalAppIcon();
|
||||
|
||||
require('electron-dl')({ saveAs: true });
|
||||
|
||||
// needed for excalidraw export https://github.com/zadam/trilium/issues/4271
|
||||
app.commandLine.appendSwitch("enable-experimental-web-platform-features");
|
||||
|
||||
// Quit when all windows are closed, except on macOS. There, it's common
|
||||
// for applications and their menu bar to stay active until the user quits
|
||||
// explicitly with Cmd + Q.
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit()
|
||||
}
|
||||
});
|
||||
|
||||
app.on('ready', async () => {
|
||||
// app.setAppUserModelId('com.github.zadam.trilium');
|
||||
|
||||
// if db is not initialized -> setup process
|
||||
// if db is initialized, then we need to wait until the migration process is finished
|
||||
if (sqlInit.isDbInitialized()) {
|
||||
await sqlInit.dbReady;
|
||||
|
||||
await windowService.createMainWindow(app);
|
||||
|
||||
if (process.platform === 'darwin') {
|
||||
app.on('activate', async () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) {
|
||||
await windowService.createMainWindow(app);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
tray.createTray();
|
||||
}
|
||||
else {
|
||||
await windowService.createSetupWindow();
|
||||
}
|
||||
|
||||
await windowService.registerGlobalShortcuts();
|
||||
});
|
||||
|
||||
app.on('will-quit', () => {
|
||||
globalShortcut.unregisterAll();
|
||||
});
|
||||
|
||||
// this is to disable electron warning spam in the dev console (local development only)
|
||||
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true';
|
||||
|
||||
require('./src/www.js');
|
63
electron.ts
Normal file
63
electron.ts
Normal file
@ -0,0 +1,63 @@
|
||||
"use strict";
|
||||
|
||||
import electron = require("electron");
|
||||
import sqlInit = require("./src/services/sql_init");
|
||||
import appIconService = require("./src/services/app_icon");
|
||||
import windowService = require("./src/services/window");
|
||||
import tray = require("./src/services/tray");
|
||||
|
||||
// Adds debug features like hotkeys for triggering dev tools and reload
|
||||
require("electron-debug")();
|
||||
|
||||
appIconService.installLocalAppIcon();
|
||||
|
||||
require("electron-dl")({ saveAs: true });
|
||||
|
||||
// needed for excalidraw export https://github.com/zadam/trilium/issues/4271
|
||||
electron.app.commandLine.appendSwitch(
|
||||
"enable-experimental-web-platform-features"
|
||||
);
|
||||
|
||||
// Quit when all windows are closed, except on macOS. There, it's common
|
||||
// for applications and their menu bar to stay active until the user quits
|
||||
// explicitly with Cmd + Q.
|
||||
electron.app.on("window-all-closed", () => {
|
||||
if (process.platform !== "darwin") {
|
||||
electron.app.quit();
|
||||
}
|
||||
});
|
||||
|
||||
electron.app.on("ready", async () => {
|
||||
// electron.app.setAppUserModelId('com.github.zadam.trilium');
|
||||
|
||||
// if db is not initialized -> setup process
|
||||
// if db is initialized, then we need to wait until the migration process is finished
|
||||
if (sqlInit.isDbInitialized()) {
|
||||
await sqlInit.dbReady;
|
||||
|
||||
await windowService.createMainWindow(electron.app);
|
||||
|
||||
if (process.platform === "darwin") {
|
||||
electron.app.on("activate", async () => {
|
||||
if (electron.BrowserWindow.getAllWindows().length === 0) {
|
||||
await windowService.createMainWindow(electron.app);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
tray.createTray();
|
||||
} else {
|
||||
await windowService.createSetupWindow();
|
||||
}
|
||||
|
||||
await windowService.registerGlobalShortcuts();
|
||||
});
|
||||
|
||||
electron.app.on("will-quit", () => {
|
||||
electron.globalShortcut.unregisterAll();
|
||||
});
|
||||
|
||||
// this is to disable electron warning spam in the dev console (local development only)
|
||||
process.env["ELECTRON_DISABLE_SECURITY_WARNINGS"] = "true";
|
||||
|
||||
require("./src/www.js");
|
@ -16,12 +16,13 @@
|
||||
"start-server": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon src/www.ts",
|
||||
"start-server-no-dir": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon src/www.ts",
|
||||
"qstart-server": "npm run qswitch-server && TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon src/www.ts",
|
||||
"start-electron": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev electron --inspect=5858 .",
|
||||
"start-electron": "rimraf ./dist && tsc && ts-node ./bin/copy-dist.ts && cross-env TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev electron ./dist/electron.js --inspect=5858 .",
|
||||
"start-electron-no-dir": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 electron --inspect=5858 .",
|
||||
"qstart-electron": "npm run qswitch-electron && TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev electron --inspect=5858 .",
|
||||
"start-test-server": "npm run qswitch-server; rm -rf ./data-test; cross-env TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data-test TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev TRILIUM_PORT=9999 node src/www.js",
|
||||
"start-test-server": "npm run qswitch-server; rm -rf ./data-test; cross-env TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data-test TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev TRILIUM_PORT=9999 ts-node src/www.ts",
|
||||
"switch-server": "rm -rf ./node_modules/better-sqlite3 && npm install",
|
||||
"switch-electron": "./node_modules/.bin/electron-rebuild",
|
||||
"rebuild": "electron-rebuild",
|
||||
"qswitch-server": "rm -rf ./node_modules/better-sqlite3/bin ; mkdir -p ./node_modules/better-sqlite3/build ; cp ./bin/better-sqlite3/linux-server-better_sqlite3.node ./node_modules/better-sqlite3/build/better_sqlite3.node",
|
||||
"qswitch-electron": "rm -rf ./node_modules/better-sqlite3/bin ; mkdir -p ./node_modules/better-sqlite3/build ; cp ./bin/better-sqlite3/linux-desktop-better_sqlite3.node ./node_modules/better-sqlite3/build/better_sqlite3.node",
|
||||
"build-backend-docs": "rm -rf ./docs/backend_api && ./node_modules/.bin/jsdoc -c jsdoc-conf.json -d ./docs/backend_api src/becca/entities/*.js src/services/backend_script_api.js src/services/sql.js",
|
||||
@ -31,7 +32,7 @@
|
||||
"test-jasmine": "TRILIUM_DATA_DIR=~/trilium/data-test jasmine",
|
||||
"test-es6": "node -r esm spec-es6/attribute_parser.spec.js ",
|
||||
"test": "npm run test-jasmine && npm run test-es6",
|
||||
"postinstall": "rimraf ./node_modules/canvas"
|
||||
"postinstall": "rimraf ./node_modules/canvas && npm run rebuild"
|
||||
},
|
||||
"dependencies": {
|
||||
"@braintree/sanitize-url": "6.0.4",
|
||||
@ -155,4 +156,4 @@
|
||||
"optionalDependencies": {
|
||||
"electron-installer-debian": "3.2.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -68,6 +68,6 @@ function getExePath() {
|
||||
return path.resolve(resourceDir.ELECTRON_APP_ROOT_DIR, 'trilium');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
export = {
|
||||
installLocalAppIcon
|
||||
};
|
||||
|
@ -8,11 +8,13 @@
|
||||
"noImplicitAny": true,
|
||||
"resolveJsonModule": true,
|
||||
"lib": ["ES2022"],
|
||||
"downlevelIteration": true
|
||||
"downlevelIteration": true,
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"include": [
|
||||
"./src/**/*.js",
|
||||
"./src/**/*.ts"
|
||||
"./src/**/*.ts",
|
||||
"./*.ts"
|
||||
],
|
||||
"exclude": ["./node_modules/**/*"],
|
||||
"ts-node": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user