diff --git a/Cargo.lock b/Cargo.lock index 594a84b..cbb4a60 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2130,7 +2130,7 @@ dependencies = [ [[package]] name = "moonlight-installer" -version = "0.2.0" +version = "0.2.1" dependencies = [ "eframe", "egui", diff --git a/assets/Info.plist b/assets/Info.plist index 050841b..afd8a3f 100644 --- a/assets/Info.plist +++ b/assets/Info.plist @@ -19,9 +19,9 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.2.0 + 0.2.1 CFBundleVersion - 0.2.0 + 0.2.1 CSResourcesFileMapped LSRequiresCarbon diff --git a/crates/libmoonlight/src/installer.rs b/crates/libmoonlight/src/installer.rs index d3bb171..7f084dd 100644 --- a/crates/libmoonlight/src/installer.rs +++ b/crates/libmoonlight/src/installer.rs @@ -1,4 +1,4 @@ -use crate::{get_app_dir, PATCHED_ASAR}; +use crate::{get_app_dir, get_moonlight_dir, PATCHED_ASAR}; use super::{ types::*, @@ -8,6 +8,7 @@ use std::path::PathBuf; const USER_AGENT: &str = "moonlight-installer (https://github.com/moonlight-mod/moonlight-installer)"; +const INSTALLED_VERSION_FILE: &str = ".moonlight-installed-version"; const GITHUB_REPO: &str = "moonlight-mod/moonlight"; const ARTIFACT_NAME: &str = "dist.tar.gz"; @@ -69,6 +70,18 @@ impl Installer { } } + pub fn get_downloaded_version(&self) -> InstallerResult> { + let dir = get_moonlight_dir(); + let version = std::fs::read_to_string(dir.join(INSTALLED_VERSION_FILE)).ok(); + Ok(version) + } + + pub fn set_downloaded_version(&self, version: &str) -> InstallerResult<()> { + let dir = get_moonlight_dir(); + std::fs::write(dir.join(INSTALLED_VERSION_FILE), version)?; + Ok(()) + } + fn get_stable_release(&self) -> InstallerResult { let url = format!( "https://api.github.com/repos/{}/releases/latest", diff --git a/crates/moonlight-cli/src/main.rs b/crates/moonlight-cli/src/main.rs index 719fea9..4d48adc 100644 --- a/crates/moonlight-cli/src/main.rs +++ b/crates/moonlight-cli/src/main.rs @@ -31,6 +31,7 @@ fn main() -> anyhow::Result<()> { Args::Install { branch } => { log::info!("Downloading moonlight branch {}", branch); let ver = installer.download_moonlight(branch)?; + installer.set_downloaded_version(&ver)?; log::info!("Downloaded version {}", ver); } diff --git a/crates/moonlight-installer/Cargo.toml b/crates/moonlight-installer/Cargo.toml index 52e1cd8..5d3a6c2 100644 --- a/crates/moonlight-installer/Cargo.toml +++ b/crates/moonlight-installer/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "moonlight-installer" license = "MIT" -version = "0.2.0" +version = "0.2.1" edition = "2021" [dependencies] diff --git a/crates/moonlight-installer/src/app.rs b/crates/moonlight-installer/src/app.rs index a43b179..e14d1fc 100644 --- a/crates/moonlight-installer/src/app.rs +++ b/crates/moonlight-installer/src/app.rs @@ -2,11 +2,12 @@ use crate::{ config::Config, logic::{app_logic_thread, LogicCommand, LogicResponse}, }; -use libmoonlight::{branch_desc, branch_name, get_download_dir, types::*}; +use libmoonlight::{branch_desc, branch_name, types::*}; use std::time::Duration; #[derive(Debug, Default)] pub struct AppState { + downloaded_version: Option>, latest_version: Option, installs: Option>, @@ -21,7 +22,6 @@ pub struct AppState { #[derive(serde::Deserialize, serde::Serialize, Default, Debug)] pub struct App { config: Config, - downloaded_version: Option, // Don't know how to clean up these skips lol #[serde(skip)] @@ -49,11 +49,6 @@ impl App { Default::default() }; - // Jank place to have this - if !get_download_dir().exists() { - app.downloaded_version = None; - } - let (main_tx, logic_rx) = flume::unbounded::(); let (logic_tx, main_rx) = flume::unbounded::(); std::thread::spawn(move || { @@ -65,6 +60,7 @@ impl App { app.tx = Some(main_tx); app.rx = Some(main_rx); + app.send(LogicCommand::GetDownloadedVersion); app.send(LogicCommand::GetLatestVersion(app.config.branch)); app.send(LogicCommand::GetInstalls); @@ -81,6 +77,11 @@ impl App { self.state.installs = Some(installs); } + LogicResponse::DownloadedVersion(version) => { + log::info!("Downloaded version: {:?}", version); + self.state.downloaded_version = Some(version); + } + LogicResponse::LatestVersion(version) => { log::info!("Latest version: {:?}", version); if let Ok(version) = version { @@ -95,10 +96,10 @@ impl App { LogicResponse::UpdateComplete(version) => { log::info!("Update complete: {:?}", version); if let Ok(version) = version { - self.downloaded_version = Some(version); + self.state.downloaded_version = Some(Some(version)); self.state.downloading_error = None; } else { - self.downloaded_version = None; + self.state.downloaded_version = Some(None); self.state.downloading_error = version.err(); } self.state.downloading = false; @@ -240,19 +241,26 @@ impl eframe::App for App { }); ui.horizontal(|ui| { ui.label("Downloaded version:"); - if let Some(version) = &self.downloaded_version { - ui.label(version); + if let Some(version) = &self.state.downloaded_version { + ui.label(version.as_deref().unwrap_or("None")); } else { - ui.label("None"); + ui.spinner(); } }); ui.horizontal(|ui| { let can_download = !self.state.downloading && self.state.latest_version.is_some() - && (self.downloaded_version.is_none() - || self.downloaded_version - != self.state.latest_version); + && (self.state.downloaded_version.is_none() + || self.state.downloaded_version == Some(None) + || self.state.downloaded_version + != Some(Some( + self.state + .latest_version + .as_ref() + .unwrap() + .clone(), + ))); if ui .add_enabled(can_download, egui::Button::new("Download")) @@ -298,7 +306,8 @@ impl eframe::App for App { "Patch" }); let can_patch = !self.state.patching - && self.downloaded_version.is_some(); + && (self.state.downloaded_version.is_some() + && self.state.downloaded_version != Some(None)); let reset_config_button = egui::Button::new("Reset config"); let can_reset_config = install.has_config; diff --git a/crates/moonlight-installer/src/logic.rs b/crates/moonlight-installer/src/logic.rs index 771d629..c39212b 100644 --- a/crates/moonlight-installer/src/logic.rs +++ b/crates/moonlight-installer/src/logic.rs @@ -3,6 +3,7 @@ use std::path::PathBuf; pub enum LogicCommand { GetInstalls, + GetDownloadedVersion, GetLatestVersion(MoonlightBranch), UpdateMoonlight(MoonlightBranch), PatchInstall(DetectedInstall), @@ -13,6 +14,7 @@ pub enum LogicCommand { pub enum LogicResponse { Installs(Vec), + DownloadedVersion(Option), LatestVersion(InstallerResult), UpdateComplete(InstallerResult), PatchComplete(InstallerResult), @@ -32,6 +34,11 @@ pub fn app_logic_thread( tx.send(LogicResponse::LatestVersion(latest_version))?; } + LogicCommand::GetDownloadedVersion => { + let downloaded_version = installer.get_downloaded_version().unwrap_or(None); + tx.send(LogicResponse::DownloadedVersion(downloaded_version))?; + } + LogicCommand::GetInstalls => { let installs = installer.get_installs().unwrap_or_default(); tx.send(LogicResponse::Installs(installs))?; @@ -39,6 +46,9 @@ pub fn app_logic_thread( LogicCommand::UpdateMoonlight(branch) => { let err = installer.download_moonlight(branch); + if let Ok(ref version) = err { + installer.set_downloaded_version(&version).ok(); + } tx.send(LogicResponse::UpdateComplete(err))?; } diff --git a/package-macos-app.sh b/package-macos-app.sh index c51557a..869b2af 100755 --- a/package-macos-app.sh +++ b/package-macos-app.sh @@ -37,7 +37,7 @@ mkdir -p "$APPDIR/Contents/Resources" # Copy our assets to it cp $PLIST "$APPDIR/Contents/Info.plist" cp $ICON "$APPDIR/Contents/Resources/Icon.icns" -# Copy the merged binary +# Copy the merged binary cp $EXECUTABLE "$APPDIR/Contents/MacOS/$EXENAME" # Apply an ad-hoc signature