Refactor Tauri crate into a library and add OS version header

This commit is contained in:
2026-07-08 21:29:26 +03:00
parent 2e80f7b8eb
commit a2581187da
17 changed files with 244 additions and 244 deletions

View File

@@ -1,42 +1,19 @@
#[path = "../src/activity.rs"]
mod activity;
#[path = "../src/commands.rs"]
mod commands;
#[path = "../src/component_detection.rs"]
mod component_detection;
#[path = "../src/models.rs"]
mod models;
#[path = "../src/process.rs"]
mod process;
#[path = "../src/adapters/proxifyre.rs"]
mod proxifyre;
#[path = "../src/adapters/proxy_router.rs"]
mod proxy_router;
#[path = "../src/adapters/singbox.rs"]
mod singbox;
#[path = "../src/singbox_service.rs"]
mod singbox_service;
#[path = "../src/storage.rs"]
mod storage;
#[path = "../src/subscription.rs"]
mod subscription;
#[path = "../src/validation.rs"]
mod validation;
use commands::{
apply_profiles_with_services, build_status, read_saved_state_with_proxifyre_config,
resolve_component_statuses, resolve_preview, save_profile_to_storage, save_target_to_storage,
Clock, CommandError, DetectedProxyApplyHelper, HelperApplyRequest, HelperApplyResult,
ProfileInputDto, ProfileItemInputDto, ProxyApplyHelper, TargetInputDto,
use proxywarden_lib::adapters::proxifyre::ProxiFyreAdapter;
use proxywarden_lib::commands::{
self, apply_profiles_with_services, apply_profiles_with_services_and_detection, build_status,
read_saved_state_with_proxifyre_config, resolve_component_statuses, resolve_preview,
save_profile_to_storage, save_target_to_storage, Clock, CommandError, DetectedProxyApplyHelper,
HelperApplyRequest, HelperApplyResult, ProfileInputDto, ProfileItemInputDto, ProxyApplyHelper,
TargetInputDto,
};
use component_detection::{
use proxywarden_lib::component_detection::{
DetectedProxyfier, ProxyfierDetectionHost, ProxyfierEngine, RegistryInstallEntry,
};
use models::{
ComponentId, ComponentState, ComponentStatus, Profile, ProfileItem, ProfileItemType, Protocol,
ProxyProtocol, Target, TargetKind,
use proxywarden_lib::models::{
self, ComponentId, ComponentState, ComponentStatus, Profile, ProfileItem, ProfileItemType,
Protocol, ProxyProtocol, Target, TargetKind,
};
use proxifyre::ProxiFyreAdapter;
use proxywarden_lib::storage::JsonStorage;
use std::collections::HashSet;
use std::fs;
use std::net::TcpListener;
@@ -44,7 +21,6 @@ use std::path::{Path, PathBuf};
#[cfg(windows)]
use std::process::Command as ProcessCommand;
use std::time::{SystemTime, UNIX_EPOCH};
use storage::JsonStorage;
#[test]
fn save_commands_normalize_and_persist_profile_and_target() {
@@ -354,11 +330,13 @@ fn apply_blocks_local_singbox_target_when_component_is_missing() {
.expect("write targets");
write_json(&storage.paths().components_file, &[singbox_missing()]);
let error = apply_profiles_with_services(
let error = apply_profiles_with_services_and_detection(
&storage,
&ProxiFyreAdapter::default(),
&MockApplyHelper,
&FixedClock,
None,
None,
)
.expect_err("missing sing-box should block local target apply");
let activity = storage.read_activity().expect("read blocked activity");

View File

@@ -1,16 +1,9 @@
#[path = "../src/component_detection.rs"]
mod component_detection;
#[path = "../src/models.rs"]
mod models;
#[path = "../src/process.rs"]
mod process;
use component_detection::{
use proxywarden_lib::component_detection::{
detect_proxyfier_install_with_host, detect_singbox_install_with_host,
proxyfier_component_from_detection, singbox_component_from_detection, ProxyfierDetectionHost,
ProxyfierEngine, RegistryInstallEntry,
};
use models::ComponentState;
use proxywarden_lib::models::ComponentState;
use std::{
collections::{HashMap, HashSet},
path::{Path, PathBuf},

View File

@@ -1,13 +1,8 @@
#[path = "../src/models.rs"]
mod models;
#[path = "../src/validation.rs"]
mod validation;
use models::{
use proxywarden_lib::models::{
ComponentId, ProfileInput, ProfileItemInput, ProfileItemType, Protocol, ProxyProtocol,
TargetInput, TargetKind,
};
use validation::{normalize_profile, normalize_target};
use proxywarden_lib::validation::{normalize_profile, normalize_target};
#[test]
fn normalizes_profile_source_items() {

View File

@@ -1,14 +1,9 @@
#[path = "../src/helper.rs"]
mod helper;
#[path = "../src/models.rs"]
mod models;
use helper::{
use proxywarden_lib::helper::{
helper_action_requires_elevation, install_request, parse_helper_response,
proxifyre_apply_request, service_request, HelperAction, HelperCommandOutput,
HelperCommandRunner, HelperCommandSpec, HelperError, HelperResponse, StructuredHelper,
};
use models::ComponentId;
use proxywarden_lib::models::ComponentId;
use serde_json::json;
use std::cell::RefCell;
use std::path::PathBuf;

View File

@@ -1,16 +1,13 @@
#[path = "../src/models.rs"]
mod models;
#[path = "../src/adapters/proxifyre.rs"]
mod proxifyre;
#[path = "../src/adapters/proxy_router.rs"]
mod proxy_router;
use models::{
use proxywarden_lib::adapters::proxifyre::{
ProxiFyreAdapter, ProxiFyreConfig, PROXIFYRE_OUTPUT_FILE,
};
use proxywarden_lib::adapters::proxy_router::{
ProxyRouterAdapter, ProxyRouterErrorKind, ProxyRouterRequest,
};
use proxywarden_lib::models::{
ComponentId, ComponentState, ComponentStatus, Profile, ProfileItem, ProfileItemType, Protocol,
ProxyProtocol, Target, TargetKind,
};
use proxifyre::{ProxiFyreAdapter, ProxiFyreConfig, PROXIFYRE_OUTPUT_FILE};
use proxy_router::{ProxyRouterAdapter, ProxyRouterErrorKind, ProxyRouterRequest};
#[test]
fn generates_proxifyre_config_for_discord_external_socks5_target() {

View File

@@ -1,26 +1,15 @@
#[path = "../src/models.rs"]
mod models;
#[path = "../src/process.rs"]
mod process;
#[path = "../src/adapters/proxifyre.rs"]
mod proxifyre;
#[path = "../src/adapters/proxy_router.rs"]
mod proxy_router;
#[path = "../src/adapters/singbox.rs"]
mod singbox;
use models::{
ComponentId, ComponentState, ComponentStatus, LocalSingBoxConfig, Profile, ProfileItem,
ProfileItemType, Protocol, ProxyProtocol, SubscriptionCache, SubscriptionServer, Target,
TargetKind,
};
use proxifyre::{ProxiFyreAdapter, ProxiFyreConfig};
use proxy_router::{ProxyRouterAdapter, ProxyRouterRequest};
use singbox::{
use proxywarden_lib::adapters::proxifyre::{ProxiFyreAdapter, ProxiFyreConfig};
use proxywarden_lib::adapters::proxy_router::{ProxyRouterAdapter, ProxyRouterRequest};
use proxywarden_lib::adapters::singbox::{
SingBoxAdapter, SingBoxCheckResult, SingBoxConfigChecker, SingBoxConfigError,
SingBoxConfigErrorKind, SingBoxGenerationRequest, DEFAULT_VPN_OUTBOUND_TAG,
SINGBOX_OUTPUT_FILE,
};
use proxywarden_lib::models::{
ComponentId, ComponentState, ComponentStatus, LocalSingBoxConfig, Profile, ProfileItem,
ProfileItemType, Protocol, ProxyProtocol, SubscriptionCache, SubscriptionServer, Target,
TargetKind,
};
use std::{
cell::RefCell,
path::{Path, PathBuf},

View File

@@ -1,44 +1,22 @@
#[path = "../src/activity.rs"]
mod activity;
#[path = "../src/commands.rs"]
mod commands;
#[path = "../src/component_detection.rs"]
mod component_detection;
#[path = "../src/models.rs"]
mod models;
#[path = "../src/process.rs"]
mod process;
#[path = "../src/adapters/proxifyre.rs"]
mod proxifyre;
#[path = "../src/adapters/proxy_router.rs"]
mod proxy_router;
#[path = "../src/adapters/singbox.rs"]
mod singbox;
#[path = "../src/singbox_service.rs"]
mod singbox_service;
#[path = "../src/storage.rs"]
mod storage;
#[path = "../src/subscription.rs"]
mod subscription;
#[path = "../src/validation.rs"]
mod validation;
use commands::{
use proxywarden_lib::adapters::singbox::{
SingBoxAdapter, SingBoxCheckResult, SingBoxConfigChecker, SingBoxConfigError,
};
use proxywarden_lib::commands::{
fetch_singbox_subscription_with_fetcher, forget_singbox_subscription_in_storage,
generate_singbox_config_with_services, save_singbox_subscription_to_storage,
select_singbox_server_in_storage, Clock, SaveSingBoxSubscriptionInputDto,
SelectSingBoxServerInputDto, SubscriptionFetcher,
};
use models::{
use proxywarden_lib::models::{
ActivityLevel, ComponentId, LocalSingBoxConfig, ProxyProtocol, SubscriptionCache,
SubscriptionServer, TargetKind,
};
use proxywarden_lib::storage::JsonStorage;
use proxywarden_lib::subscription;
use serde_json::{json, Map};
use singbox::{SingBoxAdapter, SingBoxCheckResult, SingBoxConfigChecker, SingBoxConfigError};
use std::fs;
use std::path::{Path, PathBuf};
use std::time::{SystemTime, UNIX_EPOCH};
use storage::JsonStorage;
#[test]
fn saves_subscription_url_without_exposing_secret_query() {

View File

@@ -1,14 +1,5 @@
#[path = "../src/component_detection.rs"]
mod component_detection;
#[path = "../src/models.rs"]
mod models;
#[path = "../src/process.rs"]
mod process;
#[path = "../src/singbox_service.rs"]
mod singbox_service;
use component_detection::DetectedSingBox;
use singbox_service::{
use proxywarden_lib::component_detection::DetectedSingBox;
use proxywarden_lib::singbox_service::{
build_singbox_setup_status, ensure_safe_singbox_install_dir, parse_service_command_output,
service_control_script, SingBoxServiceAction,
};

View File

@@ -1,19 +1,12 @@
#[path = "../src/activity.rs"]
mod activity;
#[path = "../src/models.rs"]
mod models;
#[path = "../src/storage.rs"]
mod storage;
use models::{
use proxywarden_lib::models::{
ActivityEntry, ActivityLevel, ComponentId, ComponentState, ComponentStatus, LocalSingBoxConfig,
Profile, ProfileItem, ProfileItemType, Protocol, ProxyProtocol, SubscriptionCache,
SubscriptionServer, Target, TargetKind,
};
use proxywarden_lib::storage::{backup_path, default_config_root, JsonStorage, StoragePaths};
use std::fs;
use std::path::{Path, PathBuf};
use std::time::{SystemTime, UNIX_EPOCH};
use storage::{backup_path, default_config_root, JsonStorage, StoragePaths};
#[test]
fn storage_defaults_to_programdata_root() {

View File

@@ -1,14 +1,11 @@
#[path = "../src/models.rs"]
mod models;
#[path = "../src/subscription.rs"]
mod subscription;
use base64::{engine::general_purpose, Engine};
use models::redact_subscription_url;
use proxywarden_lib::models::redact_subscription_url;
use proxywarden_lib::subscription::{
self, parse_subscription_body, parse_user_info, SubscriptionFetchIdentity,
};
use std::io::{Read, Write};
use std::net::TcpListener;
use std::time::Duration;
use subscription::{parse_subscription_body, parse_user_info, SubscriptionFetchIdentity};
#[test]
fn parses_singbox_json_config_servers() {
@@ -130,7 +127,8 @@ fn fetch_subscription_sends_device_hwid_header_when_identity_is_set() {
String::from_utf8_lossy(&request).to_ascii_lowercase()
});
let identity = SubscriptionFetchIdentity::with_device_hwid(Some("hwid-abc123"));
let mut identity = SubscriptionFetchIdentity::with_device_hwid(Some("hwid-abc123"));
identity.device_os_version = Some("Windows 11 Pro | 25H2 | build 26200.8655".to_string());
let cache = subscription::fetch_subscription_with_identity(&url, &identity)
.expect("fetch subscription through local test server");
let request = request_thread.join().expect("request thread");
@@ -140,6 +138,7 @@ fn fetch_subscription_sends_device_hwid_header_when_identity_is_set() {
assert!(request.contains("user-agent: proxywarden/"));
assert!(request.contains("x-app-name: proxywarden"));
assert!(request.contains("x-device-os:"));
assert!(request.contains("x-device-os-version: windows 11 pro | 25h2 | build 26200.8655"));
assert!(request.contains("x-device-model: proxywarden"));
}