mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-25 13:45:03 +08:00
e7badb1a24
* refactor(ui): simplify UpdateBadge to minimal dot indicator * feat(provider): add individual test and proxy config for providers Add support for provider-specific model test and proxy configurations: - Add ProviderTestConfig and ProviderProxyConfig types in Rust and TypeScript - Create ProviderAdvancedConfig component with collapsible panels - Update stream_check service to merge provider config with global config - Proxy config UI follows global proxy style (single URL input) Provider-level configs stored in meta field, no database schema changes needed. * feat(ui): add failover toggle and improve proxy controls - Add FailoverToggle component with slide animation - Simplify ProxyToggle style to match FailoverToggle - Add usage statistics button when proxy is active - Fix i18n parameter passing for failover messages - Add missing failover translation keys (inQueue, addQueue, priority) - Replace AboutSection icon with app logo * fix(proxy): support system proxy fallback and provider-level proxy config - Remove no_proxy() calls in http_client.rs to allow system proxy fallback - Add get_for_provider() to build HTTP client with provider-specific proxy - Update forwarder.rs and stream_check.rs to use provider proxy config - Fix EditProviderDialog.tsx to include provider.meta in useMemo deps - Add useEffect in ProviderAdvancedConfig.tsx to sync expand state Fixes #636 Fixes #583 * fix(ui): sync toast theme with app setting * feat(settings): add log config management Fixes #612 Fixes #514 * fix(proxy): increase request body size limit to 200MB Fixes #666 * docs(proxy): update timeout config descriptions and defaults Fixes #612 * fix(proxy): filter x-goog-api-key header to prevent duplication * fix(proxy): prevent proxy recursion when system proxy points to localhost Detect if HTTP_PROXY, HTTPS_PROXY, or ALL_PROXY environment variables point to loopback addresses (localhost, 127.0.0.1), and bypass system proxy in such cases to avoid infinite request loops. * fix(i18n): add providerAdvanced i18n keys and fix failover toast parameter - Add providerAdvanced.* i18n keys to en.json, zh.json, and ja.json - Fix failover toggleFailed toast to pass detail parameter - Remove Chinese fallback text from UI for English/Japanese users * fix(tray): restore tray-provider events and enable Auto failover properly - Emit provider-switched event on tray provider click (backward compatibility) - Auto button now: starts proxy, takes over live config, enables failover * fix(log): enable dynamic log level and single file mode - Initialize log at Trace level for dynamic adjustment - Change rotation strategy to KeepSome(1) for single file - Set max file size to 1GB - Delete old log file on startup for clean start * fix(tray): fix clippy uninlined format args warning Use inline format arguments: {app_type_str} instead of {} * fix(provider): allow typing :// in endpoint URL inputs Change input type from "url" to "text" to prevent browser URL validation from blocking :// input. Closes #681 * fix(stream-check): use Gemini native streaming API format - Change endpoint from OpenAI-compatible to native streamGenerateContent - Add alt=sse parameter for SSE format response - Use x-goog-api-key header instead of Bearer token - Convert request body to Gemini contents/parts format * feat(proxy): add request logging for debugging Add debug logs for outgoing requests including URL and body content with byte size, matching the existing response logging format. * fix(log): prevent usize underflow in KeepSome rotation strategy KeepSome(n) internally computes n-2, so n=1 causes underflow. Use KeepSome(2) as the minimum safe value.
164 lines
4.4 KiB
TypeScript
164 lines
4.4 KiB
TypeScript
import { invoke } from "@tauri-apps/api/core";
|
|
import type { Settings } from "@/types";
|
|
import type { AppId } from "./types";
|
|
|
|
export interface ConfigTransferResult {
|
|
success: boolean;
|
|
message: string;
|
|
filePath?: string;
|
|
backupId?: string;
|
|
}
|
|
|
|
export const settingsApi = {
|
|
async get(): Promise<Settings> {
|
|
return await invoke("get_settings");
|
|
},
|
|
|
|
async save(settings: Settings): Promise<boolean> {
|
|
return await invoke("save_settings", { settings });
|
|
},
|
|
|
|
async restart(): Promise<boolean> {
|
|
return await invoke("restart_app");
|
|
},
|
|
|
|
async checkUpdates(): Promise<void> {
|
|
await invoke("check_for_updates");
|
|
},
|
|
|
|
async isPortable(): Promise<boolean> {
|
|
return await invoke("is_portable_mode");
|
|
},
|
|
|
|
async getConfigDir(appId: AppId): Promise<string> {
|
|
return await invoke("get_config_dir", { app: appId });
|
|
},
|
|
|
|
async openConfigFolder(appId: AppId): Promise<void> {
|
|
await invoke("open_config_folder", { app: appId });
|
|
},
|
|
|
|
async selectConfigDirectory(defaultPath?: string): Promise<string | null> {
|
|
return await invoke("pick_directory", { defaultPath });
|
|
},
|
|
|
|
async getClaudeCodeConfigPath(): Promise<string> {
|
|
return await invoke("get_claude_code_config_path");
|
|
},
|
|
|
|
async getAppConfigPath(): Promise<string> {
|
|
return await invoke("get_app_config_path");
|
|
},
|
|
|
|
async openAppConfigFolder(): Promise<void> {
|
|
await invoke("open_app_config_folder");
|
|
},
|
|
|
|
async getAppConfigDirOverride(): Promise<string | null> {
|
|
return await invoke("get_app_config_dir_override");
|
|
},
|
|
|
|
async setAppConfigDirOverride(path: string | null): Promise<boolean> {
|
|
return await invoke("set_app_config_dir_override", { path });
|
|
},
|
|
|
|
async applyClaudePluginConfig(options: {
|
|
official: boolean;
|
|
}): Promise<boolean> {
|
|
const { official } = options;
|
|
return await invoke("apply_claude_plugin_config", { official });
|
|
},
|
|
|
|
async applyClaudeOnboardingSkip(): Promise<boolean> {
|
|
return await invoke("apply_claude_onboarding_skip");
|
|
},
|
|
|
|
async clearClaudeOnboardingSkip(): Promise<boolean> {
|
|
return await invoke("clear_claude_onboarding_skip");
|
|
},
|
|
|
|
async saveFileDialog(defaultName: string): Promise<string | null> {
|
|
return await invoke("save_file_dialog", { defaultName });
|
|
},
|
|
|
|
async openFileDialog(): Promise<string | null> {
|
|
return await invoke("open_file_dialog");
|
|
},
|
|
|
|
async exportConfigToFile(filePath: string): Promise<ConfigTransferResult> {
|
|
return await invoke("export_config_to_file", { filePath });
|
|
},
|
|
|
|
async importConfigFromFile(filePath: string): Promise<ConfigTransferResult> {
|
|
return await invoke("import_config_from_file", { filePath });
|
|
},
|
|
|
|
async syncCurrentProvidersLive(): Promise<void> {
|
|
const result = (await invoke("sync_current_providers_live")) as {
|
|
success?: boolean;
|
|
message?: string;
|
|
};
|
|
if (!result?.success) {
|
|
throw new Error(result?.message || "Sync current providers failed");
|
|
}
|
|
},
|
|
|
|
async openExternal(url: string): Promise<void> {
|
|
try {
|
|
const u = new URL(url);
|
|
const scheme = u.protocol.replace(":", "").toLowerCase();
|
|
if (scheme !== "http" && scheme !== "https") {
|
|
throw new Error("Unsupported URL scheme");
|
|
}
|
|
} catch {
|
|
throw new Error("Invalid URL");
|
|
}
|
|
await invoke("open_external", { url });
|
|
},
|
|
|
|
async setAutoLaunch(enabled: boolean): Promise<boolean> {
|
|
return await invoke("set_auto_launch", { enabled });
|
|
},
|
|
|
|
async getAutoLaunchStatus(): Promise<boolean> {
|
|
return await invoke("get_auto_launch_status");
|
|
},
|
|
|
|
async getToolVersions(): Promise<
|
|
Array<{
|
|
name: string;
|
|
version: string | null;
|
|
latest_version: string | null;
|
|
error: string | null;
|
|
}>
|
|
> {
|
|
return await invoke("get_tool_versions");
|
|
},
|
|
|
|
async getRectifierConfig(): Promise<RectifierConfig> {
|
|
return await invoke("get_rectifier_config");
|
|
},
|
|
|
|
async setRectifierConfig(config: RectifierConfig): Promise<boolean> {
|
|
return await invoke("set_rectifier_config", { config });
|
|
},
|
|
|
|
async getLogConfig(): Promise<LogConfig> {
|
|
return await invoke("get_log_config");
|
|
},
|
|
|
|
async setLogConfig(config: LogConfig): Promise<boolean> {
|
|
return await invoke("set_log_config", { config });
|
|
},
|
|
};
|
|
|
|
export interface RectifierConfig {
|
|
enabled: boolean;
|
|
requestThinkingSignature: boolean;
|
|
}
|
|
|
|
export interface LogConfig {
|
|
enabled: boolean;
|
|
level: "error" | "warn" | "info" | "debug" | "trace";
|
|
}
|