Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(desktop): integrate macOS window material in chrome layout

Richie McIlroyb8b843aee0a3
diff --git a/apps/desktop/src/routes/(window-chrome).tsx b/apps/desktop/src/routes/(window-chrome).tsx
index f430779b6..d2b63fde5 100644
--- a/apps/desktop/src/routes/(window-chrome).tsx
+++ b/apps/desktop/src/routes/(window-chrome).tsx
@@ -1,13 +1,20 @@
-import type { RouteSectionProps } from "@solidjs/router";
+import { type RouteSectionProps, useLocation } from "@solidjs/router";
import type { UnlistenFn } from "@tauri-apps/api/event";
import { getCurrentWindow } from "@tauri-apps/api/window";
import { type as ostype } from "@tauri-apps/plugin-os";
import { cx } from "cva";
-import { onCleanup, onMount, type ParentProps, Suspense } from "solid-js";
+import {
+ createEffect,
+ onCleanup,
+ onMount,
+ type ParentProps,
+ Suspense,
+} from "solid-js";
import { AbsoluteInsetLoader } from "~/components/Loader";
import CaptionControlsMacOS from "~/components/titlebar/controls/CaptionControlsMacOS";
import CaptionControlsWindows11 from "~/components/titlebar/controls/CaptionControlsWindows11";
+import { applyMacOSWindowMaterial } from "~/utils/macos-window-material";
import { initializeTitlebar } from "~/utils/titlebar-state";
import {
useWindowChromeContext,
@@ -16,6 +23,7 @@ import {
export default function (props: RouteSectionProps) {
let unlistenResize: UnlistenFn | undefined;
+ const location = useLocation();
onMount(async () => {
console.log("window chrome mounted");
@@ -47,11 +55,19 @@ export default function (props: RouteSectionProps) {
const isMacOS = ostype() === "macos";
+ createEffect(() => {
+ void applyMacOSWindowMaterial(
+ location.pathname.startsWith("/settings") ? "settings" : "panel",
+ ).catch((error) => {
+ console.error("Failed to apply macOS window material:", error);
+ });
+ });
+
return (
<WindowChromeContext>
<div
class={cx(
- "flex overflow-hidden flex-col w-screen h-screen max-h-screen divide-y divide-gray-5 bg-gray-1",
+ "cap-window-shell flex overflow-hidden flex-col w-screen h-screen max-h-screen divide-y divide-gray-5 bg-gray-1",
isMacOS && "rounded-[16px]",
)}
>
@@ -78,6 +94,7 @@ export default function (props: RouteSectionProps) {
function Header() {
const ctx = useWindowChromeContext();
+ const location = useLocation();
if (!ctx)
throw new Error(
"useWindowChrome must be used within a WindowChromeContext",
@@ -85,18 +102,21 @@ function Header() {
const isWindows = ostype() === "windows";
const isMacOS = ostype() === "macos";
+ const isSettings = () => location.pathname.startsWith("/settings");
+
+ if (isMacOS && isSettings()) return null;
return (
<header
class={cx(
- "flex items-center min-w-0 w-full h-9 select-none shrink-0 bg-gray-2",
+ "cap-window-header flex items-center min-w-0 w-full h-9 select-none shrink-0 bg-gray-2",
isWindows ? "flex-row" : "flex-row-reverse",
)}
data-tauri-drag-region
>
{ctx.state()?.items}
{isWindows && <CaptionControlsWindows11 class="ml-auto!" />}
- {isMacOS && (
+ {isMacOS && !isSettings() && (
<CaptionControlsMacOS
class="mr-auto! ml-3"
showMinimize={false}
@@ -109,13 +129,20 @@ function Header() {
function Inner(props: ParentProps) {
onMount(() => {
- if (location.pathname !== "/") getCurrentWindow().show();
+ const initialTargetMode = (
+ window as typeof window & {
+ __CAP__?: { initialTargetMode?: unknown };
+ }
+ ).__CAP__?.initialTargetMode;
+
+ if (location.pathname !== "/" || !initialTargetMode)
+ void getCurrentWindow().show();
});
return (
<div
data-tauri-drag-region="false"
- class="flex overflow-y-hidden flex-col flex-1 animate-in fade-in"
+ class="cap-window-body flex overflow-y-hidden flex-col flex-1 animate-in fade-in"
>
{props.children}
</div>