mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-24 12:44:18 +08:00
fix(windows): stabilize test environment (#644)
* fix(windows): embed common-controls manifest * fix(windows): prefer HOME for config paths * test(windows): fix export_sql invalid path * fix(windows): remove unused env import in config.rs
This commit is contained in:
+16
-1
@@ -1,3 +1,18 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
tauri_build::build()
|
tauri_build::build();
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
{
|
||||||
|
let manifest_path = std::path::PathBuf::from(
|
||||||
|
std::env::var("CARGO_MANIFEST_DIR").expect("missing CARGO_MANIFEST_DIR"),
|
||||||
|
)
|
||||||
|
.join("common-controls.manifest");
|
||||||
|
let manifest_arg = format!("/MANIFESTINPUT:{}", manifest_path.display());
|
||||||
|
|
||||||
|
println!("cargo:rustc-link-arg=/MANIFEST:EMBED");
|
||||||
|
println!("cargo:rustc-link-arg={}", manifest_arg);
|
||||||
|
// Avoid duplicate manifest resources in binary builds.
|
||||||
|
println!("cargo:rustc-link-arg-bins=/MANIFEST:NO");
|
||||||
|
println!("cargo:rerun-if-changed={}", manifest_path.display());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
||||||
|
<dependency>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity type="win32"
|
||||||
|
name="Microsoft.Windows.Common-Controls"
|
||||||
|
version="6.0.0.0"
|
||||||
|
processorArchitecture="*"
|
||||||
|
publicKeyToken="6595b64144ccf1df"
|
||||||
|
language="*"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
</dependency>
|
||||||
|
</assembly>
|
||||||
@@ -11,6 +11,13 @@ use std::path::Path;
|
|||||||
|
|
||||||
/// 获取用户主目录,带回退和日志
|
/// 获取用户主目录,带回退和日志
|
||||||
fn get_home_dir() -> PathBuf {
|
fn get_home_dir() -> PathBuf {
|
||||||
|
#[cfg(windows)]
|
||||||
|
if let Ok(home) = std::env::var("HOME") {
|
||||||
|
let trimmed = home.trim();
|
||||||
|
if !trimmed.is_empty() {
|
||||||
|
return PathBuf::from(trimmed);
|
||||||
|
}
|
||||||
|
}
|
||||||
dirs::home_dir().unwrap_or_else(|| {
|
dirs::home_dir().unwrap_or_else(|| {
|
||||||
log::warn!("无法获取用户主目录,回退到当前目录");
|
log::warn!("无法获取用户主目录,回退到当前目录");
|
||||||
PathBuf::from(".")
|
PathBuf::from(".")
|
||||||
|
|||||||
@@ -7,6 +7,13 @@ use crate::error::AppError;
|
|||||||
|
|
||||||
/// 获取用户主目录,带回退和日志
|
/// 获取用户主目录,带回退和日志
|
||||||
fn get_home_dir() -> PathBuf {
|
fn get_home_dir() -> PathBuf {
|
||||||
|
#[cfg(windows)]
|
||||||
|
if let Ok(home) = std::env::var("HOME") {
|
||||||
|
let trimmed = home.trim();
|
||||||
|
if !trimmed.is_empty() {
|
||||||
|
return PathBuf::from(trimmed);
|
||||||
|
}
|
||||||
|
}
|
||||||
dirs::home_dir().unwrap_or_else(|| {
|
dirs::home_dir().unwrap_or_else(|| {
|
||||||
log::warn!("无法获取用户主目录,回退到当前目录");
|
log::warn!("无法获取用户主目录,回退到当前目录");
|
||||||
PathBuf::from(".")
|
PathBuf::from(".")
|
||||||
@@ -71,10 +78,7 @@ pub fn get_app_config_dir() -> PathBuf {
|
|||||||
if let Some(custom) = crate::app_store::get_app_config_dir_override() {
|
if let Some(custom) = crate::app_store::get_app_config_dir_override() {
|
||||||
return custom;
|
return custom;
|
||||||
}
|
}
|
||||||
|
get_home_dir().join(".cc-switch")
|
||||||
dirs::home_dir()
|
|
||||||
.expect("无法获取用户主目录")
|
|
||||||
.join(".cc-switch")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 获取应用配置文件路径
|
/// 获取应用配置文件路径
|
||||||
|
|||||||
@@ -7,6 +7,13 @@ use std::path::PathBuf;
|
|||||||
|
|
||||||
/// 获取用户主目录,带回退和日志
|
/// 获取用户主目录,带回退和日志
|
||||||
fn get_home_dir() -> PathBuf {
|
fn get_home_dir() -> PathBuf {
|
||||||
|
#[cfg(windows)]
|
||||||
|
if let Ok(home) = std::env::var("HOME") {
|
||||||
|
let trimmed = home.trim();
|
||||||
|
if !trimmed.is_empty() {
|
||||||
|
return PathBuf::from(trimmed);
|
||||||
|
}
|
||||||
|
}
|
||||||
dirs::home_dir().unwrap_or_else(|| {
|
dirs::home_dir().unwrap_or_else(|| {
|
||||||
log::warn!("无法获取用户主目录,回退到当前目录");
|
log::warn!("无法获取用户主目录,回退到当前目录");
|
||||||
PathBuf::from(".")
|
PathBuf::from(".")
|
||||||
|
|||||||
@@ -154,6 +154,17 @@ impl Default for AppSettings {
|
|||||||
impl AppSettings {
|
impl AppSettings {
|
||||||
fn settings_path() -> Option<PathBuf> {
|
fn settings_path() -> Option<PathBuf> {
|
||||||
// settings.json 保留用于旧版本迁移和无数据库场景
|
// settings.json 保留用于旧版本迁移和无数据库场景
|
||||||
|
#[cfg(windows)]
|
||||||
|
if let Ok(home) = std::env::var("HOME") {
|
||||||
|
let trimmed = home.trim();
|
||||||
|
if !trimmed.is_empty() {
|
||||||
|
return Some(
|
||||||
|
PathBuf::from(trimmed)
|
||||||
|
.join(".cc-switch")
|
||||||
|
.join("settings.json"),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
dirs::home_dir().map(|h| h.join(".cc-switch").join("settings.json"))
|
dirs::home_dir().map(|h| h.join(".cc-switch").join("settings.json"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -971,12 +971,18 @@ fn export_sql_returns_error_for_invalid_path() {
|
|||||||
|
|
||||||
let state = create_test_state().expect("create test state");
|
let state = create_test_state().expect("create test state");
|
||||||
|
|
||||||
// Try to export to an invalid path (parent directory doesn't exist)
|
// Try to export to an invalid path (nonexistent parent or invalid name on Windows)
|
||||||
let invalid_path = PathBuf::from("/nonexistent/directory/export.sql");
|
let invalid_parent = if cfg!(windows) {
|
||||||
|
std::env::temp_dir().join("cc-switch-test-invalid<>dir")
|
||||||
|
} else {
|
||||||
|
PathBuf::from("/nonexistent/directory")
|
||||||
|
};
|
||||||
|
let invalid_path = invalid_parent.join("export.sql");
|
||||||
let err = state
|
let err = state
|
||||||
.db
|
.db
|
||||||
.export_sql(&invalid_path)
|
.export_sql(&invalid_path)
|
||||||
.expect_err("export to invalid path should fail");
|
.expect_err("export to invalid path should fail");
|
||||||
|
let invalid_prefix = invalid_parent.to_string_lossy();
|
||||||
|
|
||||||
// The error can be either IoContext or Io depending on where it fails
|
// The error can be either IoContext or Io depending on where it fails
|
||||||
match err {
|
match err {
|
||||||
@@ -988,8 +994,8 @@ fn export_sql_returns_error_for_invalid_path() {
|
|||||||
}
|
}
|
||||||
AppError::Io { path, .. } => {
|
AppError::Io { path, .. } => {
|
||||||
assert!(
|
assert!(
|
||||||
path.starts_with("/nonexistent"),
|
path.starts_with(invalid_prefix.as_ref()),
|
||||||
"expected error for /nonexistent path, got: {path:?}"
|
"expected error for {invalid_parent:?}, got: {path:?}"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
other => panic!("expected IoContext or Io error, got {other:?}"),
|
other => panic!("expected IoContext or Io error, got {other:?}"),
|
||||||
|
|||||||
Reference in New Issue
Block a user