-
Notifications
You must be signed in to change notification settings - Fork 125
/
Copy pathsetup.ts
51 lines (41 loc) · 1.44 KB
/
setup.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"use strict";
import sqlInit from "../services/sql_init.js";
import setupService from "../services/setup.js";
import { isElectron } from "../services/utils.js";
import assetPath from "../services/asset_path.js";
import appPath from "../services/app_path.js";
import type { Request, Response } from "express";
function setupPage(req: Request, res: Response) {
if (sqlInit.isDbInitialized()) {
if (isElectron) {
handleElectronRedirect();
} else {
res.redirect(".");
}
return;
}
// we got here because DB is not completely initialized, so if schema exists,
// it means we're in "sync in progress" state.
const syncInProgress = sqlInit.schemaExists();
if (syncInProgress) {
// trigger sync if it's not already running
setupService.triggerSync();
}
res.render("setup", {
syncInProgress: syncInProgress,
assetPath: assetPath,
appPath: appPath
});
}
async function handleElectronRedirect() {
const windowService = (await import("../services/window.js")).default;
const { app } = await import("electron");
// Wait for the main window to be created before closing the setup window to prevent triggering `window-all-closed`.
await windowService.createMainWindow(app);
windowService.closeSetupWindow();
const tray = (await import("../services/tray.js")).default;
tray.createTray();
}
export default {
setupPage
};