fix: #38 修改Windows用户名后应用启动失败

Rust端:将配置目录创建的expect改为match错误处理,失败时尝试使用临时目录作为后备方案。

TypeScript端:增强validateAndFixPaths()函数,添加挂载路径中旧用户名的检测逻辑。
This commit is contained in:
VirtualHotBar
2026-06-02 02:24:52 +08:00
parent 171bb4173d
commit 0f5f92d447
2 changed files with 26 additions and 2 deletions

View File

@@ -249,8 +249,17 @@ pub fn init() -> anyhow::Result<()> {
//判断配置目录是否存在,如不存在创建配置目录
let config_dir = app.app_data_dir();
if !config_dir.exists() {
std::fs::create_dir_all(&config_dir).expect("创建配置目录失败");
println!("创建配置目录成功");
match std::fs::create_dir_all(&config_dir) {
Ok(_) => println!("创建配置目录成功"),
Err(e) => {
eprintln!("创建配置目录失败: {} (路径: {})", e, config_dir.display());
// 尝试使用临时目录作为后备方案
let fallback_dir = std::env::temp_dir().join(".netmount");
if !fallback_dir.exists() {
let _ = std::fs::create_dir_all(&fallback_dir);
}
}
}
}
//配置文件

View File

@@ -46,6 +46,21 @@ async function validateAndFixPaths(): Promise<void> {
logger.warn('Home directory not resolved, using fallback', 'MainInit')
runtimeEnv.path.homeDir = await homeDir()
}
// 检查挂载路径是否包含旧的用户名路径
// 当 Windows 用户名变更时,挂载路径可能失效
if (nmConfig.mount && nmConfig.mount.lists) {
for (const mount of nmConfig.mount.lists) {
if (mount.mountPath && mount.mountPath.includes('/Users/') || mount.mountPath.includes('\\Users\\')) {
// 检查挂载路径是否包含当前用户的 home 目录
const normalizedHome = currentHome.replace(/\\/g, '/').toLowerCase()
const normalizedMount = mount.mountPath.replace(/\\/g, '/').toLowerCase()
if (!normalizedMount.startsWith(normalizedHome)) {
logger.warn(`Mount path may contain old username: ${mount.mountPath}`, 'MainInit')
}
}
}
}
}
export async function init(setStartStr: SetStartStrFn) {