Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

1.6 KB
Raw Blame
// screenpipe — AI that knows everything you've seen, said, or heard
// https://screenpipe.com
import { Button } from "@/components/ui/button";
import {
  Dialog,
  DialogContent,
  DialogDescription,
  DialogHeader,
  DialogTitle,
} from "@/components/ui/dialog";
import { ExternalLinkIcon } from "lucide-react";
import { create } from "zustand";
import { commands } from "@/lib/utils/tauri";

export function LoginDialog() {
  const { isOpen, setIsOpen } = useLoginDialog();

  return (
    <Dialog open={isOpen} onOpenChange={setIsOpen}>
      <DialogContent>
        <DialogHeader>
          <DialogTitle>Login required</DialogTitle>
          <DialogDescription>
            Please login to continue. You will be redirected to screenpipe.com
          </DialogDescription>
        </DialogHeader>
        <div className="flex justify-end">
          <Button
            variant="default"
            onClick={() => {
              commands.openLoginWindow(null, null);
              setIsOpen(false);
            }}
          >
            Login <ExternalLinkIcon className="w-4 h-4 ml-2" />
          </Button>
        </div>
      </DialogContent>
    </Dialog>
  );
}

interface LoginDialogState {
  isOpen: boolean;
  setIsOpen: (open: boolean) => void;
  checkLogin: (user: any | null, showDialog?: boolean) => boolean;
}

export const useLoginDialog = create<LoginDialogState>((set) => ({
  isOpen: false,
  setIsOpen: (open) => set({ isOpen: open }),
  checkLogin: (user, showDialog = true) => {
    if (!user?.token) {
      if (showDialog) {
        set({ isOpen: true });
      }
      return false;
    }
    return true;
  },
}));