From 88633b8994437180afdd66068cc2c8f02aea1db1 Mon Sep 17 00:00:00 2001
From: Ellie Huxtable <ellie@elliehuxtable.com>
Date: Mon, 17 Jun 2024 15:36:38 +0100
Subject: feat(gui): automatically install and setup the cli/shell (#2139)

* feat(gui): automatically install and setup the cli/shell

* add shell config and toasts
---
 ui/src/pages/Home.tsx | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

(limited to 'ui/src/pages/Home.tsx')

diff --git a/ui/src/pages/Home.tsx b/ui/src/pages/Home.tsx
index 93f2bf93..00752326 100644
--- a/ui/src/pages/Home.tsx
+++ b/ui/src/pages/Home.tsx
@@ -2,6 +2,8 @@ import { useEffect } from "react";
 import { formatRelative } from "date-fns";
 
 import { useStore } from "@/state/store";
+import { useToast } from "@/components/ui/use-toast";
+import { invoke } from "@tauri-apps/api/core";
 
 function Stats({ stats }: any) {
   return (
@@ -47,10 +49,36 @@ export default function Home() {
   const user = useStore((state) => state.user);
   const refreshHomeInfo = useStore((state) => state.refreshHomeInfo);
   const refreshUser = useStore((state) => state.refreshUser);
+  const { toast } = useToast();
 
   useEffect(() => {
     refreshHomeInfo();
     refreshUser();
+
+    let setup = async () => {
+      let installed = await invoke("is_cli_installed");
+      console.log("CLI installation status:", installed);
+
+      if (!installed) {
+        toast({
+          title: "Atuin CLI",
+          description: "Started CLI setup and installation...",
+        });
+
+        console.log("Installing CLI...");
+        await invoke("install_cli");
+
+        console.log("Setting up plugin...");
+        await invoke("setup_cli");
+
+        toast({
+          title: "Atuin CLI",
+          description: "Installation complete",
+        });
+      }
+    };
+
+    setup();
   }, []);
 
   if (!homeInfo) {
-- 
cgit v1.3.1

