mirror of
https://github.com/PR0M3TH3AN/VoxVera.git
synced 2025-09-08 23:18:42 +00:00
gui: add form fields to edit config
This commit is contained in:
@@ -6,12 +6,40 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>VoxVera</h1>
|
<h1>VoxVera</h1>
|
||||||
<button id="quickstart">Quickstart</button>
|
<form id="config-form">
|
||||||
|
<div><label>Name <input type="text" id="name"></label></div>
|
||||||
|
<div><label>Subdomain <input type="text" id="subdomain"></label></div>
|
||||||
|
<div><label>Title <input type="text" id="title"></label></div>
|
||||||
|
<div><label>Subtitle <input type="text" id="subtitle"></label></div>
|
||||||
|
<div><label>Headline <input type="text" id="headline"></label></div>
|
||||||
|
<div><label>Content<br><textarea id="content" rows="5" cols="60"></textarea></label></div>
|
||||||
|
<div><label>URL Message <input type="text" id="url_message"></label></div>
|
||||||
|
<div><label>URL <input type="text" id="url"></label></div>
|
||||||
|
<div><label>Tear-off link <input type="text" id="tear_off_link"></label></div>
|
||||||
|
<div><label>Binary message <input type="text" id="binary_message"></label></div>
|
||||||
|
<button type="button" id="quickstart">Generate & Serve</button>
|
||||||
|
</form>
|
||||||
<p id="onion-address"></p>
|
<p id="onion-address"></p>
|
||||||
<script>
|
<script>
|
||||||
document.getElementById('quickstart').addEventListener('click', () => {
|
async function load() {
|
||||||
window.voxvera.quickstart();
|
const cfg = await window.voxvera.loadConfig();
|
||||||
|
for (const [k, v] of Object.entries(cfg)) {
|
||||||
|
const el = document.getElementById(k);
|
||||||
|
if (el) el.value = v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
document.addEventListener('DOMContentLoaded', load);
|
||||||
|
|
||||||
|
document.getElementById('quickstart').addEventListener('click', async () => {
|
||||||
|
const ids = ['name','subdomain','title','subtitle','headline','content','url_message','url','tear_off_link','binary_message'];
|
||||||
|
const cfg = {};
|
||||||
|
ids.forEach(id => {
|
||||||
|
const el = document.getElementById(id);
|
||||||
|
if (el) cfg[id] = el.value;
|
||||||
|
});
|
||||||
|
await window.voxvera.quickstart(cfg);
|
||||||
});
|
});
|
||||||
|
|
||||||
window.voxvera.onOnionUrl(url => {
|
window.voxvera.onOnionUrl(url => {
|
||||||
document.getElementById('onion-address').textContent = `Onion address: ${url}`;
|
document.getElementById('onion-address').textContent = `Onion address: ${url}`;
|
||||||
});
|
});
|
||||||
|
@@ -2,6 +2,7 @@ const { app, BrowserWindow, ipcMain, dialog } = require('electron');
|
|||||||
const { spawn } = require('child_process');
|
const { spawn } = require('child_process');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const which = require('which');
|
const which = require('which');
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
let mainWindow;
|
let mainWindow;
|
||||||
|
|
||||||
@@ -18,7 +19,21 @@ function createWindow() {
|
|||||||
|
|
||||||
app.whenReady().then(createWindow);
|
app.whenReady().then(createWindow);
|
||||||
|
|
||||||
ipcMain.handle('run-quickstart', async () => {
|
function getConfigPath() {
|
||||||
|
return path.join(__dirname, '..', '..', 'voxvera', 'src', 'config.json');
|
||||||
|
}
|
||||||
|
|
||||||
|
ipcMain.handle('load-config', async () => {
|
||||||
|
const p = getConfigPath();
|
||||||
|
const raw = fs.readFileSync(p, 'utf8');
|
||||||
|
return JSON.parse(raw);
|
||||||
|
});
|
||||||
|
|
||||||
|
ipcMain.handle('run-quickstart', async (_, config) => {
|
||||||
|
const configPath = getConfigPath();
|
||||||
|
if (config && typeof config === 'object') {
|
||||||
|
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
||||||
|
}
|
||||||
const voxveraPath = which.sync('voxvera', { nothrow: true });
|
const voxveraPath = which.sync('voxvera', { nothrow: true });
|
||||||
if (!voxveraPath) {
|
if (!voxveraPath) {
|
||||||
dialog.showErrorBox(
|
dialog.showErrorBox(
|
||||||
@@ -28,7 +43,7 @@ ipcMain.handle('run-quickstart', async () => {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const proc = spawn(voxveraPath, ['quickstart']);
|
const proc = spawn(voxveraPath, ['--config', configPath, 'quickstart']);
|
||||||
proc.stdout.on('data', data => {
|
proc.stdout.on('data', data => {
|
||||||
const line = data.toString();
|
const line = data.toString();
|
||||||
process.stdout.write(line);
|
process.stdout.write(line);
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
const { contextBridge, ipcRenderer } = require('electron');
|
const { contextBridge, ipcRenderer } = require('electron');
|
||||||
|
|
||||||
contextBridge.exposeInMainWorld('voxvera', {
|
contextBridge.exposeInMainWorld('voxvera', {
|
||||||
quickstart: () => ipcRenderer.invoke('run-quickstart'),
|
loadConfig: () => ipcRenderer.invoke('load-config'),
|
||||||
|
quickstart: (config) => ipcRenderer.invoke('run-quickstart', config),
|
||||||
onOnionUrl: (cb) => ipcRenderer.on('onion-url', (_, url) => cb(url))
|
onOnionUrl: (cb) => ipcRenderer.on('onion-url', (_, url) => cb(url))
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user