win.loadFile("ui_templates/temp.html");
return win;
}
function createStartupInfo() {
const win2 = new BrowserWindow({
width: 400,
height: 200,
frame: false,
webPreferences: {
nodeIntegration: true,
},
});
win2.setFullScreen(false);
win2.setAlwaysOnTop(true);
win2.loadFile("ui_templates/startUp.html");
win2.show();
return win2;
}
function doneLoading() {
var fadeOutI = 1;
if (Object.keys(pageLookup).length == preLoadedAmount) {
aWin2.webContents.executeJavaScript(
"document.getElementById('current').innerHTML = 'Done';"
);
var fadeIntervall = setInterval(function () {
try {
if (fadeOutI < 0) {
clearInterval(fadeIntervall);
aWin2.webContents.executeJavaScript("window.close()");
} else {
aWin2.setOpacity(fadeOutI);
fadeOutI = fadeOutI - 0.05;
}
} catch (e) {
console.warn("Startup window got destroyed!");
clearInterval(fadeIntervall);
}
}, 20);
} else {
console.warn("Had to reschedule load finish");
setTimeout(doneLoading, 200);
}
}
function init() {
win = createWindow();
aWin2 = createStartupInfo();
setInterval(function () {
sysInf.networkInterfaces(function (data) {
networkInterfaces = data;
});
}, 2 * 60 * 1000);
sysInf.networkInterfaces(function (data) {
networkInterfaces = data;
});
var langs = new Config("./lang/langs_v1.js");
sessionState = 0;
setTimeout(function () {
console.log("Starting restfulServer API interface");
restApp.listen(restPort, () => {
console.log(`Restful is running on http://localhost:${restPort}`);
});
restApp.get("/", (req, res) => {
res.send("Hello World! The RestFul API of Enlight is up and working!");
});
restApp.get("/api/v1/ping", (req, res) => {
res.json({ state: "Succes", uptime: time.time() });
});
restApp.get("/api/v1/session/info", (req, res) => {
res.json({
state: "Succes",
name: mySession.name,
joinAble: mySession.joinable,
passwordProtected: mySession.passwordProtected,
memberAmount: mySession.members,
});
});
restApp.get("/api/v1/session/join", (req, res) => {
if (mySession.joinable) {
if (mySession.passwordProtected == false) {
uid = nanoid();
while (mySession.usedUIDs.includes(uid)) {
uid = nanoid();
}
mySession.usedUIDs.push(uid);
dev = {
type: "client",
ip: req.connection.remoteAddress,
uid: uid,
};
mySession.memberList.push();
mySession.members++;
res.json({ state: "Succes", uid: uid });
} else {
res.json({
state: "Failed",
message: "Passwords are not yet implemented",
code: -1,
});
}
} else {
res.json({
state: "Failed",
message: "Session is not joinable.",
code: 1,
});
}