feat: Windows app (WPF + WebView2) #1
+25
-12
@@ -1,5 +1,6 @@
|
||||
using Microsoft.Web.WebView2.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
@@ -28,18 +29,25 @@ public partial class LoginWindow : Window
|
||||
{
|
||||
if (!e.IsSuccess) return;
|
||||
var uri = Browser.CoreWebView2.Source;
|
||||
if (uri.Contains("claude.ai") && !uri.Contains("/login"))
|
||||
if (!uri.Contains("claude.ai")) return;
|
||||
|
||||
var cookies = await Browser.CoreWebView2.CookieManager.GetCookiesAsync("https://claude.ai");
|
||||
var signedIn = cookies.Any(c =>
|
||||
c.Name.Equals("sessionKey", StringComparison.OrdinalIgnoreCase) ||
|
||||
c.Name.StartsWith("sk-ant", StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
await Dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
// Likely signed in — enable done button
|
||||
var cookies = await Browser.CoreWebView2.CookieManager.GetCookiesAsync("https://claude.ai");
|
||||
var hasSess = cookies.Any(c => c.Name.Contains("session") || c.Name.Contains("sk-"));
|
||||
await Dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
DoneButton.IsEnabled = hasSess || uri.Contains("/chats") || uri.Contains("/new");
|
||||
StatusText.Text = DoneButton.IsEnabled
|
||||
? "Signed in! Click Done to continue."
|
||||
: "Waiting for sign-in…";
|
||||
});
|
||||
DoneButton.IsEnabled = !uri.Contains("/login") && !uri.Contains("/signin");
|
||||
StatusText.Text = signedIn
|
||||
? "Signed in — click Done to continue."
|
||||
: "Complete sign-in, then click Done.";
|
||||
});
|
||||
|
||||
// Auto-close once clearly on the main app page
|
||||
if (signedIn && (uri.Contains("/chats") || uri.Contains("/new") || uri == "https://claude.ai/"))
|
||||
{
|
||||
await SaveAndClose(cookies);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -47,7 +55,12 @@ public partial class LoginWindow : Window
|
||||
private async void Done_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var cookies = await Browser.CoreWebView2.CookieManager.GetCookiesAsync("https://claude.ai");
|
||||
await SaveAndClose(cookies);
|
||||
}
|
||||
|
||||
private async Task SaveAndClose(IReadOnlyList<CoreWebView2Cookie> cookies)
|
||||
{
|
||||
UsageViewModel.SaveCookies(cookies);
|
||||
DialogResult = true;
|
||||
await Dispatcher.InvokeAsync(() => DialogResult = true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user