mirror of
https://github.com/zhom/donutbrowser.git
synced 2026-08-02 17:28:43 +02:00
Compare commits
12
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eb3589b4c0 | ||
|
|
b71b9a00ca | ||
|
|
6535b37c98 | ||
|
|
bc72a837e2 | ||
|
|
fb84068d30 | ||
|
|
5024eab062 | ||
|
|
8137f9bf8d | ||
|
|
e2547c6ec7 | ||
|
|
d8d59d2bd5 | ||
|
|
b84350eb13 | ||
|
|
383cef916c | ||
|
|
743bc059be |
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
description:
|
||||||
|
globs:
|
||||||
|
alwaysApply: true
|
||||||
|
---
|
||||||
|
After your changes, instead of running specific tests or linting specific files, run "pnpm format && pnpm lint && pnpm test"
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
# Instructions for AI Agents
|
||||||
|
|
||||||
|
- If you want to run tests, only ever run them as "pnpm format && pnpm lint && pnpm test".
|
||||||
|
- Don't leave comments that don't add value
|
||||||
@@ -1,16 +1,38 @@
|
|||||||
# Donut Browser
|
<div align="center">
|
||||||
|
<img src="assets/logo.png" alt="Donut Browser Logo" width="150">
|
||||||
|
<h1>Donut Browser</h1>
|
||||||
|
<strong>A powerful browser orchestrator that puts you in control of your browsing experience. 🍩</strong>
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
|
||||||

