fix!: update log and data dirs for linux and windows (#108)

* fix: update log dir for linux and windows

Signed-off-by: Yinan Qin <39023210+elysia-best@users.noreply.github.com>

* fix: update log dirs for linux and windows

Signed-off-by: Yinan Qin <39023210+elysia-best@users.noreply.github.com>

* chore: refactor APPDATA variable retrieval for clarity

Signed-off-by: Yinan Qin <39023210+elysia-best@users.noreply.github.com>

* fix: update version to 0.7.0 and improve data directory handling

* fix: fix clippy error

---------

Signed-off-by: Yinan Qin <39023210+elysia-best@users.noreply.github.com>
This commit is contained in:
Yinan Qin
2025-10-27 11:06:31 +08:00
committed by GitHub
parent e00c0d5ffd
commit 68411aaaf3
3 changed files with 54 additions and 44 deletions

2
src-tauri/Cargo.lock generated
View File

@@ -2940,7 +2940,7 @@ dependencies = [
[[package]]
name = "openlist-desktop"
version = "0.6.1"
version = "0.7.0"
dependencies = [
"anyhow",
"base64 0.22.1",

View File

@@ -114,7 +114,7 @@ async fn is_rclone_running() -> bool {
let mut system = System::new_all();
system.refresh_processes(sysinfo::ProcessesToUpdate::All, true);
for (_pid, process) in system.processes() {
for process in system.processes().values() {
let process_name = process.name().to_string_lossy().to_lowercase();
if process_name.contains("rclone") {

View File

@@ -17,43 +17,61 @@ fn get_app_dir() -> Result<PathBuf, String> {
}
fn get_user_data_dir() -> Result<PathBuf, String> {
#[cfg(target_os = "macos")]
{
let home = env::var("HOME").map_err(|_| "Failed to get HOME environment variable")?;
let data_dir = PathBuf::from(home)
.join("Library")
.join("Application Support")
.join("OpenList Desktop");
fs::create_dir_all(&data_dir)
.map_err(|e| format!("Failed to create data directory: {e}"))?;
Ok(data_dir)
}
let data_dir = {
#[cfg(target_os = "macos")]
{
let home = env::var("HOME").map_err(|_| "Failed to get HOME environment variable")?;
PathBuf::from(home)
.join("Library")
.join("Application Support")
.join("OpenList Desktop")
}
#[cfg(not(target_os = "macos"))]
{
get_app_dir()
}
#[cfg(target_os = "linux")]
{
let home = env::var("HOME").map_err(|_| "Failed to get HOME environment variable")?;
PathBuf::from(home)
.join(".local")
.join("share")
.join("OpenList Desktop")
}
#[cfg(target_os = "windows")]
{
let appdata =
env::var("APPDATA").map_err(|_| "Failed to get APPDATA environment variable")?;
PathBuf::from(appdata).join("OpenList Desktop")
}
};
fs::create_dir_all(&data_dir).map_err(|e| format!("Failed to create data directory: {e}"))?;
data_dir
.canonicalize()
.map_err(|e| format!("Failed to canonicalize data directory: {e}"))
}
fn get_user_logs_dir() -> Result<PathBuf, String> {
#[cfg(target_os = "macos")]
{
let home = env::var("HOME").map_err(|_| "Failed to get HOME environment variable")?;
let logs_dir = PathBuf::from(home)
.join("Library")
.join("Logs")
.join("OpenList Desktop");
fs::create_dir_all(&logs_dir)
.map_err(|e| format!("Failed to create logs directory: {e}"))?;
Ok(logs_dir)
}
let logs_dir = {
#[cfg(target_os = "macos")]
{
let home = env::var("HOME").map_err(|_| "Failed to get HOME environment variable")?;
PathBuf::from(home)
.join("Library")
.join("Logs")
.join("OpenList Desktop")
}
#[cfg(not(target_os = "macos"))]
{
let logs = get_app_dir()?.join("logs");
fs::create_dir_all(&logs).map_err(|e| e.to_string())?;
Ok(logs)
}
#[cfg(not(target_os = "macos"))]
{
get_user_data_dir()?.join("logs")
}
};
fs::create_dir_all(&logs_dir).map_err(|e| format!("Failed to create logs directory: {e}"))?;
logs_dir
.canonicalize()
.map_err(|e| format!("Failed to canonicalize logs directory: {e}"))
}
fn get_binary_path(binary: &str, service_name: &str) -> Result<PathBuf, String> {
@@ -96,15 +114,7 @@ pub fn get_rclone_config_path() -> Result<PathBuf, String> {
}
pub fn get_default_openlist_data_dir() -> Result<PathBuf, String> {
#[cfg(target_os = "macos")]
{
Ok(get_user_data_dir()?.join("data"))
}
#[cfg(not(target_os = "macos"))]
{
Ok(get_app_dir()?.join("data"))
}
Ok(get_user_data_dir()?.join("data"))
}
pub fn get_service_log_path() -> Result<PathBuf, String> {
@@ -123,6 +133,6 @@ pub fn get_service_log_path() -> Result<PathBuf, String> {
#[cfg(not(target_os = "macos"))]
{
Ok(get_app_dir()?.join("openlist-desktop-service.log"))
Ok(get_user_data_dir()?.join("openlist-desktop-service.log"))
}
}