initial electron wrapper

This commit is contained in:
liamcottle
2024-05-27 17:31:20 +12:00
parent 9d1c0bce1a
commit 4cdc900133
8 changed files with 1089 additions and 0 deletions

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 KiB

View File

File diff suppressed because one or more lines are too long

70
electron/loading.html Normal file
View File

@@ -0,0 +1,70 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>Reticulum WebChat</title>
<script src="./assets/js/tailwindcss/tailwind-v3.4.3-forms-v0.5.7.js"></script>
</head>
<body class="bg-gray-100 flex">
<div class="flex flex-col mx-auto my-auto">
<!-- logo -->
<div class="mx-auto my-auto">
<img class="w-24 h-24" src="./assets/images/logo.png"/>
</div>
<!-- about -->
<div class="mx-auto text-center mb-2">
<div class="font-bold">Reticulum WebChat</div>
<div class="text-sm">v1.0.0 Developed by Liam Cottle</div>
</div>
<!-- loading spinner -->
<div class="mx-auto">
<svg class="animate-spin h-6 w-6 text-gray-500" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
</svg>
</div>
</div>
<script>
check();
async function check() {
try {
// fetch status api
const url = "http://localhost:9337/api/v1/status";
const result = await fetch(url, {
cache: "no-store", // don't read page from cache, we want to make sure server is up
});
// check status api says ok
const status = result.status;
const data = await result.json();
if(status === 200 && data.status === "ok"){
onReady();
return;
}
} catch(e) {}
// try again shortly
setTimeout(check, 250);
}
function onReady() {
window.location.href = "http://localhost:9337";
}
</script>
</body>
</html>

61
electron/main.js Normal file
View File

@@ -0,0 +1,61 @@
const { app, BrowserWindow } = require('electron');
const { spawn } = require('child_process');
const path = require('node:path');
// remember child process for exe so when can kill it when app exits
var exeChildProcess = null;
app.whenReady().then(async () => {
// create browser window
const win = new BrowserWindow({
width: 1024,
height: 768,
})
// navigate to loading page
await win.loadFile(path.join(__dirname, 'loading.html'));
// find path to reticulum webchat python/cxfreexe executable
const exe = path.join(__dirname, '..', 'build/exe.macosx-12.4-x86_64-3.11/ReticulumWebChat');
// spawn exe
exeChildProcess = spawn(exe, [
'--headless',
'--port', '9337', // FIXME: let system pick a random unused port?
]);
// listen to stdout
exeChildProcess.stdout.setEncoding('utf8');
exeChildProcess.stdout.on('data', function(data) {
console.log('stdout: ' + data);
});
// listen to stderror
exeChildProcess.stderr.setEncoding('utf8');
exeChildProcess.stderr.on('data', function(data) {
console.log('stderr: ' + data);
});
// listen to process exit
exeChildProcess.on('exit', function(code) {
console.log("exit: " + code);
});
});
function quit() {
// kill python process
if(exeChildProcess){
exeChildProcess.kill();
}
// quit electron app
app.quit();
}
app.on('window-all-closed', () => {
quit();
});