diff options
Diffstat (limited to 'src-tauri/src')
-rw-r--r-- | src-tauri/src/github/pull_requests.rs | 35 | ||||
-rw-r--r-- | src-tauri/src/main.rs | 44 | ||||
-rw-r--r-- | src-tauri/src/mod_management/mod.rs | 12 |
3 files changed, 74 insertions, 17 deletions
diff --git a/src-tauri/src/github/pull_requests.rs b/src-tauri/src/github/pull_requests.rs index 96ac623f..a56fb647 100644 --- a/src-tauri/src/github/pull_requests.rs +++ b/src-tauri/src/github/pull_requests.rs @@ -66,17 +66,34 @@ pub enum PullRequestType { /// Parse pull requests from specified URL pub async fn get_pull_requests(url: String) -> Result<Vec<PullsApiResponseElement>, String> { - let json_response = match fetch_github_releases_api(&url).await { - Ok(result) => result, - Err(err) => return Err(err), - }; + let mut all_pull_requests: Vec<PullsApiResponseElement> = vec![]; - let pulls_response: Vec<PullsApiResponseElement> = match serde_json::from_str(&json_response) { - Ok(res) => res, - Err(err) => return Err(err.to_string()), - }; + let mut i = 1; // pagination on GitHub starts with `1`. + loop { + let paginated_url = format!("{}?page={}", url, i); + + let json_response = match fetch_github_releases_api(&paginated_url).await { + Ok(result) => result, + Err(err) => return Err(err), + }; + + let pulls_response: Vec<PullsApiResponseElement> = + match serde_json::from_str(&json_response) { + Ok(res) => res, + Err(err) => return Err(err.to_string()), + }; + + // Check if we still got a result + if pulls_response.is_empty() { + // Empty result means we went through all pages with content + break; + } + + all_pull_requests.extend(pulls_response); + i += 1; + } - Ok(pulls_response) + Ok(all_pull_requests) } /// Gets either launcher or mods PRs diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 3aa17459..2e4b3370 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -9,6 +9,11 @@ use std::{ time::Duration, }; +#[cfg(target_os = "windows")] +use std::ptr::null_mut; +#[cfg(target_os = "windows")] +use winapi::um::winuser::{MessageBoxW, MB_ICONERROR, MB_OK, MB_USERICON}; + use app::{ constants::{APP_USER_AGENT, MASTER_SERVER_URL, REFRESH_DELAY, SERVER_BROWSER_ENDPOINT}, *, @@ -66,7 +71,7 @@ fn main() { }, )); - tauri::Builder::default() + match tauri::Builder::default() .plugin(tauri_plugin_store::Builder::default().build()) .setup(|app| { let app_handle = app.app_handle(); @@ -148,7 +153,42 @@ fn main() { close_application, ]) .run(tauri::generate_context!()) - .expect("error while running tauri application"); + { + Ok(()) => (), + Err(err) => { + // Failed to launch system native web view + + // Log error on Linux + #[cfg(not(target_os = "windows"))] + { + log::error!("{err}"); + } + + // On Windows we can show an error window using Windows API to show how to install WebView2 + #[cfg(target_os = "windows")] + { + log::error!("WebView2 not installed: {err}"); + // Display a message box to the user with a button to open the installation instructions + let title = "WebView2 not found" + .encode_utf16() + .chain(Some(0)) + .collect::<Vec<_>>(); + let message = "FlightCore requires WebView2 to run.\n\nClick OK to open installation instructions.".encode_utf16().chain(Some(0)).collect::<Vec<_>>(); + unsafe { + let result = MessageBoxW( + null_mut(), + message.as_ptr(), + title.as_ptr(), + MB_OK | MB_ICONERROR | MB_USERICON, + ); + if result == 1 { + // Open the installation instructions URL in the user's default web browser + open::that("https://github.com/R2NorthstarTools/FlightCore/blob/main/docs/TROUBLESHOOTING.md#flightcore-wont-launch").unwrap(); + } + } + } + } + }; } #[tauri::command] diff --git a/src-tauri/src/mod_management/mod.rs b/src-tauri/src/mod_management/mod.rs index 728e72c0..25dea2bb 100644 --- a/src-tauri/src/mod_management/mod.rs +++ b/src-tauri/src/mod_management/mod.rs @@ -16,18 +16,18 @@ use app::GameInstall; struct ParsedThunderstoreModString { author_name: String, mod_name: String, - version: Option<String>, + version: String, } impl std::str::FromStr for ParsedThunderstoreModString { - type Err = (); + type Err = &'static str; // todo use an better error management fn from_str(s: &str) -> Result<Self, Self::Err> { let mut parts = s.split('-'); - let author_name = parts.next().unwrap().to_string(); - let mod_name = parts.next().unwrap().to_string(); - let version = parts.next().map(|s| s.to_string()); + let author_name = parts.next().ok_or("None value on author_name")?.to_string(); + let mod_name = parts.next().ok_or("None value on mod_name")?.to_string(); + let version = parts.next().ok_or("None value on version")?.to_string(); Ok(ParsedThunderstoreModString { author_name, @@ -268,7 +268,7 @@ async fn get_ns_mod_download_url(thunderstore_mod_string: &str) -> Result<String "{}/{}/{}", parsed_ts_mod_string.author_name, parsed_ts_mod_string.mod_name, - parsed_ts_mod_string.version.unwrap() + parsed_ts_mod_string.version ); for ns_mod in index { |