Skip to content

Commit 81a3765

Browse files
authored
Merge branch 'main' into t3code/fix-wrong-pr-autosettle
2 parents 54bca01 + db0659f commit 81a3765

13 files changed

Lines changed: 189 additions & 53 deletions

File tree

‎apps/desktop/src/app/DesktopAppIdentity.test.ts‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ describe("DesktopAppIdentity", () => {
199199
assert.equal(calls.setAboutPanelOptions[0]?.applicationName, "T3 Code (Alpha)");
200200
assert.equal(calls.setAboutPanelOptions[0]?.applicationVersion, "1.2.3");
201201
assert.equal(calls.setAboutPanelOptions[0]?.version, "0123456789ab");
202-
assert.deepEqual(calls.setDockIcon, ["/icon.png"]);
202+
// Packaged: the bundle's own icon stands, so a custom one the user
203+
// attached survives.
204+
assert.deepEqual(calls.setDockIcon, []);
203205
}),
204206
{
205207
calls,
@@ -212,4 +214,28 @@ describe("DesktopAppIdentity", () => {
212214
},
213215
);
214216
});
217+
218+
it.effect("sets the dock icon only when running unpackaged", () => {
219+
const calls: ElectronAppCalls = {
220+
setAboutPanelOptions: [],
221+
setDockIcon: [],
222+
setName: [],
223+
};
224+
225+
return withIdentity(
226+
Effect.gen(function* () {
227+
const identity = yield* DesktopAppIdentity.DesktopAppIdentity;
228+
yield* identity.configure;
229+
230+
// Electron shows a generic icon for an unpackaged run, which is the
231+
// reason this call exists at all.
232+
assert.deepEqual(calls.setDockIcon, ["/icon.png"]);
233+
}),
234+
{
235+
calls,
236+
environment: { isPackaged: false },
237+
pngIconPath: Option.some("/icon.png"),
238+
},
239+
);
240+
});
215241
});

