Merge pull request #78 from PR0M3TH3AN/codex/display-and-update-onion-address-in-gui

Display onion address in Electron GUI
This commit is contained in:
thePR0M3TH3AN
2025-06-21 14:36:54 -04:00
committed by GitHub
3 changed files with 22 additions and 4 deletions

View File

@@ -7,10 +7,14 @@
<body> <body>
<h1>VoxVera</h1> <h1>VoxVera</h1>
<button id="quickstart">Quickstart</button> <button id="quickstart">Quickstart</button>
<p id="onion-address"></p>
<script> <script>
document.getElementById('quickstart').addEventListener('click', () => { document.getElementById('quickstart').addEventListener('click', () => {
window.voxvera.quickstart(); window.voxvera.quickstart();
}); });
window.voxvera.onOnionUrl(url => {
document.getElementById('onion-address').textContent = `Onion address: ${url}`;
});
</script> </script>
</body> </body>
</html> </html>

View File

@@ -3,15 +3,17 @@ const { spawn } = require('child_process');
const path = require('path'); const path = require('path');
const which = require('which'); const which = require('which');
let mainWindow;
function createWindow() { function createWindow() {
const win = new BrowserWindow({ mainWindow = new BrowserWindow({
width: 800, width: 800,
height: 600, height: 600,
webPreferences: { webPreferences: {
preload: path.join(__dirname, 'preload.js') preload: path.join(__dirname, 'preload.js')
} }
}); });
win.loadFile('index.html'); mainWindow.loadFile('index.html');
} }
app.whenReady().then(createWindow); app.whenReady().then(createWindow);
@@ -26,7 +28,18 @@ ipcMain.handle('run-quickstart', async () => {
return -1; return -1;
} }
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const proc = spawn(voxveraPath, ['quickstart'], { stdio: 'inherit' }); const proc = spawn(voxveraPath, ['quickstart']);
proc.stdout.on('data', data => {
const line = data.toString();
process.stdout.write(line);
const m = line.match(/Onion URL:\s*(https?:\/\/[a-z0-9.-]+\.onion)/i);
if (m && mainWindow) {
mainWindow.webContents.send('onion-url', m[1]);
}
});
proc.stderr.on('data', data => {
process.stderr.write(data);
});
proc.on('close', code => resolve(code)); proc.on('close', code => resolve(code));
proc.on('error', err => reject(err)); proc.on('error', err => reject(err));
}); });

View File

@@ -1,5 +1,6 @@
const { contextBridge, ipcRenderer } = require('electron'); const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('voxvera', { contextBridge.exposeInMainWorld('voxvera', {
quickstart: () => ipcRenderer.invoke('run-quickstart') quickstart: () => ipcRenderer.invoke('run-quickstart'),
onOnionUrl: (cb) => ipcRenderer.on('onion-url', (_, url) => cb(url))
}); });