Skip to content

首页博客

v0.1.6 released — optimized update logic

Version 0.1.6 - Optimized update logic ​

🚀 Key improvements ​

1. Smart update logic ​

  • Backend update mechanism:

    • Added playback state detection (is_playing field)
    • Implemented a smart update strategy to avoid unnecessary duplicate updates
    • Added a timestamp mechanism to ensure forced updates (every 5 seconds)
    • Dynamically adjusted the polling interval: 100ms while playing, 200ms while paused
  • Frontend update optimizations:

    • Implemented data change detection to avoid redundant rendering
    • Dynamically adjusted the polling frequency: 100ms while playing, 200ms while paused
    • Improved error handling; a 250ms default interval is used on errors

2. Data structure improvements ​

  • Song struct:
    • Added the is_playing: bool field to indicate the current playback state
    • Added the last_update: u64 field for timestamp management
    • Derived the PartialEq trait to support struct comparison

3. Error handling improvements ​

  • Strengthened error handling for Windows API calls
  • Added handling for session manager acquisition failures
  • Improved the error handling pattern for async operations

4. Performance optimizations ​

  • Reduced unnecessary state writes
  • Optimized the polling mechanism to lower CPU usage
  • Implemented dynamic update frequency based on playback state

📝 Documentation updates ​

  • README.md:
    • Improved the build dependency instructions
    • Listed the main dependencies and their versions in detail
    • Separated the Windows-specific dependency instructions
    • Improved the document structure and readability

🔧 Technical details ​

Backend changes (src/main.rs) ​

rust
// 新增字段
#[derive(Default, Clone, Serialize, PartialEq)]
struct Song {
    // ... 原有字段
    is_playing: bool,
    last_update: u64,
}

// 智能更新逻辑
let should_update = if current_song.is_playing != last_song.is_playing {
    true
} else if current_song.position != last_position {
    true
} else if !current_song.is_playing && no_change_count < 10 {
    no_change_count += 1;
    true
} else {
    timestamp.saturating_sub(last_song.last_update) > 5
};

Frontend changes (frontend/main.js) ​

javascript
// 数据变化检测
if (JSON.stringify(data) !== JSON.stringify(lastData)) {
    Object.assign(info, {
        ...data,
        pct: data.pct ?? 0,
    });
    lastData = data;
}

// 动态轮询间隔
const pollInterval = info.is_playing ? 100 : 200;
setTimeout(poll, pollInterval);

📦 Version info ​

  • Version: upgraded from 0.1.5 to 0.1.6
  • Update date: September 10, 2025
  • Commit hash: 18920652694b2a849a59b929653613877408aea2

💡 Results ​

  • Significantly reduced unnecessary network requests and state updates
  • Improved the real-time responsiveness of playback state
  • Reduced system resource usage
  • Improved application stability and reliability

Note: This version focuses on performance optimizations and user experience improvements. All users are recommended to upgrade to the latest version for a better experience.

VirusTotal scan result

基于 MIT 许可 发布