Skip to content

Commit 78af372

Browse files
feat(web): add an interactive 3D device workspace (pingdotgg#12787)
1 parent f1add18 commit 78af372

55 files changed

Lines changed: 4704 additions & 348 deletions

Some content is hidden

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

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ describe("ElectronProtocol", () => {
105105
);
106106
assert.include(
107107
response.headers.get("content-security-policy") ?? "",
108-
"connect-src 'self' http: https: ws: wss:",
108+
"connect-src 'self' blob: http: https: ws: wss:",
109109
);
110110
assert.include(
111111
response.headers.get("content-security-policy") ?? "",
@@ -255,7 +255,14 @@ describe("ElectronProtocol", () => {
255255
"https://clerk.t3.codes",
256256
"https://challenges.cloudflare.com",
257257
]);
258-
assert.deepEqual(directives["connect-src"], ["'self'", "http:", "https:", "ws:", "wss:"]);
258+
assert.deepEqual(directives["connect-src"], [
259+
"'self'",
260+
"blob:",
261+
"http:",
262+
"https:",
263+
"ws:",
264+
"wss:",
265+
]);
259266
assert.deepEqual(directives["img-src"], [
260267
"'self'",
261268
"t3code:",

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ export function makeDesktopContentSecurityPolicy(input: DesktopProtocolRegistrat
8484
// the build-configured Clerk, relay, and OTLP endpoints. Those environment
8585
// origins are not known when this response policy is created, so restrict
8686
// connections by the network schemes the client supports instead of by host.
87-
const connectSources = ["'self'", "http:", "https:", "ws:", "wss:"];
87+
// GLTFLoader fetches embedded textures through blob URLs after parsing the model.
88+
const connectSources = ["'self'", "blob:", "http:", "https:", "ws:", "wss:"];
8889

8990
return [
9091
"default-src 'self'",

‎apps/desktop/src/ipc/channels.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const MENU_ACTION_CHANNEL = "desktop:menu-action";
1111
export const PASTE_AS_TEXT_CHANNEL = "desktop:paste-as-text";
1212
export const SNAP_SHOT_EVENT_CHANNEL = "desktop:snap-shot-event";
1313
export const QUIT_SHORTCUT_CHANNEL = "desktop:quit-shortcut";
14+
export const TRACKPAD_SCROLL_END_CHANNEL = "desktop:trackpad-scroll-end";
1415
export const GET_WINDOW_FULLSCREEN_STATE_CHANNEL = "desktop:get-window-fullscreen-state";
1516
export const WINDOW_FULLSCREEN_STATE_CHANNEL = "desktop:window-fullscreen-state";
1617
export const DESKTOP_APP_ACTIVATION_READY_CHANNEL = "desktop:app-activation-ready";

‎apps/desktop/src/preload.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ contextBridge.exposeInMainWorld("desktopBridge", {
7979
ipcRenderer.on(IpcChannels.SET_NOTIFICATION_BADGE_CHANNEL, handler);
8080
return () => ipcRenderer.removeListener(IpcChannels.SET_NOTIFICATION_BADGE_CHANNEL, handler);
8181
},
82+
onTrackpadScrollEnd: (listener) => {
83+
const handler = () => listener();
84+
ipcRenderer.on(IpcChannels.TRACKPAD_SCROLL_END_CHANNEL, handler);
85+
return () => ipcRenderer.removeListener(IpcChannels.TRACKPAD_SCROLL_END_CHANNEL, handler);
86+
},
8287
getSystemLocale: () => {
8388
const result = ipcRenderer.sendSync(IpcChannels.GET_SYSTEM_LOCALE_CHANNEL);
8489
return typeof result === "string" ? result : null;

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import * as ElectronWindow from "../electron/ElectronWindow.ts";
4949
import {
5050
MENU_ACTION_CHANNEL,
5151
SNAP_SHOT_EVENT_CHANNEL,
52+
TRACKPAD_SCROLL_END_CHANNEL,
5253
WINDOW_FULLSCREEN_STATE_CHANNEL,
5354
} from "../ipc/channels.ts";
5455
import * as DesktopServerExposure from "../backend/DesktopServerExposure.ts";
@@ -709,6 +710,30 @@ describe("DesktopWindow", () => {
709710
}),
710711
);
711712

713+
it.effect("forwards native trackpad release to the renderer", () =>
714+
Effect.gen(function* () {
715+
const fakeWindow = makeFakeBrowserWindow();
716+
const send = vi.spyOn(fakeWindow.window.webContents, "send");
717+
const createCount = yield* Ref.make(0);
718+
const mainWindow = yield* Ref.make<Option.Option<Electron.BrowserWindow>>(Option.none());
719+
const layer = makeTestLayer({ window: fakeWindow.window, createCount, mainWindow });
720+
721+
yield* Effect.gen(function* () {
722+
const desktopWindow = yield* DesktopWindow.DesktopWindow;
723+
yield* desktopWindow.handleBackendReady(new URL("http://127.0.0.1:3773"));
724+
const onInput = fakeWindow.webContentsListeners.get("input-event");
725+
if (!onInput) return yield* Effect.die("input-event listener was not registered");
726+
onInput({}, { type: "gestureScrollUpdate" });
727+
assert.notInclude(
728+
send.mock.calls.map(([channel]) => channel),
729+
TRACKPAD_SCROLL_END_CHANNEL,
730+
);
731+
onInput({}, { type: "gestureScrollEnd" });
732+
assert.isTrue(send.mock.calls.some(([channel]) => channel === TRACKPAD_SCROLL_END_CHANNEL));
733+
}).pipe(Effect.provide(layer));
734+
}),
735+
);
736+
712737
// Chromium hands the main window's zoom level down to embedded preview
713738
// guests, so every app zoom has to put the preview browser back at its own
714739
// zoom or zooming the UI drags the previewed page with it.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
MENU_ACTION_CHANNEL,
2323
QUIT_SHORTCUT_CHANNEL,
2424
SNAP_SHOT_EVENT_CHANNEL,
25+
TRACKPAD_SCROLL_END_CHANNEL,
2526
WINDOW_FULLSCREEN_STATE_CHANNEL,
2627
} from "../ipc/channels.ts";
2728
import * as PreviewManager from "../preview/Manager.ts";
@@ -661,6 +662,9 @@ export const make = Effect.gen(function* () {
661662
event.preventDefault();
662663
}
663664
});
665+
window.webContents.on("input-event", (_event, input) => {
666+
if (input.type === "gestureScrollEnd") window.webContents.send(TRACKPAD_SCROLL_END_CHANNEL);
667+
});
664668

665669
window.on("page-title-updated", (event) => {
666670
event.preventDefault();

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

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import { ScrollArea } from "~/components/ui/scroll-area";
6363
import { PanelTabCloseButton } from "~/components/ui/panel-tab-close-button";
6464
import { faviconUrlForOrigin } from "~/lib/favicon";
6565
import { useTheme } from "~/hooks/useTheme";
66+
import { useDeviceState } from "~/state/device";
6667
import {
6768
newestPullRequestSummary,
6869
pullRequestEnvironment,
@@ -1244,7 +1245,17 @@ export function RightPanelTabs(props: RightPanelTabsProps) {
12441245
</button>
12451246
}
12461247
/>
1247-
<TooltipPopup>{title}</TooltipPopup>
1248+
<TooltipPopup>
1249+
{surface.kind === "device" ? (
1250+
<DeviceTabTooltip
1251+
surface={surface}
1252+
environmentId={props.environmentId}
1253+
title={title}
1254+
/>
1255+
) : (
1256+
title
1257+
)}
1258+
</TooltipPopup>
12481259
</Tooltip>
12491260
)}
12501261
</div>
@@ -1421,3 +1432,27 @@ export function RightPanelTabs(props: RightPanelTabsProps) {
14211432
</PreviewPanelShell>
14221433
);
14231434
}
1435+
1436+
function DeviceTabTooltip(props: {
1437+
surface: Extract<RightPanelSurface, { kind: "device" }>;
1438+
environmentId: EnvironmentId | null;
1439+
title: string;
1440+
}) {
1441+
const target = props.surface.target;
1442+
const { state } = useDeviceState(target ? props.environmentId : null);
1443+
const device = target
1444+
? state.devices.find((entry) => entry.hostId === target.hostId && entry.id === target.deviceId)
1445+
: undefined;
1446+
const host = target ? state.hosts.find((entry) => entry.id === target.hostId) : undefined;
1447+
return (
1448+
<div className="flex flex-col gap-0.5">
1449+
<span>{props.title}</span>
1450+
{target ? (
1451+
<span className="text-muted-foreground">
1452+
{host?.label ?? "Device host"} ·{" "}
1453+
{device?.version ?? (target.platform === "ios" ? "iOS" : "Android")}
1454+
</span>
1455+
) : null}
1456+
</div>
1457+
);
1458+
}

0 commit comments

Comments
 (0)