This repository has been archived by the owner on Jul 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathloader.html
104 lines (88 loc) · 4.32 KB
/
loader.html
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<html>
<head>
<link href="./default.css" rel="stylesheet" />
<script>
const {ipcRenderer} = require('electron')
const shell = require('electron').shell
const Store = require('electron-store');
const store = new Store({ watch: true });
let fullURL
let badgeHTML
let settingDisplayHTML
let serviceDownHTML
let updateAvailableHTML
let updateAvailable = false
let updateProgress = false
let updateComplete = false
let updateProgressMessage
// Inital page variables
fullURL = "https:\/\/" + store.get('server.URL') + "/ui"
badgeHTML = "<img src=\"./assets/icons/html5/HTML5_Badge_12.png\">"
serviceDownHTML = "<td><font color=\"red\">VMWare Cip Message Proxy Service is Stopped. <button class=\"button\" onclick=\"startCIPMessageProxy()\">Start Service</button></font></td>"
updateAvailableHTML = "<td><button class=\"button\" onclick=\"startUpdate()\">Download Update</button></font></td>"
finishUpdateHTML = "<td><button class=\"button\" onclick=\"finishUpdate()\">Install Update</button></td>"
// Allows Main process functions to update status bar
ipcRenderer.on('updateinfo', (event, message) => {
console.log(message)
if (message === "Update available") { updateAvailable = true }
if (message === "Download Complete") { updateProgress = false; updateComplete = true }
if (message.includes("Downloading")) { updateAvailable = false; updateProgress = true; updateProgressMessage = message }
updateSettingDisplayHTML()
})
// Update status bar
function updateSettingDisplayHTML() {
settingDisplayHTML = "<table class=\"status\"><tr>"
if (serviceStatus() == false) { settingDisplayHTML = settingDisplayHTML + serviceDownHTML }
if (updateAvailable) { settingDisplayHTML = settingDisplayHTML + updateAvailableHTML }
if (updateProgress) { settingDisplayHTML = settingDisplayHTML + "<td><font color=\"yellow\">" + updateProgressMessage + "</font></td>" }
if (updateComplete) { settingDisplayHTML = settingDisplayHTML + finishUpdateHTML }
settingDisplayHTML = settingDisplayHTML + "<td width=\"100%\"></td><td>Currently connected to: " + store.get('server.URL') + "</td><td></td><td>" + badgeHTML + "</td></tr></table>"
document.getElementById("settingdisplay").innerHTML = settingDisplayHTML
}
// Check whether CIP Message Proxy service is running
function serviceStatus() {
var child = require('child_process')
try {
var cmdOutput = child.execSync('sc query CipMsgProxyService | findstr STATE')
if (cmdOutput.includes("STOPPED")) {
return false
} else { return true }
}
catch(err) { return true }
}
// Send a request to Main process to start CIP Message Proxy service
function startCIPMessageProxy() {
ipcRenderer.send('start-service')
while (serviceStatus() == false) {
setTimeout(serviceStatus,1000)
}
}
// Send a request to Main process to download update
function startUpdate() {
ipcRenderer.send('start-update')
updateAvailable = false
}
// Send a request to Main process to install update
function finishUpdate() {
ipcRenderer.send('install-update')
}
// Load the page
function loadPage() {
// Send request to Main process to check whether updates are available
ipcRenderer.send('check-update-status')
document.getElementById("webview").innerHTML = "<webview id=\"host\" src=\"" + fullURL + "\" autosize></webview>"
updateSettingDisplayHTML()
var webview = document.getElementById('host')
var indicator = document.getElementById('indicator')
webview.addEventListener('new-window', (event) => {
shell.openExternal(event.url)
})
}
window.onload = loadPage
</script>
</head>
<body>
<div id="webview"></div>
<div id="settingdisplay" class="settingdisplay" align="right"></div>
</body>
</html>