Tunglies
710c5ef614
refactor: improve code quality with clippy fixes and standardized logging
...
- Replace dangerous unwrap()/expect() calls with proper error handling
- Standardize logging from log:: to logging\! macro with Type:: classifications
- Fix app handle panics with graceful fallback patterns
- Improve error resilience across 35+ modules without breaking functionality
- Reduce clippy warnings from 300+ to 0 in main library code
2025-08-17 11:03:27 +08:00
Tunglies
b1e2940db6
refactor: optimize singleton macro usage with Default trait implementations ( #4279 )
...
* refactor: implement DRY principle improvements across backend
Major DRY violations identified and addressed:
1. **IPC Stream Monitor Pattern**:
- Created `utils/ipc_monitor.rs` with generic `IpcStreamMonitor` trait
- Added `IpcMonitorManager` for common async task management patterns
- Eliminates duplication across traffic.rs, memory.rs, and logs.rs
2. **Singleton Pattern Duplication**:
- Created `utils/singleton.rs` with `singleton\!` and `singleton_with_logging\!` macros
- Replaces 16+ duplicate singleton implementations across codebase
- Provides consistent, tested patterns for global instances
3. **macOS Activation Policy Refactoring**:
- Consolidated 3 duplicate methods into single parameterized `set_activation_policy()`
- Eliminated code duplication while maintaining backward compatibility
- Reduced maintenance burden for macOS-specific functionality
These improvements enhance maintainability, reduce bug potential, and ensure consistent patterns across the backend codebase.
* fix: resolve test failures and clippy warnings
- Fix doctest in singleton.rs by using rust,ignore syntax and proper code examples
- Remove unused time::Instant import from ipc_monitor.rs
- Add #[allow(dead_code)] attributes to future-use utility modules
- All 11 unit tests now pass successfully
- All clippy checks pass with -D warnings strict mode
- Documentation tests properly ignore example code that requires full context
* refactor: migrate code to use new utility tools (partial)
Progress on systematic migration to use created utility tools:
1. **Reorganized IPC Monitor**:
- Moved ipc_monitor.rs to src-tauri/src/ipc/monitor.rs for better organization
- Updated module structure to emphasize IPC relationship
2. **IpcManager Singleton Migration**:
- Replaced manual OnceLock singleton pattern with singleton_with_logging\! macro
- Simplified initialization code and added consistent logging
- Removed unused imports (OnceLock, logging::Type)
3. **ProxyRequestCache Singleton Migration**:
- Migrated from once_cell::sync::OnceCell to singleton\! macro
- Cleaner, more maintainable singleton pattern
- Consistent with project-wide singleton approach
These migrations demonstrate the utility and effectiveness of the created tools:
- Less boilerplate code
- Consistent patterns across codebase
- Easier maintenance and debugging
* feat: complete migration to new utility tools - phase 1
Successfully migrated core components to use the created utility tools:
- Moved `ipc_monitor.rs` to `src-tauri/src/ipc/monitor.rs`
- Better organization emphasizing IPC relationship
- Updated module exports and imports
- **IpcManager**: Migrated to `singleton_with_logging\!` macro
- **ProxyRequestCache**: Migrated to `singleton\!` macro
- Eliminated ~30 lines of boilerplate singleton code
- Consistent logging and initialization patterns
- Removed unused imports (OnceLock, once_cell, logging::Type)
- Cleaner, more maintainable code structure
- All 11 unit tests pass successfully
- Zero compilation warnings
- **Lines of code reduced**: ~50+ lines of boilerplate
- **Consistency improved**: Unified singleton patterns
- **Maintainability enhanced**: Centralized utility functions
- **Test coverage maintained**: 100% test pass rate
Remaining complex monitors (traffic, memory, logs) will be migrated to use the shared IPC monitoring patterns in the next phase, which requires careful refactoring of their streaming logic.
* refactor: complete singleton pattern migration to utility macros
Migrate remaining singleton patterns across the backend to use standardized
utility macros, achieving significant code reduction and consistency improvements.
- **LogsMonitor** (ipc/logs.rs): `OnceLock` → `singleton_with_logging\!`
- **Sysopt** (core/sysopt.rs): `OnceCell` → `singleton_lazy\!`
- **Tray** (core/tray/mod.rs): Complex `OnceCell` → `singleton_lazy\!`
- **Handle** (core/handle.rs): `OnceCell` → `singleton\!`
- **CoreManager** (core/core.rs): `OnceCell` → `singleton_lazy\!`
- **TrafficMonitor** (ipc/traffic.rs): `OnceLock` → `singleton_lazy_with_logging\!`
- **MemoryMonitor** (ipc/memory.rs): `OnceLock` → `singleton_lazy_with_logging\!`
- `singleton_lazy\!` - For complex initialization patterns
- `singleton_lazy_with_logging\!` - For complex initialization with logging
- **Code Reduction**: -33 lines of boilerplate singleton code
- **DRY Compliance**: Eliminated duplicate initialization patterns
- **Consistency**: Unified singleton approach across codebase
- **Maintainability**: Centralized singleton logic in utility macros
- **Zero Breaking Changes**: All existing APIs remain compatible
All tests pass and clippy warnings resolved.
* refactor: optimize singleton macros using Default trait implementation
Simplify singleton macro usage by implementing Default trait for complex
initialization patterns, significantly improving code readability and maintainability.
- **MemoryMonitor**: Move IPC client initialization to Default impl
- **TrafficMonitor**: Move IPC client initialization to Default impl
- **Sysopt**: Move Arc<Mutex> initialization to Default impl
- **Tray**: Move struct field initialization to Default impl
- **CoreManager**: Move Arc<Mutex> initialization to Default impl
```rust
singleton_lazy_with_logging\!(MemoryMonitor, INSTANCE, "MemoryMonitor", || {
let ipc_path_buf = ipc_path().unwrap();
let ipc_path = ipc_path_buf.to_str().unwrap_or_default();
let client = IpcStreamClient::new(ipc_path).unwrap();
MemoryMonitor::new(client)
});
```
```rust
impl Default for MemoryMonitor { /* initialization logic */ }
singleton_lazy_with_logging\!(MemoryMonitor, INSTANCE, "MemoryMonitor", MemoryMonitor::default);
```
- **Code Reduction**: -17 lines of macro closure code (80%+ simplification)
- **Separation of Concerns**: Initialization logic moved to proper Default impl
- **Readability**: Single-line macro calls vs multi-line closures
- **Testability**: Default implementations can be tested independently
- **Rust Idioms**: Using standard Default trait pattern
- **Performance**: Function calls more efficient than closures
All tests pass and clippy warnings resolved.
* refactor: implement MonitorData and StreamingParser traits for IPC monitors
* refactor: add timeout and retry_interval fields to IpcStreamMonitor; update TrafficMonitorState to derive Default
* refactor: migrate AppHandleManager to unified singleton control
- Replace manual singleton implementation with singleton_with_logging\! macro
- Remove std::sync::Once dependency in favor of OnceLock-based pattern
- Improve error handling for macOS activation policy methods
- Maintain thread safety with parking_lot::Mutex for AppHandle storage
- Add proper initialization check to prevent duplicate handle assignment
- Enhance logging consistency across AppHandleManager operations
* refactor: improve hotkey management with enum-based operations
- Add HotkeyFunction enum for type-safe function selection
- Add SystemHotkey enum for predefined system shortcuts
- Implement Display and FromStr traits for type conversions
- Replace string-based hotkey registration with enum methods
- Add register_system_hotkey() and unregister_system_hotkey() methods
- Maintain backward compatibility with string-based register() method
- Migrate singleton pattern to use singleton_with_logging\! macro
- Extract hotkey function execution logic into centralized execute_function()
- Update lib.rs to use new enum-based SystemHotkey operations
- Improve type safety and reduce string manipulation errors
Benefits:
- Type safety prevents invalid hotkey function names
- Centralized function execution reduces code duplication
- Enum-based API provides better IDE autocomplete support
- Maintains full backward compatibility with existing configurations
* fix: resolve LightWeightState initialization order panic
- Modify with_lightweight_status() to safely handle unmanaged state using try_state()
- Return Option<R> instead of R to gracefully handle state unavailability
- Update is_in_lightweight_mode() to use unwrap_or(false) for safe defaults
- Add state availability check in auto_lightweight_mode_init() before access
- Maintain singleton check priority while preventing early state access panics
- Fix clippy warnings for redundant pattern matching
Resolves runtime panic: "state() called before manage() for LightWeightState"
* refactor: add unreachable patterns for non-macOS in hotkey handling
* refactor: simplify SystemHotkey enum by removing redundant cfg attributes
* refactor: add macOS conditional compilation for system hotkey registration methods
* refactor: streamline hotkey unregistration and error logging for macOS
2025-07-31 14:35:13 +08:00
Tunglies
a574ced428
Refactor logging statements to use the new formatting syntax for improved readability and consistency across the codebase. This includes updating error, warning, and info logs in various modules such as system commands, configuration, core functionalities, and utilities. Additionally, minor adjustments were made to string formatting in backup and proxy features to enhance clarity.
2025-06-27 23:30:59 +08:00
wonfen
ac7307b1f7
feat: enhance profile management and proxy refresh with improved event listening and state updates
2025-06-17 11:38:53 +08:00
wonfen
4840e07da8
refactor: remove redundant logic
2025-05-25 21:56:04 +08:00
wonfen
af1689ee07
refactor: add debounce to optimize config updates and provider refresh handling
2025-05-25 21:34:48 +08:00
Tunglies
4024b72954
feat: enhance auto log cleaning options with 1-day retention and update related configurations
2025-05-20 22:34:02 +08:00
wonfen
b70e202201
refactor: simplify frontend event dispatch by restructuring notification system
2025-05-18 20:58:59 +08:00
wonfen
8448217bd4
refactor: move event dispatch logic into notifier thread to improve efficiency
2025-05-17 19:42:43 +08:00
Tunglies
53a46d0dc6
refactor: simplify proxy type handling and improve error handling in network commands
2025-05-16 00:09:47 +08:00
wonfen
ce42ca77a9
fix: timeout mechanism for sending notice messages
2025-05-04 16:47:10 +08:00
wonfen
ba0f4cdde0
refactor: separate notification thread in frontend to prevent UI freeze
2025-05-04 09:21:32 +08:00
wonfen
73b9a71c84
feat: add retry mechanism to optimize network requests, improve async message handling and timeout for scheduled tasks
2025-05-03 09:38:25 +08:00
Tunglies
b6a6f5f434
Add AsyncHandler for wrapping task spawning
2025-04-11 17:30:30 +08:00
wonfen
1bd503a654
feat: add error prompt for initial config loading to prevent switching to invalid subscription
2025-03-30 10:56:30 +08:00
Tunglies
e8e16f7d57
refactor(logging): replace log_err! with structured logging_error! calls
...
refactor(cm-service): better error handling from Backend to Frontend
2025-03-28 03:39:34 +08:00
Tunglies
df5424d55e
feat: add logging module and update running mode terminology
2025-03-25 23:05:09 +08:00
wonfen
86f69fd574
feat: add singleton check after core startup in sidecar mode
2025-03-22 15:01:55 +08:00
Tunglies
91ccb3045c
feat: implement lightweight mode functionality and update related settings
2025-03-20 03:23:14 +08:00
Tunglies
772ecdd3b0
refactor: improve proxy retrieval and add window destruction method
2025-03-19 02:04:01 +08:00
wonfen
07bdc108ed
feat: show service mode installation prompts in user mode
2025-03-03 14:42:31 +08:00
wonfen
277390e597
feat: Add sidecar mode as an alternative to service mode
...
- Auto-fallback to sidecar mode if service mode fails
2025-03-03 03:34:34 +08:00
huzibaca
97864e8df3
feat: macos system tray addition rate display
2024-12-31 04:42:55 +08:00
huzibaca
ba195c41b6
refactor: when updating the tray, the logic is split to improve performance.
2024-12-24 04:52:14 +08:00
huzibaca
98c6e0311b
fix: windows cannot save window state(2)
2024-11-20 00:27:53 +08:00
huzibaca
ac884da56b
fix: performance issues caused by closing windows on mac
2024-10-30 06:27:29 +08:00
huzibaca
45b48ede44
refactor: unify and simplify the call of app_handle(2)
2024-09-23 23:15:51 +08:00
huzibaca
1c894f3cfa
refactor: unify and simplify the call of app_handle
2024-09-23 16:31:58 +08:00
huzibaca
3d6faecaed
chore: update
2024-09-22 22:15:36 +08:00
huzibaca
f9f1721d66
chore: update
2024-09-22 15:39:52 +08:00
huzibaca
dffd663d7a
Fix: Custom tray icon not working
...
1. Contains potential deadlock
2024-09-20 16:26:23 +08:00
huzibaca
4a76997044
feat: Optimize kernel startup logic
...
1. tun mode startup logic
2. Remove invalid creation process PID logic
2024-09-12 15:35:08 +08:00
huzibaca
6cc81fe6b8
chore: update
2024-09-02 19:33:17 +08:00
MystiPanda
3a883b9e41
refactor: cargo clippy
2024-01-10 17:36:35 +08:00
GyDi
4f3751b7ce
refactor: for windows
2022-11-17 20:19:40 +08:00
GyDi
837422fbb8
refactor: wip
2022-11-14 01:26:33 +08:00
GyDi
a45c61f19e
chore: format rust code
2022-11-12 11:37:23 +08:00
GyDi
2f9a3fa942
feat: system tray support zh language
2022-10-28 00:40:29 +08:00
GyDi
a75706f329
feat: optimize config feedback
2022-09-26 20:46:29 +08:00
GyDi
29397ca04f
fix: refresh clash ui await patch
2022-09-24 14:01:28 +08:00
GyDi
09807cfcad
fix: handle is none
2022-09-12 00:45:19 +08:00
GyDi
2d00ddad2b
refactor: optimize
2022-09-11 20:58:55 +08:00