‎apps/desktop/src/app/DesktopAppIdentity.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ export const make = Effect.gen(function* () {
134134
yield* electronApp.setDesktopName(environment.linuxDesktopEntryName);
135135
}
136136

137-
if (environment.platform === "darwin") {
137+
// Unpackaged runs only. A packaged bundle already carries its icon in
138+
// Info.plist, so setting the dock tile again changes nothing except to
139+
// overwrite a custom icon the user attached to the app themselves.
140+
if (environment.platform === "darwin" && !environment.isPackaged) {
138141
const iconPaths = yield* assets.iconPaths;
139142
yield* Option.match(iconPaths.png, {
140143
onNone: () => Effect.void,

‎apps/desktop/src/window/QuitHold.test.ts‎

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,32 @@ describe("makeQuitHoldHandler", () => {
7777
expect(harness.notifications).toEqual(["down", "up"]);
7878
});
7979

80-
it("quits once the shortcut auto-repeats past the hold duration", async () => {
80+
it("quits after a completed hold is released", async () => {
8181
const harness = makeHarness();
8282
await harness.send(makeInput({}));
83-
await harness.holdFor(QUIT_HOLD_DURATION_MS - 200);
83+
await harness.holdFor(QUIT_HOLD_DURATION_MS + 200);
84+
expect(harness.quit).not.toHaveBeenCalled();
85+
await harness.send(makeInput({ type: "keyUp", key: "Meta", meta: false }));
8486
expect(harness.quit).not.toHaveBeenCalled();
85-
await harness.holdFor(400);
87+
vi.advanceTimersByTime(QUIT_HOLD_RELEASE_GRACE_MS);
8688
expect(harness.quit).toHaveBeenCalledTimes(1);
87-
// Exactly one hint cycle for the whole hold.
8889
expect(harness.notifications).toEqual(["down", "up"]);
8990
});
9091

92+
it("waits for Q release when Cmd is released first", async () => {
93+
const harness = makeHarness();
94+
await harness.send(makeInput({}));
95+
await harness.holdFor(QUIT_HOLD_DURATION_MS + 200);
96+
await harness.send(makeInput({ type: "keyUp", key: "Meta", meta: false }));
97+
harness.preventDefault.mockClear();
98+
await harness.send(makeInput({ meta: false, isAutoRepeat: true }));
99+
expect(harness.preventDefault).toHaveBeenCalledTimes(1);
100+
vi.advanceTimersByTime(QUIT_HOLD_RELEASE_GRACE_MS * 2);
101+
expect(harness.quit).not.toHaveBeenCalled();
102+
await harness.send(makeInput({ type: "keyUp", meta: false }));
103+
expect(harness.quit).toHaveBeenCalledTimes(1);
104+
});
105+
91106
it("does not quit when the hold stops before the duration", async () => {
92107
const harness = makeHarness();
93108
await harness.send(makeInput({}));
@@ -107,12 +122,11 @@ describe("makeQuitHoldHandler", () => {
107122
expect(harness.quit).not.toHaveBeenCalled();
108123
});
109124

110-
it("quits immediately on a single press when disabled", async () => {
125+
it("quits without showing a hint when hold-to-quit is disabled", async () => {
111126
const harness = makeHarness({ enabled: false });
112127
await harness.send(makeInput({}));
113128
expect(harness.quit).toHaveBeenCalledTimes(1);
114-
// The hint is dismissed in case the quit gets cancelled downstream.
115-
expect(harness.notifications).toEqual(["down", "up"]);
129+
expect(harness.notifications).toEqual([]);
116130
});
117131

118132
it("discards a stale isEnabled resolution from a superseded press", async () => {
@@ -138,6 +152,7 @@ describe("makeQuitHoldHandler", () => {
138152
// Press #2 resolves enabled and completes a full hold.
139153
resolvers[1]?.(true);
140154
await harness.holdFor(QUIT_HOLD_DURATION_MS + 200);
155+
await harness.send(makeInput({ type: "keyUp" }));
141156
expect(harness.quit).toHaveBeenCalledTimes(1);
142157
});
143158

@@ -196,6 +211,7 @@ describe("makeQuitHoldHandler", () => {
196211
await harness.send(makeInput({ meta: false, control: true }));
197212
expect(harness.preventDefault).toHaveBeenCalledTimes(1);
198213
await harness.holdFor(QUIT_HOLD_DURATION_MS + 200, { meta: false, control: true });
214+
await harness.send(makeInput({ type: "keyUp", meta: false, control: true }));
199215
expect(harness.quit).toHaveBeenCalledTimes(1);
200216
});
201217
});

‎apps/desktop/src/window/QuitHold.ts‎

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22

33
// Chrome-style hold-to-quit. The quit accelerator is intercepted in
44
// before-input-event (which runs before the native menu accelerator), and the
5-
// app only quits once the shortcut has been held for QUIT_HOLD_DURATION_MS.
5+
// app only quits after the shortcut has been held for QUIT_HOLD_DURATION_MS
6+
// and released.
67
// A quick tap just shows the renderer's "Hold to Quit" hint, and a second tap
78
// within QUIT_DOUBLE_TAP_MS quits immediately. Quitting from the application
89
// menu itself is untouched and quits immediately.
910
export const QUIT_HOLD_DURATION_MS = 1200;
1011
// A second quick tap of the shortcut is the user insisting: quit immediately.
1112
export const QUIT_DOUBLE_TAP_MS = 500;
1213
// "Still held" is proven by auto-repeat keydowns, not by the absence of a
13-
// release: macOS suppresses a letter's keyUp while the command key is down, so
14-
// a tap's release can go completely unseen and a release-based timer would
15-
// quit anyway. The press is treated as released once no key event has arrived
16-
// for QUIT_HOLD_RELEASE_GRACE_MS past the hold duration. Keyboards with
17-
// auto-repeat disabled cannot hold-to-quit and fall back to the menu's Quit.
14+
// release: macOS suppresses a letter keyUp while the command key is down, so a
15+
// tap release can go completely unseen and a release-based timer would quit
16+
// anyway. Once held, quitting waits for Q keyUp or a quiet grace period after
17+
// modifier keyUp so repeats cannot reach the next app. Keyboards with
18+
// auto-repeat disabled fall back to the application menu Quit action.
1819
export const QUIT_HOLD_RELEASE_GRACE_MS = 600;
1920

2021
export type QuitHoldState = "down" | "up";
@@ -42,8 +43,9 @@ export function makeQuitHoldHandler(
4243
const modifierKey = options.platform === "darwin" ? "meta" : "control";
4344
let watchdog: NodeJS.Timeout | undefined;
4445
let holding = false;
45-
// Set once isEnabled resolves true; auto-repeats may only quit when armed.
46+
// Set once isEnabled resolves true; auto-repeats may only complete the hold when armed.
4647
let armed = false;
48+
let quitOnRelease = false;
4749
let heldSince = 0;
4850
let lastPressAt = 0;
4951
// Incremented on every new press and every release/quit so a pending
@@ -60,14 +62,16 @@ export function makeQuitHoldHandler(
6062

6163
const release = () => {
6264
if (!holding) return;
65+
const shouldNotify = armed || quitOnRelease;
6366
generation += 1;
6467
holding = false;
6568
armed = false;
69+
quitOnRelease = false;
6670
clearWatchdog();
67-
options.notify("up");
71+
if (shouldNotify) options.notify("up");
6872
};
6973

70-
// Dismisses the overlay first: if the quit is cancelled downstream the
74+
// Dismisses any overlay first: if the quit is cancelled downstream the
7175
// renderer must not be left with a stuck "Hold to Quit" hint.
7276
const quitNow = () => {
7377
release();
@@ -77,11 +81,27 @@ export function makeQuitHoldHandler(
7781
return (event, input) => {
7882
const key = input.key.toLowerCase();
7983
if (input.type === "keyUp") {
80-
if (key === "q" || key === modifierKey) release();
84+
if (key === "q") {
85+
const shouldQuit = quitOnRelease;
86+
release();
87+
if (shouldQuit) options.quit();
88+
} else if (key === modifierKey) {
89+
if (!quitOnRelease) {
90+
release();
91+
} else {
92+
watchdog = setTimeout(quitNow, QUIT_HOLD_RELEASE_GRACE_MS);
93+
}
94+
}
8195
return;
8296
}
8397
if (input.type !== "keyDown") return;
8498

99+
if (quitOnRelease && input.isAutoRepeat && key === "q") {
100+
event.preventDefault();
101+
clearWatchdog();
102+
return;
103+
}
104+
85105
const modifierDown = options.platform === "darwin" ? input.meta : input.control;
86106
if (!modifierDown || input.alt || input.shift || key !== "q") {
87107
// Any other key (or an extra modifier) pressed mid-hold breaks the
@@ -101,7 +121,9 @@ export function makeQuitHoldHandler(
101121

102122
if (input.isAutoRepeat) {
103123
if (armed && Date.now() - heldSince >= QUIT_HOLD_DURATION_MS) {
104-
quitNow();
124+
armed = false;
125+
quitOnRelease = true;
126+
clearWatchdog();
105127
}
106128
return;
107129
}
@@ -121,7 +143,6 @@ export function makeQuitHoldHandler(
121143
const pressGeneration = generation;
122144
holding = true;
123145
heldSince = now;
124-
options.notify("down");
125146
void options.isEnabled().then(
126147
(enabled) => {
127148
if (generation !== pressGeneration) return;
@@ -131,6 +152,7 @@ export function makeQuitHoldHandler(
131152
return;
132153
}
133154
armed = true;
155+
options.notify("down");
134156
// No auto-repeat by then means the key was released (possibly with a
135157
// suppressed keyUp) or repeat is disabled; either way, don't quit.
136158
watchdog = setTimeout(() => {

‎apps/server/src/pullRequest/GitHubPullRequestCli.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,8 +1451,7 @@ export const make = Effect.gen(function* () {
14511451
// the page. Narrowed to a command that ran and was refused: a missing `gh` or a
14521452
// signed-out one fails the same way for every request.
14531453
Effect.catchTags({
1454-
GitHubCliCommandError: (error) =>
1455-
filesPage(1).pipe(Effect.catch(() => Effect.fail(error))),
1454+
GitHubCliCommandError: (error) => filesPage(1).pipe(Effect.mapError(() => error)),
14561455
}),
14571456
);
14581457
},

‎apps/web/src/browser/browserTargetResolver.test.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,19 @@ describe("browser target resolver", () => {
173173
kind: "environment-port",
174174
port: 5173,
175175
}).resolvedUrl,
176-
).toBe("http://[::1]:5173/");
176+
).toBe("http://localhost:5173/");
177+
});
178+
179+
it("maps local IPv4 environment ports onto localhost for dual-stack guests", async () => {
180+
readPreparedConnection.mockReturnValue({ httpBaseUrl: "http://127.0.0.1:3773" });
181+
const { resolveBrowserNavigationTarget } = await import("./browserTargetResolver");
182+
expect(
183+
resolveBrowserNavigationTarget(EnvironmentId.make("environment-1"), {
184+
kind: "environment-port",
185+
port: 5173,
186+
path: "/app",
187+
}).resolvedUrl,
188+
).toBe("http://localhost:5173/app");
177189
});
178190

179191
it("leaves malformed input for the normal navigation error path", async () => {

‎apps/web/src/browser/browserTargetResolver.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,13 @@ const resolveEnvironmentPortTarget = (
178178
const protocol = target.protocol ?? "http";
179179
const path = target.path?.startsWith("/") ? target.path : `/${target.path ?? ""}`;
180180
const normalizedEnvironmentHost = environmentUrl.hostname.replace(/^\[|\]$/g, "");
181-
const resolvedHost = normalizedEnvironmentHost.includes(":")
182-
? `[${normalizedEnvironmentHost}]`
183-
: normalizedEnvironmentHost;
181+
// Local loopback environments should advertise `localhost` so Chromium
182+
// dual-stack lookup can reach a Vite server bound only to ::1 or 127.0.0.1.
183+
const resolvedHost = isLocalLoopbackHost(normalizedEnvironmentHost)
184+
? "localhost"
185+
: normalizedEnvironmentHost.includes(":")
186+
? `[${normalizedEnvironmentHost}]`
187+
: normalizedEnvironmentHost;
184188
const resolved = sourceUrl
185189
? new URL(sourceUrl)
186190
: new URL(path, `${protocol}://${resolvedHost}:${target.port}`);

‎apps/web/src/components/CommandPalette.logic.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,15 @@ export function buildProjectActionItems(input: {
150150
icon: (project: Project) => ReactNode;
151151
runProject: (project: Project) => Promise<void>;
152152
searchTerms?: (project: Project) => ReadonlyArray<string>;
153+
renderDescription?: (project: Project) => ReactNode;
153154
shortcutCommand?: KeybindingCommand;
154155
}): CommandPaletteActionItem[] {
155156
return input.projects.map((project) => ({
156157
kind: "action",
157158
value: `${input.valuePrefix}:${project.environmentId}:${project.id}`,
158159
searchTerms: [project.title, project.workspaceRoot, ...(input.searchTerms?.(project) ?? [])],
159160
title: project.title,
160-
description: project.workspaceRoot,
161+
description: input.renderDescription?.(project) ?? project.workspaceRoot,
161162
icon: input.icon(project),
162163
...(input.shortcutCommand !== undefined ? { shortcutCommand: input.shortcutCommand } : {}),
163164
run: async () => {

‎apps/web/src/components/CommandPalette.tsx‎

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import {
4141
LinkIcon,
4242
MessageSquareIcon,
4343
PaletteIcon,
44+
ServerIcon,
4445
SettingsIcon,
4546
SquarePenIcon,
4647
TextSearchIcon,
@@ -131,7 +132,11 @@ import { ProjectFavicon } from "./ProjectFavicon";
131132
import { ProjectFilePicker } from "./files/ProjectFilePicker";
132133
import { ProjectContentSearchDialog } from "./search/ProjectContentSearchDialog";
133134
import { toggleThemeEditorForTheme } from "./settings/themeEditorStore";
134-
import { ThreadCommandSubtitle } from "./ThreadCommandSubtitle";
135+
import {
136+
COMMAND_PALETTE_META_ICON_CLASS,
137+
CommandPaletteMetaDot,
138+
ThreadCommandSubtitle,
139+
} from "./ThreadCommandSubtitle";
135140
import { ThreadRowLeadingStatus, ThreadRowTrailingStatus } from "./ThreadStatusIndicators";
136141
import { primaryServerKeybindingsAtom, primaryServerProvidersAtom } from "../state/server";
137142
import {
@@ -657,6 +662,27 @@ function OpenCommandPaletteDialog(props: {
657662
),
658663
[environments],
659664
);
665+
const projectEnvironmentLocationById = useMemo(
666+
() =>
667+
new Map(
668+
environments.map((environment) => {
669+
const isPrimary = environment.entry.target._tag === "PrimaryConnectionTarget";
670+
const isLocal = isPrimary || isDesktopLocalConnectionTarget(environment.entry.target);
671+
return [
672+
environment.environmentId,
673+
{
674+
kind: isLocal ? "local" : "remote",
675+
label: isPrimary
676+
? "Local"
677+
: isLocal
678+
? `${environment.label} (Local)`
679+
: environment.label,
680+
},
681+
] as const;
682+
}),
683+
),
684+
[environments],
685+
);
660686
const orderedProjects = useMemo(
661687
() =>
662688
orderItemsByPreferredIds({
@@ -1011,8 +1037,29 @@ function OpenCommandPaletteDialog(props: {
10111037
valuePrefix: "new-thread-in",
10121038
searchTerms: (project) => {
10131039
const group = projectGroupByTargetKey.get(`${project.environmentId}:${project.id}`);
1040+
const location = projectEnvironmentLocationById.get(project.environmentId);
1041+
return [
1042+
...(group?.memberProjects.flatMap((member) => [member.title, member.workspaceRoot]) ??
1043+
[]),
1044+
...(location ? [location.label] : []),
1045+
];
1046+
},
1047+
renderDescription: (project) => {
1048+
const location = projectEnvironmentLocationById.get(project.environmentId) ?? {
1049+
kind: "remote",
1050+
label: "Remote",
1051+
};
10141052
return (
1015-
group?.memberProjects.flatMap((member) => [member.title, member.workspaceRoot]) ?? []
1053+
<span className="flex min-w-0 items-center gap-1">
1054+
<span className="inline-flex min-w-0 items-center gap-1">
1055+
{location.kind === "remote" ? (
1056+
<ServerIcon aria-hidden className={COMMAND_PALETTE_META_ICON_CLASS} />
1057+
) : null}
1058+
<span className="truncate">{location.label}</span>
1059+
</span>
1060+
<CommandPaletteMetaDot />
1061+
<span className="truncate">{project.workspaceRoot}</span>
1062+
</span>
10161063
);
10171064
},
10181065
icon: projectFavicon,
@@ -1033,7 +1080,13 @@ function OpenCommandPaletteDialog(props: {
10331080
},
10341081
}),
10351082
),
1036-
[contextualProjectRef, handleNewThread, pickerProjects, projectGroupByTargetKey],
1083+
[
1084+
contextualProjectRef,
1085+
handleNewThread,
1086+
pickerProjects,
1087+
projectEnvironmentLocationById,
1088+
projectGroupByTargetKey,
1089+
],
10371090
);
10381091

10391092
const allThreadItems = useMemo(

0 commit comments

Comments
 (0)