← Commit history
host: cache+replay hello on bridge reconnect (no stuck-provisional after bridge restart)
1 file changed
+14−1
host/native-host.js+14−1@@ -270,6 +270,12 @@ function pumpStdin() { const _id = (msg.profile && (msg.profile.email || msg.profile.id)) || 'default'; myBrowser = browser; myEmail = (msg.profile && msg.profile.email) || ''; // for autologin decryption acquireSingleton(`${browser}:${_id}`);+ // Cache the tagged hello so we can REPLAY it whenever we (re)connect to the bridge. The extension+ // only sends hello ONCE (when its connectNative port first opens); if the BRIDGE later restarts+ // (e.g. an update/refresh_bridges), the SW's port is unbroken so it never re-hellos - without a+ // replay the restarted bridge would leave this profile stuck as a provisional "pending-N" (unknown+ // version, not drivable by its real key) until the SW happens to restart minutes later.+ lastHello = msg; } sendToBridge(msg); }@@ -282,6 +288,7 @@ process.stdin.on('error', () => process.exit(0)); // frame like the `hello` handshake (the extension sends it the instant it connects) gets dropped and // the bridge never learns this profile. Flushed on bridge 'connect'. let outQueue = [];+let lastHello = null; // last tagged hello, re-sent on every bridge (re)connect so a restarted bridge re-learns us function sendToBridge(msg) { const line = JSON.stringify(msg) + '\n'; if (bridge && !bridge.destroyed) bridge.write(line);@@ -320,7 +327,13 @@ function connectBridge() { attempts++; const sock = net.connect(port, '127.0.0.1'); let buf = '';- sock.on('connect', () => { bridge = sock; everConnected = true; connectedAt = Date.now(); flushOut(); });+ sock.on('connect', () => {+ bridge = sock; everConnected = true; connectedAt = Date.now();+ // Re-announce ourselves FIRST so a freshly (re)started bridge immediately re-learns this profile ++ // version, instead of leaving us provisional until the SW next restarts. Idempotent on the bridge.+ if (lastHello) { try { sock.write(JSON.stringify(lastHello) + '\n'); } catch {} }+ flushOut();+ }); sock.on('data', (chunk) => { buf += chunk.toString('utf8'); let nl;