mirror of
https://github.com/TheGreyDiamond/Enlight.git
synced 2025-07-17 20:33:48 +02:00
Network and clock feature added
This commit is contained in:
98
index.js
98
index.js
@ -1,7 +1,7 @@
|
||||
const { app, BrowserWindow, screen } = require("electron");
|
||||
const fs = require('fs');
|
||||
const { app, BrowserWindow, screen, ipcMain } = require("electron");
|
||||
const fs = require("fs");
|
||||
const { win32 } = require("path");
|
||||
const sysInf = require('systeminformation');
|
||||
const sysInf = require("systeminformation");
|
||||
|
||||
var aWin2 = undefined;
|
||||
|
||||
@ -14,12 +14,9 @@ function createWindow() {
|
||||
},
|
||||
});
|
||||
win.setFullScreen(true);
|
||||
win.setMenuBarVisibility(false)
|
||||
win.setAutoHideMenuBar(true)
|
||||
win.setMenuBarVisibility(false);
|
||||
win.setAutoHideMenuBar(true);
|
||||
win.loadFile("ui_templates/index.html");
|
||||
setInterval(function(){
|
||||
// Updating battery
|
||||
}, 500)
|
||||
}
|
||||
|
||||
function createStartupInfo() {
|
||||
@ -36,38 +33,83 @@ function createStartupInfo() {
|
||||
win2.setAlwaysOnTop(true);
|
||||
win2.loadFile("ui_templates/startUp.html");
|
||||
win2.show();
|
||||
return(win2)
|
||||
return win2;
|
||||
}
|
||||
|
||||
function doneLoading(){
|
||||
function doneLoading() {
|
||||
var fadeOutI = 1;
|
||||
aWin2.webContents.executeJavaScript("document.getElementById('current').innerHTML = 'Done';")
|
||||
var fadeIntervall = setInterval(function(){
|
||||
try{if(fadeOutI < 0){
|
||||
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);
|
||||
aWin2.webContents.executeJavaScript("window.close()")
|
||||
}else{
|
||||
aWin2.setOpacity(fadeOutI)
|
||||
fadeOutI = fadeOutI - 0.05
|
||||
}
|
||||
}catch(e){
|
||||
console.warn("Startup window got destroyed!")
|
||||
clearInterval(fadeIntervall);
|
||||
}
|
||||
|
||||
|
||||
}, 20)
|
||||
}, 20);
|
||||
//aWin2.webContents.executeJavaScript("window.close()")
|
||||
|
||||
}
|
||||
|
||||
function init() {
|
||||
createWindow();
|
||||
aWin2 = createStartupInfo();
|
||||
setTimeout(doneLoading, 2000);
|
||||
//sysInf.battery()
|
||||
//.then(data => console.log(data))
|
||||
//.catch(error => console.error(error));
|
||||
ipcMain.on("asynchronous-message", (event, arg) => {
|
||||
console.log(arg); // prints "ping"
|
||||
if (arg == "hasBattery") {
|
||||
event.reply("asynchronous-reply", sysInf.battery().hasbattery);
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.on("synchronous-message", (event, arg) => {
|
||||
//console.log(arg) // prints "ping"
|
||||
if (String(arg).includes("hasBattery")) {
|
||||
sysInf.battery(function (data) {
|
||||
event.returnValue = data.hasbattery;
|
||||
//event.returnValue = true
|
||||
});
|
||||
}else if (String(arg).includes("getBatteryLevel")) {
|
||||
sysInf.battery(function (data) {
|
||||
//event.returnValue = 2
|
||||
event.returnValue = data.percent;
|
||||
});
|
||||
}else if (String(arg).includes("loadOverride")) {
|
||||
event.returnValue = false;
|
||||
}else if (String(arg).includes("getNetworks")) {
|
||||
sysInf.networkInterfaces(function (data) {
|
||||
event.returnValue = data;
|
||||
});
|
||||
}else if (String(arg).includes("set:newNetwork")) {
|
||||
fs.writeFile('usrStore/lastNetwork.data', String(arg).split("|")[1], function (err) {
|
||||
if (err) return console.log(err);
|
||||
console.log('Saved new main network');
|
||||
});
|
||||
event.returnValue = "";
|
||||
} else if (String(arg).includes("getMainNetwork")) {
|
||||
try{
|
||||
last = fs.readFileSync("usrStore/lastNetwork.data")
|
||||
console.log(last.toString())
|
||||
event.returnValue = last.toString();
|
||||
}catch(e){
|
||||
sysInf.networkInterfaces(function (data) {
|
||||
fs.writeFileSync("usrStore/lastNetwork.data", data[0].ifaceName);
|
||||
event.returnValue = data[0].ifaceName
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}else{
|
||||
event.returnValue = "ERR:UNKNOW_CMD"
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
app.whenReady().then(init);
|
||||
|
@ -2,34 +2,178 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>Hello World!</title>
|
||||
<title>Enlight - Screen 1</title>
|
||||
<!--<meta
|
||||
http-equiv="Content-Security-Policy"
|
||||
content="script-src 'self' 'unsafe-inline';"
|
||||
/>-->
|
||||
<script src="static/jquery-1.7.1.min.js" type="text/javascript"></script>
|
||||
<script src="static/js/helper.js" type="text/javascript"></script>
|
||||
<!--<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>*-->
|
||||
<link href="static/default.css" rel="stylesheet" />
|
||||
<link href="static/fontawesome-free-5.15.1-web/css/all.css" rel="stylesheet">
|
||||
<link
|
||||
href="static/fontawesome-free-5.15.1-web/css/all.css"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
<!--<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">-->
|
||||
</head>
|
||||
<body>
|
||||
<div id="header-bar" class="header-bar">
|
||||
<clock id="clock" class="header-clock"></clock>
|
||||
<battery id="battery" class="battery"><i class="fas fa-battery-full"></i></battery>
|
||||
<div class="areaRight">
|
||||
<network>
|
||||
<i
|
||||
class="fas fa-network-wired"
|
||||
id="networkBtn"
|
||||
onclick='document.getElementById("networkDropdown").classList.toggle("show");'
|
||||
></i>
|
||||
<div id="networkDropdown" class="dropdown-content"></div>
|
||||
</network>
|
||||
<battery id="battery" class="fa"></battery>
|
||||
<clock id="clock" class="header-clock"></clock>
|
||||
<i
|
||||
class="fa-spin loader1 fa"
|
||||
style="font-size: 18px; padding-right: 4px"
|
||||
id="loader"
|
||||
></i
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
function updateTime(k) {
|
||||
if (k < 10) {
|
||||
return "0" + k;
|
||||
const { ipcRenderer } = require("electron");
|
||||
setInterval(function () {
|
||||
// Pulling general info from main thread
|
||||
loadOverride = ipcRenderer.sendSync(
|
||||
"synchronous-message",
|
||||
"loadOverride"
|
||||
);
|
||||
if (loadOverride) {
|
||||
document.getElementById("loader").innerHTML = "";
|
||||
} else {
|
||||
return k;
|
||||
document.getElementById("loader").innerHTML = "";
|
||||
}
|
||||
}, 200);
|
||||
|
||||
// Network info
|
||||
var allNetworkNames = [];
|
||||
function buildNetworkDropDown() {
|
||||
allNetworks = ipcRenderer.sendSync(
|
||||
"synchronous-message",
|
||||
"getNetworks"
|
||||
);
|
||||
lastNetwork = ipcRenderer.sendSync(
|
||||
"synchronous-message",
|
||||
"getMainNetwork"
|
||||
);
|
||||
allNetworkNames = []
|
||||
console.log(lastNetwork);
|
||||
i = 0;
|
||||
var dropDown = document.getElementById("networkDropdown");
|
||||
dropDown.innerHTML = ""
|
||||
while (i < allNetworks.length) {
|
||||
temp =
|
||||
"<a id='networkEntry" +
|
||||
String(i) +
|
||||
"' onclick='selectNewNetwork(" +
|
||||
String(i) +
|
||||
")'> " +
|
||||
encode_html(allNetworks[i].ifaceName) +
|
||||
"</a>";
|
||||
dropDown.innerHTML += temp;
|
||||
allNetworkNames.push(allNetworks[i].ifaceName);
|
||||
i++;
|
||||
}
|
||||
|
||||
if (does_list_contain(allNetworkNames, lastNetwork)) {
|
||||
nameOfElm =
|
||||
"networkEntry" + String(allNetworkNames.indexOf(lastNetwork));
|
||||
networkEntryElm = document.getElementById(nameOfElm);
|
||||
networkEntryElm.innerHTML = networkEntryElm.innerHTML.replace(
|
||||
" ",
|
||||
"✔"
|
||||
);
|
||||
} else {
|
||||
console.warn("Network is no longer valid");
|
||||
ipcRenderer.sendSync(
|
||||
"synchronous-message",
|
||||
"state:networkNoLongerValid"
|
||||
);
|
||||
}
|
||||
}
|
||||
setInterval(function(){
|
||||
|
||||
function selectNewNetwork(id) {
|
||||
idAsNumber = parseInt(id);
|
||||
newNetwork = allNetworkNames[id];
|
||||
ipcRenderer.sendSync("synchronous-message", "set:newNetwork|" + newNetwork);
|
||||
buildNetworkDropDown();
|
||||
|
||||
nameOfElm = "networkEntry" + String(idAsNumber);
|
||||
networkEntryElm = document.getElementById(nameOfElm);
|
||||
networkEntryElm.innerHTML = networkEntryElm.innerHTML.replace(
|
||||
" ",
|
||||
"✔"
|
||||
);
|
||||
//alert(newNetwork);
|
||||
}
|
||||
buildNetworkDropDown();
|
||||
</script>
|
||||
<script>
|
||||
// Battery info screen
|
||||
batteryExists = ipcRenderer.sendSync("synchronous-message", "hasBattery"); // prints "pong"
|
||||
var batteryShowdStart = false;
|
||||
if (batteryExists) {
|
||||
batteryLevel = ipcRenderer.sendSync(
|
||||
"synchronous-message",
|
||||
"getBatteryLevel"
|
||||
);
|
||||
|
||||
//Setup regular updates
|
||||
setInterval(function () {
|
||||
batteryLevel = parseInt(
|
||||
ipcRenderer.sendSync("synchronous-message", "getBatteryLevel")
|
||||
);
|
||||
|
||||
batteryShowdStart = true;
|
||||
if (batteryLevel > 75) {
|
||||
document.getElementById("battery").innerHTML = "";
|
||||
} else if (batteryLevel <= 75 && batteryLevel > 50) {
|
||||
document.getElementById("battery").innerHTML = "";
|
||||
} else if (batteryLevel <= 50 && batteryLevel > 25) {
|
||||
document.getElementById("battery").innerHTML = "";
|
||||
} else if (batteryLevel <= 25 && batteryLevel > 5) {
|
||||
document.getElementById("battery").innerHTML = "";
|
||||
} else {
|
||||
document.getElementById("battery").innerHTML = "";
|
||||
}
|
||||
}, 2000);
|
||||
} else {
|
||||
batteryShowdStart = true;
|
||||
}
|
||||
if (batteryShowdStart) {
|
||||
document.getElementById("loader").innerHTML = "";
|
||||
}
|
||||
|
||||
setInterval(function () {
|
||||
var date = new Date();
|
||||
hour = updateTime(date.getHours());
|
||||
min = updateTime(date.getMinutes());
|
||||
sec = updateTime(date.getSeconds());
|
||||
document.getElementById("clock").innerHTML = hour + ":" + min + ":" + sec;
|
||||
}, 200);
|
||||
document.getElementById("clock").innerHTML =
|
||||
hour + ":" + min + ":" + sec;
|
||||
}, 500);
|
||||
</script>
|
||||
<script>
|
||||
window.onclick = function (event) {
|
||||
if (!event.target.matches("#networkBtn")) {
|
||||
var dropdowns = document.getElementsByClassName("dropdown-content");
|
||||
var i;
|
||||
for (i = 0; i < dropdowns.length; i++) {
|
||||
var openDropdown = dropdowns[i];
|
||||
if (openDropdown.classList.contains("show")) {
|
||||
openDropdown.classList.remove("show");
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<h1>Hello World!</h1>
|
||||
We are using node
|
||||
|
@ -5,8 +5,9 @@
|
||||
<title>Enlight - Starting</title>
|
||||
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
|
||||
<link href="static/default.css" rel="stylesheet"/>
|
||||
<link href="static/fontawesome-free-5.15.1-web/css/all.css" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
<body class="fa-spin">
|
||||
<center>
|
||||
|
||||
<img src="static/icon.png" alt="Logo" height="40px"></img>
|
||||
|
@ -21,8 +21,6 @@ small {
|
||||
}
|
||||
|
||||
.header-clock {
|
||||
right: 0px;
|
||||
position: fixed;
|
||||
padding: 2px;
|
||||
padding-right: 4px;
|
||||
}
|
||||
@ -32,4 +30,38 @@ small {
|
||||
position: fixed;
|
||||
padding: 2px;
|
||||
padding-right: 4px;
|
||||
}
|
||||
}
|
||||
.loader1 {
|
||||
position: fixed;
|
||||
right: 80px;
|
||||
}
|
||||
|
||||
.areaRight {
|
||||
float: right;
|
||||
}
|
||||
|
||||
.dropdown-content {
|
||||
display: none;
|
||||
position: absolute;
|
||||
background-color: #f1f1f1;
|
||||
min-width: 160px;
|
||||
overflow: auto;
|
||||
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
|
||||
z-index: 1;
|
||||
right: 0px;
|
||||
}
|
||||
|
||||
.dropdown-content a {
|
||||
color: black;
|
||||
padding: 12px 16px;
|
||||
text-decoration: none;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.dropdown a:hover {background-color: #ddd;}
|
||||
|
||||
.show {display: block;}
|
||||
|
||||
network{
|
||||
cursor: pointer;
|
||||
}
|
4
ui_templates/static/jquery-1.7.1.min.js
vendored
Normal file
4
ui_templates/static/jquery-1.7.1.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
23
ui_templates/static/js/helper.js
Normal file
23
ui_templates/static/js/helper.js
Normal file
@ -0,0 +1,23 @@
|
||||
function encode_html(rawStr) {
|
||||
var encodedStr = rawStr.replace(/[\u00A0-\u9999<>\&]/g, function (i) {
|
||||
return "&#" + i.charCodeAt(0) + ";";
|
||||
});
|
||||
|
||||
return encodedStr;
|
||||
}
|
||||
|
||||
function does_list_contain(list, needle) {
|
||||
if (list.indexOf(needle) >= 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function updateTime(k) {
|
||||
if (k < 10) {
|
||||
return "0" + k;
|
||||
} else {
|
||||
return k;
|
||||
}
|
||||
}
|
1
usrStore/lastNetwork.data
Normal file
1
usrStore/lastNetwork.data
Normal file
@ -0,0 +1 @@
|
||||
Microsoft Loopbackadapter f<>r KM-TEST
|
Reference in New Issue
Block a user