mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-28 16:56:16 +08:00
feat(welcome): show first-run welcome dialog on fresh install
Introduce a one-time welcome dialog that explains CC Switch's workflow to new users: how their existing config is preserved as a "default" provider and how the bundled "Official" preset enables one-click revert. Upgrade users are excluded by checking is_providers_empty() at startup and never see the dialog. Persistence follows the existing *_confirmed convention in AppSettings (proxy/usage/stream_check/failover), stored in settings.json. The field is only written when the user explicitly clicks the confirm button, keeping its semantics strictly about user acknowledgement. Also adds two reusable DAO helpers: - Database::is_providers_empty for fresh-install detection, using EXISTS(SELECT 1) for a short-circuit query. - Database::get_bool_flag accepting "true" | "1", with init_default_official_providers migrated to use it. Dialog copy in zh/en/ja uses conditional phrasing so it stays accurate whether or not existing live config was found.
This commit is contained in:
@@ -502,6 +502,20 @@ impl Database {
|
||||
}))
|
||||
}
|
||||
|
||||
/// 判断 providers 表是否为空(全 app_type 一起算)。
|
||||
///
|
||||
/// 用于区分"全新安装"和"升级用户":在启动流程 import/seed 之前调用。
|
||||
/// 使用 `EXISTS` 短路查询,比 `COUNT(*)` 在将来表变大时更高效。
|
||||
pub fn is_providers_empty(&self) -> Result<bool, AppError> {
|
||||
let conn = lock_conn!(self.conn);
|
||||
let exists: bool = conn
|
||||
.query_row("SELECT EXISTS(SELECT 1 FROM providers)", [], |row| {
|
||||
row.get(0)
|
||||
})
|
||||
.map_err(|e| AppError::Database(e.to_string()))?;
|
||||
Ok(!exists)
|
||||
}
|
||||
|
||||
/// 仅获取指定 app 下所有 provider 的 id 集合。
|
||||
///
|
||||
/// 比 `get_all_providers` 轻量得多:只读 id 列、无 endpoint 子查询。
|
||||
@@ -568,11 +582,11 @@ impl Database {
|
||||
pub fn init_default_official_providers(&self) -> Result<usize, AppError> {
|
||||
use crate::database::dao::providers_seed::OFFICIAL_SEEDS;
|
||||
|
||||
// flag 检查:已执行过则跳过
|
||||
if let Ok(Some(flag)) = self.get_setting("official_providers_seeded") {
|
||||
if flag == "true" || flag == "1" {
|
||||
return Ok(0);
|
||||
}
|
||||
if self
|
||||
.get_bool_flag("official_providers_seeded")
|
||||
.unwrap_or(false)
|
||||
{
|
||||
return Ok(0);
|
||||
}
|
||||
|
||||
let mut inserted = 0_usize;
|
||||
|
||||
@@ -33,6 +33,18 @@ impl Database {
|
||||
}
|
||||
}
|
||||
|
||||
/// 以布尔语义读取 flag:`"true"` 或 `"1"` → true,其它全部 false。
|
||||
///
|
||||
/// 用于一次性启动 flag(`official_providers_seeded` / `first_run_notice_shown` 等)。
|
||||
/// 与 `is_legacy_common_config_migrated` 等只认 `"true"` 的历史辅助函数**不同**——
|
||||
/// 这里同时接受 `"1"` 是为了兼容 `init_default_official_providers` 既有写法。
|
||||
pub fn get_bool_flag(&self, key: &str) -> Result<bool, AppError> {
|
||||
Ok(matches!(
|
||||
self.get_setting(key)?.as_deref(),
|
||||
Some("true") | Some("1")
|
||||
))
|
||||
}
|
||||
|
||||
/// 设置值
|
||||
pub fn set_setting(&self, key: &str, value: &str) -> Result<(), AppError> {
|
||||
let conn = lock_conn!(self.conn);
|
||||
|
||||
Reference in New Issue
Block a user