|
<p align="center">
|
||||||
|
<a style="text-decoration: none;" href="https://github.com/zhom/donutbrowser/releases/latest" target="_blank"><img alt="GitHub release" src="https://img.shields.io/github/v/release/zhom/donutbrowser">
|
||||||
|
</a>
|
||||||
|
<a style="text-decoration: none;" href="https://github.com/zhom/donutbrowser/issues" target="_blank">
|
||||||
|
<img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat" alt="PRs Welcome">
|
||||||
|
</a>
|
||||||
|
<a style="text-decoration: none;" href="https://github.com/zhom/donutbrowser/blob/main/LICENSE" target="_blank">
|
||||||
|
<img src="https://img.shields.io/badge/license-AGPL--3.0-blue.svg" alt="License">
|
||||||
|
</a>
|
||||||
|
<a style="text-decoration: none;" href="https://github.com/zhom/donutbrowser/stargazers" target="_blank">
|
||||||
|
<img src="https://img.shields.io/github/stars/zhom/donutbrowser?style=social" alt="GitHub stars">
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
> **A powerful browser orchestrator that puts you in control of your browsing experience. 🍩**
|
## Donut Browser
|
||||||
|
|
||||||
[](https://github.com/zhom/donutbrowser/releases/latest)
|
> A free and open source browser orchestrator built with [Tauri](https://v2.tauri.app/).
|
||||||
[](https://github.com/zhom/donutbrowser/issues)
|
|
||||||
[](https://github.com/zhom/donutbrowser/blob/main/LICENSE)
|
|
||||||
[](https://github.com/zhom/donutbrowser/stargazers)
|
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- Create unlimited number of local browser profiles completely isolated from each other
|
||||||
|
- Proxy support with basic auth for all browsers except for TOR Browser
|
||||||
|
- Import profiles from your existing browsers
|
||||||
|
- Automatic updates both for browsers and for the app itself
|
||||||
|
- Set Donut Browser as your default browser to control in which profile to open links
|
||||||
|
|
||||||
## Download
|
## Download
|
||||||
|
|
||||||
> As of right now, the app is not signed by Apple. You need to have Gatekeeper disabled to run it. The app automatically checks for updates on each launch.
|
> As of right now, the app is not signed by Apple. You need to have Gatekeeper disabled to run it. The app automatically checks for updates on each launch.
|
||||||
@@ -28,8 +50,6 @@ The app can be downloaded from the [releases page](https://github.com/zhom/donut
|
|||||||
|
|
||||||
### Contributing
|
### Contributing
|
||||||
|
|
||||||
> Donut Browser is built with [Tauri](https://v2.tauri.app/).
|
|
||||||
|
|
||||||
See [CONTRIBUTING.md](CONTRIBUTING.md).
|
See [CONTRIBUTING.md](CONTRIBUTING.md).
|
||||||
|
|
||||||
## Issues
|
## Issues
|
||||||
@@ -45,7 +65,13 @@ Have questions or want to contribute? We'd love to hear from you!
|
|||||||
|
|
||||||
## Star History
|
## Star History
|
||||||
|
|
||||||
[](https://www.star-history.com/#zhom/donutbrowser&Date)
|
<a href="https://www.star-history.com/#zhom/donutbrowser&Date">
|
||||||
|
<picture>
|
||||||
|
<source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=zhom/donutbrowser&type=Date&theme=dark" />
|
||||||
|
<source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=zhom/donutbrowser&type=Date" />
|
||||||
|
<img alt="Star History Chart" src="https://api.star-history.com/svg?repos=zhom/donutbrowser&type=Date" />
|
||||||
|
</picture>
|
||||||
|
</a>
|
||||||
|
|
||||||
## Contact
|
## Contact
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
"name": "donutbrowser",
|
"name": "donutbrowser",
|
||||||
"private": true,
|
"private": true,
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"version": "0.3.0",
|
"version": "0.3.1",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev --turbopack",
|
"dev": "next dev --turbopack",
|
||||||
|
|||||||
Generated
+1
-1
@@ -993,7 +993,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "donutbrowser"
|
name = "donutbrowser"
|
||||||
version = "0.3.0"
|
version = "0.3.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"base64 0.22.1",
|
"base64 0.22.1",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "donutbrowser"
|
name = "donutbrowser"
|
||||||
version = "0.3.0"
|
version = "0.3.1"
|
||||||
description = "Simple Yet Powerful Browser Orchestrator"
|
description = "Simple Yet Powerful Browser Orchestrator"
|
||||||
authors = ["zhom@github"]
|
authors = ["zhom@github"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>1</string>
|
<string>1</string>
|
||||||
<key>CFBundleShortVersionString</key>
|
<key>CFBundleShortVersionString</key>
|
||||||
<string>0.3.0</string>
|
<string>0.3.1</string>
|
||||||
<key>CFBundlePackageType</key>
|
<key>CFBundlePackageType</key>
|
||||||
<string>APPL</string>
|
<string>APPL</string>
|
||||||
<key>CFBundleIconFile</key>
|
<key>CFBundleIconFile</key>
|
||||||
|
|||||||
+49
-68
@@ -229,10 +229,42 @@ pub fn is_nightly_version(version: &str) -> bool {
|
|||||||
version_comp.pre_release.is_some()
|
version_comp.pre_release.is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Browser-specific alpha version detection for Zen Browser
|
/// Centralized function to determine if a browser version/release is nightly/prerelease
|
||||||
pub fn is_zen_nightly_version(version: &str) -> bool {
|
/// This is the single source of truth for nightly detection across the entire codebase
|
||||||
// For Zen Browser, only "twilight" is considered alpha/pre-release
|
pub fn is_browser_version_nightly(
|
||||||
version.to_lowercase() == "twilight"
|
browser: &str,
|
||||||
|
version: &str,
|
||||||
|
release_name: Option<&str>,
|
||||||
|
) -> bool {
|
||||||
|
match browser {
|
||||||
|
"zen" => {
|
||||||
|
// For Zen Browser, only "twilight" is considered nightly
|
||||||
|
version.to_lowercase() == "twilight"
|
||||||
|
}
|
||||||
|
"brave" => {
|
||||||
|
// For Brave Browser, only releases titled "Release" are stable, everything else is nightly
|
||||||
|
if let Some(name) = release_name {
|
||||||
|
!name.starts_with("Release")
|
||||||
|
} else {
|
||||||
|
// Fallback to version string analysis if no release name
|
||||||
|
is_nightly_version(version)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"firefox" | "firefox-developer" => {
|
||||||
|
// For Firefox, use the category from the API response to determine stability
|
||||||
|
// This will be handled in the API parsing, so this fallback is for cached versions
|
||||||
|
is_nightly_version(version)
|
||||||
|
}
|
||||||
|
"mullvad-browser" | "tor-browser" => is_nightly_version(version),
|
||||||
|
"chromium" => {
|
||||||
|
// Chromium builds are generally stable snapshots
|
||||||
|
false
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
// Default fallback
|
||||||
|
is_nightly_version(version)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
@@ -256,7 +288,6 @@ pub struct BrowserRelease {
|
|||||||
pub version: String,
|
pub version: String,
|
||||||
pub date: String,
|
pub date: String,
|
||||||
pub is_prerelease: bool,
|
pub is_prerelease: bool,
|
||||||
pub download_url: Option<String>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
@@ -278,7 +309,6 @@ pub struct ApiClient {
|
|||||||
github_api_base: String,
|
github_api_base: String,
|
||||||
chromium_api_base: String,
|
chromium_api_base: String,
|
||||||
tor_archive_base: String,
|
tor_archive_base: String,
|
||||||
mozilla_download_base: String,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ApiClient {
|
impl ApiClient {
|
||||||
@@ -291,7 +321,6 @@ impl ApiClient {
|
|||||||
chromium_api_base: "https://commondatastorage.googleapis.com/chromium-browser-snapshots"
|
chromium_api_base: "https://commondatastorage.googleapis.com/chromium-browser-snapshots"
|
||||||
.to_string(),
|
.to_string(),
|
||||||
tor_archive_base: "https://archive.torproject.org/tor-package-archive/torbrowser".to_string(),
|
tor_archive_base: "https://archive.torproject.org/tor-package-archive/torbrowser".to_string(),
|
||||||
mozilla_download_base: "https://download.mozilla.org".to_string(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -302,7 +331,6 @@ impl ApiClient {
|
|||||||
github_api_base: String,
|
github_api_base: String,
|
||||||
chromium_api_base: String,
|
chromium_api_base: String,
|
||||||
tor_archive_base: String,
|
tor_archive_base: String,
|
||||||
mozilla_download_base: String,
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
client: Client::new(),
|
client: Client::new(),
|
||||||
@@ -311,7 +339,6 @@ impl ApiClient {
|
|||||||
github_api_base,
|
github_api_base,
|
||||||
chromium_api_base,
|
chromium_api_base,
|
||||||
tor_archive_base,
|
tor_archive_base,
|
||||||
mozilla_download_base,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -449,11 +476,7 @@ impl ApiClient {
|
|||||||
BrowserRelease {
|
BrowserRelease {
|
||||||
version: version.clone(),
|
version: version.clone(),
|
||||||
date: "".to_string(), // Cache doesn't store dates
|
date: "".to_string(), // Cache doesn't store dates
|
||||||
is_prerelease: is_nightly_version(&version),
|
is_prerelease: is_browser_version_nightly("firefox", &version, None),
|
||||||
download_url: Some(format!(
|
|
||||||
"{}/?product=firefox-{}&os=osx&lang=en-US",
|
|
||||||
self.mozilla_download_base, version
|
|
||||||
)),
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
@@ -489,10 +512,6 @@ impl ApiClient {
|
|||||||
version: release.version.clone(),
|
version: release.version.clone(),
|
||||||
date: release.date,
|
date: release.date,
|
||||||
is_prerelease: !is_stable,
|
is_prerelease: !is_stable,
|
||||||
download_url: Some(format!(
|
|
||||||
"{}/?product=firefox-{}&os=osx&lang=en-US",
|
|
||||||
self.mozilla_download_base, release.version
|
|
||||||
)),
|
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@@ -534,11 +553,7 @@ impl ApiClient {
|
|||||||
BrowserRelease {
|
BrowserRelease {
|
||||||
version: version.clone(),
|
version: version.clone(),
|
||||||
date: "".to_string(), // Cache doesn't store dates
|
date: "".to_string(), // Cache doesn't store dates
|
||||||
is_prerelease: is_nightly_version(&version),
|
is_prerelease: is_browser_version_nightly("firefox-developer", &version, None),
|
||||||
download_url: Some(format!(
|
|
||||||
"{}/?product=devedition-{}&os=osx&lang=en-US",
|
|
||||||
self.mozilla_download_base, version
|
|
||||||
)),
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
@@ -580,10 +595,6 @@ impl ApiClient {
|
|||||||
version: release.version.clone(),
|
version: release.version.clone(),
|
||||||
date: release.date,
|
date: release.date,
|
||||||
is_prerelease: !is_stable,
|
is_prerelease: !is_stable,
|
||||||
download_url: Some(format!(
|
|
||||||
"{}/?product=devedition-{}&os=osx&lang=en-US",
|
|
||||||
self.mozilla_download_base, release.version
|
|
||||||
)),
|
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@@ -685,7 +696,8 @@ impl ApiClient {
|
|||||||
// Check for twilight updates and mark alpha releases
|
// Check for twilight updates and mark alpha releases
|
||||||
for release in &mut releases {
|
for release in &mut releases {
|
||||||
// Use browser-specific alpha detection for Zen Browser - only "twilight" is nightly
|
// Use browser-specific alpha detection for Zen Browser - only "twilight" is nightly
|
||||||
release.is_nightly = is_zen_nightly_version(&release.tag_name);
|
release.is_nightly =
|
||||||
|
is_browser_version_nightly("zen", &release.tag_name, Some(&release.name));
|
||||||
|
|
||||||
// Check for twilight update if this is a twilight release
|
// Check for twilight update if this is a twilight release
|
||||||
if release.tag_name.to_lowercase() == "twilight" {
|
if release.tag_name.to_lowercase() == "twilight" {
|
||||||
@@ -749,9 +761,9 @@ impl ApiClient {
|
|||||||
let has_compatible_asset = Self::has_compatible_brave_asset(&release.assets, &os, &arch);
|
let has_compatible_asset = Self::has_compatible_brave_asset(&release.assets, &os, &arch);
|
||||||
|
|
||||||
if has_compatible_asset {
|
if has_compatible_asset {
|
||||||
// Set is_nightly based on the release name
|
// Use the centralized nightly detection function
|
||||||
// Stable releases start with "Release", everything else is nightly
|
release.is_nightly =
|
||||||
release.is_nightly = !release.name.starts_with("Release");
|
is_browser_version_nightly("brave", &release.tag_name, Some(&release.name));
|
||||||
Some(release)
|
Some(release)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@@ -877,7 +889,6 @@ impl ApiClient {
|
|||||||
version: version.clone(),
|
version: version.clone(),
|
||||||
date: "".to_string(), // Cache doesn't store dates
|
date: "".to_string(), // Cache doesn't store dates
|
||||||
is_prerelease: false, // Chromium versions are generally stable builds
|
is_prerelease: false, // Chromium versions are generally stable builds
|
||||||
download_url: None,
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
@@ -914,7 +925,6 @@ impl ApiClient {
|
|||||||
version: version.clone(),
|
version: version.clone(),
|
||||||
date: "".to_string(),
|
date: "".to_string(),
|
||||||
is_prerelease: false,
|
is_prerelease: false,
|
||||||
download_url: None,
|
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
)
|
)
|
||||||
@@ -934,11 +944,7 @@ impl ApiClient {
|
|||||||
BrowserRelease {
|
BrowserRelease {
|
||||||
version: version.clone(),
|
version: version.clone(),
|
||||||
date: "".to_string(), // Cache doesn't store dates
|
date: "".to_string(), // Cache doesn't store dates
|
||||||
is_prerelease: is_nightly_version(&version),
|
is_prerelease: is_browser_version_nightly("tor-browser", &version, None),
|
||||||
download_url: Some(format!(
|
|
||||||
"{}/{version}/tor-browser-macos-{version}.dmg",
|
|
||||||
self.tor_archive_base
|
|
||||||
)),
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
@@ -1013,10 +1019,6 @@ impl ApiClient {
|
|||||||
version: version.clone(),
|
version: version.clone(),
|
||||||
date: "".to_string(), // TOR archive doesn't provide structured dates
|
date: "".to_string(), // TOR archive doesn't provide structured dates
|
||||||
is_prerelease: false, // Assume all archived versions are stable
|
is_prerelease: false, // Assume all archived versions are stable
|
||||||
download_url: Some(format!(
|
|
||||||
"{}/{version}/tor-browser-macos-{version}.dmg",
|
|
||||||
self.tor_archive_base
|
|
||||||
)),
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
@@ -1065,13 +1067,11 @@ impl ApiClient {
|
|||||||
struct TwilightInfo {
|
struct TwilightInfo {
|
||||||
file_size: u64,
|
file_size: u64,
|
||||||
last_updated: u64,
|
last_updated: u64,
|
||||||
download_url: String,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let current_info = TwilightInfo {
|
let current_info = TwilightInfo {
|
||||||
file_size: asset.size,
|
file_size: asset.size,
|
||||||
last_updated: Self::get_current_timestamp(),
|
last_updated: Self::get_current_timestamp(),
|
||||||
download_url: asset.browser_download_url.clone(),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if !twilight_cache_file.exists() {
|
if !twilight_cache_file.exists() {
|
||||||
@@ -1137,7 +1137,6 @@ mod tests {
|
|||||||
base_url.clone(), // github_api_base
|
base_url.clone(), // github_api_base
|
||||||
base_url.clone(), // chromium_api_base
|
base_url.clone(), // chromium_api_base
|
||||||
base_url.clone(), // tor_archive_base
|
base_url.clone(), // tor_archive_base
|
||||||
base_url.clone(), // mozilla_download_base
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1317,12 +1316,6 @@ mod tests {
|
|||||||
let releases = result.unwrap();
|
let releases = result.unwrap();
|
||||||
assert!(!releases.is_empty());
|
assert!(!releases.is_empty());
|
||||||
assert_eq!(releases[0].version, "139.0");
|
assert_eq!(releases[0].version, "139.0");
|
||||||
assert!(releases[0].download_url.is_some());
|
|
||||||
assert!(releases[0]
|
|
||||||
.download_url
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.contains(&server.uri()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@@ -1365,12 +1358,6 @@ mod tests {
|
|||||||
let releases = result.unwrap();
|
let releases = result.unwrap();
|
||||||
assert!(!releases.is_empty());
|
assert!(!releases.is_empty());
|
||||||
assert_eq!(releases[0].version, "140.0b1");
|
assert_eq!(releases[0].version, "140.0b1");
|
||||||
assert!(releases[0].download_url.is_some());
|
|
||||||
assert!(releases[0]
|
|
||||||
.download_url
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.contains(&server.uri()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@@ -1615,12 +1602,6 @@ mod tests {
|
|||||||
let releases = result.unwrap();
|
let releases = result.unwrap();
|
||||||
assert!(!releases.is_empty());
|
assert!(!releases.is_empty());
|
||||||
assert_eq!(releases[0].version, "14.0.4");
|
assert_eq!(releases[0].version, "14.0.4");
|
||||||
assert!(releases[0].download_url.is_some());
|
|
||||||
assert!(releases[0]
|
|
||||||
.download_url
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.contains(&server.uri()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@@ -1693,13 +1674,13 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_is_zen_nightly_version() {
|
fn test_is_zen_nightly_version() {
|
||||||
// Only "twilight" should be considered nightly for Zen Browser
|
// Only "twilight" should be considered nightly for Zen Browser
|
||||||
assert!(is_zen_nightly_version("twilight"));
|
assert!(is_browser_version_nightly("zen", "twilight", None));
|
||||||
assert!(is_zen_nightly_version("TWILIGHT")); // Case insensitive
|
assert!(is_browser_version_nightly("zen", "TWILIGHT", None)); // Case insensitive
|
||||||
|
|
||||||
// Versions with "b" should NOT be considered nightly for Zen Browser
|
// Versions with "b" should NOT be considered nightly for Zen Browser
|
||||||
assert!(!is_zen_nightly_version("1.12.8b"));
|
assert!(!is_browser_version_nightly("zen", "1.12.8b", None));
|
||||||
assert!(!is_zen_nightly_version("1.0.0b1"));
|
assert!(!is_browser_version_nightly("zen", "1.0.0b1", None));
|
||||||
assert!(!is_zen_nightly_version("2.0.0"));
|
assert!(!is_browser_version_nightly("zen", "2.0.0", None));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
|||||||
@@ -346,12 +346,9 @@ impl AutoUpdater {
|
|||||||
// Helper methods
|
// Helper methods
|
||||||
|
|
||||||
fn is_nightly_version(&self, version: &str) -> bool {
|
fn is_nightly_version(&self, version: &str) -> bool {
|
||||||
version.contains("alpha")
|
// Use the centralized nightly detection function
|
||||||
|| version.contains("beta")
|
// Since we don't have browser context here, use the general fallback
|
||||||
|| version.contains("rc")
|
crate::api_client::is_nightly_version(version)
|
||||||
|| version.contains("a")
|
|
||||||
|| version.contains("b")
|
|
||||||
|| version.contains("dev")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_version_newer(&self, version1: &str, version2: &str) -> bool {
|
fn is_version_newer(&self, version1: &str, version2: &str) -> bool {
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ impl BrowserVersionService {
|
|||||||
.map(|version| {
|
.map(|version| {
|
||||||
BrowserVersionInfo {
|
BrowserVersionInfo {
|
||||||
version: version.clone(),
|
version: version.clone(),
|
||||||
is_prerelease: crate::api_client::is_nightly_version(&version),
|
is_prerelease: crate::api_client::is_browser_version_nightly(browser, &version, None),
|
||||||
date: "".to_string(), // Cache doesn't store dates
|
date: "".to_string(), // Cache doesn't store dates
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -240,7 +240,9 @@ impl BrowserVersionService {
|
|||||||
} else {
|
} else {
|
||||||
BrowserVersionInfo {
|
BrowserVersionInfo {
|
||||||
version: version.clone(),
|
version: version.clone(),
|
||||||
is_prerelease: crate::api_client::is_nightly_version(&version),
|
is_prerelease: crate::api_client::is_browser_version_nightly(
|
||||||
|
"firefox", &version, None,
|
||||||
|
),
|
||||||
date: "".to_string(),
|
date: "".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -261,7 +263,11 @@ impl BrowserVersionService {
|
|||||||
} else {
|
} else {
|
||||||
BrowserVersionInfo {
|
BrowserVersionInfo {
|
||||||
version: version.clone(),
|
version: version.clone(),
|
||||||
is_prerelease: crate::api_client::is_nightly_version(&version),
|
is_prerelease: crate::api_client::is_browser_version_nightly(
|
||||||
|
"firefox-developer",
|
||||||
|
&version,
|
||||||
|
None,
|
||||||
|
),
|
||||||
date: "".to_string(),
|
date: "".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -303,7 +309,7 @@ impl BrowserVersionService {
|
|||||||
} else {
|
} else {
|
||||||
BrowserVersionInfo {
|
BrowserVersionInfo {
|
||||||
version: version.clone(),
|
version: version.clone(),
|
||||||
is_prerelease: false, // Zen Browser releases are usually stable
|
is_prerelease: crate::api_client::is_browser_version_nightly("zen", &version, None),
|
||||||
date: "".to_string(),
|
date: "".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -324,7 +330,9 @@ impl BrowserVersionService {
|
|||||||
} else {
|
} else {
|
||||||
BrowserVersionInfo {
|
BrowserVersionInfo {
|
||||||
version: version.clone(),
|
version: version.clone(),
|
||||||
is_prerelease: version.contains("beta") || version.contains("dev"),
|
is_prerelease: crate::api_client::is_browser_version_nightly(
|
||||||
|
"brave", &version, None,
|
||||||
|
),
|
||||||
date: "".to_string(),
|
date: "".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -360,7 +368,11 @@ impl BrowserVersionService {
|
|||||||
if let Some(release) = releases.iter().find(|r| r.version == version) {
|
if let Some(release) = releases.iter().find(|r| r.version == version) {
|
||||||
BrowserVersionInfo {
|
BrowserVersionInfo {
|
||||||
version: release.version.clone(),
|
version: release.version.clone(),
|
||||||
is_prerelease: crate::api_client::is_nightly_version(&version),
|
is_prerelease: crate::api_client::is_browser_version_nightly(
|
||||||
|
"tor-browser",
|
||||||
|
&release.version,
|
||||||
|
None,
|
||||||
|
),
|
||||||
date: release.date.clone(),
|
date: release.date.clone(),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -423,11 +435,16 @@ impl BrowserVersionService {
|
|||||||
|
|
||||||
match browser {
|
match browser {
|
||||||
"firefox" => {
|
"firefox" => {
|
||||||
let os_param = match (&os[..], &arch[..]) {
|
let (platform_path, filename, is_archive) = match (&os[..], &arch[..]) {
|
||||||
("windows", _) => "win64",
|
("windows", "x64") => ("win64", format!("Firefox Setup {version}.exe"), false),
|
||||||
("linux", "x64") => "linux64",
|
("windows", "arm64") => (
|
||||||
("linux", "arm64") => "linux64-aarch64",
|
"win64-aarch64",
|
||||||
("macos", _) => "osx",
|
format!("Firefox Setup {version}.exe"),
|
||||||
|
false,
|
||||||
|
),
|
||||||
|
("linux", "x64") => ("linux-x86_64", format!("firefox-{version}.tar.bz2"), true),
|
||||||
|
("linux", "arm64") => ("linux-aarch64", format!("firefox-{version}.tar.bz2"), true),
|
||||||
|
("macos", _) => ("mac", format!("Firefox {version}.dmg"), true),
|
||||||
_ => {
|
_ => {
|
||||||
return Err(
|
return Err(
|
||||||
format!("Unsupported platform/architecture for Firefox: {os}/{arch}").into(),
|
format!("Unsupported platform/architecture for Firefox: {os}/{arch}").into(),
|
||||||
@@ -435,27 +452,25 @@ impl BrowserVersionService {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let (filename, is_archive) = match os.as_str() {
|
|
||||||
"windows" => (format!("firefox-{version}.exe"), false),
|
|
||||||
"linux" => (format!("firefox-{version}.tar.xz"), true),
|
|
||||||
"macos" => (format!("firefox-{version}.dmg"), true),
|
|
||||||
_ => return Err(format!("Unsupported platform for Firefox: {os}").into()),
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(DownloadInfo {
|
Ok(DownloadInfo {
|
||||||
url: format!(
|
url: format!(
|
||||||
"https://download.mozilla.org/?product=firefox-{version}&os={os_param}&lang=en-US"
|
"https://download-installer.cdn.mozilla.net/pub/firefox/releases/{version}/{platform_path}/en-US/{filename}"
|
||||||
),
|
),
|
||||||
filename,
|
filename,
|
||||||
is_archive,
|
is_archive,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
"firefox-developer" => {
|
"firefox-developer" => {
|
||||||
let os_param = match (&os[..], &arch[..]) {
|
let (platform_path, filename, is_archive) = match (&os[..], &arch[..]) {
|
||||||
("windows", _) => "win64",
|
("windows", "x64") => ("win64", format!("Firefox Setup {version}.exe"), false),
|
||||||
("linux", "x64") => "linux64",
|
("windows", "arm64") => (
|
||||||
("linux", "arm64") => "linux64-aarch64",
|
"win64-aarch64",
|
||||||
("macos", _) => "osx",
|
format!("Firefox Setup {version}.exe"),
|
||||||
|
false,
|
||||||
|
),
|
||||||
|
("linux", "x64") => ("linux-x86_64", format!("firefox-{version}.tar.bz2"), true),
|
||||||
|
("linux", "arm64") => ("linux-aarch64", format!("firefox-{version}.tar.bz2"), true),
|
||||||
|
("macos", _) => ("mac", format!("Firefox {version}.dmg"), true),
|
||||||
_ => {
|
_ => {
|
||||||
return Err(
|
return Err(
|
||||||
format!("Unsupported platform/architecture for Firefox Developer: {os}/{arch}")
|
format!("Unsupported platform/architecture for Firefox Developer: {os}/{arch}")
|
||||||
@@ -464,16 +479,9 @@ impl BrowserVersionService {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let (filename, is_archive) = match os.as_str() {
|
|
||||||
"windows" => (format!("firefox-developer-{version}.exe"), false),
|
|
||||||
"linux" => (format!("firefox-developer-{version}.tar.xz"), true),
|
|
||||||
"macos" => (format!("firefox-developer-{version}.dmg"), true),
|
|
||||||
_ => return Err(format!("Unsupported platform for Firefox Developer: {os}").into()),
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(DownloadInfo {
|
Ok(DownloadInfo {
|
||||||
url: format!(
|
url: format!(
|
||||||
"https://download.mozilla.org/?product=firefox-devedition-{version}&os={os_param}&lang=en-US"
|
"https://download-installer.cdn.mozilla.net/pub/devedition/releases/{version}/{platform_path}/en-US/{filename}"
|
||||||
),
|
),
|
||||||
filename,
|
filename,
|
||||||
is_archive,
|
is_archive,
|
||||||
@@ -826,7 +834,6 @@ mod tests {
|
|||||||
base_url.clone(), // github_api_base
|
base_url.clone(), // github_api_base
|
||||||
base_url.clone(), // chromium_api_base
|
base_url.clone(), // chromium_api_base
|
||||||
base_url.clone(), // tor_archive_base
|
base_url.clone(), // tor_archive_base
|
||||||
base_url.clone(), // mozilla_download_base
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1468,16 +1475,24 @@ mod tests {
|
|||||||
|
|
||||||
// Test Firefox
|
// Test Firefox
|
||||||
let firefox_info = service.get_download_info("firefox", "139.0").unwrap();
|
let firefox_info = service.get_download_info("firefox", "139.0").unwrap();
|
||||||
assert_eq!(firefox_info.filename, "firefox-139.0.dmg");
|
assert_eq!(firefox_info.filename, "Firefox 139.0.dmg");
|
||||||
assert!(firefox_info.url.contains("firefox-139.0"));
|
assert!(firefox_info
|
||||||
|
.url
|
||||||
|
.contains("download-installer.cdn.mozilla.net"));
|
||||||
|
assert!(firefox_info.url.contains("/pub/firefox/releases/139.0/"));
|
||||||
assert!(firefox_info.is_archive);
|
assert!(firefox_info.is_archive);
|
||||||
|
|
||||||
// Test Firefox Developer
|
// Test Firefox Developer
|
||||||
let firefox_dev_info = service
|
let firefox_dev_info = service
|
||||||
.get_download_info("firefox-developer", "139.0b1")
|
.get_download_info("firefox-developer", "139.0b1")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(firefox_dev_info.filename, "firefox-developer-139.0b1.dmg");
|
assert_eq!(firefox_dev_info.filename, "Firefox 139.0b1.dmg");
|
||||||
assert!(firefox_dev_info.url.contains("devedition-139.0b1"));
|
assert!(firefox_dev_info
|
||||||
|
.url
|
||||||
|
.contains("download-installer.cdn.mozilla.net"));
|
||||||
|
assert!(firefox_dev_info
|
||||||
|
.url
|
||||||
|
.contains("/pub/devedition/releases/139.0b1/"));
|
||||||
assert!(firefox_dev_info.is_archive);
|
assert!(firefox_dev_info.is_archive);
|
||||||
|
|
||||||
// Test Mullvad Browser
|
// Test Mullvad Browser
|
||||||
|
|||||||
@@ -459,7 +459,6 @@ mod tests {
|
|||||||
base_url.clone(), // github_api_base
|
base_url.clone(), // github_api_base
|
||||||
base_url.clone(), // chromium_api_base
|
base_url.clone(), // chromium_api_base
|
||||||
base_url.clone(), // tor_archive_base
|
base_url.clone(), // tor_archive_base
|
||||||
base_url.clone(), // mozilla_download_base
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+542
-135
@@ -34,8 +34,15 @@ impl Extractor {
|
|||||||
};
|
};
|
||||||
let _ = app_handle.emit("download-progress", &progress);
|
let _ = app_handle.emit("download-progress", &progress);
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"Starting extraction of {} for browser {}",
|
||||||
|
archive_path.display(),
|
||||||
|
browser_type.as_str()
|
||||||
|
);
|
||||||
|
|
||||||
// Try to detect the actual file type by reading the file header
|
// Try to detect the actual file type by reading the file header
|
||||||
let actual_format = self.detect_file_format(archive_path)?;
|
let actual_format = self.detect_file_format(archive_path)?;
|
||||||
|
println!("Detected format: {actual_format}");
|
||||||
|
|
||||||
match actual_format.as_str() {
|
match actual_format.as_str() {
|
||||||
"dmg" => {
|
"dmg" => {
|
||||||
@@ -88,6 +95,14 @@ impl Extractor {
|
|||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
|
||||||
|
// First check file extension for DMG files since they're common on macOS
|
||||||
|
// and can have misleading magic numbers
|
||||||
|
if let Some(ext) = file_path.extension().and_then(|ext| ext.to_str()) {
|
||||||
|
if ext.to_lowercase() == "dmg" {
|
||||||
|
return Ok("dmg".to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let mut file = File::open(file_path)?;
|
let mut file = File::open(file_path)?;
|
||||||
let mut buffer = [0u8; 12]; // Read first 12 bytes for magic number detection
|
let mut buffer = [0u8; 12]; // Read first 12 bytes for magic number detection
|
||||||
file.read_exact(&mut buffer)?;
|
file.read_exact(&mut buffer)?;
|
||||||
@@ -179,6 +194,12 @@ impl Extractor {
|
|||||||
dmg_path: &Path,
|
dmg_path: &Path,
|
||||||
dest_dir: &Path,
|
dest_dir: &Path,
|
||||||
) -> Result<PathBuf, Box<dyn std::error::Error + Send + Sync>> {
|
) -> Result<PathBuf, Box<dyn std::error::Error + Send + Sync>> {
|
||||||
|
println!(
|
||||||
|
"Extracting DMG: {} to {}",
|
||||||
|
dmg_path.display(),
|
||||||
|
dest_dir.display()
|
||||||
|
);
|
||||||
|
|
||||||
// Create a temporary mount point
|
// Create a temporary mount point
|
||||||
let mount_point = std::env::temp_dir().join(format!(
|
let mount_point = std::env::temp_dir().join(format!(
|
||||||
"donut_mount_{}",
|
"donut_mount_{}",
|
||||||
@@ -189,6 +210,8 @@ impl Extractor {
|
|||||||
));
|
));
|
||||||
create_dir_all(&mount_point)?;
|
create_dir_all(&mount_point)?;
|
||||||
|
|
||||||
|
println!("Created mount point: {}", mount_point.display());
|
||||||
|
|
||||||
// Mount the DMG
|
// Mount the DMG
|
||||||
let output = Command::new("hdiutil")
|
let output = Command::new("hdiutil")
|
||||||
.args([
|
.args([
|
||||||
@@ -201,42 +224,109 @@ impl Extractor {
|
|||||||
.output()?;
|
.output()?;
|
||||||
|
|
||||||
if !output.status.success() {
|
if !output.status.success() {
|
||||||
return Err(
|
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||||
format!(
|
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||||
"Failed to mount DMG: {}",
|
println!("Failed to mount DMG. stdout: {stdout}, stderr: {stderr}");
|
||||||
String::from_utf8_lossy(&output.stderr)
|
|
||||||
)
|
// Clean up mount point before returning error
|
||||||
.into(),
|
let _ = fs::remove_dir_all(&mount_point);
|
||||||
);
|
|
||||||
|
return Err(format!("Failed to mount DMG: {stderr}").into());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the .app directory in the mount point
|
println!("Successfully mounted DMG");
|
||||||
let app_entry = fs::read_dir(&mount_point)?
|
|
||||||
.filter_map(Result::ok)
|
// List the contents for debugging
|
||||||
.find(|entry| entry.path().extension().is_some_and(|ext| ext == "app"))
|
println!("Mount point contents:");
|
||||||
.ok_or("No .app found in DMG")?;
|
if let Ok(entries) = fs::read_dir(&mount_point) {
|
||||||
|
for entry in entries.flatten() {
|
||||||
|
let path = entry.path();
|
||||||
|
println!(
|
||||||
|
" - {} ({})",
|
||||||
|
path.display(),
|
||||||
|
if path.is_dir() { "dir" } else { "file" }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find the .app directory in the mount point with enhanced search
|
||||||
|
let app_result = self.find_app_in_directory(&mount_point).await;
|
||||||
|
|
||||||
|
let app_entry = match app_result {
|
||||||
|
Ok(app_path) => app_path,
|
||||||
|
Err(e) => {
|
||||||
|
println!("Failed to find .app in mount point: {e}");
|
||||||
|
|
||||||
|
// Enhanced debugging - look for any interesting files/directories
|
||||||
|
if let Ok(entries) = fs::read_dir(&mount_point) {
|
||||||
|
println!("Detailed mount point analysis:");
|
||||||
|
for entry in entries.flatten() {
|
||||||
|
let path = entry.path();
|
||||||
|
let metadata = fs::metadata(&path);
|
||||||
|
println!(
|
||||||
|
" - {} ({}) - {:?}",
|
||||||
|
path.display(),
|
||||||
|
if path.is_dir() { "dir" } else { "file" },
|
||||||
|
metadata.map(|m| m.len()).unwrap_or(0)
|
||||||
|
);
|
||||||
|
|
||||||
|
// If it's a directory, look one level deep
|
||||||
|
if path.is_dir() {
|
||||||
|
if let Ok(sub_entries) = fs::read_dir(&path) {
|
||||||
|
for sub_entry in sub_entries.flatten().take(5) {
|
||||||
|
// Limit to first 5 items
|
||||||
|
let sub_path = sub_entry.path();
|
||||||
|
println!(
|
||||||
|
" - {} ({})",
|
||||||
|
sub_path.display(),
|
||||||
|
if sub_path.is_dir() { "dir" } else { "file" }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to unmount before returning error
|
||||||
|
let _ = Command::new("hdiutil")
|
||||||
|
.args(["detach", "-force", mount_point.to_str().unwrap()])
|
||||||
|
.output();
|
||||||
|
let _ = fs::remove_dir_all(&mount_point);
|
||||||
|
|
||||||
|
return Err("No .app found after extraction".into());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
println!("Found .app bundle: {}", app_entry.display());
|
||||||
|
|
||||||
// Copy the .app to the destination
|
// Copy the .app to the destination
|
||||||
let app_path = dest_dir.join(app_entry.file_name());
|
let app_path = dest_dir.join(app_entry.file_name().unwrap());
|
||||||
|
|
||||||
|
println!("Copying .app to: {}", app_path.display());
|
||||||
|
|
||||||
let output = Command::new("cp")
|
let output = Command::new("cp")
|
||||||
.args([
|
.args([
|
||||||
"-R",
|
"-R",
|
||||||
app_entry.path().to_str().unwrap(),
|
app_entry.to_str().unwrap(),
|
||||||
app_path.to_str().unwrap(),
|
app_path.to_str().unwrap(),
|
||||||
])
|
])
|
||||||
.output()?;
|
.output()?;
|
||||||
|
|
||||||
if !output.status.success() {
|
if !output.status.success() {
|
||||||
return Err(
|
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||||
format!(
|
println!("Failed to copy app: {stderr}");
|
||||||
"Failed to copy app: {}",
|
|
||||||
String::from_utf8_lossy(&output.stderr)
|
// Unmount before returning error
|
||||||
)
|
let _ = Command::new("hdiutil")
|
||||||
.into(),
|
.args(["detach", "-force", mount_point.to_str().unwrap()])
|
||||||
);
|
.output();
|
||||||
|
let _ = fs::remove_dir_all(&mount_point);
|
||||||
|
|
||||||
|
return Err(format!("Failed to copy app: {stderr}").into());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println!("Successfully copied .app bundle");
|
||||||
|
|
||||||
// Remove quarantine attributes
|
// Remove quarantine attributes
|
||||||
let _ = Command::new("xattr")
|
let _ = Command::new("xattr")
|
||||||
.args(["-dr", "com.apple.quarantine", app_path.to_str().unwrap()])
|
.args(["-dr", "com.apple.quarantine", app_path.to_str().unwrap()])
|
||||||
@@ -246,29 +336,19 @@ impl Extractor {
|
|||||||
.args(["-cr", app_path.to_str().unwrap()])
|
.args(["-cr", app_path.to_str().unwrap()])
|
||||||
.output();
|
.output();
|
||||||
|
|
||||||
// Try to unmount the DMG with retries
|
println!("Removed quarantine attributes");
|
||||||
let mut retry_count = 0;
|
|
||||||
let max_retries = 3;
|
|
||||||
let mut unmounted = false;
|
|
||||||
|
|
||||||
while retry_count < max_retries && !unmounted {
|
// Unmount the DMG
|
||||||
// Wait a bit before trying to unmount
|
let output = Command::new("hdiutil")
|
||||||
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
|
.args(["detach", mount_point.to_str().unwrap()])
|
||||||
|
.output()?;
|
||||||
|
|
||||||
let output = Command::new("hdiutil")
|
if !output.status.success() {
|
||||||
.args(["detach", mount_point.to_str().unwrap()])
|
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||||
.output()?;
|
println!("Warning: Failed to unmount DMG: {stderr}");
|
||||||
|
// Don't fail if unmount fails - the extraction was successful
|
||||||
if output.status.success() {
|
} else {
|
||||||
unmounted = true;
|
println!("Successfully unmounted DMG");
|
||||||
} else if retry_count == max_retries - 1 {
|
|
||||||
// Force unmount on last retry
|
|
||||||
let _ = Command::new("hdiutil")
|
|
||||||
.args(["detach", "-force", mount_point.to_str().unwrap()])
|
|
||||||
.output();
|
|
||||||
unmounted = true; // Consider it unmounted even if force fails
|
|
||||||
}
|
|
||||||
retry_count += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean up mount point directory
|
// Clean up mount point directory
|
||||||
@@ -277,6 +357,79 @@ impl Extractor {
|
|||||||
Ok(app_path)
|
Ok(app_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
async fn find_app_in_directory(
|
||||||
|
&self,
|
||||||
|
dir: &Path,
|
||||||
|
) -> Result<PathBuf, Box<dyn std::error::Error + Send + Sync>> {
|
||||||
|
self.find_app_recursive(dir, 0).await
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
async fn find_app_recursive(
|
||||||
|
&self,
|
||||||
|
dir: &Path,
|
||||||
|
depth: usize,
|
||||||
|
) -> Result<PathBuf, Box<dyn std::error::Error + Send + Sync>> {
|
||||||
|
// Limit search depth to avoid infinite loops
|
||||||
|
if depth > 4 {
|
||||||
|
return Err("Maximum search depth reached".into());
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Ok(entries) = fs::read_dir(dir) {
|
||||||
|
let mut subdirs = Vec::new();
|
||||||
|
let mut hidden_subdirs = Vec::new();
|
||||||
|
|
||||||
|
// First pass: look for .app bundles directly
|
||||||
|
for entry in entries.flatten() {
|
||||||
|
let path = entry.path();
|
||||||
|
if path.is_dir() {
|
||||||
|
if let Some(extension) = path.extension() {
|
||||||
|
if extension == "app" {
|
||||||
|
println!("Found .app bundle at depth {}: {}", depth, path.display());
|
||||||
|
return Ok(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collect subdirectories for second pass
|
||||||
|
let filename = path.file_name().unwrap_or_default().to_string_lossy();
|
||||||
|
if filename.starts_with('.') {
|
||||||
|
// Hidden directories - search these with lower priority
|
||||||
|
hidden_subdirs.push(path);
|
||||||
|
} else {
|
||||||
|
// Regular directories - search these first
|
||||||
|
subdirs.push(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Second pass: search regular subdirectories first
|
||||||
|
for subdir in subdirs {
|
||||||
|
// Skip common directories that are unlikely to contain .app files
|
||||||
|
let dirname = subdir.file_name().unwrap_or_default().to_string_lossy();
|
||||||
|
if matches!(
|
||||||
|
dirname.as_ref(),
|
||||||
|
"Documents" | "Downloads" | "Desktop" | "Library" | "System" | "tmp" | "var"
|
||||||
|
) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Ok(result) = Box::pin(self.find_app_recursive(&subdir, depth + 1)).await {
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Third pass: search hidden directories if nothing found in regular ones
|
||||||
|
for hidden_dir in hidden_subdirs {
|
||||||
|
if let Ok(result) = Box::pin(self.find_app_recursive(&hidden_dir, depth + 1)).await {
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Err(format!("No .app found in directory: {}", dir.display()).into())
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn extract_zip(
|
pub async fn extract_zip(
|
||||||
&self,
|
&self,
|
||||||
zip_path: &Path,
|
zip_path: &Path,
|
||||||
@@ -608,34 +761,65 @@ impl Extractor {
|
|||||||
&self,
|
&self,
|
||||||
dest_dir: &Path,
|
dest_dir: &Path,
|
||||||
) -> Result<PathBuf, Box<dyn std::error::Error + Send + Sync>> {
|
) -> Result<PathBuf, Box<dyn std::error::Error + Send + Sync>> {
|
||||||
// First, try to find any .app file in the destination directory
|
println!("Searching for .app bundle in: {}", dest_dir.display());
|
||||||
if let Ok(entries) = fs::read_dir(dest_dir) {
|
|
||||||
for entry in entries.flatten() {
|
|
||||||
let path = entry.path();
|
|
||||||
if path.extension().is_some_and(|ext| ext == "app") {
|
|
||||||
return Ok(path);
|
|
||||||
}
|
|
||||||
// For Chromium, check subdirectories (chrome-mac folder)
|
|
||||||
if path.is_dir() {
|
|
||||||
if let Ok(sub_entries) = fs::read_dir(&path) {
|
|
||||||
for sub_entry in sub_entries.flatten() {
|
|
||||||
let sub_path = sub_entry.path();
|
|
||||||
if sub_path.extension().is_some_and(|ext| ext == "app") {
|
|
||||||
// Move the app to the root destination directory
|
|
||||||
let target_path = dest_dir.join(sub_path.file_name().unwrap());
|
|
||||||
fs::rename(&sub_path, &target_path)?;
|
|
||||||
|
|
||||||
// Clean up the now-empty subdirectory
|
// Use the enhanced recursive search
|
||||||
let _ = fs::remove_dir_all(&path);
|
match self.find_app_in_directory(dest_dir).await {
|
||||||
return Ok(target_path);
|
Ok(app_path) => {
|
||||||
|
// Check if the app is in a subdirectory and move it to the root if needed
|
||||||
|
let app_parent = app_path.parent().unwrap();
|
||||||
|
if app_parent != dest_dir {
|
||||||
|
println!(
|
||||||
|
"Found .app in subdirectory, moving to root: {} -> {}",
|
||||||
|
app_path.display(),
|
||||||
|
dest_dir.display()
|
||||||
|
);
|
||||||
|
let target_path = dest_dir.join(app_path.file_name().unwrap());
|
||||||
|
|
||||||
|
// Move the app to the root destination directory
|
||||||
|
fs::rename(&app_path, &target_path)?;
|
||||||
|
|
||||||
|
// Try to clean up the now-empty subdirectory (ignore errors)
|
||||||
|
if let Some(parent_dir) = app_path.parent() {
|
||||||
|
if parent_dir != dest_dir {
|
||||||
|
let _ = fs::remove_dir_all(parent_dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("Successfully moved .app to: {}", target_path.display());
|
||||||
|
Ok(target_path)
|
||||||
|
} else {
|
||||||
|
println!("Found .app at root level: {}", app_path.display());
|
||||||
|
Ok(app_path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
println!("Failed to find .app bundle: {e}");
|
||||||
|
|
||||||
|
// List contents for debugging
|
||||||
|
if let Ok(entries) = fs::read_dir(dest_dir) {
|
||||||
|
println!("Destination directory contents:");
|
||||||
|
for entry in entries.flatten() {
|
||||||
|
let path = entry.path();
|
||||||
|
let metadata = if path.is_dir() { "dir" } else { "file" };
|
||||||
|
println!(" - {} ({})", path.display(), metadata);
|
||||||
|
|
||||||
|
// If it's a directory, also list its contents
|
||||||
|
if path.is_dir() {
|
||||||
|
if let Ok(sub_entries) = fs::read_dir(&path) {
|
||||||
|
for sub_entry in sub_entries.flatten() {
|
||||||
|
let sub_path = sub_entry.path();
|
||||||
|
let sub_metadata = if sub_path.is_dir() { "dir" } else { "file" };
|
||||||
|
println!(" - {} ({})", sub_path.display(), sub_metadata);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Err("No .app found after extraction".into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Err("No .app found after extraction".into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
@@ -904,7 +1088,8 @@ impl Extractor {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use std::fs::File;
|
use std::fs::{create_dir_all, File};
|
||||||
|
use std::io::Write;
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -915,50 +1100,81 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_unsupported_archive_format() {
|
fn test_unsupported_archive_format() {
|
||||||
let _ = Extractor::new();
|
let extractor = Extractor::new();
|
||||||
let temp_dir = TempDir::new().unwrap();
|
let temp_dir = TempDir::new().unwrap();
|
||||||
let fake_archive = temp_dir.path().join("test.rar");
|
let fake_archive = temp_dir.path().join("test.rar");
|
||||||
File::create(&fake_archive).unwrap();
|
|
||||||
|
|
||||||
// Create a mock app handle (this won't work in real tests without Tauri runtime)
|
// Create a file with invalid header
|
||||||
// For now, we'll just test the logic without the actual extraction
|
let mut file = File::create(&fake_archive).unwrap();
|
||||||
|
file.write_all(b"invalid content").unwrap();
|
||||||
|
|
||||||
// Test that unsupported formats return an error
|
// Test format detection
|
||||||
let extension = fake_archive
|
let result = extractor.detect_file_format(&fake_archive);
|
||||||
.extension()
|
assert!(result.is_ok());
|
||||||
.and_then(|ext| ext.to_str())
|
assert_eq!(result.unwrap(), "unknown");
|
||||||
.unwrap_or("");
|
|
||||||
|
|
||||||
assert_eq!(extension, "rar");
|
|
||||||
// We know this would fail with "Unsupported archive format: rar"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_dmg_path_validation() {
|
fn test_format_detection_zip() {
|
||||||
let temp_dir = TempDir::new().unwrap();
|
let extractor = Extractor::new();
|
||||||
let dmg_path = temp_dir.path().join("test.dmg");
|
|
||||||
|
|
||||||
// Test that we can identify DMG files correctly
|
|
||||||
let extension = dmg_path
|
|
||||||
.extension()
|
|
||||||
.and_then(|ext| ext.to_str())
|
|
||||||
.unwrap_or("");
|
|
||||||
|
|
||||||
assert_eq!(extension, "dmg");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_zip_path_validation() {
|
|
||||||
let temp_dir = TempDir::new().unwrap();
|
let temp_dir = TempDir::new().unwrap();
|
||||||
let zip_path = temp_dir.path().join("test.zip");
|
let zip_path = temp_dir.path().join("test.zip");
|
||||||
|
|
||||||
// Test that we can identify ZIP files correctly
|
// Create a file with ZIP magic number
|
||||||
let extension = zip_path
|
let mut file = File::create(&zip_path).unwrap();
|
||||||
.extension()
|
file.write_all(&[0x50, 0x4B, 0x03, 0x04]).unwrap(); // ZIP magic
|
||||||
.and_then(|ext| ext.to_str())
|
file.write_all(&[0; 8]).unwrap(); // padding
|
||||||
.unwrap_or("");
|
|
||||||
|
|
||||||
assert_eq!(extension, "zip");
|
let result = extractor.detect_file_format(&zip_path);
|
||||||
|
assert!(result.is_ok());
|
||||||
|
assert_eq!(result.unwrap(), "zip");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_format_detection_dmg_by_extension() {
|
||||||
|
let extractor = Extractor::new();
|
||||||
|
let temp_dir = TempDir::new().unwrap();
|
||||||
|
let dmg_path = temp_dir.path().join("test.dmg");
|
||||||
|
|
||||||
|
// Create a file (magic number won't match, but extension will)
|
||||||
|
let mut file = File::create(&dmg_path).unwrap();
|
||||||
|
file.write_all(b"fake dmg content").unwrap();
|
||||||
|
|
||||||
|
let result = extractor.detect_file_format(&dmg_path);
|
||||||
|
assert!(result.is_ok());
|
||||||
|
assert_eq!(result.unwrap(), "dmg");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_format_detection_exe() {
|
||||||
|
let extractor = Extractor::new();
|
||||||
|
let temp_dir = TempDir::new().unwrap();
|
||||||
|
let exe_path = temp_dir.path().join("test.exe");
|
||||||
|
|
||||||
|
// Create a file with PE header
|
||||||
|
let mut file = File::create(&exe_path).unwrap();
|
||||||
|
file.write_all(&[0x4D, 0x5A]).unwrap(); // PE magic
|
||||||
|
file.write_all(&[0; 10]).unwrap(); // padding
|
||||||
|
|
||||||
|
let result = extractor.detect_file_format(&exe_path);
|
||||||
|
assert!(result.is_ok());
|
||||||
|
assert_eq!(result.unwrap(), "exe");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_format_detection_tar_gz() {
|
||||||
|
let extractor = Extractor::new();
|
||||||
|
let temp_dir = TempDir::new().unwrap();
|
||||||
|
let tar_gz_path = temp_dir.path().join("test.tar.gz");
|
||||||
|
|
||||||
|
// Create a file with gzip magic
|
||||||
|
let mut file = File::create(&tar_gz_path).unwrap();
|
||||||
|
file.write_all(&[0x1F, 0x8B, 0x08]).unwrap(); // gzip magic
|
||||||
|
file.write_all(&[0; 9]).unwrap(); // padding
|
||||||
|
|
||||||
|
let result = extractor.detect_file_format(&tar_gz_path);
|
||||||
|
assert!(result.is_ok());
|
||||||
|
assert_eq!(result.unwrap(), "tar.gz");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -987,56 +1203,247 @@ mod tests {
|
|||||||
assert!(mount_point2.to_string_lossy().contains("donut_mount_"));
|
assert!(mount_point2.to_string_lossy().contains("donut_mount_"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[tokio::test]
|
||||||
fn test_app_path_detection() {
|
#[cfg(target_os = "macos")]
|
||||||
|
async fn test_find_app_at_root_level() {
|
||||||
|
let extractor = Extractor::new();
|
||||||
let temp_dir = TempDir::new().unwrap();
|
let temp_dir = TempDir::new().unwrap();
|
||||||
|
|
||||||
// Create a fake .app directory
|
// Create a Firefox.app directory
|
||||||
let app_dir = temp_dir.path().join("TestApp.app");
|
let firefox_app = temp_dir.path().join("Firefox.app");
|
||||||
std::fs::create_dir_all(&app_dir).unwrap();
|
create_dir_all(&firefox_app).unwrap();
|
||||||
|
|
||||||
// Test finding .app directories
|
// Create the standard macOS app structure
|
||||||
let entries: Vec<_> = fs::read_dir(temp_dir.path())
|
let contents_dir = firefox_app.join("Contents");
|
||||||
.unwrap()
|
let macos_dir = contents_dir.join("MacOS");
|
||||||
.filter_map(Result::ok)
|
create_dir_all(&macos_dir).unwrap();
|
||||||
.filter(|entry| entry.path().extension().is_some_and(|ext| ext == "app"))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
assert_eq!(entries.len(), 1);
|
// Create the executable
|
||||||
assert_eq!(entries[0].file_name(), "TestApp.app");
|
let executable = macos_dir.join("firefox");
|
||||||
|
File::create(&executable).unwrap();
|
||||||
|
|
||||||
|
// Test finding the app
|
||||||
|
let result = extractor.find_app_in_directory(temp_dir.path()).await;
|
||||||
|
assert!(result.is_ok());
|
||||||
|
|
||||||
|
let found_app = result.unwrap();
|
||||||
|
assert_eq!(found_app.file_name().unwrap(), "Firefox.app");
|
||||||
|
assert!(found_app.exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[tokio::test]
|
||||||
fn test_nested_app_detection() {
|
#[cfg(target_os = "macos")]
|
||||||
|
async fn test_find_app_in_subdirectory() {
|
||||||
|
let extractor = Extractor::new();
|
||||||
let temp_dir = TempDir::new().unwrap();
|
let temp_dir = TempDir::new().unwrap();
|
||||||
|
|
||||||
// Create a nested structure like Chromium
|
// Create a nested structure like some browsers have
|
||||||
let chrome_dir = temp_dir.path().join("chrome-mac");
|
let subdir = temp_dir.path().join("chrome-mac");
|
||||||
std::fs::create_dir_all(&chrome_dir).unwrap();
|
create_dir_all(&subdir).unwrap();
|
||||||
|
|
||||||
let app_dir = chrome_dir.join("Chromium.app");
|
// Create a Brave Browser.app directory
|
||||||
std::fs::create_dir_all(&app_dir).unwrap();
|
let brave_app = subdir.join("Brave Browser.app");
|
||||||
|
create_dir_all(&brave_app).unwrap();
|
||||||
|
|
||||||
// Test finding nested .app directories
|
// Create the standard macOS app structure
|
||||||
let mut found_app = false;
|
let contents_dir = brave_app.join("Contents");
|
||||||
|
let macos_dir = contents_dir.join("MacOS");
|
||||||
|
create_dir_all(&macos_dir).unwrap();
|
||||||
|
|
||||||
if let Ok(entries) = fs::read_dir(temp_dir.path()) {
|
// Create the executable
|
||||||
for entry in entries.flatten() {
|
let executable = macos_dir.join("Brave Browser");
|
||||||
let path = entry.path();
|
File::create(&executable).unwrap();
|
||||||
if path.is_dir() {
|
|
||||||
if let Ok(sub_entries) = fs::read_dir(&path) {
|
// Test finding the app
|
||||||
for sub_entry in sub_entries.flatten() {
|
let result = extractor.find_app_in_directory(temp_dir.path()).await;
|
||||||
let sub_path = sub_entry.path();
|
assert!(result.is_ok());
|
||||||
if sub_path.extension().is_some_and(|ext| ext == "app") {
|
|
||||||
found_app = true;
|
let found_app = result.unwrap();
|
||||||
break;
|
assert_eq!(found_app.file_name().unwrap(), "Brave Browser.app");
|
||||||
}
|
assert!(found_app.exists());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
#[tokio::test]
|
||||||
}
|
#[cfg(target_os = "macos")]
|
||||||
|
async fn test_find_app_multiple_levels_deep() {
|
||||||
|
let extractor = Extractor::new();
|
||||||
|
let temp_dir = TempDir::new().unwrap();
|
||||||
|
|
||||||
|
// Create a deeply nested structure
|
||||||
|
let level1 = temp_dir.path().join("level1");
|
||||||
|
let level2 = level1.join("level2");
|
||||||
|
create_dir_all(&level2).unwrap();
|
||||||
|
|
||||||
|
// Create a Mullvad Browser.app directory
|
||||||
|
let mullvad_app = level2.join("Mullvad Browser.app");
|
||||||
|
create_dir_all(&mullvad_app).unwrap();
|
||||||
|
|
||||||
|
// Create the standard macOS app structure
|
||||||
|
let contents_dir = mullvad_app.join("Contents");
|
||||||
|
let macos_dir = contents_dir.join("MacOS");
|
||||||
|
create_dir_all(&macos_dir).unwrap();
|
||||||
|
|
||||||
|
// Create the executable
|
||||||
|
let executable = macos_dir.join("firefox");
|
||||||
|
File::create(&executable).unwrap();
|
||||||
|
|
||||||
|
// Test finding the app
|
||||||
|
let result = extractor.find_app_in_directory(temp_dir.path()).await;
|
||||||
|
assert!(result.is_ok());
|
||||||
|
|
||||||
|
let found_app = result.unwrap();
|
||||||
|
assert_eq!(found_app.file_name().unwrap(), "Mullvad Browser.app");
|
||||||
|
assert!(found_app.exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
async fn test_find_app_no_app_found() {
|
||||||
|
let extractor = Extractor::new();
|
||||||
|
let temp_dir = TempDir::new().unwrap();
|
||||||
|
|
||||||
|
// Create some files and directories that are NOT .app bundles
|
||||||
|
let regular_dir = temp_dir.path().join("regular_directory");
|
||||||
|
create_dir_all(®ular_dir).unwrap();
|
||||||
|
|
||||||
|
let regular_file = temp_dir.path().join("regular_file.txt");
|
||||||
|
File::create(®ular_file).unwrap();
|
||||||
|
|
||||||
|
// Create a directory that looks like an app but isn't (wrong extension)
|
||||||
|
let fake_app = temp_dir.path().join("NotAnApp.app-backup");
|
||||||
|
create_dir_all(&fake_app).unwrap();
|
||||||
|
|
||||||
|
// Test that no app is found
|
||||||
|
let result = extractor.find_app_in_directory(temp_dir.path()).await;
|
||||||
|
assert!(result.is_err());
|
||||||
|
assert!(result.unwrap_err().to_string().contains("No .app found"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
async fn test_find_app_recursive_depth_limit() {
|
||||||
|
let extractor = Extractor::new();
|
||||||
|
let temp_dir = TempDir::new().unwrap();
|
||||||
|
|
||||||
|
// Create a very deep nested structure (deeper than our limit of 4)
|
||||||
|
let mut current_path = temp_dir.path().to_path_buf();
|
||||||
|
for i in 0..6 {
|
||||||
|
current_path = current_path.join(format!("level{i}"));
|
||||||
|
create_dir_all(¤t_path).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
assert!(found_app);
|
// Create an app at the deepest level
|
||||||
|
let deep_app = current_path.join("Deep.app");
|
||||||
|
create_dir_all(&deep_app).unwrap();
|
||||||
|
|
||||||
|
// Test that the app is NOT found due to depth limit
|
||||||
|
let result = extractor.find_app_in_directory(temp_dir.path()).await;
|
||||||
|
assert!(result.is_err());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
async fn test_find_macos_app_and_move_from_subdir() {
|
||||||
|
let extractor = Extractor::new();
|
||||||
|
let temp_dir = TempDir::new().unwrap();
|
||||||
|
|
||||||
|
// Create a nested structure where the app is in a subdirectory
|
||||||
|
let subdir = temp_dir.path().join("extracted_content");
|
||||||
|
create_dir_all(&subdir).unwrap();
|
||||||
|
|
||||||
|
// Create a Tor Browser.app directory in the subdirectory
|
||||||
|
let tor_app = subdir.join("Tor Browser.app");
|
||||||
|
create_dir_all(&tor_app).unwrap();
|
||||||
|
|
||||||
|
// Create the standard macOS app structure
|
||||||
|
let contents_dir = tor_app.join("Contents");
|
||||||
|
let macos_dir = contents_dir.join("MacOS");
|
||||||
|
create_dir_all(&macos_dir).unwrap();
|
||||||
|
|
||||||
|
// Create the executable
|
||||||
|
let executable = macos_dir.join("firefox");
|
||||||
|
File::create(&executable).unwrap();
|
||||||
|
|
||||||
|
// Test finding and moving the app
|
||||||
|
let result = extractor.find_macos_app(temp_dir.path()).await;
|
||||||
|
assert!(result.is_ok());
|
||||||
|
|
||||||
|
let found_app = result.unwrap();
|
||||||
|
assert_eq!(found_app.file_name().unwrap(), "Tor Browser.app");
|
||||||
|
|
||||||
|
// Verify the app was moved to the root level
|
||||||
|
assert_eq!(found_app.parent().unwrap(), temp_dir.path());
|
||||||
|
assert!(found_app.exists());
|
||||||
|
|
||||||
|
// Verify the original subdirectory structure was cleaned up
|
||||||
|
assert!(!subdir.exists() || fs::read_dir(&subdir).unwrap().count() == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
async fn test_multiple_apps_found_returns_first() {
|
||||||
|
let extractor = Extractor::new();
|
||||||
|
let temp_dir = TempDir::new().unwrap();
|
||||||
|
|
||||||
|
// Create multiple .app directories
|
||||||
|
let firefox_app = temp_dir.path().join("Firefox.app");
|
||||||
|
create_dir_all(&firefox_app).unwrap();
|
||||||
|
|
||||||
|
let chrome_app = temp_dir.path().join("Chrome.app");
|
||||||
|
create_dir_all(&chrome_app).unwrap();
|
||||||
|
|
||||||
|
// Test that we find one of them (implementation should be consistent)
|
||||||
|
let result = extractor.find_app_in_directory(temp_dir.path()).await;
|
||||||
|
assert!(result.is_ok());
|
||||||
|
|
||||||
|
let found_app = result.unwrap();
|
||||||
|
let app_name = found_app.file_name().unwrap().to_str().unwrap();
|
||||||
|
assert!(app_name == "Firefox.app" || app_name == "Chrome.app");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_browser_specific_app_names() {
|
||||||
|
// Test that we can identify common browser app names correctly
|
||||||
|
let common_browser_apps = [
|
||||||
|
"Firefox.app",
|
||||||
|
"Firefox Developer Edition.app",
|
||||||
|
"Brave Browser.app",
|
||||||
|
"Mullvad Browser.app",
|
||||||
|
"Tor Browser.app",
|
||||||
|
"Zen Browser.app",
|
||||||
|
"Chromium.app",
|
||||||
|
"Google Chrome.app",
|
||||||
|
];
|
||||||
|
|
||||||
|
for app_name in &common_browser_apps {
|
||||||
|
let path = std::path::Path::new(app_name);
|
||||||
|
let extension = path.extension().and_then(|ext| ext.to_str());
|
||||||
|
assert_eq!(extension, Some("app"), "Failed for {app_name}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_edge_cases_in_path_handling() {
|
||||||
|
let temp_dir = TempDir::new().unwrap();
|
||||||
|
|
||||||
|
// Test paths with spaces and special characters
|
||||||
|
let problematic_names = [
|
||||||
|
"Firefox Developer Edition.app",
|
||||||
|
"Brave Browser.app",
|
||||||
|
"App with (parentheses).app",
|
||||||
|
"App-with-dashes.app",
|
||||||
|
"App_with_underscores.app",
|
||||||
|
];
|
||||||
|
|
||||||
|
for app_name in &problematic_names {
|
||||||
|
let app_path = temp_dir.path().join(app_name);
|
||||||
|
create_dir_all(&app_path).unwrap();
|
||||||
|
|
||||||
|
// Verify we can detect the .app extension correctly
|
||||||
|
assert!(app_path.extension().is_some_and(|ext| ext == "app"));
|
||||||
|
|
||||||
|
// Verify file_name extraction works
|
||||||
|
assert_eq!(app_path.file_name().unwrap().to_str().unwrap(), *app_name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://schema.tauri.app/config/2",
|
"$schema": "https://schema.tauri.app/config/2",
|
||||||
"productName": "Donut Browser",
|
"productName": "Donut Browser",
|
||||||
"version": "0.3.0",
|
"version": "0.3.1",
|
||||||
"identifier": "com.donutbrowser",
|
"identifier": "com.donutbrowser",
|
||||||
"build": {
|
"build": {
|
||||||
"beforeDevCommand": "pnpm dev",
|
"beforeDevCommand": "pnpm dev",
|
||||||
|
|||||||
Reference in New Issue
Block a user