mirror of
https://github.com/PR0M3TH3AN/VoxVera.git
synced 2025-09-08 23:18:42 +00:00
Merge pull request #85 from PR0M3TH3AN/codex/start-onionshare-and-generate-static-site
Improve OnionShare reliability
This commit is contained in:
@@ -6,6 +6,8 @@ const fs = require('fs');
|
|||||||
|
|
||||||
let mainWindow;
|
let mainWindow;
|
||||||
let onionProc;
|
let onionProc;
|
||||||
|
// 🔧 merged conflicting changes from codex/start-onionshare-and-generate-static-site vs main
|
||||||
|
let restarting = false;
|
||||||
|
|
||||||
function createWindow() {
|
function createWindow() {
|
||||||
mainWindow = new BrowserWindow({
|
mainWindow = new BrowserWindow({
|
||||||
@@ -18,6 +20,7 @@ function createWindow() {
|
|||||||
mainWindow.loadFile('index.html');
|
mainWindow.loadFile('index.html');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 🔧 merged conflicting changes from codex/start-onionshare-and-generate-static-site vs main
|
||||||
function startOnionShare() {
|
function startOnionShare() {
|
||||||
const configPath = getConfigPath();
|
const configPath = getConfigPath();
|
||||||
const voxveraPath = which.sync('voxvera', { nothrow: true });
|
const voxveraPath = which.sync('voxvera', { nothrow: true });
|
||||||
@@ -29,32 +32,55 @@ function startOnionShare() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const build = spawn(voxveraPath, ['--config', configPath, 'build']);
|
const build = spawn(voxveraPath, ['--config', configPath, 'build']);
|
||||||
build.on('close', () => {
|
build.on('error', err => {
|
||||||
const args = ['--config', configPath, 'serve'];
|
dialog.showErrorBox('voxvera build error', err.message);
|
||||||
onionProc = spawn(voxveraPath, args);
|
});
|
||||||
onionProc.stdout.on('data', data => {
|
build.on('close', code => {
|
||||||
const line = data.toString();
|
if (code !== 0) {
|
||||||
process.stdout.write(line);
|
dialog.showErrorBox('voxvera build error', `build exited with code ${code}.`);
|
||||||
if (mainWindow) {
|
return;
|
||||||
mainWindow.webContents.send('log', { text: line, isError: false });
|
}
|
||||||
}
|
runServe();
|
||||||
const m = line.match(/Onion URL:\s*(https?:\/\/[a-z0-9.-]+\.onion)/i);
|
});
|
||||||
if (m && mainWindow) {
|
}
|
||||||
mainWindow.webContents.send('onion-url', m[1]);
|
|
||||||
}
|
function runServe(retry = false) {
|
||||||
});
|
const configPath = getConfigPath();
|
||||||
onionProc.stderr.on('data', data => {
|
const voxveraPath = which.sync('voxvera', { nothrow: true });
|
||||||
const line = data.toString();
|
const args = ['--config', configPath, 'serve'];
|
||||||
process.stderr.write(line);
|
onionProc = spawn(voxveraPath, args);
|
||||||
if (mainWindow) {
|
onionProc.stdout.on('data', data => {
|
||||||
mainWindow.webContents.send('log', { text: line, isError: true });
|
const line = data.toString();
|
||||||
}
|
process.stdout.write(line);
|
||||||
});
|
if (mainWindow) {
|
||||||
onionProc.on('close', code => {
|
mainWindow.webContents.send('log', { text: line, isError: false });
|
||||||
if (code !== 0) {
|
}
|
||||||
dialog.showErrorBox('OnionShare error', `onionshare exited with code ${code}.`);
|
const m = line.match(/Onion URL:\s*(https?:\/\/[a-z0-9.-]+\.onion)/i);
|
||||||
}
|
if (m && mainWindow) {
|
||||||
});
|
mainWindow.webContents.send('onion-url', m[1]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
onionProc.stderr.on('data', data => {
|
||||||
|
const line = data.toString();
|
||||||
|
process.stderr.write(line);
|
||||||
|
if (mainWindow) {
|
||||||
|
mainWindow.webContents.send('log', { text: line, isError: true });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
onionProc.on('error', err => {
|
||||||
|
dialog.showErrorBox('OnionShare error', err.message);
|
||||||
|
});
|
||||||
|
onionProc.on('close', code => {
|
||||||
|
if ((code !== 0 && code !== null) || retry) {
|
||||||
|
dialog.showErrorBox('OnionShare error', `onionshare exited with code ${code}.`);
|
||||||
|
}
|
||||||
|
if (!restarting && (code !== 0 || code === null)) {
|
||||||
|
restarting = true;
|
||||||
|
setTimeout(() => {
|
||||||
|
restarting = false;
|
||||||
|
runServe(true);
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user