Skip to content

Commit 2c8685a

Browse files
authored
Merge branch 'main' into t3/fork-checkout-options-rebased
2 parents 78619e3 + 1451e7c commit 2c8685a

233 files changed

Lines changed: 8077 additions & 1764 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/desktop-macos-preview.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ jobs:
7878
- name: Install browser secret helper build libraries
7979
run: sudo apt-get update && sudo apt-get install -y libsecret-1-dev pkg-config
8080

81+
# desktop-macos-preview-publish.yml packages this bundle as the preview channel.
8182
- name: Build JS bundle
83+
env:
84+
T3CODE_TELEMETRY_CHANNEL: ${{ github.repository == 'pingdotgg/t3code' && 'preview' || 'dev' }}
8285
run: vp run build:desktop
8386

8487
# Same layout as release.yml's js-bundle so release-desktop.yml can

‎.github/workflows/release-desktop.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,9 @@ jobs:
501501
# the runner, and only exact versions have a dist directory. Keep in
502502
# step with SEA_NODE_VERSION in apps/server/vite.config.ts.
503503
VP_NODE_VERSION: "26.8.2"
504+
# The executable bundles the server again, so it needs the same stamp
505+
# as release.yml's JS bundle.
506+
T3CODE_TELEMETRY_CHANNEL: ${{ github.repository == 'pingdotgg/t3code' && inputs.release_channel || 'dev' }}
504507
run: node apps/server/scripts/cli.ts build-exe --verbose
505508

506509
- name: Import macOS signing certificate for the CLI archive

‎.github/workflows/release.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,11 @@ jobs:
525525
# Runs t3#build (which depends on @t3tools/web#build) and
526526
# @t3tools/desktop#build, so apps/server/dist holds the server bundle
527527
# plus the web client and apps/desktop/dist-electron the Electron main.
528+
# The release channel is already stable, nightly, or preview. Builds in
529+
# other repositories report "dev" telemetry.
528530
- name: Build JS bundle
531+
env:
532+
T3CODE_TELEMETRY_CHANNEL: ${{ github.repository == 'pingdotgg/t3code' && needs.preflight.outputs.release_channel || 'dev' }}
529533
run: vp run build:desktop
530534

531535
# Two paths under apps/ so the artifact root is apps/; consumers download

‎apps/desktop/src/electron/ElectronProtocol.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ describe("ElectronProtocol", () => {
322322
]);
323323
assert.deepEqual(directives["media-src"], ["'self'", "t3code:", "blob:", "http:", "https:"]);
324324
assert.deepEqual(directives["frame-src"], ["'self'", "blob:", "http:", "https:"]);
325+
assert.deepEqual(directives["object-src"], ["'self'", "blob:", "http:", "https:"]);
325326
assert.deepEqual(directives["font-src"], ["'self'", "t3code:", "data:"]);
326327
});
327328
});

‎apps/desktop/src/electron/ElectronProtocol.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ export function makeDesktopContentSecurityPolicy(input: DesktopProtocolRegistrat
9595
`font-src 'self' ${input.scheme}: data:`,
9696
"worker-src 'self' blob:",
9797
"frame-src 'self' blob: http: https:",
98+
"object-src 'self' blob: http: https:",
9899
"form-action 'self'",
99100
].join("; ");
100101
}

