Skip to content

armgit / gecko

Public Imported from GitHub
0

A GameCube/Wii emulator and debugger written in Rust.

main launcher: open game feature, check for updates, new compatibility menu, report an issue, commit hash instead of version

Layle4e0f40d5c8ba
diff --git a/Cargo.lock b/Cargo.lock
index 717d3f0..ef32ac2 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -199,7 +199,7 @@ version = "1.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc"
dependencies = [
- "windows-sys 0.60.2",
+ "windows-sys 0.61.2",
]
[[package]]
@@ -210,7 +210,7 @@ checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d"
dependencies = [
"anstyle",
"once_cell_polyfill",
- "windows-sys 0.60.2",
+ "windows-sys 0.61.2",
]
[[package]]
@@ -991,7 +991,7 @@ version = "3.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "faf9468729b8cbcea668e36183cb69d317348c2e08e994829fb56ebfdfbaac34"
dependencies = [
- "windows-sys 0.59.0",
+ "windows-sys 0.61.2",
]
[[package]]
@@ -1822,6 +1822,15 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0"
+[[package]]
+name = "encoding_rs"
+version = "0.8.35"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3"
+dependencies = [
+ "cfg-if",
+]
+
[[package]]
name = "endi"
version = "1.1.1"
@@ -1916,7 +1925,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
dependencies = [
"libc",
- "windows-sys 0.59.0",
+ "windows-sys 0.61.2",
]
[[package]]
@@ -2317,6 +2326,7 @@ dependencies = [
"iced_aw",
"image 0.1.0",
"mimalloc",
+ "reqwest",
"rfd",
"ringbuf",
"serde",
@@ -2516,6 +2526,25 @@ dependencies = [
"svg_fmt",
]
+[[package]]
+name = "h2"
+version = "0.4.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "171fefbc92fe4a4de27e0698d6a5b392d6a0e333506bc49133760b3bcf948733"
+dependencies = [
+ "atomic-waker",
+ "bytes",
+ "fnv",
+ "futures-core",
+ "futures-sink",
+ "http",
+ "indexmap",
+ "slab",
+ "tokio",
+ "tokio-util",
+ "tracing",
+]
+
[[package]]
name = "half"
version = "2.7.1"
@@ -2725,6 +2754,7 @@ dependencies = [
"bytes",
"futures-channel",
"futures-core",
+ "h2",
"http",
"http-body",
"httparse",
@@ -2768,9 +2798,11 @@ dependencies = [
"percent-encoding",
"pin-project-lite",
"socket2",
+ "system-configuration",
"tokio",
"tower-service",
"tracing",
+ "windows-registry",
]
[[package]]
@@ -3236,7 +3268,7 @@ checksum = "3640c1c38b8e4e43584d8df18be5fc6b0aa314ce6ebf51b53313d4306cca8e46"
dependencies = [
"hermit-abi",
"libc",
- "windows-sys 0.59.0",
+ "windows-sys 0.61.2",
]
[[package]]
@@ -3834,6 +3866,12 @@ dependencies = [
"libmimalloc-sys",
]
+[[package]]
+name = "mime"
+version = "0.3.17"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
+
[[package]]
name = "miniz_oxide"
version = "0.8.9"
@@ -4071,7 +4109,7 @@ version = "0.50.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"
dependencies = [
- "windows-sys 0.59.0",
+ "windows-sys 0.61.2",
]
[[package]]
@@ -4644,7 +4682,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d8fae84b431384b68627d0f9b3b1245fcf9f46f6c0e3dc902e9dce64edd1967"
dependencies = [
"libc",
- "windows-sys 0.45.0",
+ "windows-sys 0.61.2",
]
[[package]]
@@ -5394,13 +5432,15 @@ checksum = "19b30a45b0cd0bcca8037f3d0dc3421eaf95327a17cad11964fb8179b4fc4832"
[[package]]
name = "reqwest"
-version = "0.13.3"
+version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "62e0021ea2c22aed41653bc7e1419abb2c97e038ff2c33d0e1309e49a97deec0"
+checksum = "219c5811de6525e5416c7d5d53bb656d3afdbc6c5af816e0802bcfa42dbdc1c3"
dependencies = [
"base64",
"bytes",
+ "encoding_rs",
"futures-core",
+ "h2",
"http",
"http-body",
"http-body-util",
@@ -5409,6 +5449,7 @@ dependencies = [
"hyper-util",
"js-sys",
"log",
+ "mime",
"percent-encoding",
"pin-project-lite",
"quinn",
@@ -5618,7 +5659,7 @@ dependencies = [
"errno",
"libc",
"linux-raw-sys 0.12.1",
- "windows-sys 0.59.0",
+ "windows-sys 0.61.2",
]
[[package]]
@@ -5675,7 +5716,7 @@ dependencies = [
"security-framework",
"security-framework-sys",
"webpki-root-certs",
- "windows-sys 0.59.0",
+ "windows-sys 0.61.2",
]
[[package]]
@@ -6126,7 +6167,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a766e1110788c36f4fa1c2b71b387a7815aa65f88ce0229841826633d93723e"
dependencies = [
"libc",
- "windows-sys 0.60.2",
+ "windows-sys 0.61.2",
]
[[package]]
@@ -6299,6 +6340,27 @@ dependencies = [
"libc",
]
+[[package]]
+name = "system-configuration"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a13f3d0daba03132c0aa9767f98351b3488edc2c100cda2d2ec2b04f3d8d3c8b"
+dependencies = [
+ "bitflags 2.11.1",
+ "core-foundation 0.9.4",
+ "system-configuration-sys",
+]
+
+[[package]]
+name = "system-configuration-sys"
+version = "0.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4"
+dependencies = [
+ "core-foundation-sys",
+ "libc",
+]
+
[[package]]
name = "target-features"
version = "0.1.6"
@@ -6321,7 +6383,7 @@ dependencies = [
"getrandom 0.4.2",
"once_cell",
"rustix 1.1.4",
- "windows-sys 0.59.0",
+ "windows-sys 0.61.2",
]
[[package]]
@@ -6341,7 +6403,7 @@ version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8c27177b12a6399ffc08b98f76f7c9a1f4fe9fc967c784c5a071fa8d93cf7e1"
dependencies = [
- "windows-sys 0.59.0",
+ "windows-sys 0.61.2",
]
[[package]]
@@ -6817,7 +6879,7 @@ checksum = "f2f6fb2847f6742cd76af783a2a2c49e9375d0a111c7bef6f71cd9e738c72d6e"
dependencies = [
"memoffset",
"tempfile",
- "windows-sys 0.60.2",
+ "windows-sys 0.61.2",
]
[[package]]
@@ -7600,7 +7662,7 @@ version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
dependencies = [
- "windows-sys 0.59.0",
+ "windows-sys 0.61.2",
]
[[package]]
@@ -7692,6 +7754,17 @@ dependencies = [
"windows-link",
]
+[[package]]
+name = "windows-registry"
+version = "0.6.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "02752bf7fbdcce7f2a27a742f798510f3e5ad88dbe84871e5168e2120c3d5720"
+dependencies = [
+ "windows-link",
+ "windows-result",
+ "windows-strings",
+]
+
[[package]]
name = "windows-result"
version = "0.4.1"
diff --git a/crates/app/Cargo.toml b/crates/app/Cargo.toml
index f037597..bd7cbff 100644
--- a/crates/app/Cargo.toml
+++ b/crates/app/Cargo.toml
@@ -31,3 +31,4 @@ tracing-subscriber = { version = "0.3.23", features = ["env-filter"] }
clap = { version = "4.6.1", features = ["derive"] }
anyhow = "1.0.102"
webbrowser = "1.0.5"
+reqwest = { version = "0.13.4", features = ["json"] }
diff --git a/crates/app/build.rs b/crates/app/build.rs
new file mode 100644
index 0000000..bca7a67
--- /dev/null
+++ b/crates/app/build.rs
@@ -0,0 +1,55 @@
+use std::path::Path;
+use std::process::Command;
+
+fn main() {
+ let hash = self::git_output(&["rev-parse", "--short", "HEAD"]).unwrap_or_else(|| "unknown".to_owned());
+ let sha = self::git_output(&["rev-parse", "HEAD"]).unwrap_or_default();
+ let date = self::git_output(&[
+ "show",
+ "-s",
+ "--date=format-local:%Y-%m-%dT%H:%M:%SZ",
+ "--format=%cd",
+ "HEAD",
+ ])
+ .unwrap_or_default();
+
+ let branch = std::env::var("GECKO_CHANNEL")
+ .ok()
+ .filter(|s| !s.is_empty())
+ .or_else(|| self::git_output(&["rev-parse", "--abbrev-ref", "HEAD"]))
+ .unwrap_or_default();
+ let channel = if branch == "dev" || branch == "nightly" {
+ "nightly"
+ } else {
+ ""
+ };
+
+ println!("cargo:rustc-env=GECKO_GIT_HASH={hash}");
+ println!("cargo:rustc-env=GECKO_GIT_SHA={sha}");
+ println!("cargo:rustc-env=GECKO_COMMIT_DATE={date}");
+ println!("cargo:rustc-env=GECKO_CHANNEL={channel}");
+ println!("cargo:rerun-if-env-changed=GECKO_CHANNEL");
+
+ let git_dir = Path::new("../../.git");
+ let head = git_dir.join("HEAD");
+ println!("cargo:rerun-if-changed={}", head.display());
+
+ if let Ok(contents) = std::fs::read_to_string(&head)
+ && let Some(reference) = contents.strip_prefix("ref:")
+ {
+ let ref_path = git_dir.join(reference.trim());
+ println!("cargo:rerun-if-changed={}", ref_path.display());
+ }
+}
+
+fn git_output(args: &[&str]) -> Option<String> {
+ Command::new("git")
+ .env("TZ", "UTC")
+ .args(args)
+ .output()
+ .ok()
+ .filter(|out| out.status.success())
+ .and_then(|out| String::from_utf8(out.stdout).ok())
+ .map(|s| s.trim().to_owned())
+ .filter(|s| !s.is_empty())
+}
diff --git a/crates/app/src/app.rs b/crates/app/src/app.rs
index 9928b07..2110b46 100644
--- a/crates/app/src/app.rs
+++ b/crates/app/src/app.rs
@@ -10,13 +10,15 @@ use iced::{Background, Border, Color, Element, Length, Padding, Subscription, Ta
use crate::cache::{self, LibraryCache};
use crate::config::{self, Config};
-use crate::game::{CpuMode, Game, Platform, ThemePreference};
+use crate::game::{CpuMode, Format, Game, Platform, ThemePreference};
use crate::library::{self, ScanProgress};
use crate::player::{self, PlayerState, PlayerStatus};
use crate::theme::{self, Palette};
+use crate::update::{self, Outcome};
use crate::widgets::{game_row, menubar, search_bar, statusbar};
const REPO_URL: &str = "https://github.com/ioncodes/gecko";
+pub(crate) const ISSUE_URL: &str = "https://github.com/ioncodes/gecko/issues/new?template=bug_report.md";
const DOUBLE_CLICK_WINDOW: Duration = Duration::from_millis(400);
const TOAST_DURATION: Duration = Duration::from_secs(3);
@@ -32,6 +34,9 @@ pub enum Message {
ScanProgress(ScanProgress),
SearchChanged(String),
MenuChooseLibrary(Platform),
+ MenuOpenGame,
+ GameFilePicked(Option<PathBuf>),
+ GameFileLoaded(Result<Box<Game>, String>),
MenuRescan,
MenuQuit,
MenuToggleCpu(CpuMode),
@@ -39,7 +44,9 @@ pub enum Message {
MenuSetTheme(ThemePreference),
MenuAbout,
AboutClose,
- OpenRepo,
+ OpenUrl(String),
+ CheckForUpdates,
+ UpdateChecked(Outcome),
GameClicked(usize),
LaunchPlayer(usize),
SystemThemeLoaded(Mode),
@@ -50,6 +57,16 @@ pub enum Message {
PlayerScreenshot(window::Id),
}
+#[derive(Debug, Clone)]
+pub enum UpdateState {
+ Idle,
+ Checking,
+ UpToDate,
+ Available(String),
+ Unpublished,
+ Failed,
+}
+
pub struct Toast {
title: String,
detail: String,
@@ -89,6 +106,7 @@ pub struct App {
last_click: Option<(usize, Instant)>,
library_window: Option<window::Id>,
players: HashMap<window::Id, PlayerWindow>,
+ update: UpdateState,
}
impl App {
@@ -118,6 +136,7 @@ impl App {
last_click: None,
library_window: None,
players: HashMap::new(),
+ update: UpdateState::Idle,
};
let (_, open_lib) = window::open(window::Settings {
@@ -266,6 +285,41 @@ impl App {
move |opt| Message::LibraryPicked(platform, opt),
)
}
+ Message::MenuOpenGame => Task::perform(
+ async move {
+ rfd::AsyncFileDialog::new()
+ .set_title("Open game")
+ .add_filter("Disc images", &["iso", "rvz", "zip"])
+ .pick_file()
+ .await
+ .map(|h| h.path().to_path_buf())
+ },
+ Message::GameFilePicked,
+ ),
+ Message::GameFilePicked(None) => Task::none(),
+ Message::GameFilePicked(Some(path)) => {
+ let Some(format) = Format::from_path(&path) else {
+ tracing::warn!(path = %path.display(), "unsupported file type");
+ return Task::none();
+ };
+
+ Task::perform(
+ async move {
+ tokio::task::spawn_blocking(move || library::load_one(&path, format).map(Box::new))
+ .await
+ .unwrap_or_else(|err| Err(err.to_string()))
+ },
+ Message::GameFileLoaded,
+ )
+ }
+ Message::GameFileLoaded(Err(err)) => {
+ tracing::warn!(%err, "failed to load picked game");
+ Task::none()
+ }
+ Message::GameFileLoaded(Ok(game)) => {
+ tracing::info!(path = %game.path.display(), title = %game.title, "launching picked game");
+ self.launch_game(*game)
+ }
Message::MenuRescan => {
if self.effective_library_roots().is_empty() {
Task::done(Message::MenuChooseLibrary(Platform::Gcn))
@@ -298,12 +352,35 @@ impl App {
self.about_open = false;
Task::none()
}
- Message::OpenRepo => {
- if let Err(err) = webbrowser::open(REPO_URL) {
- tracing::warn!(%err, url = REPO_URL, "failed to open repo URL");
+ Message::OpenUrl(url) => {
+ if let Err(err) = webbrowser::open(&url) {
+ tracing::warn!(%err, %url, "failed to open URL");
}
Task::none()
}
+ Message::CheckForUpdates => {
+ if matches!(self.update, UpdateState::Checking) {
+ return Task::none();
+ }
+
+ self.update = UpdateState::Checking;
+ Task::perform(update::check(), Message::UpdateChecked)
+ }
+ Message::UpdateChecked(outcome) => {
+ self.update = match outcome {
+ Outcome::UpToDate => UpdateState::UpToDate,
+ Outcome::Available(url) => {
+ tracing::info!(%url, "update available");
+ UpdateState::Available(url)
+ }
+ Outcome::Unpublished => UpdateState::Unpublished,
+ Outcome::Failed(err) => {
+ tracing::warn!(%err, "update check failed");
+ UpdateState::Failed
+ }
+ };
+ Task::none()
+ }
Message::GameClicked(idx) => {
let now = Instant::now();
let is_double = self
@@ -326,13 +403,7 @@ impl App {
return Task::none();
};
- let state = PlayerState::new(&game, &self.config);
- let (_, open) = window::open(window::Settings {
- size: iced::Size::new(960.0, 720.0),
- ..window::Settings::default()
- });
-
- open.map(move |id| Message::PlayerWindowOpened(id, Box::new(game.clone()), state.clone()))
+ self.launch_game(game)
}
Message::SystemThemeLoaded(mode) | Message::SystemThemeChanged(mode) => {
self.system_mode = mode;
@@ -411,9 +482,9 @@ impl App {
let body: Element<'_, Message> = if self.games.is_empty() {
let (msg, hint) = if self.scanning {
- ("Scanning…", "Reading disc headers")
+ ("Scanning...", "Reading disc headers")
} else if self.effective_library_roots().is_empty() {
- ("No libraries set", "File → Set GameCube / Wii Folder…")
+ ("No libraries set", "File → Set GameCube / Wii Folder...")
} else {
("No games found", "Drop ISO, RVZ, or ZIP files into the library folder")
};
@@ -435,7 +506,13 @@ impl App {
menubar::menubar(palette, self.config.cpu_mode, self.config.theme, self.config.skip_ipl),
search_bar::search_bar(palette, &self.search),
body,
- statusbar::statusbar(palette, self.config.cpu_mode, self.games.len(), self.scanning),
+ statusbar::statusbar(
+ palette,
+ self.config.cpu_mode,
+ self.games.len(),
+ self.scanning,
+ &self.update
+ ),
];
let root = container(main)
@@ -548,6 +625,26 @@ impl App {
fn refresh_palette(&mut self) {
self.palette = self::resolve_palette(self.config.theme, self.system_mode);
}
+
+ fn launch_game(&self, game: Game) -> Task<Message> {
+ let state = PlayerState::new(&game, &self.config);
+ let (_, open) = window::open(window::Settings {
+ size: iced::Size::new(960.0, 720.0),
+ ..window::Settings::default()
+ });
+
+ open.map(move |id| Message::PlayerWindowOpened(id, Box::new(game.clone()), state.clone()))
+ }
+}
+
+fn version_label() -> String {
+ let hash = env!("GECKO_GIT_HASH");
+ let channel = env!("GECKO_CHANNEL");
+ if channel.is_empty() {
+ hash.to_owned()
+ } else {
+ format!("{hash}-{channel}")
+ }
}
fn resolve_palette(pref: ThemePreference, system_mode: Mode) -> Palette {
@@ -686,7 +783,7 @@ fn about_overlay(palette: &Palette) -> Element<'static, Message> {
};
let link_button = button(text(REPO_URL).size(12).color(link_color))
- .on_press(Message::OpenRepo)
+ .on_press(Message::OpenUrl(REPO_URL.to_owned()))
.padding(Padding::from([2, 4]))
.style(move |_: &Theme, status| {
let bg = match status {
@@ -731,7 +828,7 @@ fn about_overlay(palette: &Palette) -> Element<'static, Message> {
]
.spacing(2)
.align_x(iced::Alignment::Center),
- text("v0.1.0").size(11).color(mute),
+ text(self::version_label()).size(11).color(mute),
button(text("Close").size(13))
.on_press(Message::AboutClose)
.padding(Padding::from([6, 14]))
diff --git a/crates/app/src/library.rs b/crates/app/src/library.rs
index 21fd353..1def863 100644
--- a/crates/app/src/library.rs
+++ b/crates/app/src/library.rs
@@ -136,7 +136,7 @@ fn enumerate_many(roots: &[PathBuf]) -> Result<Vec<(PathBuf, Format, FileFingerp
Ok(out)
}
-fn load_one(path: &Path, format: Format) -> Result<Game, String> {
+pub fn load_one(path: &Path, format: Format) -> Result<Game, String> {
let data = std::fs::read(path).map_err(|e| e.to_string())?;
let result = std::panic::catch_unwind(AssertUnwindSafe(|| {
let dvd = image::load_dvd(data);
diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs
index e28544c..0a9226b 100644
--- a/crates/app/src/main.rs
+++ b/crates/app/src/main.rs
@@ -5,6 +5,7 @@ mod game;
mod library;
mod player;
mod theme;
+mod update;
mod widgets;
#[global_allocator]
diff --git a/crates/app/src/update.rs b/crates/app/src/update.rs
new file mode 100644
index 0000000..adbd0e2
--- /dev/null
+++ b/crates/app/src/update.rs
@@ -0,0 +1,125 @@
+use serde::Deserialize;
+
+const REPO: &str = "ioncodes/gecko";
+const SELF_SHA: &str = env!("GECKO_GIT_SHA");
+const SELF_DATE: &str = env!("GECKO_COMMIT_DATE");
+
+const RELEASE_PAGE: &str = "https://github.com/ioncodes/gecko/releases/tag/release";
+const NIGHTLY_PAGE: &str = "https://github.com/ioncodes/gecko/releases/tag/nightly";
+
+#[derive(Debug, Clone)]
+pub enum Outcome {
+ UpToDate,
+ Available(String),
+ Unpublished,
+ Failed(String),
+}
+
+enum CompareError {
+ NotPublished,
+ Failed(String),
+}
+
+#[derive(Deserialize)]
+struct Comparison {
+ ahead_by: u32,
+ behind_by: u32,
+}
+
+#[derive(Deserialize)]
+struct Commit {
+ commit: CommitBody,
+}
+
+#[derive(Deserialize)]
+struct CommitBody {
+ committer: CommitActor,
+}
+
+#[derive(Deserialize)]
+struct CommitActor {
+ date: String,
+}
+
+pub async fn check() -> Outcome {
+ if SELF_SHA.is_empty() {
+ return Outcome::Failed("this build has no embedded commit".to_owned());
+ }
+
+ let client = match reqwest::Client::builder().user_agent("gecko-updater").build() {
+ Ok(client) => client,
+ Err(err) => return Outcome::Failed(err.to_string()),
+ };
+
+ let release = match self::compare(&client, "release").await {
+ Ok(cmp) => cmp,
+ Err(CompareError::NotPublished) => return Outcome::Unpublished,
+ Err(CompareError::Failed(err)) => return Outcome::Failed(err),
+ };
+
+ if release.behind_by == 0 {
+ return if release.ahead_by > 0 {
+ Outcome::Available(RELEASE_PAGE.to_owned())
+ } else {
+ Outcome::UpToDate
+ };
+ }
+
+ let nightly_fresh = matches!(self::compare(&client, "nightly").await, Ok(cmp) if cmp.ahead_by > 0);
+ if nightly_fresh {
+ return Outcome::Available(NIGHTLY_PAGE.to_owned());
+ }
+
+ if self::release_is_newer(&client).await {
+ return Outcome::Available(RELEASE_PAGE.to_owned());
+ }
+
+ Outcome::UpToDate
+}
+
+async fn compare(client: &reqwest::Client, head: &str) -> Result<Comparison, CompareError> {
+ let url = format!("https://api.github.com/repos/{REPO}/compare/{SELF_SHA}...{head}?per_page=1");
+ let resp = client
+ .get(url)
+ .header("Accept", "application/vnd.github+json")
+ .send()
+ .await
+ .map_err(|err| CompareError::Failed(err.to_string()))?;
+
+ if resp.status() == reqwest::StatusCode::NOT_FOUND {
+ return Err(CompareError::NotPublished);
+ }
+
+ if !resp.status().is_success() {
+ return Err(CompareError::Failed(format!("GitHub API returned {}", resp.status())));
+ }
+
+ resp.json::<Comparison>()
+ .await
+ .map_err(|err| CompareError::Failed(err.to_string()))
+}
+
+async fn release_is_newer(client: &reqwest::Client) -> bool {
+ if SELF_DATE.is_empty() {
+ return false;
+ }
+
+ let url = format!("https://api.github.com/repos/{REPO}/commits/release");
+ let fetched = client
+ .get(url)
+ .header("Accept", "application/vnd.github+json")
+ .send()
+ .await
+ .ok()
+ .filter(|resp| resp.status().is_success());
+
+ let Some(resp) = fetched else {
+ return false;
+ };
+
+ let Ok(commit) = resp.json::<Commit>().await else {
+ return false;
+ };
+
+ commit.commit.committer.date.as_str() > SELF_DATE
+}
diff --git a/crates/app/src/widgets/menubar.rs b/crates/app/src/widgets/menubar.rs
index c66120e..f8f7a09 100644
--- a/crates/app/src/widgets/menubar.rs
+++ b/crates/app/src/widgets/menubar.rs
@@ -6,6 +6,9 @@ use crate::app::Message;
use crate::game::{CpuMode, Platform, ThemePreference};
use crate::theme::Palette;
+const WII_DB_URL: &str = "https://emu.layle.dev/gecko-wii";
+const GC_DB_URL: &str = "https://emu.layle.dev/gecko-gc";
+
pub fn menubar(
palette: &Palette,
cpu: CpuMode,
@@ -22,6 +25,10 @@ pub fn menubar(
self::top_label(palette, "Settings"),
self::settings_menu(palette, cpu, theme_pref, skip_ipl),
),
+ Item::with_menu(
+ self::top_label(palette, "Compatibility"),
+ self::compatibility_menu(palette),
+ ),
Item::with_menu(self::top_label(palette, "About"), self::about_menu(palette)),
])
.draw_path(menu::DrawPath::Backdrop)
@@ -174,15 +181,17 @@ fn section_header(palette: &Palette, label: &'static str) -> Element<'static, Me
fn file_menu(palette: &Palette) -> Menu<'static, Message, iced::Theme, iced::Renderer> {
Menu::new(vec![
+ Item::new(self::menu_item(palette, "Open Game", Message::MenuOpenGame, None)),
+ Item::new(self::separator(palette)),
Item::new(self::menu_item(
palette,
- "Set GameCube Folder…",
+ "Set GameCube Folder",
Message::MenuChooseLibrary(Platform::Gcn),
None,
)),
Item::new(self::menu_item(
palette,
- "Set Wii Folder…",
+ "Set Wii Folder",
Message::MenuChooseLibrary(Platform::Wii),
None,
)),
@@ -249,13 +258,43 @@ fn settings_menu(
.spacing(2.0)
}
+fn compatibility_menu(palette: &Palette) -> Menu<'static, Message, iced::Theme, iced::Renderer> {
+ Menu::new(vec![
+ Item::new(self::menu_item(
+ palette,
+ "Wii Database",
+ Message::OpenUrl(WII_DB_URL.to_owned()),
+ None,
+ )),
+ Item::new(self::menu_item(
+ palette,
+ "GameCube Database",
+ Message::OpenUrl(GC_DB_URL.to_owned()),
+ None,
+ )),
+ ])
+ .max_width(220.0)
+ .offset(4.0)
+ .spacing(2.0)
+}
+
fn about_menu(palette: &Palette) -> Menu<'static, Message, iced::Theme, iced::Renderer> {
- Menu::new(vec![Item::new(self::menu_item(
- palette,
- "About Gecko",
- Message::MenuAbout,
- None,
- ))])
+ Menu::new(vec![
+ Item::new(self::menu_item(palette, "About Gecko", Message::MenuAbout, None)),
+ Item::new(self::menu_item(
+ palette,
+ "Check for Updates",
+ Message::CheckForUpdates,
+ None,
+ )),
+ Item::new(self::separator(palette)),
+ Item::new(self::menu_item(
+ palette,
+ "Report an Issue",
+ Message::OpenUrl(crate::app::ISSUE_URL.to_owned()),
+ None,
+ )),
+ ])
.max_width(200.0)
.offset(4.0)
.spacing(2.0)
diff --git a/crates/app/src/widgets/statusbar.rs b/crates/app/src/widgets/statusbar.rs
index 0277c8d..8ac7968 100644
--- a/crates/app/src/widgets/statusbar.rs
+++ b/crates/app/src/widgets/statusbar.rs
@@ -1,11 +1,17 @@
-use iced::widget::{Space, container, row, text};
-use iced::{Alignment, Background, Border, Element, Length, Padding};
+use iced::widget::{Space, button, container, row, text};
+use iced::{Alignment, Background, Border, Color, Element, Length, Padding};
-use crate::app::Message;
+use crate::app::{Message, UpdateState};
use crate::game::CpuMode;
use crate::theme::Palette;
-pub fn statusbar(palette: &Palette, cpu: CpuMode, count: usize, scanning: bool) -> Element<'static, Message> {
+pub fn statusbar(
+ palette: &Palette,
+ cpu: CpuMode,
+ count: usize,
+ scanning: bool,
+ update: &UpdateState,
+) -> Element<'static, Message> {
let led_color = match cpu {
CpuMode::Jit => palette.accent,
CpuMode::Interpreter => palette.text_mute,
@@ -30,35 +36,76 @@ pub fn statusbar(palette: &Palette, cpu: CpuMode, count: usize, scanning: bool)
format!("{count} games")
};
let count_text = if scanning {
- format!("Scanning… · {count_label}")
+ format!("Scanning... · {count_label}")
} else {
count_label
};
let count_color = if scanning { palette.accent } else { palette.text_dim };
let right = text(count_text).size(11).color(count_color);
+ let content = row![
+ left,
+ Space::new().width(Length::Fill),
+ self::update_center(palette, update),
+ Space::new().width(Length::Fill),
+ right,
+ ]
+ .align_y(Alignment::Center)
+ .width(Length::Fill)
+ .height(Length::Fill);
+
let bg = palette.bg_2;
let border = palette.border;
let text_color = palette.text_dim;
- container(
- row![left, Space::new().width(Length::Fill), right]
- .align_y(Alignment::Center)
- .width(Length::Fill)
- .height(Length::Fill),
- )
- .width(Length::Fill)
- .height(28)
- .padding(Padding::from([0, 12]))
- .style(move |_| container::Style {
- background: Some(Background::Color(bg)),
- border: Border {
- color: border,
- width: 1.0,
- radius: 0.0.into(),
- },
- text_color: Some(text_color),
- ..container::Style::default()
- })
- .into()
+ container(content)
+ .width(Length::Fill)
+ .height(28)
+ .padding(Padding::from([0, 12]))
+ .style(move |_| container::Style {
+ background: Some(Background::Color(bg)),
+ border: Border {
+ color: border,
+ width: 1.0,
+ radius: 0.0.into(),
+ },
+ text_color: Some(text_color),
+ ..container::Style::default()
+ })
+ .into()
+}
+
+fn update_center(palette: &Palette, update: &UpdateState) -> Element<'static, Message> {
+ let muted =
+ |label: &'static str| -> Element<'static, Message> { text(label).size(11).color(palette.text_mute).into() };
+
+ match update {
+ UpdateState::Idle => Space::new().into(),
+ UpdateState::Checking => muted("Checking for updates..."),
+ UpdateState::UpToDate => muted("Up to date"),
+ UpdateState::Unpublished => muted("Development build"),
+ UpdateState::Failed => muted("Update check failed"),
+ UpdateState::Available(url) => {
+ let accent = palette.accent;
+ button(text("Update available").size(11).color(accent))
+ .padding(Padding::from([2, 8]))
+ .on_press(Message::OpenUrl(url.clone()))
+ .style(move |_, status| {
+ let bg = match status {
+ button::Status::Hovered | button::Status::Pressed => Color { a: 0.10, ..accent },
+ _ => Color::TRANSPARENT,
+ };
+ button::Style {
+ background: Some(Background::Color(bg)),
+ text_color: accent,
+ border: Border {
+ radius: 4.0.into(),
+ ..Border::default()
+ },
+ ..button::Style::default()
+ }
+ })
+ .into()
+ }
+ }
}