2017-12-03 22:29:23 -05:00
|
|
|
"use strict";
|
|
|
|
|
|
2024-07-18 21:35:17 +03:00
|
|
|
import sqlInit from "../services/sql_init.js";
|
|
|
|
|
import setupService from "../services/setup.js";
|
2025-01-22 18:57:06 +01:00
|
|
|
import { isElectron } from "../services/utils.js";
|
2024-07-18 21:35:17 +03:00
|
|
|
import assetPath from "../services/asset_path.js";
|
|
|
|
|
import appPath from "../services/app_path.js";
|
2025-01-09 18:36:24 +02:00
|
|
|
import type { Request, Response } from "express";
|
2018-07-24 08:12:36 +02:00
|
|
|
|
2024-07-18 23:36:26 +03:00
|
|
|
function setupPage(req: Request, res: Response) {
|
2020-06-20 12:31:38 +02:00
|
|
|
if (sqlInit.isDbInitialized()) {
|
2025-01-22 18:57:06 +01:00
|
|
|
if (isElectron) {
|
2024-12-22 15:42:15 +02:00
|
|
|
handleElectronRedirect();
|
2024-07-18 23:36:26 +03:00
|
|
|
} else {
|
2025-01-09 18:07:02 +02:00
|
|
|
res.redirect(".");
|
2019-12-24 14:42:03 +01:00
|
|
|
}
|
2022-01-12 19:32:23 +01:00
|
|
|
|
|
|
|
|
return;
|
2018-07-24 08:12:36 +02:00
|
|
|
}
|
|
|
|
|
|
2023-06-29 23:32:19 +02:00
|
|
|
// we got here because DB is not completely initialized, so if schema exists,
|
|
|
|
|
// it means we're in "sync in progress" state.
|
2020-06-20 12:31:38 +02:00
|
|
|
const syncInProgress = sqlInit.schemaExists();
|
2018-07-24 08:12:36 +02:00
|
|
|
|
|
|
|
|
if (syncInProgress) {
|
|
|
|
|
// trigger sync if it's not already running
|
|
|
|
|
setupService.triggerSync();
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
res.render("setup", {
|
2022-10-26 23:50:54 +02:00
|
|
|
syncInProgress: syncInProgress,
|
2022-12-25 11:58:24 +01:00
|
|
|
assetPath: assetPath,
|
|
|
|
|
appPath: appPath
|
2018-07-24 08:12:36 +02:00
|
|
|
});
|
2018-03-30 19:31:22 -04:00
|
|
|
}
|
2017-12-03 22:29:23 -05:00
|
|
|
|
2024-07-18 23:36:26 +03:00
|
|
|
async function handleElectronRedirect() {
|
2024-07-24 20:33:35 +03:00
|
|
|
const windowService = (await import("../services/window.js")).default;
|
2024-07-18 23:36:26 +03:00
|
|
|
const { app } = await import("electron");
|
|
|
|
|
windowService.createMainWindow(app);
|
|
|
|
|
windowService.closeSetupWindow();
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-18 21:42:44 +03:00
|
|
|
export default {
|
2018-03-30 19:31:22 -04:00
|
|
|
setupPage
|
|
|
|
|
};
|