From c4bd0ad4104123046c7637b75b0a5fd64941a296 Mon Sep 17 00:00:00 2001
From: HsiangNianian <i@jyunko.cn>
Date: Tue, 13 Jan 2026 19:12:23 +0800
Subject: feat: update Microsoft account client ID and enhance login UX with
 clipboard and auto-open functionality

---
 ui/src/App.svelte | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

(limited to 'ui/src/App.svelte')

diff --git a/ui/src/App.svelte b/ui/src/App.svelte
index 8ec0da1..c3848b2 100644
--- a/ui/src/App.svelte
+++ b/ui/src/App.svelte
@@ -1,5 +1,6 @@
 <script lang="ts">
   import { invoke } from "@tauri-apps/api/core";
+  import { open } from "@tauri-apps/plugin-shell";
   import { onMount } from "svelte";
   import DownloadMonitor from "./lib/DownloadMonitor.svelte";
   import GameConsole from "./lib/GameConsole.svelte";
@@ -143,6 +144,17 @@
     msLoginLoading = true;
     try {
       deviceCodeData = await invoke("start_microsoft_login") as DeviceCodeResponse;
+      
+      // UX Improvements: Auto Copy & Auto Open
+      if (deviceCodeData) {
+          try {
+              await navigator.clipboard.writeText(deviceCodeData.user_code);
+              // alert("Code copied to clipboard: " + deviceCodeData.user_code); 
+          } catch (e) { console.error("Clipboard failed", e); }
+          
+          openLink(deviceCodeData.verification_uri);
+      }
+
     } catch(e) {
         alert("Failed to start Microsoft login: " + e);
         loginMode = 'select'; // Go back
@@ -159,17 +171,14 @@
         isLoginModalOpen = false;
     } catch(e) {
         alert("Login failed: " + e + "\n\nMake sure you authorized the app in your browser.");
+        // If it fails, users often want to retry checking without restarting the flow
     } finally {
         msLoginLoading = false;
     }
   }
 
   function openLink(url: string) {
-      // Use tauri open if possible, or window.open
-      invoke('start_microsoft_login').catch(() => window.open(url, '_blank'));
-      // Wait, we invoke 'start_microsoft_login' above already. 
-      // Just use window.open for the verification URI
-      window.open(url, '_blank');
+      open(url);
   }
 
   async function startGame() {
-- 
cgit v1.2.3-70-g09d2

