forked from Blendman974/faceclaw
Fix reconnect-loop issue when device MAC address is configured but not paired
This commit is contained in:
1 parent
1a1416c8f0
commit
16d3b7c25f
4 files changed
+126
-3
No files matched your search
@@ -220,6 +220,7 @@ class DashboardController {
|
||||
// underneath it, so it waits for this to clear.
|
||||
private connectRunning = false;
|
||||
private incompatibleDisconnectPending = false;
|
||||
private unpairedDisconnectPending = false;
|
||||
|
||||
constructor() {
|
||||
const sharedActions = {
|
||||
@@ -871,6 +872,14 @@ class DashboardController {
|
||||
this.appendLog(line);
|
||||
});
|
||||
this.offState = communicator.onStateChange((state) => {
|
||||
if (state.phase === "unpaired") {
|
||||
// Java parked its retry loop: an arm's Android bond is gone, so
|
||||
// every redial would fail the same way until the user re-pairs.
|
||||
// Tear down into the manual-disconnected state and keep the
|
||||
// re-pair instruction as the visible status.
|
||||
this.scheduleUnpairedDisconnect(state.status);
|
||||
return;
|
||||
}
|
||||
const mappedPhase =
|
||||
state.phase === "connected"
|
||||
? "connected"
|
||||
@@ -1132,6 +1141,40 @@ class DashboardController {
|
||||
setTimeout(attempt, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* A connect attempt found an arm whose Android bond is missing, so the Java
|
||||
* worker stopped retrying. Drop into the manual-disconnected state (no
|
||||
* auto-reconnect: it would just fail again) and leave the re-pair
|
||||
* instruction from Java as the status the user sees.
|
||||
*/
|
||||
private scheduleUnpairedDisconnect(message: string): void {
|
||||
if (this.unpairedDisconnectPending) return;
|
||||
this.unpairedDisconnectPending = true;
|
||||
const attempt = () => {
|
||||
// The unpaired report can arrive while connect() is still mid-flight;
|
||||
// let it finish so the teardown doesn't race its surface setup.
|
||||
if (this.connectRunning) {
|
||||
setTimeout(attempt, 200);
|
||||
return;
|
||||
}
|
||||
this.unpairedDisconnectPending = false;
|
||||
if (this.phase === "disconnected" || this.phase === "disconnecting") {
|
||||
// The session ended some other way; still stop auto-reconnect from
|
||||
// re-dialing glasses that are no longer paired.
|
||||
suppressAutoReconnect();
|
||||
this.setStatus(message);
|
||||
return;
|
||||
}
|
||||
this.appendLog(`Disconnecting: ${message} Auto-reconnect is disabled until you connect manually.`);
|
||||
void this.disconnect({ skipFirmwareCleanup: true })
|
||||
.then(() => this.setStatus(message))
|
||||
.catch((error) => {
|
||||
this.appendLog(`unpaired disconnect failed: ${this.formatError(error)}`);
|
||||
});
|
||||
};
|
||||
setTimeout(attempt, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tear down the connection and enter the manual-disconnected state: every
|
||||
* caller is deliberate (the phone/glasses Disconnect actions, entering the
|
||||
|
||||
@@ -11,6 +11,7 @@ export type CommunicatorPhase =
|
||||
| "connected"
|
||||
| "charging"
|
||||
| "retrying"
|
||||
| "unpaired"
|
||||
| "disconnecting";
|
||||
|
||||
export type CommunicatorState = {
|
||||
|
||||
Reference in new issue
Block a user