updated app name + fixed missing icon in pkgbuild

This commit is contained in:
nvrl committed 2026-06-30 04:58:03 +02:00
1 parent aa70077ad0
commit 86fa8aef03
7 files changed
+118 -5

No files matched your search

+9 -2
View File
@@ -12,7 +12,7 @@ use proton_sdk::config::ProtonClientConfiguration;
use proton_sdk::session::{PasswordMode, ProtonApiSession, ResumeParameters};
use serde::{Deserialize, Serialize};
use crate::config::{APP_VERSION, KEYRING_SERVICE, USER_AGENT};
use crate::config::{AppDirs, APP_VERSION, KEYRING_SERVICE, USER_AGENT};
use crate::error::{Error, Result};
/// Fixed keyring account name for the single stored session blob.
@@ -53,7 +53,14 @@ impl StoredSession {
}
fn client_config() -> ProtonClientConfiguration {
ProtonClientConfiguration::new(APP_VERSION).with_user_agent(USER_AGENT)
let (app_version, user_agent) = match AppDirs::new() {
Ok(dirs) => {
let config = dirs.load_config();
(config.app_version, config.user_agent)
}
Err(_) => (APP_VERSION.to_string(), USER_AGENT.to_string()),
};
ProtonClientConfiguration::new(app_version).with_user_agent(user_agent)
}
fn keyring_entry() -> Result<Entry> {
+71
View File
@@ -3,6 +3,7 @@
use std::path::PathBuf;
use directories::ProjectDirs;
use serde::{Deserialize, Serialize};
use crate::error::{Error, Result};
@@ -18,6 +19,22 @@ pub const KEYRING_SERVICE: &str = "proton-drive-linux";
/// blobs back under this; pinned files are exempt. See [`crate::cache`].
pub const DEFAULT_CACHE_BUDGET_BYTES: u64 = 5 * 1024 * 1024 * 1024;
/// Configuration structure allowing the user to customize client identification headers.
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct AppConfig {
pub app_version: String,
pub user_agent: String,
}
impl Default for AppConfig {
fn default() -> Self {
Self {
app_version: APP_VERSION.to_string(),
user_agent: USER_AGENT.to_string(),
}
}
}
/// Resolved XDG locations for state, cache, and the default mountpoint.
pub struct AppDirs {
dirs: ProjectDirs,
@@ -30,6 +47,30 @@ impl AppDirs {
Ok(Self { dirs })
}
/// Configuration file path (e.g. ~/.config/proton-drive-linux/config.json).
pub fn config_path(&self) -> PathBuf {
self.dirs.config_dir().join("config.json")
}
/// Load config from disk, creating default if missing.
pub fn load_config(&self) -> AppConfig {
let path = self.config_path();
if path.exists() {
if let Ok(content) = std::fs::read_to_string(&path) {
if let Ok(config) = serde_json::from_str::<AppConfig>(&content) {
return config;
}
}
}
let default_config = AppConfig::default();
if let Ok(content) = serde_json::to_string_pretty(&default_config) {
let _ = std::fs::create_dir_all(self.dirs.config_dir());
let _ = std::fs::write(&path, content);
}
default_config
}
/// Persistent state: inode map / cache index DB lives here.
pub fn state_dir(&self) -> PathBuf {
// `state_dir` is Linux-only in `directories`; fall back to data dir.
@@ -59,6 +100,11 @@ impl AppDirs {
self.state_dir().join("control.sock")
}
/// Unix domain socket the tray uses to ensure single instance.
pub fn tray_socket(&self) -> PathBuf {
self.state_dir().join("tray.sock")
}
/// Default mountpoint when the user does not pass one explicitly.
pub fn default_mountpoint(&self) -> PathBuf {
directories::UserDirs::new()
@@ -70,6 +116,31 @@ impl AppDirs {
pub fn ensure(&self) -> Result<()> {
std::fs::create_dir_all(self.state_dir())?;
std::fs::create_dir_all(self.cache_dir())?;
let _ = std::fs::create_dir_all(self.dirs.config_dir());
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_app_config_serialization() {
let config = AppConfig {
app_version: "external-drive-test-client@1.0.0".to_string(),
user_agent: "test-agent/1.0".to_string(),
};
let json = serde_json::to_string(&config).unwrap();
let decoded: AppConfig = serde_json::from_str(&json).unwrap();
assert_eq!(decoded.app_version, "external-drive-test-client@1.0.0");
assert_eq!(decoded.user_agent, "test-agent/1.0");
}
#[test]
fn test_default_app_config() {
let default_config = AppConfig::default();
assert_eq!(default_config.app_version, APP_VERSION);
assert_eq!(default_config.user_agent, USER_AGENT);
}
}