Skip to content

Commit

Permalink
0.2.1: save the version differently update
Browse files Browse the repository at this point in the history
  • Loading branch information
NotNite committed Oct 9, 2024
1 parent f9d7164 commit 64a8bbb
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions assets/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.2.0</string>
<string>0.2.1</string>
<key>CFBundleVersion</key>
<string>0.2.0</string>
<string>0.2.1</string>
<key>CSResourcesFileMapped</key>
<true/>
<key>LSRequiresCarbon</key>
Expand Down
15 changes: 14 additions & 1 deletion crates/libmoonlight/src/installer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{get_app_dir, PATCHED_ASAR};
use crate::{get_app_dir, get_moonlight_dir, PATCHED_ASAR};

use super::{
types::*,
Expand All @@ -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";
Expand Down Expand Up @@ -69,6 +70,18 @@ impl Installer {
}
}

pub fn get_downloaded_version(&self) -> InstallerResult<Option<String>> {
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<GitHubRelease> {
let url = format!(
"https://api.github.com/repos/{}/releases/latest",
Expand Down
1 change: 1 addition & 0 deletions crates/moonlight-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion crates/moonlight-installer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "moonlight-installer"
license = "MIT"
version = "0.2.0"
version = "0.2.1"
edition = "2021"

[dependencies]
Expand Down
41 changes: 25 additions & 16 deletions crates/moonlight-installer/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Option<String>>,
latest_version: Option<String>,
installs: Option<Vec<InstallInfo>>,

Expand All @@ -21,7 +22,6 @@ pub struct AppState {
#[derive(serde::Deserialize, serde::Serialize, Default, Debug)]
pub struct App {
config: Config,
downloaded_version: Option<String>,

// Don't know how to clean up these skips lol
#[serde(skip)]
Expand Down Expand Up @@ -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::<LogicCommand>();
let (logic_tx, main_rx) = flume::unbounded::<LogicResponse>();
std::thread::spawn(move || {
Expand All @@ -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);

Expand All @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions crates/moonlight-installer/src/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::path::PathBuf;

pub enum LogicCommand {
GetInstalls,
GetDownloadedVersion,
GetLatestVersion(MoonlightBranch),
UpdateMoonlight(MoonlightBranch),
PatchInstall(DetectedInstall),
Expand All @@ -13,6 +14,7 @@ pub enum LogicCommand {

pub enum LogicResponse {
Installs(Vec<InstallInfo>),
DownloadedVersion(Option<String>),
LatestVersion(InstallerResult<String>),
UpdateComplete(InstallerResult<String>),
PatchComplete(InstallerResult<PathBuf>),
Expand All @@ -32,13 +34,21 @@ 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))?;
}

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))?;
}

Expand Down
2 changes: 1 addition & 1 deletion package-macos-app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 64a8bbb

Please sign in to comment.