mirror of
https://github.com/nimbold/Firelink.git
synced 2026-08-19 15:46:17 +00:00
style: run cargo fmt to resolve CI failure
This commit is contained in:
+59
-24
@@ -8,7 +8,11 @@ pub async fn get_system_proxy() -> Result<Option<String>, String> {
|
||||
match sysproxy::Sysproxy::get_system_proxy() {
|
||||
Ok(proxy) => {
|
||||
if proxy.enable {
|
||||
let protocol = if proxy.host.contains("://") { "" } else { "http://" };
|
||||
let protocol = if proxy.host.contains("://") {
|
||||
""
|
||||
} else {
|
||||
"http://"
|
||||
};
|
||||
Ok(Some(format!("{}{}:{}", protocol, proxy.host, proxy.port)))
|
||||
} else {
|
||||
Ok(None)
|
||||
@@ -26,12 +30,28 @@ pub fn get_file_category(filename: String) -> DownloadCategory {
|
||||
.map(|s| s.to_lowercase())
|
||||
.unwrap_or_default();
|
||||
|
||||
let music_exts = ["mp3", "wav", "aac", "flac", "ogg", "m4a", "wma", "alac", "ape", "mid", "midi"];
|
||||
let movie_exts = ["mp4", "mkv", "avi", "mov", "wmv", "flv", "webm", "m4v", "mpeg", "mpg", "3gp", "ts", "vob"];
|
||||
let compressed_exts = ["zip", "rar", "7z", "tar", "gz", "xz", "bz2", "lz", "lzma", "zst", "iso", "cab", "tgz", "tbz", "z", "sit", "sitx"];
|
||||
let picture_exts = ["jpg", "jpeg", "png", "gif", "webp", "bmp", "tiff", "svg", "ico", "heic", "raw", "psd", "ai"];
|
||||
let document_exts = ["pdf", "doc", "docx", "xls", "xlsx", "ppt", "pptx", "txt", "rtf", "csv", "md", "epub", "mobi", "azw3"];
|
||||
let app_exts = ["exe", "msi", "bat", "cmd", "app", "dmg", "pkg", "apk", "appx", "deb", "rpm", "appimage", "run", "sh", "bin", "jar"];
|
||||
let music_exts = [
|
||||
"mp3", "wav", "aac", "flac", "ogg", "m4a", "wma", "alac", "ape", "mid", "midi",
|
||||
];
|
||||
let movie_exts = [
|
||||
"mp4", "mkv", "avi", "mov", "wmv", "flv", "webm", "m4v", "mpeg", "mpg", "3gp", "ts", "vob",
|
||||
];
|
||||
let compressed_exts = [
|
||||
"zip", "rar", "7z", "tar", "gz", "xz", "bz2", "lz", "lzma", "zst", "iso", "cab", "tgz",
|
||||
"tbz", "z", "sit", "sitx",
|
||||
];
|
||||
let picture_exts = [
|
||||
"jpg", "jpeg", "png", "gif", "webp", "bmp", "tiff", "svg", "ico", "heic", "raw", "psd",
|
||||
"ai",
|
||||
];
|
||||
let document_exts = [
|
||||
"pdf", "doc", "docx", "xls", "xlsx", "ppt", "pptx", "txt", "rtf", "csv", "md", "epub",
|
||||
"mobi", "azw3",
|
||||
];
|
||||
let app_exts = [
|
||||
"exe", "msi", "bat", "cmd", "app", "dmg", "pkg", "apk", "appx", "deb", "rpm", "appimage",
|
||||
"run", "sh", "bin", "jar",
|
||||
];
|
||||
|
||||
if music_exts.contains(&ext.as_str()) {
|
||||
DownloadCategory::Musics
|
||||
@@ -65,8 +85,13 @@ pub struct AvailableReleaseUpdate {
|
||||
#[serde(tag = "type")]
|
||||
#[ts(export, export_to = "../../src/bindings/")]
|
||||
pub enum ReleaseCheckOutcome {
|
||||
UpdateAvailable { update: AvailableReleaseUpdate },
|
||||
UpToDate { latest_version: String, local_version: String },
|
||||
UpdateAvailable {
|
||||
update: AvailableReleaseUpdate,
|
||||
},
|
||||
UpToDate {
|
||||
latest_version: String,
|
||||
local_version: String,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
@@ -81,11 +106,14 @@ struct GitHubRelease {
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn check_for_updates(app_handle: tauri::AppHandle) -> Result<ReleaseCheckOutcome, String> {
|
||||
pub async fn check_for_updates(
|
||||
app_handle: tauri::AppHandle,
|
||||
) -> Result<ReleaseCheckOutcome, String> {
|
||||
let current_version = app_handle.package_info().version.to_string();
|
||||
|
||||
|
||||
let client = reqwest::Client::new();
|
||||
let res = client.get("https://api.github.com/repos/nimbold/Firelink/releases?per_page=30")
|
||||
let res = client
|
||||
.get("https://api.github.com/repos/nimbold/Firelink/releases?per_page=30")
|
||||
.header("User-Agent", "Firelink")
|
||||
.header("Accept", "application/vnd.github+json")
|
||||
.send()
|
||||
@@ -97,11 +125,12 @@ pub async fn check_for_updates(app_handle: tauri::AppHandle) -> Result<ReleaseCh
|
||||
}
|
||||
|
||||
let releases: Vec<GitHubRelease> = res.json().await.map_err(|e| e.to_string())?;
|
||||
|
||||
let latest_stable = releases.into_iter()
|
||||
|
||||
let latest_stable = releases
|
||||
.into_iter()
|
||||
.filter(|r| !r.draft && !r.prerelease)
|
||||
.max_by(|a, b| cmp_versions(&a.tag_name, &b.tag_name));
|
||||
|
||||
|
||||
let release = match latest_stable {
|
||||
Some(r) => r,
|
||||
None => return Err("No stable release was found.".to_string()),
|
||||
@@ -115,10 +144,12 @@ pub async fn check_for_updates(app_handle: tauri::AppHandle) -> Result<ReleaseCh
|
||||
version: latest_version.clone(),
|
||||
tag_name: release.tag_name.clone(),
|
||||
title: release.name.unwrap_or(release.tag_name),
|
||||
release_notes: release.body.unwrap_or_else(|| "No release notes were provided for this version.".to_string()),
|
||||
release_notes: release.body.unwrap_or_else(|| {
|
||||
"No release notes were provided for this version.".to_string()
|
||||
}),
|
||||
release_url: release.html_url,
|
||||
published_at: release.published_at,
|
||||
}
|
||||
},
|
||||
})
|
||||
} else {
|
||||
Ok(ReleaseCheckOutcome::UpToDate {
|
||||
@@ -130,13 +161,13 @@ pub async fn check_for_updates(app_handle: tauri::AppHandle) -> Result<ReleaseCh
|
||||
|
||||
fn cmp_versions(a: &str, b: &str) -> std::cmp::Ordering {
|
||||
use semver::Version;
|
||||
|
||||
|
||||
let a_clean = a.trim_start_matches(['v', 'V']);
|
||||
let b_clean = b.trim_start_matches(['v', 'V']);
|
||||
|
||||
|
||||
let a_ver = Version::parse(a_clean).unwrap_or_else(|_| Version::new(0, 0, 0));
|
||||
let b_ver = Version::parse(b_clean).unwrap_or_else(|_| Version::new(0, 0, 0));
|
||||
|
||||
|
||||
a_ver.cmp(&b_ver)
|
||||
}
|
||||
|
||||
@@ -181,14 +212,18 @@ pub async fn create_category_directories(
|
||||
}
|
||||
|
||||
pub static SUPPORTED_DOMAINS: &[&str] = &[
|
||||
"youtube.com", "youtu.be",
|
||||
"twitter.com", "x.com",
|
||||
"youtube.com",
|
||||
"youtu.be",
|
||||
"twitter.com",
|
||||
"x.com",
|
||||
"vimeo.com",
|
||||
"twitch.tv",
|
||||
"instagram.com",
|
||||
"tiktok.com",
|
||||
"facebook.com", "fb.watch",
|
||||
"reddit.com", "v.redd.it",
|
||||
"facebook.com",
|
||||
"fb.watch",
|
||||
"reddit.com",
|
||||
"v.redd.it",
|
||||
"soundcloud.com",
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user