Skip to content

Commit 6a885b7

Browse files
fix(desktop): reconnect to the shortcut portal as soon as it goes away
Waiting for a new portal owner left the shortcut stuck in a pending 'Reconnecting…' state when nothing restarted xdg-desktop-portal. Reconnecting at once sends Register to the well-known name, which D-Bus-activates the portal, or fails through the existing error path with retry available. AI-assisted; verified with the tests and tools listed above.
1 parent 1e40329 commit 6a885b7

2 files changed

Lines changed: 4 additions & 7 deletions

File tree

‎apps/desktop/src/snapShot/PortalCaptureShortcut.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,8 @@ it("handles a disappearing portal without keeping a false registered state", asy
341341
expect(client.state.shortcutMessage).toContain("restarted");
342342
expect(client.hasSession).toBe(false);
343343
expect(bus.disconnect).not.toHaveBeenCalled();
344+
await vi.waitFor(() => expect(client.state.shortcutRegistered).toBe(true));
345+
expect(bus.calls.filter((call) => call.member === "CreateSession")).toHaveLength(2);
344346
});
345347

346348
it("binds a new session when the portal restarts", async () => {

‎apps/desktop/src/snapShot/PortalCaptureShortcut.ts‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ export class PortalCaptureShortcut {
6868
readonly ready: Promise<void>;
6969
private closed = false;
7070
private connection = 0;
71-
private portalLost = false;
7271
private owner = "";
7372
private namespace = "";
7473
private session = "";
@@ -126,8 +125,6 @@ export class PortalCaptureShortcut {
126125
}
127126

128127
private portalGone() {
129-
this.connection++;
130-
this.portalLost = true;
131128
this.rejectStopped(new Error("The desktop shortcut service restarted."));
132129
this.resetStopped();
133130
this.owner = "";
@@ -140,6 +137,8 @@ export class PortalCaptureShortcut {
140137
shortcutPending: true,
141138
shortcutMessage: "The desktop shortcut service restarted. Reconnecting…",
142139
});
140+
// Register is sent to the well-known name, so it D-Bus-activates a portal that is not running.
141+
void this.connect();
143142
}
144143

145144
close = () => {
@@ -246,10 +245,6 @@ export class PortalCaptureShortcut {
246245
message.body[0] === PORTAL
247246
) {
248247
if (this.owner && message.body[1] === this.owner) this.portalGone();
249-
if (this.portalLost && message.body[2]) {
250-
this.portalLost = false;
251-
void this.connect();
252-
}
253248
return;
254249
}
255250
if (!this.owner || message.sender !== this.owner) return;

0 commit comments

Comments
 (0)