Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions desktop-ui/src/components/app/remote/remote-access-dialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
"use client";

import { useRef, useState } from "react";

import { Button } from "@/components/ui/button";
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import { accessRequestTitle } from "@/lib/util.remote-controls";
import { useRemote } from "@/providers/remote-provider";

/**
* Another machine asks this Mac for remote controls (docs/remote-machines.md, "Asking for
* access", step 4). The switches are machine-wide, so the question says so. Only `Allow` or
* `Don't allow` answers it: Escape and a click outside leave it to expire.
*/
export function RemoteAccessDialog() {
const { access } = useRemote();
if (!access) return null;
// A fresh dialog, and a cleared checkbox, for each request.
return <AccessRequestDialog key={access.requestId} />;
}

function AccessRequestDialog() {
const { access, answerAccess } = useRemote();
const [suppress, setSuppress] = useState(false);
// Focus lands on the dialog, not a button, so typing in a terminal can't answer it.
const popup = useRef<HTMLDivElement>(null);
if (!access) return null;

return (
<Dialog open onOpenChange={() => undefined}>
<DialogContent
ref={popup}
tabIndex={-1}
initialFocus={popup}
showCloseButton={false}
className="sm:max-w-md"
>
<DialogHeader>
<DialogTitle>{accessRequestTitle(access.name, access.fingerprint)}</DialogTitle>
<DialogDescription render={<div />}>
<p>
Allow every paired machine to start, stop and restart services on this Mac, until you
turn it off in Settings?
</p>
{access.wants === "backgroundStarts" ? (
<p className="mt-2">…also when Localify is closed here, in the background.</p>
) : null}
</DialogDescription>
<label className="mt-2 flex items-center gap-2 text-sm text-foreground">
<input
type="checkbox"
checked={suppress}
disabled={access.answering}
onChange={(event) => setSuppress(event.target.checked)}
className="size-4 accent-foreground"
/>
Don't ask again from {access.name}
</label>
{access.error ? (
<p role="alert" className="mt-2 text-sm text-destructive">
Could not answer the request: {access.error}
</p>
) : null}
</DialogHeader>
<DialogFooter>
<Button
variant="outline"
disabled={access.answering}
onClick={() => answerAccess(false, suppress)}
>
Don't allow
</Button>
<Button
variant="primary"
disabled={access.answering}
onClick={() => answerAccess(true, suppress)}
>
Allow
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}
25 changes: 25 additions & 0 deletions desktop-ui/src/components/app/remote/remote-command.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"use client";

import { CheckIcon, CopyIcon } from "@/components/icons";
import { Button } from "@/components/ui/button";
import { useCopyToClipboard } from "@/hooks/use-copy-to-clipboard";

/** A command to run on the target, with a copy button. */
export function RemoteCommand({ command }: { command: string }) {
const { copy, copied } = useCopyToClipboard();
return (
<div className="flex items-center gap-1 rounded-md bg-muted px-2 py-1">
<code className="min-w-0 flex-1 font-mono text-xs break-all text-foreground select-all">
{command}
</code>
<Button
size="icon-xs"
variant="ghost"
aria-label={copied ? "Command copied" : "Copy the command"}
onClick={() => void copy(command)}
>
{copied ? <CheckIcon className="text-emerald-500" /> : <CopyIcon />}
</Button>
</div>
);
}
Loading
Loading