2017-12-04 11:29:23 +08:00
|
|
|
"use strict";
|
|
|
|
|
2018-07-24 14:12:36 +08:00
|
|
|
const sqlInit = require('../services/sql_init');
|
|
|
|
const setupService = require('../services/setup');
|
2019-12-24 21:42:03 +08:00
|
|
|
const utils = require('../services/utils');
|
2018-07-24 14:12:36 +08:00
|
|
|
|
2020-06-20 18:31:38 +08:00
|
|
|
function setupPage(req, res) {
|
|
|
|
if (sqlInit.isDbInitialized()) {
|
2019-12-24 21:42:03 +08:00
|
|
|
if (utils.isElectron()) {
|
2020-05-08 16:24:57 +08:00
|
|
|
const windowService = require('../services/window');
|
2020-06-20 18:31:38 +08:00
|
|
|
windowService.createMainWindow();
|
2019-12-24 21:42:03 +08:00
|
|
|
windowService.closeSetupWindow();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
res.redirect('/');
|
|
|
|
}
|
2018-07-24 14:12:36 +08: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 18:31:38 +08:00
|
|
|
const syncInProgress = sqlInit.schemaExists();
|
2018-07-24 14:12:36 +08:00
|
|
|
|
|
|
|
if (syncInProgress) {
|
|
|
|
// trigger sync if it's not already running
|
|
|
|
setupService.triggerSync();
|
|
|
|
}
|
|
|
|
|
|
|
|
res.render('setup', {
|
|
|
|
syncInProgress: syncInProgress
|
|
|
|
});
|
2018-03-31 07:31:22 +08:00
|
|
|
}
|
2017-12-04 11:29:23 +08:00
|
|
|
|
2018-03-31 07:31:22 +08:00
|
|
|
module.exports = {
|
|
|
|
setupPage
|
|
|
|
};
|