File size: 5,551 Bytes
a21c316 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | use serde::{Deserialize, Serialize};
use crate::proxy::ProxyConfig;
use crate::modules::cloudflared::CloudflaredConfig;
/// Application configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AppConfig {
pub language: String,
pub theme: String,
pub auto_refresh: bool,
pub refresh_interval: i32, // minutes
pub auto_sync: bool,
pub sync_interval: i32, // minutes
pub default_export_path: Option<String>,
#[serde(default)]
pub proxy: ProxyConfig,
pub antigravity_executable: Option<String>, // [NEW] Manually specified Antigravity executable path
pub antigravity_args: Option<Vec<String>>, // [NEW] Antigravity startup arguments
#[serde(default)]
pub auto_launch: bool, // Launch on startup
#[serde(default)]
pub scheduled_warmup: ScheduledWarmupConfig, // [NEW] Scheduled warmup configuration
#[serde(default)]
pub quota_protection: QuotaProtectionConfig, // [NEW] Quota protection configuration
#[serde(default)]
pub pinned_quota_models: PinnedQuotaModelsConfig, // [NEW] Pinned quota models list
#[serde(default)]
pub circuit_breaker: CircuitBreakerConfig, // [NEW] Circuit breaker configuration
#[serde(default)]
pub hidden_menu_items: Vec<String>, // Hidden menu item path list
#[serde(default)]
pub cloudflared: CloudflaredConfig, // [NEW] Cloudflared configuration
}
/// Scheduled warmup configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ScheduledWarmupConfig {
/// Whether smart warmup is enabled
pub enabled: bool,
/// List of models to warmup
#[serde(default = "default_warmup_models")]
pub monitored_models: Vec<String>,
}
fn default_warmup_models() -> Vec<String> {
vec![
"gemini-3-flash".to_string(),
"claude".to_string(),
"gemini-3-pro-high".to_string(),
"gemini-3-pro-image".to_string(),
]
}
impl ScheduledWarmupConfig {
pub fn new() -> Self {
Self {
enabled: false,
monitored_models: default_warmup_models(),
}
}
}
impl Default for ScheduledWarmupConfig {
fn default() -> Self {
Self::new()
}
}
/// Quota protection configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct QuotaProtectionConfig {
/// Whether quota protection is enabled
pub enabled: bool,
/// Reserved quota percentage (1-99)
pub threshold_percentage: u32,
/// List of monitored models (e.g. gemini-3-flash, gemini-3-pro-high, gemini-3.1-pro-high, claude-sonnet-4-6)
#[serde(default = "default_monitored_models")]
pub monitored_models: Vec<String>,
}
fn default_monitored_models() -> Vec<String> {
vec![
"claude".to_string(),
"gemini-3-pro-high".to_string(),
"gemini-3-flash".to_string(),
"gemini-3-pro-image".to_string(),
]
}
impl QuotaProtectionConfig {
pub fn new() -> Self {
Self {
enabled: false,
threshold_percentage: 10, // Default 10% reserve
monitored_models: default_monitored_models(),
}
}
}
impl Default for QuotaProtectionConfig {
fn default() -> Self {
Self::new()
}
}
/// Pinned quota models configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PinnedQuotaModelsConfig {
/// List of pinned models (displayed outside the account list)
#[serde(default = "default_pinned_models")]
pub models: Vec<String>,
}
fn default_pinned_models() -> Vec<String> {
vec![
"gemini-3-pro-high".to_string(),
"gemini-3-flash".to_string(),
"gemini-3-pro-image".to_string(),
"claude-sonnet-4-6-thinking".to_string(),
]
}
impl PinnedQuotaModelsConfig {
pub fn new() -> Self {
Self {
models: default_pinned_models(),
}
}
}
impl Default for PinnedQuotaModelsConfig {
fn default() -> Self {
Self::new()
}
}
/// Circuit breaker configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CircuitBreakerConfig {
/// Whether circuit breaker is enabled
pub enabled: bool,
/// Unified backoff steps (seconds)
/// Default: [60, 300, 1800, 7200]
#[serde(default = "default_backoff_steps")]
pub backoff_steps: Vec<u64>,
}
fn default_backoff_steps() -> Vec<u64> {
vec![60, 300, 1800, 7200]
}
impl CircuitBreakerConfig {
pub fn new() -> Self {
Self {
enabled: true,
backoff_steps: default_backoff_steps(),
}
}
}
impl Default for CircuitBreakerConfig {
fn default() -> Self {
Self::new()
}
}
impl AppConfig {
pub fn new() -> Self {
Self {
language: "zh".to_string(),
theme: "system".to_string(),
auto_refresh: true,
refresh_interval: 15,
auto_sync: false,
sync_interval: 5,
default_export_path: None,
proxy: ProxyConfig::default(),
antigravity_executable: None,
antigravity_args: None,
auto_launch: false,
scheduled_warmup: ScheduledWarmupConfig::default(),
quota_protection: QuotaProtectionConfig::default(),
pinned_quota_models: PinnedQuotaModelsConfig::default(),
circuit_breaker: CircuitBreakerConfig::default(),
hidden_menu_items: Vec::new(),
cloudflared: CloudflaredConfig::default(),
}
}
}
impl Default for AppConfig {
fn default() -> Self {
Self::new()
}
}
|