|
|
|
|
@ -2,6 +2,9 @@ import cls from "@triliumnext/server/src/services/cls.js";
|
|
|
|
|
import fs from "fs/promises";
|
|
|
|
|
import fsExtra from "fs-extra";
|
|
|
|
|
import path from "path";
|
|
|
|
|
import electron from "electron";
|
|
|
|
|
import { deferred, type DeferredPromise } from "@triliumnext/server/src/services/utils.js";
|
|
|
|
|
import windowService from "@triliumnext/server/src/services/window.js";
|
|
|
|
|
|
|
|
|
|
export function initializeDatabase(skipDemoDb: boolean) {
|
|
|
|
|
return new Promise<void>(async (resolve) => {
|
|
|
|
|
@ -15,8 +18,30 @@ export function initializeDatabase(skipDemoDb: boolean) {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function startElectron() {
|
|
|
|
|
await import("@triliumnext/desktop/src/electron-main.js");
|
|
|
|
|
/**
|
|
|
|
|
* Electron has a behaviour in which the "ready" event must have a listener attached before it gets to initialize.
|
|
|
|
|
* If async tasks are awaited before the "ready" event is bound, then the window will never shown.
|
|
|
|
|
* This method works around by creating a deferred promise. It will immediately bind to the "ready" event and wait for that promise to be resolved externally.
|
|
|
|
|
*
|
|
|
|
|
* @param callback a method to be called after the server and Electron is initialized.
|
|
|
|
|
* @returns the deferred promise that must be resolved externally before the Electron app is started.
|
|
|
|
|
*/
|
|
|
|
|
export function startElectron(callback: () => void): DeferredPromise<void> {
|
|
|
|
|
const initializedPromise = deferred<void>();
|
|
|
|
|
electron.app.on("ready", async () => {
|
|
|
|
|
await initializedPromise;
|
|
|
|
|
|
|
|
|
|
console.log("Electron is ready!");
|
|
|
|
|
|
|
|
|
|
// Start the server.
|
|
|
|
|
await import("@triliumnext/server/src/main.js");
|
|
|
|
|
|
|
|
|
|
// Create the main window.
|
|
|
|
|
await windowService.createMainWindow(electron.app);
|
|
|
|
|
|
|
|
|
|
callback();
|
|
|
|
|
});
|
|
|
|
|
return initializedPromise;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function extractZip(zipFilePath: string, outputPath: string, ignoredFiles?: Set<string>) {
|
|
|
|
|
|