mirror of
https://github.com/zhom/donutbrowser.git
synced 2026-06-06 15:03:58 +02:00
refactor: only use is_browser_version_nightly for release checks
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::api_client::is_browser_version_nightly;
|
||||||
use crate::browser_runner::{BrowserProfile, BrowserRunner};
|
use crate::browser_runner::{BrowserProfile, BrowserRunner};
|
||||||
use crate::browser_version_service::{BrowserVersionInfo, BrowserVersionService};
|
use crate::browser_version_service::{BrowserVersionInfo, BrowserVersionService};
|
||||||
use crate::settings_manager::SettingsManager;
|
use crate::settings_manager::SettingsManager;
|
||||||
@@ -101,16 +102,19 @@ impl AutoUpdater {
|
|||||||
// Apply chromium threshold logic
|
// Apply chromium threshold logic
|
||||||
if browser == "chromium" {
|
if browser == "chromium" {
|
||||||
// For chromium, only show notifications if there are 50+ new versions
|
// For chromium, only show notifications if there are 50+ new versions
|
||||||
// Count how many versions are newer than the current profile version
|
let current_version = &profile.version.parse::<u32>().unwrap();
|
||||||
let newer_versions_count = versions
|
let new_version = &update.new_version.parse::<u32>().unwrap();
|
||||||
.iter()
|
|
||||||
.filter(|v| self.is_version_newer(&v.version, &profile.version))
|
|
||||||
.count();
|
|
||||||
|
|
||||||
if newer_versions_count >= 50 {
|
let result = new_version - current_version;
|
||||||
|
println!(
|
||||||
|
"Current version: {current_version}, New version: {new_version}, Result: {result}"
|
||||||
|
);
|
||||||
|
if result > 50 {
|
||||||
notifications.push(update);
|
notifications.push(update);
|
||||||
} else {
|
} else {
|
||||||
println!("Skipping chromium update notification: only {newer_versions_count} new versions (need 50+)");
|
println!(
|
||||||
|
"Skipping chromium update notification: only {result} new versions (need 50+)"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
notifications.push(update);
|
notifications.push(update);
|
||||||
@@ -123,6 +127,8 @@ impl AutoUpdater {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn check_for_updates_with_progress(&self, app_handle: &tauri::AppHandle) {
|
pub async fn check_for_updates_with_progress(&self, app_handle: &tauri::AppHandle) {
|
||||||
|
println!("Starting auto-update check with progress...");
|
||||||
|
|
||||||
// Check for browser updates and trigger auto-downloads
|
// Check for browser updates and trigger auto-downloads
|
||||||
match self.check_for_updates().await {
|
match self.check_for_updates().await {
|
||||||
Ok(update_notifications) => {
|
Ok(update_notifications) => {
|
||||||
@@ -139,22 +145,63 @@ impl AutoUpdater {
|
|||||||
notification.browser, notification.new_version
|
notification.browser, notification.new_version
|
||||||
);
|
);
|
||||||
|
|
||||||
// Emit a custom event to trigger auto-download
|
// Clone app_handle for the async task
|
||||||
let auto_update_event = serde_json::json!({
|
let app_handle_clone = app_handle.clone();
|
||||||
"browser": notification.browser,
|
let browser = notification.browser.clone();
|
||||||
"new_version": notification.new_version,
|
let new_version = notification.new_version.clone();
|
||||||
"notification_id": notification.id,
|
let notification_id = notification.id.clone();
|
||||||
"affected_profiles": notification.affected_profiles
|
let affected_profiles = notification.affected_profiles.clone();
|
||||||
});
|
|
||||||
|
|
||||||
if let Err(e) = app_handle.emit("browser-auto-update-available", &auto_update_event) {
|
// Spawn async task to handle the download and auto-update
|
||||||
eprintln!(
|
tokio::spawn(async move {
|
||||||
"Failed to emit auto-update event for {}: {e}",
|
// First, check if browser already exists
|
||||||
notification.browser
|
match crate::browser_runner::is_browser_downloaded(
|
||||||
);
|
browser.clone(),
|
||||||
} else {
|
new_version.clone(),
|
||||||
println!("Emitted auto-update event for {}", notification.browser);
|
) {
|
||||||
}
|
true => {
|
||||||
|
println!("Browser {browser} {new_version} already downloaded, proceeding to auto-update profiles");
|
||||||
|
|
||||||
|
// Browser already exists, go straight to profile update
|
||||||
|
match crate::auto_updater::complete_browser_update_with_auto_update(
|
||||||
|
browser.clone(),
|
||||||
|
new_version.clone(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(updated_profiles) => {
|
||||||
|
println!(
|
||||||
|
"Auto-update completed for {} profiles: {:?}",
|
||||||
|
updated_profiles.len(),
|
||||||
|
updated_profiles
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("Failed to complete auto-update for {browser}: {e}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
false => {
|
||||||
|
println!("Downloading browser {browser} version {new_version}...");
|
||||||
|
|
||||||
|
// Emit the auto-update event to trigger frontend handling
|
||||||
|
let auto_update_event = serde_json::json!({
|
||||||
|
"browser": browser,
|
||||||
|
"new_version": new_version,
|
||||||
|
"notification_id": notification_id,
|
||||||
|
"affected_profiles": affected_profiles
|
||||||
|
});
|
||||||
|
|
||||||
|
if let Err(e) =
|
||||||
|
app_handle_clone.emit("browser-auto-update-available", &auto_update_event)
|
||||||
|
{
|
||||||
|
eprintln!("Failed to emit auto-update event for {browser}: {e}");
|
||||||
|
} else {
|
||||||
|
println!("Emitted auto-update event for {browser}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
println!("No browser updates needed");
|
println!("No browser updates needed");
|
||||||
@@ -173,16 +220,15 @@ impl AutoUpdater {
|
|||||||
available_versions: &[BrowserVersionInfo],
|
available_versions: &[BrowserVersionInfo],
|
||||||
) -> Result<Option<UpdateNotification>, Box<dyn std::error::Error + Send + Sync>> {
|
) -> Result<Option<UpdateNotification>, Box<dyn std::error::Error + Send + Sync>> {
|
||||||
let current_version = &profile.version;
|
let current_version = &profile.version;
|
||||||
let is_current_stable = !self.is_nightly_version(current_version);
|
let is_current_nightly = is_browser_version_nightly(&profile.browser, current_version, None);
|
||||||
|
|
||||||
// Find the best available update
|
// Find the best available update
|
||||||
let best_update = available_versions
|
let best_update = available_versions
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|v| {
|
.filter(|v| {
|
||||||
// Only consider versions newer than current
|
// Only consider versions newer than current
|
||||||
self.is_version_newer(&v.version, current_version) &&
|
self.is_version_newer(&v.version, current_version)
|
||||||
// Respect version type preference
|
&& is_browser_version_nightly(&profile.browser, &v.version, None) == is_current_nightly
|
||||||
is_current_stable != v.is_prerelease
|
|
||||||
})
|
})
|
||||||
.max_by(|a, b| self.compare_versions(&a.version, &b.version));
|
.max_by(|a, b| self.compare_versions(&a.version, &b.version));
|
||||||
|
|
||||||
@@ -367,14 +413,6 @@ impl AutoUpdater {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper methods
|
|
||||||
|
|
||||||
fn is_nightly_version(&self, version: &str) -> bool {
|
|
||||||
// Use the centralized nightly detection function
|
|
||||||
// Since we don't have browser context here, use the general fallback
|
|
||||||
crate::api_client::is_nightly_version(version)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_version_newer(&self, version1: &str, version2: &str) -> bool {
|
fn is_version_newer(&self, version1: &str, version2: &str) -> bool {
|
||||||
self.compare_versions(version1, version2) == std::cmp::Ordering::Greater
|
self.compare_versions(version1, version2) == std::cmp::Ordering::Greater
|
||||||
}
|
}
|
||||||
@@ -502,21 +540,6 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_is_nightly_version() {
|
|
||||||
let updater = AutoUpdater::new();
|
|
||||||
|
|
||||||
assert!(updater.is_nightly_version("1.0.0-alpha"));
|
|
||||||
assert!(updater.is_nightly_version("1.0.0-beta"));
|
|
||||||
assert!(updater.is_nightly_version("1.0.0-rc"));
|
|
||||||
assert!(updater.is_nightly_version("1.0.0a1"));
|
|
||||||
assert!(updater.is_nightly_version("1.0.0b1"));
|
|
||||||
assert!(updater.is_nightly_version("1.0.0-dev"));
|
|
||||||
|
|
||||||
assert!(!updater.is_nightly_version("1.0.0"));
|
|
||||||
assert!(!updater.is_nightly_version("1.2.3"));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_compare_versions() {
|
fn test_compare_versions() {
|
||||||
let updater = AutoUpdater::new();
|
let updater = AutoUpdater::new();
|
||||||
|
|||||||
@@ -263,149 +263,108 @@ impl VersionUpdater {
|
|||||||
&self,
|
&self,
|
||||||
app_handle: &tauri::AppHandle,
|
app_handle: &tauri::AppHandle,
|
||||||
) -> Result<Vec<BackgroundUpdateResult>, Box<dyn std::error::Error + Send + Sync>> {
|
) -> Result<Vec<BackgroundUpdateResult>, Box<dyn std::error::Error + Send + Sync>> {
|
||||||
println!("Starting background version update for all browsers");
|
let supported_browsers = self.version_service.get_supported_browsers();
|
||||||
|
let total_browsers = supported_browsers.len();
|
||||||
let all_browsers = [
|
|
||||||
"firefox",
|
|
||||||
"firefox-developer",
|
|
||||||
"mullvad-browser",
|
|
||||||
"zen",
|
|
||||||
"brave",
|
|
||||||
"chromium",
|
|
||||||
"tor-browser",
|
|
||||||
];
|
|
||||||
|
|
||||||
// Filter browsers to only include those supported on the current platform
|
|
||||||
let browsers: Vec<&str> = all_browsers
|
|
||||||
.iter()
|
|
||||||
.filter(|browser| {
|
|
||||||
self
|
|
||||||
.version_service
|
|
||||||
.is_browser_supported(browser)
|
|
||||||
.unwrap_or(false)
|
|
||||||
})
|
|
||||||
.copied()
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let total_browsers = browsers.len();
|
|
||||||
let mut results = Vec::new();
|
let mut results = Vec::new();
|
||||||
let mut total_new_versions = 0;
|
let mut total_new_versions = 0;
|
||||||
|
|
||||||
println!(
|
// Emit initial progress
|
||||||
"Updating {} supported browsers (filtered from {} total)",
|
let initial_progress = VersionUpdateProgress {
|
||||||
browsers.len(),
|
current_browser: String::new(),
|
||||||
all_browsers.len()
|
|
||||||
);
|
|
||||||
|
|
||||||
// Emit start event
|
|
||||||
let progress = VersionUpdateProgress {
|
|
||||||
current_browser: "".to_string(),
|
|
||||||
total_browsers,
|
total_browsers,
|
||||||
completed_browsers: 0,
|
completed_browsers: 0,
|
||||||
new_versions_found: 0,
|
new_versions_found: 0,
|
||||||
browser_new_versions: 0,
|
browser_new_versions: 0,
|
||||||
status: "updating".to_string(),
|
status: "updating".to_string(),
|
||||||
};
|
};
|
||||||
if let Err(e) = app_handle.emit("version-update-progress", &progress) {
|
|
||||||
eprintln!("Failed to emit start progress: {e}");
|
if let Err(e) = app_handle.emit("version-update-progress", &initial_progress) {
|
||||||
} else {
|
eprintln!("Failed to emit initial progress: {e}");
|
||||||
println!("Emitted start progress event");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (index, browser) in browsers.iter().enumerate() {
|
for (index, browser) in supported_browsers.iter().enumerate() {
|
||||||
println!(
|
println!("Updating browser versions for: {browser}");
|
||||||
"Processing browser {} ({}/{}): {}",
|
|
||||||
browser,
|
|
||||||
index + 1,
|
|
||||||
total_browsers,
|
|
||||||
browser
|
|
||||||
);
|
|
||||||
|
|
||||||
// Emit progress for current browser
|
// Emit progress update for current browser
|
||||||
let progress = VersionUpdateProgress {
|
let progress = VersionUpdateProgress {
|
||||||
current_browser: browser.to_string(),
|
current_browser: browser.clone(),
|
||||||
total_browsers,
|
total_browsers,
|
||||||
completed_browsers: index,
|
completed_browsers: index,
|
||||||
new_versions_found: total_new_versions,
|
new_versions_found: total_new_versions,
|
||||||
browser_new_versions: 0,
|
browser_new_versions: 0,
|
||||||
status: "updating".to_string(),
|
status: "updating".to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Err(e) = app_handle.emit("version-update-progress", &progress) {
|
if let Err(e) = app_handle.emit("version-update-progress", &progress) {
|
||||||
eprintln!("Failed to emit progress for {browser}: {e}");
|
eprintln!("Failed to emit progress for {browser}: {e}");
|
||||||
} else {
|
|
||||||
println!("Emitted progress event for browser: {browser}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.version_service.should_update_cache(browser) {
|
match self.update_browser_versions(browser).await {
|
||||||
println!("Skipping {browser} - cache is still fresh");
|
Ok(new_versions_count) => {
|
||||||
|
results.push(BackgroundUpdateResult {
|
||||||
let browser_result = BackgroundUpdateResult {
|
browser: browser.clone(),
|
||||||
browser: browser.to_string(),
|
new_versions_count,
|
||||||
new_versions_count: 0,
|
total_versions_count: 0, // We don't track total for background updates
|
||||||
total_versions_count: 0,
|
|
||||||
updated_successfully: true,
|
|
||||||
error: None,
|
|
||||||
};
|
|
||||||
results.push(browser_result);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("Fetching new versions for browser: {browser}");
|
|
||||||
|
|
||||||
let result = self.update_browser_versions(browser).await;
|
|
||||||
|
|
||||||
match result {
|
|
||||||
Ok(new_count) => {
|
|
||||||
total_new_versions += new_count;
|
|
||||||
let browser_result = BackgroundUpdateResult {
|
|
||||||
browser: browser.to_string(),
|
|
||||||
new_versions_count: new_count,
|
|
||||||
total_versions_count: 0, // We'll update this if needed
|
|
||||||
updated_successfully: true,
|
updated_successfully: true,
|
||||||
error: None,
|
error: None,
|
||||||
};
|
});
|
||||||
results.push(browser_result);
|
|
||||||
|
|
||||||
println!("Found {new_count} new versions for {browser}");
|
total_new_versions += new_versions_count;
|
||||||
|
|
||||||
|
// Emit progress update with new versions found
|
||||||
|
let progress = VersionUpdateProgress {
|
||||||
|
current_browser: browser.clone(),
|
||||||
|
total_browsers,
|
||||||
|
completed_browsers: index,
|
||||||
|
new_versions_found: total_new_versions,
|
||||||
|
browser_new_versions: new_versions_count,
|
||||||
|
status: "updating".to_string(),
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Err(e) = app_handle.emit("version-update-progress", &progress) {
|
||||||
|
eprintln!("Failed to emit progress with versions for {browser}: {e}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("Failed to update versions for {browser}: {e}");
|
results.push(BackgroundUpdateResult {
|
||||||
let browser_result = BackgroundUpdateResult {
|
browser: browser.clone(),
|
||||||
browser: browser.to_string(),
|
|
||||||
new_versions_count: 0,
|
new_versions_count: 0,
|
||||||
total_versions_count: 0,
|
total_versions_count: 0,
|
||||||
updated_successfully: false,
|
updated_successfully: false,
|
||||||
error: Some(e.to_string()),
|
error: Some(e.to_string()),
|
||||||
};
|
});
|
||||||
results.push(browser_result);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Small delay between browsers to avoid overwhelming APIs
|
|
||||||
tokio::time::sleep(Duration::from_millis(200)).await;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self
|
// Emit completion
|
||||||
.auto_updater
|
let final_progress = VersionUpdateProgress {
|
||||||
.check_for_updates_with_progress(app_handle)
|
current_browser: String::new(),
|
||||||
.await;
|
|
||||||
|
|
||||||
// Emit completion event
|
|
||||||
let progress = VersionUpdateProgress {
|
|
||||||
current_browser: "".to_string(),
|
|
||||||
total_browsers,
|
total_browsers,
|
||||||
completed_browsers: total_browsers,
|
completed_browsers: total_browsers,
|
||||||
new_versions_found: total_new_versions,
|
new_versions_found: total_new_versions,
|
||||||
browser_new_versions: 0,
|
browser_new_versions: 0,
|
||||||
status: "completed".to_string(),
|
status: "completed".to_string(),
|
||||||
};
|
};
|
||||||
if let Err(e) = app_handle.emit("version-update-progress", &progress) {
|
|
||||||
|
if let Err(e) = app_handle.emit("version-update-progress", &final_progress) {
|
||||||
eprintln!("Failed to emit completion progress: {e}");
|
eprintln!("Failed to emit completion progress: {e}");
|
||||||
} else {
|
|
||||||
println!("Emitted completion progress event");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("Version update completed. Found {total_new_versions} new versions total");
|
// After all version updates are complete, trigger auto-update check
|
||||||
|
if total_new_versions > 0 {
|
||||||
|
println!(
|
||||||
|
"Found {total_new_versions} new versions across all browsers. Checking for auto-updates..."
|
||||||
|
);
|
||||||
|
|
||||||
|
// Trigger auto-update check which will automatically download browsers
|
||||||
|
self
|
||||||
|
.auto_updater
|
||||||
|
.check_for_updates_with_progress(app_handle)
|
||||||
|
.await;
|
||||||
|
} else {
|
||||||
|
println!("No new versions found, skipping auto-update check");
|
||||||
|
}
|
||||||
|
|
||||||
Ok(results)
|
Ok(results)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user