‎apps/desktop/src/preview/BrowserSession.test.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ describe("BrowserSession", () => {
180180
for (const permission of [
181181
"clipboard-read",
182182
"clipboard-sanitized-write",
183-
"notifications",
184183
"geolocation",
185184
"fullscreen",
186185
]) {
@@ -194,7 +193,7 @@ describe("BrowserSession", () => {
194193
// `clipboard-write` is not a real Electron permission — the async write API
195194
// uses `clipboard-sanitized-write` — so the stale name must not be granted,
196195
// and unrelated permissions stay denied.
197-
for (const permission of ["clipboard-write", "midi"]) {
196+
for (const permission of ["clipboard-write", "notifications", "midi"]) {
198197
assert.isFalse(requestAllows(permission), `request handler should deny ${permission}`);
199198
assert.isFalse(
200199
checkHandler(null, permission) as boolean,

‎apps/desktop/src/preview/BrowserSession.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export type BrowserSessionPartitionNamespace = "profile";
3333
const ALLOWED_PREVIEW_PERMISSIONS: ReadonlySet<string> = new Set([
3434
"clipboard-read",
3535
"clipboard-sanitized-write",
36-
"notifications",
3736
"geolocation",
3837
// `DesktopWindow` disables HTML fullscreen window resizing for the app window
3938
// and every preview guest, so a page that goes fullscreen fills its own
@@ -42,6 +41,8 @@ const ALLOWED_PREVIEW_PERMISSIONS: ReadonlySet<string> = new Set([
4241
// Deliberately NOT local-fonts: preview sessions run untrusted web content,
4342
// and silently granting it would hand every page the user's installed-font
4443
// fingerprint (and font file bytes via FontData.blob()).
44+
// Deliberately NOT notifications: a page could post OS notifications branded
45+
// as T3 Code. T3's own come from the app window on the default session.
4546
]);
4647

4748
const NEVER_EXTERNAL_PROTOCOLS: ReadonlySet<string> = new Set([

‎apps/desktop/src/preview/Manager.test.ts‎

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,6 +1886,8 @@ describe("PreviewManager", () => {
18861886
const sendCommand = vi.fn<(method: string, params?: unknown) => Promise<unknown>>(
18871887
async () => undefined,
18881888
);
1889+
const detachListeners = new Set<() => void>();
1890+
let chromiumDetaches = 0;
18891891
let destroyed = false;
18901892
const wc = {
18911893
id,
@@ -1914,19 +1916,30 @@ describe("PreviewManager", () => {
19141916
setIgnoreMenuShortcuts: vi.fn(),
19151917
setWindowOpenHandler: vi.fn(),
19161918
debugger: {
1917-
isAttached: () => attach.mock.calls.length > detach.mock.calls.length,
1919+
isAttached: () => attach.mock.calls.length > detach.mock.calls.length + chromiumDetaches,
19181920
attach,
19191921
detach,
19201922
sendCommand,
1921-
on: vi.fn(),
1922-
off: vi.fn(),
1923+
on: (event: string, listener: () => void) => {
1924+
if (event === "detach") detachListeners.add(listener);
1925+
},
1926+
off: (event: string, listener: () => void) => {
1927+
if (event === "detach") detachListeners.delete(listener);
1928+
},
19231929
},
19241930
};
1931+
/** Chromium dropping the debugger without a detach() call. */
1932+
const chromiumDetach = () => {
1933+
chromiumDetaches += 1;
1934+
// Snapshot like an EventEmitter, so a listener added during emit waits for the next one.
1935+
for (const listener of Array.from(detachListeners)) listener();
1936+
};
19251937
return {
19261938
wc: wc as unknown as Electron.WebContents,
19271939
attach,
19281940
detach,
19291941
sendCommand,
1942+
chromiumDetach,
19301943
destroy: () => {
19311944
destroyed = true;
19321945
listeners.get("destroyed")?.();
@@ -1965,6 +1978,24 @@ describe("PreviewManager", () => {
19651978
),
19661979
);
19671980

1981+
effectIt.effect("reattaches a debugger that Chromium dropped on its own", () =>
1982+
withManager((manager) =>
1983+
Effect.gen(function* () {
1984+
const guest = makeAttachingGuest(48);
1985+
fromId.mockReturnValue(guest.wc);
1986+
yield* manager.createTab("tab_detached");
1987+
yield* manager.registerWebview("tab_detached", 48);
1988+
yield* Effect.yieldNow;
1989+
expect(guest.attach).toHaveBeenCalledTimes(1);
1990+
1991+
guest.chromiumDetach();
1992+
yield* Effect.yieldNow;
1993+
yield* Effect.yieldNow;
1994+
expect(guest.attach).toHaveBeenCalledTimes(2);
1995+
}),
1996+
),
1997+
);
1998+
19681999
effectIt.effect("skips a guest destroyed while another guest's session opens", () =>
19692000
withManager((manager) =>
19702001
Effect.gen(function* () {

‎apps/desktop/src/preview/Manager.ts‎

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,13 +1023,22 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
10231023
copy.delete(webContentsId);
10241024
}),
10251025
]);
1026-
if (control) {
1027-
if (closedServerTab) browserHost.detach(closedServerTab);
1028-
for (const tab of (yield* SynchronizedRef.get(tabsRef)).values()) {
1029-
if (tab.webContentsId === webContentsId && tab.serverTab) browserHost.detach(tab.serverTab);
1026+
if (control) yield* releaseControlSession(control, closedServerTab);
1027+
});
1028+
1029+
// Closes a session already removed from `controlSessionsRef`. The server can
1030+
// only drive a tab while the desktop holds its debugger.
1031+
const releaseControlSession = Effect.fnUntraced(function* (
1032+
control: BrowserControlSession,
1033+
closedServerTab?: PreviewTabState["serverTab"],
1034+
) {
1035+
if (closedServerTab) browserHost.detach(closedServerTab);
1036+
for (const tab of (yield* SynchronizedRef.get(tabsRef)).values()) {
1037+
if (tab.webContentsId === control.webContentsId && tab.serverTab) {
1038+
browserHost.detach(tab.serverTab);
10301039
}
1031-
yield* Scope.close(control.scope, Exit.void).pipe(Effect.ignore);
10321040
}
1041+
yield* Scope.close(control.scope, Exit.void).pipe(Effect.ignore);
10331042
});
10341043

10351044
const ensureControlSession = Effect.fn("PreviewManager.ensureControlSession")(function* (
@@ -1141,23 +1150,36 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
11411150
const onMessage: BrowserControlSession["onMessage"] = (_event, method, params) => {
11421151
runFork(handleDebuggerMessage(method, params));
11431152
};
1144-
yield* Scope.addFinalizer(
1145-
scope,
1146-
attempt({ operation: "detachControlSession", webContentsId: wc.id }, () => {
1147-
wcDebugger.off("message", onMessage);
1148-
if (wcDebugger.isAttached()) wcDebugger.detach();
1149-
}).pipe(Effect.ignore),
1150-
);
11511153
const control: BrowserControlSession = {
11521154
webContentsId: wc.id,
11531155
debugger: wcDebugger,
11541156
semaphore,
11551157
scope,
11561158
onMessage,
11571159
};
1160+
// Electron emits `detach` when Chromium closes the debugger session on its
1161+
// own. The cached session would then fail every command until the webview
1162+
// is replaced.
1163+
let dropped = false;
1164+
const onDetach = () => {
1165+
dropped = true;
1166+
runFork(recoverDetachedControlSession(wc, control));
1167+
};
1168+
// The listener comes off before detach() so a detach this manager requested
1169+
// never looks like a dropped one. A dropped session has nothing left to
1170+
// detach: `wc.debugger` is shared, so detaching here would hit a successor.
1171+
yield* Scope.addFinalizer(
1172+
scope,
1173+
attempt({ operation: "detachControlSession", webContentsId: wc.id }, () => {
1174+
wcDebugger.off("message", onMessage);
1175+
wcDebugger.off("detach", onDetach);
1176+
if (!dropped && wcDebugger.isAttached()) wcDebugger.detach();
1177+
}).pipe(Effect.ignore),
1178+
);
11581179
const initialize = Effect.fn("PreviewManager.initializeControlSession")(function* () {
11591180
yield* attempt({ operation: "attachDebuggerListeners", webContentsId: wc.id }, () => {
11601181
wcDebugger.on("message", onMessage);
1182+
wcDebugger.on("detach", onDetach);
11611183
wcDebugger.attach("1.3");
11621184
});
11631185
// Without this, dark-scheme pages with no background of their own (text/plain, e.g.
@@ -2356,6 +2378,30 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
23562378
}
23572379
}).pipe(Effect.ignore);
23582380

2381+
// Only the session that saw the detach is replaced: by the time the event is
2382+
// handled the guest may already hold a newer one, which must stay.
2383+
const recoverDetachedControlSession = Effect.fn("PreviewManager.recoverDetachedControlSession")(
2384+
function* (wc: Electron.WebContents, detached: BrowserControlSession) {
2385+
const removed = yield* SynchronizedRef.modify(controlSessionsRef, (sessions) =>
2386+
sessions.get(wc.id) === detached
2387+
? ([
2388+
true,
2389+
replaceMap(sessions, (copy) => {
2390+
copy.delete(wc.id);
2391+
}),
2392+
] as const)
2393+
: ([false, sessions] as const),
2394+
);
2395+
if (!removed) return;
2396+
yield* releaseControlSession(detached);
2397+
if (wc.isDestroyed()) return;
2398+
const tabId = yield* tabIdForWebContents(wc.id);
2399+
if (tabId === null) return;
2400+
yield* restoreControlSession(tabId, wc);
2401+
},
2402+
(recover) => Effect.ignore(recover),
2403+
);
2404+
23592405
const setColorScheme = Effect.fn("PreviewManager.setColorScheme")(function* (
23602406
tabId: string,
23612407
colorScheme: DesktopPreviewColorScheme,

‎apps/mobile/app.config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ const config: ExpoConfig = {
317317
},
318318
plugins: [
319319
"expo-asset",
320+
"react-native-pdf-jsi",
320321
[
321322
"expo-font",
322323
{

0 commit comments

Comments
 (0)