refactor(settings-view): streamline authentication status handling

- Removed unused state variables related to shortcut editing in the settings view.
- Updated authentication status handling for Claude and Codex to use more precise type definitions, improving type safety and clarity.
- Enhanced the ElectronAPI and SetupAPI interfaces to include optional properties for stored OAuth and API keys, ensuring better alignment with the runtime API responses.
This commit is contained in:
Kacper
2025-12-10 23:19:09 +01:00
parent 8a6309ccc9
commit 6086d22a44
2 changed files with 19 additions and 14 deletions

View File

@@ -41,7 +41,6 @@ import {
RefreshCw, RefreshCw,
Info, Info,
Keyboard, Keyboard,
RotateCcw,
} from "lucide-react"; } from "lucide-react";
import { getElectronAPI } from "@/lib/electron"; import { getElectronAPI } from "@/lib/electron";
import { import {
@@ -52,7 +51,7 @@ import {
DialogHeader, DialogHeader,
DialogTitle, DialogTitle,
} from "@/components/ui/dialog"; } from "@/components/ui/dialog";
import { useSetupStore } from "@/store/setup-store"; import { useSetupStore, type ClaudeAuthStatus, type CodexAuthStatus } from "@/store/setup-store";
import { KeyboardMap, ShortcutReferencePanel } from "@/components/ui/keyboard-map"; import { KeyboardMap, ShortcutReferencePanel } from "@/components/ui/keyboard-map";
import { Checkbox } from "../ui/checkbox"; import { Checkbox } from "../ui/checkbox";
@@ -163,9 +162,6 @@ export function SettingsView() {
hasOpenAIKey: boolean; hasOpenAIKey: boolean;
hasGoogleKey: boolean; hasGoogleKey: boolean;
} | null>(null); } | null>(null);
const [editingShortcut, setEditingShortcut] = useState<string | null>(null);
const [shortcutValue, setShortcutValue] = useState("");
const [shortcutError, setShortcutError] = useState<string | null>(null);
const scrollContainerRef = useRef<HTMLDivElement>(null); const scrollContainerRef = useRef<HTMLDivElement>(null);
// Get authentication status from setup store // Get authentication status from setup store
@@ -217,20 +213,19 @@ export function SettingsView() {
try { try {
const result = await api.setup.getClaudeStatus(); const result = await api.setup.getClaudeStatus();
if (result.success && result.auth) { if (result.success && result.auth) {
// Cast to any because runtime API returns more properties than type definition const auth = result.auth;
const auth = result.auth as any; const authStatus: ClaudeAuthStatus = {
const authStatus = {
authenticated: auth.authenticated, authenticated: auth.authenticated,
method: auth.method === "oauth_token" method: auth.method === "oauth_token"
? "oauth" ? "oauth"
: auth.method?.includes("api_key") : auth.method?.includes("api_key")
? "api_key" ? "api_key"
: "none", : "none",
hasCredentialsFile: false, hasCredentialsFile: auth.hasCredentialsFile ?? false,
oauthTokenValid: auth.hasStoredOAuthToken, oauthTokenValid: auth.hasStoredOAuthToken,
apiKeyValid: auth.hasStoredApiKey || auth.hasEnvApiKey, apiKeyValid: auth.hasStoredApiKey || auth.hasEnvApiKey,
}; };
setClaudeAuthStatus(authStatus as any); setClaudeAuthStatus(authStatus);
} }
} catch (error) { } catch (error) {
console.error("Failed to check Claude auth status:", error); console.error("Failed to check Claude auth status:", error);
@@ -242,13 +237,13 @@ export function SettingsView() {
try { try {
const result = await api.setup.getCodexStatus(); const result = await api.setup.getCodexStatus();
if (result.success && result.auth) { if (result.success && result.auth) {
// Cast to any because runtime API returns more properties than type definition const auth = result.auth;
const auth = result.auth as any; const authStatus: CodexAuthStatus = {
setCodexAuthStatus({
authenticated: auth.authenticated, authenticated: auth.authenticated,
method: auth.hasEnvApiKey ? "env" : auth.hasStoredApiKey ? "api_key" : "none", method: auth.hasEnvApiKey ? "env" : auth.hasStoredApiKey ? "api_key" : "none",
apiKeyValid: auth.hasStoredApiKey || auth.hasEnvApiKey, apiKeyValid: auth.hasStoredApiKey || auth.hasEnvApiKey,
}); };
setCodexAuthStatus(authStatus);
} }
} catch (error) { } catch (error) {
console.error("Failed to check Codex auth status:", error); console.error("Failed to check Codex auth status:", error);

View File

@@ -184,6 +184,9 @@ export interface ElectronAPI {
method: string; method: string;
hasCredentialsFile: boolean; hasCredentialsFile: boolean;
hasToken: boolean; hasToken: boolean;
hasStoredOAuthToken?: boolean;
hasStoredApiKey?: boolean;
hasEnvApiKey?: boolean;
}; };
error?: string; error?: string;
}>; }>;
@@ -198,6 +201,8 @@ export interface ElectronAPI {
method: string; method: string;
hasAuthFile: boolean; hasAuthFile: boolean;
hasEnvKey: boolean; hasEnvKey: boolean;
hasStoredApiKey?: boolean;
hasEnvApiKey?: boolean;
}; };
error?: string; error?: string;
}>; }>;
@@ -542,6 +547,9 @@ interface SetupAPI {
method: string; method: string;
hasCredentialsFile: boolean; hasCredentialsFile: boolean;
hasToken: boolean; hasToken: boolean;
hasStoredOAuthToken?: boolean;
hasStoredApiKey?: boolean;
hasEnvApiKey?: boolean;
}; };
error?: string; error?: string;
}>; }>;
@@ -556,6 +564,8 @@ interface SetupAPI {
method: string; method: string;
hasAuthFile: boolean; hasAuthFile: boolean;
hasEnvKey: boolean; hasEnvKey: boolean;
hasStoredApiKey?: boolean;
hasEnvApiKey?: boolean;
}; };
error?: string; error?: string;
}>; }>;