reconnect desktop on tunnel lost, add download logs button

This commit is contained in:
kulikov0 committed 2026-05-11 23:00:03 +02:00
1 parent c029fc8e50
commit 149c9d680c
6 files changed
+78 -10

No files matched your search

+26 -3
View File
@@ -34,6 +34,8 @@ import (
type statusEmitter struct{}
var tunnelLostCh = make(chan struct{}, 1)
func (statusEmitter) EmitStatus(status string) {
log.Printf("[status] %s", status)
// CAPTCHA:url is fired by the VK auth path when an interactive
@@ -42,8 +44,20 @@ func (statusEmitter) EmitStatus(status string) {
if strings.HasPrefix(status, "CAPTCHA:") {
fmt.Printf("STATUS:%s\n", status)
}
if status == common.StatusTunnelLost {
select {
case tunnelLostCh <- struct{}{}:
default:
}
}
}
func (statusEmitter) EmitStatusError(msg string) {
log.Printf("[status] ERROR: %s", msg)
select {
case tunnelLostCh <- struct{}{}:
default:
}
}
func (statusEmitter) EmitStatusError(msg string) { log.Printf("[status] ERROR: %s", msg) }
type fileCacheStore struct{ dir string }
@@ -234,13 +248,22 @@ func main() {
log.Fatalf("[config] unknown --platform %q", *platform)
}
<-sig
log.Printf("[main] shutting down")
var lost bool
select {
case <-sig:
log.Printf("[main] shutting down")
case <-tunnelLostCh:
log.Printf("[main] tunnel lost, exiting with code 2 to trigger auto-reconnect")
lost = true
}
if tun != nil {
tun.Stop()
}
// Give in-flight goroutines a beat to drain before the process exits.
time.Sleep(200 * time.Millisecond)
if lost {
os.Exit(2)
}
}
func splitCSV(s string) []string {
+1 -1
View File
@@ -79,7 +79,7 @@
</div>
</section>
<section class="log-wrap">
<h2>Log</h2>
<h2>Log <img class="log-download-btn" id="downloadLogs" src="resources/icons8-download-64.png" title="Download logs"></h2>
<pre id="log"></pre>
</section>
</main>
Binary file not shown.

After

Width:  |  Height:  |  Size: 374 B

+38 -5
View File
@@ -9,6 +9,11 @@ import { IPC, JoinerSettings } from '../constants';
let joinerProcess: ChildProcess | null = null;
let mainWindow: BrowserWindow | null = null;
let captchaWindow: BrowserWindow | null = null;
let userRequestedStop = false;
let reconnectTimer: NodeJS.Timeout | null = null;
let retryCount = 0;
let lastSettings: JoinerSettings | null = null;
const MAX_RETRIES = 8;
function openCaptchaWindow(url: string) {
if (captchaWindow && !captchaWindow.isDestroyed()) {
@@ -89,10 +94,7 @@ app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit();
});
ipcMain.handle(IPC.START, async (_e, settings: JoinerSettings) => {
if (joinerProcess) {
return { ok: false, error: 'joiner already running' };
}
function spawnJoiner(settings: JoinerSettings): { ok: boolean; error?: string } {
const exe = resolveJoinerExe();
if (!existsSync(exe)) {
return { ok: false, error: `desktop-joiner binary not found at ${exe}` };
@@ -142,7 +144,10 @@ ipcMain.handle(IPC.START, async (_e, settings: JoinerSettings) => {
const handleOutput = (text: string) => {
send(IPC.LOG, text);
if (text.includes('TUNNEL ACTIVE')) send(IPC.STATUS, 'active');
if (text.includes('TUNNEL CONNECTED')) send(IPC.STATUS, 'connected');
if (text.includes('TUNNEL CONNECTED')) {
send(IPC.STATUS, 'connected');
retryCount = 0;
}
const captchaMatch = text.match(/STATUS:CAPTCHA:(\S+)/);
if (captchaMatch) {
openCaptchaWindow(captchaMatch[1]);
@@ -158,11 +163,39 @@ ipcMain.handle(IPC.START, async (_e, settings: JoinerSettings) => {
send(IPC.STATUS, 'stopped');
send(IPC.RUNNING, false);
joinerProcess = null;
if (userRequestedStop || !lastSettings) return;
if (retryCount >= MAX_RETRIES) {
send(IPC.LOG, `[main] auto-reconnect: giving up after ${MAX_RETRIES} attempts\n`);
return;
}
retryCount++;
const delayMs = Math.min(30_000, 2_000 * 2 ** (retryCount - 1));
send(IPC.LOG, `[main] auto-reconnect attempt ${retryCount}/${MAX_RETRIES} in ${Math.round(delayMs / 1000)}s\n`);
reconnectTimer = setTimeout(() => {
reconnectTimer = null;
if (userRequestedStop || !lastSettings) return;
const r = spawnJoiner(lastSettings);
if (!r.ok) send(IPC.LOG, `[main] auto-reconnect spawn failed: ${r.error}\n`);
}, delayMs);
});
return { ok: true };
}
ipcMain.handle(IPC.START, async (_e, settings: JoinerSettings) => {
if (joinerProcess) {
return { ok: false, error: 'joiner already running' };
}
userRequestedStop = false;
retryCount = 0;
lastSettings = settings;
if (reconnectTimer) { clearTimeout(reconnectTimer); reconnectTimer = null; }
return spawnJoiner(settings);
});
ipcMain.handle(IPC.STOP, async () => {
userRequestedStop = true;
if (reconnectTimer) { clearTimeout(reconnectTimer); reconnectTimer = null; }
stopJoiner();
return { ok: true };
});
+10
View File
@@ -34,11 +34,21 @@ const logEl = $('log') as HTMLPreElement;
const statusEl = $('status');
const startBtn = $('start') as HTMLButtonElement;
const stopBtn = $('stop') as HTMLButtonElement;
const downloadLogsBtn = $('downloadLogs') as HTMLImageElement;
const platformHint = $('platformHint');
const linkInput = input('link');
stopBtn.disabled = true;
downloadLogsBtn.addEventListener('click', () => {
const blob = new Blob([logEl.textContent || ''], { type: 'text/plain' });
const anchor = document.createElement('a');
anchor.href = URL.createObjectURL(blob);
anchor.download = 'joiner-logs-' + new Date().toISOString().replace(/[:.]/g, '-') + '.txt';
anchor.click();
URL.revokeObjectURL(anchor.href);
});
function refreshPlatformHint() {
const p = detectPlatform(linkInput.value.trim());
platformHint.textContent = `Detected platform: ${platformLabel(p)}`;
+3 -1
View File
@@ -29,7 +29,9 @@ h1 { font-size: 14px; margin: 0; }
main { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 12px; min-height: 0; }
section.form { display: flex; flex-direction: column; gap: 10px; }
section.log-wrap { display: flex; flex-direction: column; min-height: 0; }
section.log-wrap h2 { font-size: 12px; margin: 0 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
section.log-wrap h2 { font-size: 12px; margin: 0 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; display: flex; align-items: center; }
.log-download-btn { width: 14px; height: 14px; margin-left: auto; cursor: pointer; filter: invert(0.55); }
.log-download-btn:hover { filter: invert(0.88); }
pre#log {
flex: 1; margin: 0; padding: 10px; background: var(--bg-elev);
border: 1px solid #2c2e35; border-radius: 6px;