From 97fe5046f68b5e4ee5f750945bcc39a27f5eb37b Mon Sep 17 00:00:00 2001
From: 苏向夜 <fu050409@163.com>
Date: Sun, 29 Mar 2026 00:54:21 +0800
Subject: chore(ui): refactor effect instance check

---
 packages/ui/src/components/instance-editor-modal.tsx | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

(limited to 'packages/ui/src/components/instance-editor-modal.tsx')

diff --git a/packages/ui/src/components/instance-editor-modal.tsx b/packages/ui/src/components/instance-editor-modal.tsx
index d964185..2a2bd7d 100644
--- a/packages/ui/src/components/instance-editor-modal.tsx
+++ b/packages/ui/src/components/instance-editor-modal.tsx
@@ -1,8 +1,8 @@
-import { invoke } from "@tauri-apps/api/core";
+
+import { toNumber } from "es-toolkit/compat";
 import { Folder, Loader2, Save, Trash2, X } from "lucide-react";
 import { useCallback, useEffect, useState } from "react";
 import { toast } from "sonner";
-
 import { Button } from "@/components/ui/button";
 import {
   Dialog,
@@ -14,12 +14,11 @@ import {
 } from "@/components/ui/dialog";
 import { Input } from "@/components/ui/input";
 import { Textarea } from "@/components/ui/textarea";
-
-import { toNumber } from "@/lib/tsrs-utils";
 import { useInstanceStore } from "@/models/instance";
 import { useSettingsStore } from "@/models/settings";
 import type { FileInfo } from "../types/bindings/core";
 import type { Instance } from "../types/bindings/instance";
+import { deleteInstanceFile, listInstanceDirectory, openFileExplorer } from "@/client";
 
 type Props = {
   open: boolean;
@@ -94,11 +93,8 @@ export function InstanceEditorModal({ open, instance, onOpenChange }: Props) {
       if (!instance) return;
       setLoadingFiles(true);
       try {
-        const files = await invoke<FileInfo[]>("list_instance_directory", {
-          instanceId: instance.id,
-          folder,
-        });
-        setFileList(files || []);
+        const files = await listInstanceDirectory(instance.id, folder);
+        setFileList(files);
       } catch (err) {
         console.error("Failed to load files:", err);
         toast.error("Failed to load files: " + String(err));
@@ -135,7 +131,7 @@ export function InstanceEditorModal({ open, instance, onOpenChange }: Props) {
     }
     setDeletingPath(filePath);
     try {
-      await invoke("delete_instance_file", { path: filePath });
+      await deleteInstanceFile(filePath);
       // refresh the currently selected folder
       await loadFileList(selectedFileFolder);
       toast.success("Deleted");
@@ -149,7 +145,7 @@ export function InstanceEditorModal({ open, instance, onOpenChange }: Props) {
 
   async function openInExplorer(filePath: string) {
     try {
-      await invoke("open_file_explorer", { path: filePath });
+      await openFileExplorer(filePath);
     } catch (err) {
       console.error("Failed to open in explorer:", err);
       toast.error("Failed to open file explorer: " + String(err));
-- 
cgit v1.2.3-70-g09d2


From 397cbb34b327a0addfdf8e36f859b456956b66fe Mon Sep 17 00:00:00 2001
From: 苏向夜 <fu050409@163.com>
Date: Sun, 29 Mar 2026 01:19:25 +0800
Subject: fix(lint): apply ui code lint

---
 packages/ui/src/components/bottom-bar.tsx            | 14 ++++++++++----
 packages/ui/src/components/instance-editor-modal.tsx | 15 +++++++++------
 packages/ui/src/models/auth.ts                       |  5 ++++-
 packages/ui/src/models/instance.ts                   |  5 ++++-
 packages/ui/src/pages/home-view.tsx                  | 10 +++++-----
 packages/ui/src/pages/index.tsx                      |  7 ++++++-
 packages/ui/src/pages/instances-view.tsx             | 16 ++++++++++++----
 packages/ui/src/stores/game-store.ts                 |  4 +++-
 8 files changed, 53 insertions(+), 23 deletions(-)

(limited to 'packages/ui/src/components/instance-editor-modal.tsx')

diff --git a/packages/ui/src/components/bottom-bar.tsx b/packages/ui/src/components/bottom-bar.tsx
index 8f70985..2746e00 100644
--- a/packages/ui/src/components/bottom-bar.tsx
+++ b/packages/ui/src/components/bottom-bar.tsx
@@ -21,13 +21,17 @@ export function BottomBar() {
   const account = useAuthStore((state) => state.account);
   const instances = useInstanceStore((state) => state.instances);
   const activeInstance = useInstanceStore((state) => state.activeInstance);
-  const setActiveInstance = useInstanceStore((state) => state.setActiveInstance);
+  const setActiveInstance = useInstanceStore(
+    (state) => state.setActiveInstance,
+  );
   const selectedVersion = useGameStore((state) => state.selectedVersion);
   const setSelectedVersion = useGameStore((state) => state.setSelectedVersion);
   const startGame = useGameStore((state) => state.startGame);
   const stopGame = useGameStore((state) => state.stopGame);
   const runningInstanceId = useGameStore((state) => state.runningInstanceId);
-  const launchingInstanceId = useGameStore((state) => state.launchingInstanceId);
+  const launchingInstanceId = useGameStore(
+    (state) => state.launchingInstanceId,
+  );
   const stoppingInstanceId = useGameStore((state) => state.stoppingInstanceId);
 
   const [showLoginModal, setShowLoginModal] = useState(false);
@@ -39,7 +43,7 @@ export function BottomBar() {
     }
 
     setSelectedVersion(nextVersion);
-  }, [activeInstance?.id, activeInstance?.versionId, selectedVersion, setSelectedVersion]);
+  }, [activeInstance?.versionId, selectedVersion, setSelectedVersion]);
 
   const handleInstanceChange = useCallback(
     async (instanceId: string) => {
@@ -47,7 +51,9 @@ export function BottomBar() {
         return;
       }
 
-      const nextInstance = instances.find((instance) => instance.id === instanceId);
+      const nextInstance = instances.find(
+        (instance) => instance.id === instanceId,
+      );
       if (!nextInstance) {
         return;
       }
diff --git a/packages/ui/src/components/instance-editor-modal.tsx b/packages/ui/src/components/instance-editor-modal.tsx
index 2a2bd7d..105d7e9 100644
--- a/packages/ui/src/components/instance-editor-modal.tsx
+++ b/packages/ui/src/components/instance-editor-modal.tsx
@@ -1,8 +1,12 @@
-
 import { toNumber } from "es-toolkit/compat";
 import { Folder, Loader2, Save, Trash2, X } from "lucide-react";
 import { useCallback, useEffect, useState } from "react";
 import { toast } from "sonner";
+import {
+  deleteInstanceFile,
+  listInstanceDirectory,
+  openFileExplorer,
+} from "@/client";
 import { Button } from "@/components/ui/button";
 import {
   Dialog,
@@ -18,7 +22,6 @@ import { useInstanceStore } from "@/models/instance";
 import { useSettingsStore } from "@/models/settings";
 import type { FileInfo } from "../types/bindings/core";
 import type { Instance } from "../types/bindings/instance";
-import { deleteInstanceFile, listInstanceDirectory, openFileExplorer } from "@/client";
 
 type Props = {
   open: boolean;
@@ -97,7 +100,7 @@ export function InstanceEditorModal({ open, instance, onOpenChange }: Props) {
         setFileList(files);
       } catch (err) {
         console.error("Failed to load files:", err);
-        toast.error("Failed to load files: " + String(err));
+        toast.error(`Failed to load files: ${String(err)}`);
         setFileList([]);
       } finally {
         setLoadingFiles(false);
@@ -137,7 +140,7 @@ export function InstanceEditorModal({ open, instance, onOpenChange }: Props) {
       toast.success("Deleted");
     } catch (err) {
       console.error("Failed to delete file:", err);
-      toast.error("Failed to delete file: " + String(err));
+      toast.error(`Failed to delete file: ${String(err)}`);
     } finally {
       setDeletingPath(null);
     }
@@ -148,7 +151,7 @@ export function InstanceEditorModal({ open, instance, onOpenChange }: Props) {
       await openFileExplorer(filePath);
     } catch (err) {
       console.error("Failed to open in explorer:", err);
-      toast.error("Failed to open file explorer: " + String(err));
+      toast.error(`Failed to open file explorer: ${String(err)}`);
     }
   }
 
@@ -180,7 +183,7 @@ export function InstanceEditorModal({ open, instance, onOpenChange }: Props) {
     } catch (err) {
       console.error("Failed to save instance:", err);
       setErrorMessage(String(err));
-      toast.error("Failed to save instance: " + String(err));
+      toast.error(`Failed to save instance: ${String(err)}`);
     } finally {
       setSaving(false);
     }
diff --git a/packages/ui/src/models/auth.ts b/packages/ui/src/models/auth.ts
index 9c814d2..d64b67a 100644
--- a/packages/ui/src/models/auth.ts
+++ b/packages/ui/src/models/auth.ts
@@ -95,7 +95,10 @@ export const useAuthStore = create<AuthState>((set, get) => ({
     } catch (error) {
       const message = getAuthErrorMessage(error);
       console.error("Failed to start Microsoft login:", error);
-      set({ loginMode: null, statusMessage: `Failed to start login: ${message}` });
+      set({
+        loginMode: null,
+        statusMessage: `Failed to start login: ${message}`,
+      });
       toast.error(`Failed to start Microsoft login: ${message}`);
     }
   },
diff --git a/packages/ui/src/models/instance.ts b/packages/ui/src/models/instance.ts
index e1eb7c1..2f338b5 100644
--- a/packages/ui/src/models/instance.ts
+++ b/packages/ui/src/models/instance.ts
@@ -26,7 +26,10 @@ interface InstanceState {
   setActiveInstance: (instance: Instance) => Promise<void>;
   duplicate: (id: string, newName: string) => Promise<Instance | null>;
   exportArchive: (id: string, archivePath: string) => Promise<void>;
-  importArchive: (archivePath: string, newName?: string) => Promise<Instance | null>;
+  importArchive: (
+    archivePath: string,
+    newName?: string,
+  ) => Promise<Instance | null>;
   repair: () => Promise<void>;
   get: (id: string) => Promise<Instance | null>;
 }
diff --git a/packages/ui/src/pages/home-view.tsx b/packages/ui/src/pages/home-view.tsx
index 6060370..da7238f 100644
--- a/packages/ui/src/pages/home-view.tsx
+++ b/packages/ui/src/pages/home-view.tsx
@@ -32,20 +32,20 @@ export function HomeView() {
 
   const handleSaturnTouchStart = (e: React.TouchEvent) => {
     if (e.touches && e.touches.length === 1) {
-        const clientX = e.touches[0].clientX;
-        saturn?.handleTouchStart(clientX);
+      const clientX = e.touches[0].clientX;
+      saturn?.handleTouchStart(clientX);
     }
   };
 
   const handleSaturnTouchMove = (e: React.TouchEvent) => {
     if (e.touches && e.touches.length === 1) {
-        const clientX = e.touches[0].clientX;
-        saturn?.handleTouchMove(clientX);
+      const clientX = e.touches[0].clientX;
+      saturn?.handleTouchMove(clientX);
     }
   };
 
   const handleSaturnTouchEnd = () => {
-      saturn?.handleTouchEnd();
+    saturn?.handleTouchEnd();
   };
 
   return (
diff --git a/packages/ui/src/pages/index.tsx b/packages/ui/src/pages/index.tsx
index bccca22..2acd377 100644
--- a/packages/ui/src/pages/index.tsx
+++ b/packages/ui/src/pages/index.tsx
@@ -22,7 +22,12 @@ export function IndexPage() {
     void initGameLifecycle().catch((error) => {
       console.error("Failed to initialize game lifecycle:", error);
     });
-  }, [authStore.init, settingsStore.refresh, instanceStore.refresh, initGameLifecycle]);
+  }, [
+    authStore.init,
+    settingsStore.refresh,
+    instanceStore.refresh,
+    initGameLifecycle,
+  ]);
 
   return (
     <div className="relative h-screen w-full overflow-hidden bg-background font-sans">
diff --git a/packages/ui/src/pages/instances-view.tsx b/packages/ui/src/pages/instances-view.tsx
index 07a2135..7bb3302 100644
--- a/packages/ui/src/pages/instances-view.tsx
+++ b/packages/ui/src/pages/instances-view.tsx
@@ -35,7 +35,9 @@ export function InstancesView() {
   const startGame = useGameStore((state) => state.startGame);
   const stopGame = useGameStore((state) => state.stopGame);
   const runningInstanceId = useGameStore((state) => state.runningInstanceId);
-  const launchingInstanceId = useGameStore((state) => state.launchingInstanceId);
+  const launchingInstanceId = useGameStore(
+    (state) => state.launchingInstanceId,
+  );
   const stoppingInstanceId = useGameStore((state) => state.stoppingInstanceId);
   const [isImporting, setIsImporting] = useState(false);
   const [repairing, setRepairing] = useState(false);
@@ -191,7 +193,8 @@ export function InstancesView() {
             const isRunning = runningInstanceId === instance.id;
             const isLaunching = launchingInstanceId === instance.id;
             const isStopping = stoppingInstanceId === instance.id;
-            const otherInstanceRunning = runningInstanceId !== null && !isRunning;
+            const otherInstanceRunning =
+              runningInstanceId !== null && !isRunning;
 
             return (
               <li
@@ -259,7 +262,10 @@ export function InstancesView() {
                           try {
                             await instancesStore.setActiveInstance(instance);
                           } catch (error) {
-                            console.error("Failed to set active instance:", error);
+                            console.error(
+                              "Failed to set active instance:",
+                              error,
+                            );
                             toast.error("Error setting active instance");
                             return;
                           }
@@ -284,7 +290,9 @@ export function InstancesView() {
                             () => undefined,
                           );
                         }}
-                        disabled={otherInstanceRunning || isLaunching || isStopping}
+                        disabled={
+                          otherInstanceRunning || isLaunching || isStopping
+                        }
                       >
                         {isLaunching || isStopping ? (
                           <span className="text-xs">...</span>
diff --git a/packages/ui/src/stores/game-store.ts b/packages/ui/src/stores/game-store.ts
index 1eaf7e7..7b6e746 100644
--- a/packages/ui/src/stores/game-store.ts
+++ b/packages/ui/src/stores/game-store.ts
@@ -70,7 +70,9 @@ export const useGameStore = create<GameState>((set, get) => ({
       });
 
       if (wasStopped) {
-        toast.success(`Stopped Minecraft ${versionId} for instance ${instanceId}`);
+        toast.success(
+          `Stopped Minecraft ${versionId} for instance ${instanceId}`,
+        );
       } else {
         toast.info(`Minecraft ${versionId} exited for instance ${instanceId}`);
       }
-- 
cgit v1.2.3-70-g09d2

