The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 23, 04:15 UTC
fix(desktop): ignore snapshot shortcut repeats during flight (#11037)
Matthew Feroz committed
Oct 18, 2026 at 15:28 UTC
d6087091889a835faba58e0cf87e951aa9352a11
3 files changed
+79
-2
apps/desktop/src/snapShot/DesktopSnapShot.test.ts
+68
@@ -869,6 +869,69 @@ it.effect("captures the active Windows window without enumerating desktop source
869
).pipe(Effect.provide(layer));
870
});
871
872
+it.effect.each(["darwin", "win32"] as const)(
873
+ "drops shortcut bursts during flight and accepts a fresh capture after landing on %s",
874
+ (platform) => {
875
+ const fixture = concurrentCaptureFixture(platform, true);
876
+ fixture.releaseAll();
877
+ const flying = Promise.withResolvers<void>();
878
+ const heldFlights: Array<() => void> = [];
879
+ const push = heldFlights.push.bind(heldFlights);
880
+ vi.spyOn(heldFlights, "push").mockImplementation((...resolvers) => {
881
+ const count = push(...resolvers);
882
+ flying.resolve();
883
+ return count;
884
+ });
885
+ transitionScriptState.heldFlights = heldFlights;
886
+ return Effect.scoped(
887
+ Effect.gen(function* () {
888
+ const service = yield* DesktopSnapShot.make;
889
+ yield* service.configure(fixture.settings);
890
+ yield* Effect.promise(fixture.trigger);
891
+ const firstId = fixture.readyIds[0]!;
892
+ const landing = yield* service
893
+ .setAnimationDestination(firstId, {
894
+ frame: { x: 100, y: 400, width: 208, height: 112 },
895
+ backgroundColor: "#fff",
896
+ borderColor: "#ccc",
897
+ borderWidth: 1,
898
+ cornerRadius: 8,
899
+ scaleFactor: 1,
900
+ })
901
+ .pipe(Effect.forkChild({ startImmediately: true }));
902
+ yield* Effect.promise(() => flying.promise);
903
+ const overlayCount = flashWindows.length;
904
+
905
+ for (let repeat = 0; repeat < 20; repeat++) {
906
+ yield* TestClock.adjust("200 millis");
907
+ yield* Effect.promise(fixture.trigger);
908
+ }
909
+ assert.equal(fixture.state.snapshots, 1);
910
+ assert.lengthOf(fixture.readyIds, 1);
911
+ assert.lengthOf(flashWindows, overlayCount);
912
+ assert.isTrue(flashWindows.every((window) => !window.destroyed));
913
+
914
+ for (const finish of heldFlights) finish();
915
+ yield* Fiber.join(landing);
916
+ // Landing releases the guard even before the first capture is acknowledged.
917
+ yield* Effect.promise(fixture.trigger);
918
+ assert.equal(fixture.state.snapshots, 2);
919
+ assert.lengthOf(fixture.readyIds, 2);
920
+ assert.isTrue(fixture.second.oldOverlaysCleared);
921
+ }),
922
+ ).pipe(
923
+ Effect.provide(fixture.layer),
924
+ Effect.ensuring(
925
+ Effect.sync(() => {
926
+ for (const finish of heldFlights) finish();
927
+ transitionScriptState.heldFlights = null;
928
+ fixture.reset();
929
+ }),
930
+ ),
931
+ );
932
+ },
933
+);
934
+
935
it.effect.each([
936
{ length: 1_000, suffix: "", expectedLength: 1_000 },
937
{ length: 1_001, suffix: "", expectedLength: 1_000 },
@@ -2203,7 +2266,9 @@ it("does not flash a dismissed overlay after its initial compositor receipt arri
2266
true,
2267
);
2268
await readingFrame.promise;
2269
+ assert.isFalse(transition.isAnimating);
2270
transition.dismiss("capture-1");
2271
+ assert.isFalse(transition.isAnimating);
2272
frame.resolve();
2273
await begin;
2274
@@ -2292,7 +2357,9 @@ it("does not start a dismissed transition after its compositor receipt arrives",
2357
});
2358
const landing = transition.waitForLanding("capture-1");
2359
await readingFrame.promise;
2360
+ assert.isTrue(transition.isAnimating);
2361
transition.dismiss("capture-1");
2362
+ assert.isFalse(transition.isAnimating);
2363
frame.resolve();
2364
await landing;
2365
@@ -2424,6 +2491,7 @@ it("does not let a failed transition fail landing or capture completion", async
2491
});
2492
2493
await transition.waitForLanding("capture-1");
2494
+ assert.isFalse(transition.isAnimating);
2495
await transition.complete("capture-1");
2496
2497
assert.isTrue(flashWindows[0]?.destroyed);
apps/desktop/src/snapShot/DesktopSnapShot.ts
+3
-1
@@ -994,7 +994,9 @@ export const make = Effect.gen(function* () {
994
}).pipe(Effect.withSpan("desktop.snapShot.capture"));
995
996
const captureFromShortcut = Effect.gen(function* () {
997
- if (shortcutSuppressed) return;
997
+ // Repeated shortcuts must not tear down a moving capture and start another
998
+ // renderer. Drop them while the flight runs, just as during pixel acquisition.
999
+ if (shortcutSuppressed || transition.isAnimating) return;
1000
shortcutVerified = true;
1001
const now = yield* Clock.currentTimeNanos;
1002
if (lastShortcutAt !== undefined && now - lastShortcutAt < SHORTCUT_COOLDOWN_NS) return;
apps/desktop/src/snapShot/SnapShotTransition.ts
+8
-1
@@ -52,6 +52,7 @@ type ActiveTransition = {
52
details?: SnapShotAnimationDetails | undefined;
53
timer?: Fiber.Fiber<void> | undefined;
54
flight?: Promise<void> | undefined;
55
+ landed?: boolean | undefined;
56
};
57
58
type SnapShotTransitionOptions = {
@@ -206,6 +207,10 @@ export class SnapShotTransition {
207
private readonly alwaysOnTopLevel: SnapShotTransitionOptions["alwaysOnTopLevel"];
208
private readonly showWindow: (window: Electron.BaseWindow) => void;
209
210
+ get isAnimating(): boolean {
211
+ return this.active?.flight !== undefined && !this.active.landed;
212
+ }
213
+
214
constructor(options: SnapShotTransitionOptions = {}) {
215
this.boundOverlayToCaptureDisplays = options.boundOverlayToCaptureDisplays ?? false;
216
this.waitForCompositorFrame = options.waitForCompositorFrame ?? false;
@@ -350,7 +355,9 @@ export class SnapShotTransition {
355
}
356
return;
357
}
353
- active.flight = this.runFlight(active, destination);
358
+ active.flight = this.runFlight(active, destination).finally(() => {
359
+ active.landed = true;
360
+ });
361
}
362
363
private async runFlight(