Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0c67290f74 | ||
|
|
aef091e205 | ||
|
|
4ce081d6ed | ||
|
|
6155236a4c |
No files matched your search
Generated
+1
-1
@@ -3643,7 +3643,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rmcl"
|
name = "rmcl"
|
||||||
version = "0.4.0"
|
version = "0.4.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "rmcl"
|
name = "rmcl"
|
||||||
version = "0.4.0"
|
version = "0.4.1"
|
||||||
authors = ["objz"]
|
authors = ["objz"]
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
description = "A fully featured Minecraft TUI launcher"
|
description = "A fully featured Minecraft TUI launcher"
|
||||||
|
|||||||
@@ -12,6 +12,9 @@
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
[Report Bug](https://github.com/objz/rmcl/issues) · [Request Feature](https://github.com/objz/rmcl/issues)
|
[Report Bug](https://github.com/objz/rmcl/issues) · [Request Feature](https://github.com/objz/rmcl/issues)
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@@ -163,7 +166,44 @@ rmcl ships with 10 built-in themes:
|
|||||||
|
|
||||||
`catppuccin` · `dracula` · `nord` · `gruvbox` · `one-dark` · `solarized` · `tailwind` · `tokyo-night` · `rose-pine` · `terminal`
|
`catppuccin` · `dracula` · `nord` · `gruvbox` · `one-dark` · `solarized` · `tailwind` · `tokyo-night` · `rose-pine` · `terminal`
|
||||||
|
|
||||||
you can create your own by dropping a TOML file in `~/.config/rmcl/theme/` and referencing it by name, or point to an absolute path.
|
pick one in `~/.config/rmcl/theme.toml`:
|
||||||
|
|
||||||
|
```toml
|
||||||
|
theme = "gruvbox"
|
||||||
|
border_style = "rounded" # rounded | plain | double | thick
|
||||||
|
```
|
||||||
|
|
||||||
|
### custom themes
|
||||||
|
|
||||||
|
drop a TOML file in `~/.config/rmcl/theme/` and reference it by name, or point `theme` at an absolute path. keys are flat and top level, don't nest them under `[theme]`. only `name`, `id` and `accent` are required, the rest falls back to a default:
|
||||||
|
|
||||||
|
```toml
|
||||||
|
# ~/.config/rmcl/theme/my-theme.toml
|
||||||
|
name = "My Theme"
|
||||||
|
id = "my-theme"
|
||||||
|
|
||||||
|
accent = { Rgb = [249, 115, 22] }
|
||||||
|
accent_dim = "#7f5539"
|
||||||
|
text = "#cdd6f4"
|
||||||
|
text_dim = "DarkGray"
|
||||||
|
text_bright = "#ffffff"
|
||||||
|
success = "#a6e3a1"
|
||||||
|
error = "#f38ba8"
|
||||||
|
warning = "#f9e2af"
|
||||||
|
info = "#89dceb"
|
||||||
|
diff_added = "#a6e3a1"
|
||||||
|
diff_removed = "#f38ba8"
|
||||||
|
diff_context = "DarkGray"
|
||||||
|
border = "#585b70"
|
||||||
|
surface = "#313244"
|
||||||
|
background = "#1e1e2e"
|
||||||
|
```
|
||||||
|
|
||||||
|
then set `theme = "my-theme"` in `theme.toml`.
|
||||||
|
|
||||||
|
colors accept `"#f97316"`, ANSI names (`"Red"`, `"LightBlue"`), `{ Rgb = [r, g, b] }` or `{ Indexed = n }`.
|
||||||
|
|
||||||
|
note that `[custom]` in `theme.toml` is only for overriding single values of a builtin, it doesn't define a new theme. same for `border_style`, that one lives in `theme.toml`, not in a theme file.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
# example custom theme -> ~/.config/rmcl/theme/my-theme.toml
|
||||||
|
# activate it in ~/.config/rmcl/theme.toml with: theme = "my-theme"
|
||||||
|
#
|
||||||
|
# this file is a theme, not the config: keys live at the top level, NOT under
|
||||||
|
# [theme] or [custom]. only name, id and accent are required; every other key
|
||||||
|
# falls back to a sane default.
|
||||||
|
#
|
||||||
|
# color formats: "#f97316" | "Red" / "LightBlue" (ANSI names) |
|
||||||
|
# { Rgb = [249, 115, 22] } | { Indexed = 42 }
|
||||||
|
|
||||||
|
name = "My Theme"
|
||||||
|
id = "my-theme"
|
||||||
|
|
||||||
|
accent = { Rgb = [249, 115, 22] }
|
||||||
|
accent_dim = "#7f5539"
|
||||||
|
|
||||||
|
text = "#cdd6f4"
|
||||||
|
text_dim = "DarkGray"
|
||||||
|
text_bright = "#ffffff"
|
||||||
|
|
||||||
|
success = "#a6e3a1"
|
||||||
|
error = "#f38ba8"
|
||||||
|
warning = "#f9e2af"
|
||||||
|
info = "#89dceb"
|
||||||
|
|
||||||
|
diff_added = "#a6e3a1"
|
||||||
|
diff_removed = "#f38ba8"
|
||||||
|
diff_context = "DarkGray"
|
||||||
|
|
||||||
|
border = "#585b70"
|
||||||
|
surface = "#313244"
|
||||||
|
background = "#1e1e2e"
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 1.3 MiB |
Binary file not shown.
|
Before Width: | Height: | Size: 389 KiB After Width: | Height: | Size: 1.1 MiB |
Binary file not shown.
|
Before Width: | Height: | Size: 3.7 MiB After Width: | Height: | Size: 354 KiB |
+4
-2
@@ -2,9 +2,11 @@
|
|||||||
# catppuccin, dracula, nord, gruvbox, one-dark,
|
# catppuccin, dracula, nord, gruvbox, one-dark,
|
||||||
# solarized, tailwind, tokyo-night, rose-pine, terminal
|
# solarized, tailwind, tokyo-night, rose-pine, terminal
|
||||||
#
|
#
|
||||||
# custom themes:
|
# custom themes:
|
||||||
# theme = "my-theme" (loads ~/.config/mcl/theme/my-theme.toml)
|
# theme = "my-theme" (loads ~/.config/rmcl/theme/my-theme.toml)
|
||||||
# theme = "/path/to/file" (loads from absolute path)
|
# theme = "/path/to/file" (loads from absolute path)
|
||||||
|
# a theme file has flat top-level keys (name, id, accent, ...), not the
|
||||||
|
# [custom] table below. see assets/example-theme.toml in the repo.
|
||||||
theme = "gruvbox"
|
theme = "gruvbox"
|
||||||
|
|
||||||
# rounded, plain, double, thick
|
# rounded, plain, double, thick
|
||||||
|
|||||||
@@ -66,6 +66,28 @@ fn resolve_builtin_theme() {
|
|||||||
assert_eq!(theme.id(), expected);
|
assert_eq!(theme.id(), expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// a theme file in config/theme/ is a flat CustomTheme: name/id/accent are
|
||||||
|
// required, everything else falls back to themekit defaults.
|
||||||
|
#[test]
|
||||||
|
fn custom_theme_file_parses() {
|
||||||
|
let full = toml::from_str::<CustomTheme>(include_str!("../../../assets/example-theme.toml"))
|
||||||
|
.expect("bundled example theme must parse");
|
||||||
|
assert_eq!(full.id, "my-theme");
|
||||||
|
assert_eq!(full.accent, Color::Rgb(249, 115, 22));
|
||||||
|
assert_eq!(full.text, Color::Rgb(205, 214, 244));
|
||||||
|
|
||||||
|
let minimal =
|
||||||
|
toml::from_str::<CustomTheme>("name = \"X\"\nid = \"x\"\naccent = \"#f97316\"\n").unwrap();
|
||||||
|
assert_eq!(minimal.accent, Color::Rgb(249, 115, 22));
|
||||||
|
|
||||||
|
// the two failure modes users hit: nesting under [theme], or omitting name/id
|
||||||
|
assert!(
|
||||||
|
toml::from_str::<CustomTheme>("[theme]\nname = \"X\"\nid = \"x\"\naccent = \"Red\"\n")
|
||||||
|
.is_err()
|
||||||
|
);
|
||||||
|
assert!(toml::from_str::<CustomTheme>("accent = \"Red\"\n").is_err());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn theme_config_empty_toml_uses_defaults() {
|
fn theme_config_empty_toml_uses_defaults() {
|
||||||
let config: ThemeConfig = toml::from_str("").unwrap();
|
let config: ThemeConfig = toml::from_str("").unwrap();
|
||||||
|
|||||||
+7
-4
@@ -151,10 +151,13 @@ fn load_base_theme(name: &str) -> Box<dyn Theme> {
|
|||||||
if let Some(path) = path
|
if let Some(path) = path
|
||||||
&& let Ok(content) = std::fs::read_to_string(&path)
|
&& let Ok(content) = std::fs::read_to_string(&path)
|
||||||
{
|
{
|
||||||
if let Ok(custom) = toml::from_str::<CustomTheme>(&content) {
|
match toml::from_str::<CustomTheme>(&content) {
|
||||||
return Box::new(custom);
|
Ok(custom) => return Box::new(custom),
|
||||||
} else {
|
Err(e) => tracing::warn!(
|
||||||
tracing::warn!("Failed to parse theme file: {}", path.display());
|
"Failed to parse theme file {}: {e}. Theme files need top-level \
|
||||||
|
name, id and accent keys (not nested under [theme]).",
|
||||||
|
path.display()
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -372,14 +372,43 @@ pub struct ProviderRegistry {
|
|||||||
providers: Vec<Box<dyn ContentProvider>>,
|
providers: Vec<Box<dyn ContentProvider>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Newest entry by publish date. Providers are not required to sort their
|
||||||
|
/// responses, so list order is only the tie-breaker.
|
||||||
|
pub(crate) fn newest_version(versions: &[VersionInfo]) -> Option<&VersionInfo> {
|
||||||
|
let first = versions.first()?;
|
||||||
|
Some(versions.iter().fold(first, |newest, version| {
|
||||||
|
match (published_at(version), published_at(newest)) {
|
||||||
|
(Some(candidate), Some(current)) if candidate > current => version,
|
||||||
|
_ => newest,
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether `target` supersedes `installed`. Falls back to identity when a
|
||||||
|
/// provider omits publish dates, which keeps the newest-first list order as the
|
||||||
|
/// only signal we have left.
|
||||||
|
pub(crate) fn is_newer(target: &VersionInfo, installed: &VersionInfo) -> bool {
|
||||||
|
match (published_at(target), published_at(installed)) {
|
||||||
|
(Some(target), Some(installed)) => target > installed,
|
||||||
|
_ => target.id != installed.id,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn published_at(version: &VersionInfo) -> Option<chrono::DateTime<chrono::FixedOffset>> {
|
||||||
|
chrono::DateTime::parse_from_rfc3339(&version.date_published).ok()
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn has_newer_compatible_version(
|
pub(crate) fn has_newer_compatible_version(
|
||||||
versions: &[VersionInfo],
|
versions: &[VersionInfo],
|
||||||
installed_version_id: &str,
|
installed_version_id: &str,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
versions
|
let Some(installed) = versions
|
||||||
.iter()
|
.iter()
|
||||||
.position(|version| version.id == installed_version_id)
|
.find(|version| version.id == installed_version_id)
|
||||||
.is_some_and(|position| position > 0)
|
else {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
newest_version(versions).is_some_and(|target| is_newer(target, installed))
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProviderRegistry {
|
impl ProviderRegistry {
|
||||||
|
|||||||
+122
-20
@@ -22,10 +22,17 @@ pub struct UpdateSnapshot {
|
|||||||
pub loader: ModLoader,
|
pub loader: ModLoader,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub inventory: Vec<ProviderProject>,
|
pub inventory: Vec<ProviderProject>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub checked_at: i64,
|
||||||
pub updates: Vec<AvailableUpdate>,
|
pub updates: Vec<AvailableUpdate>,
|
||||||
pub failures: Vec<UpdateCheckFailure>,
|
pub failures: Vec<UpdateCheckFailure>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// How long a snapshot is trusted before the next reconciliation rechecks it.
|
||||||
|
/// Anything shorter re-scans every mod against the provider APIs each time the
|
||||||
|
/// instance is selected.
|
||||||
|
const RECHECK_AFTER_SECONDS: i64 = 30 * 60;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct UpdateCheckFailure {
|
pub struct UpdateCheckFailure {
|
||||||
pub installed: ProviderProject,
|
pub installed: ProviderProject,
|
||||||
@@ -87,6 +94,29 @@ impl UpdateSnapshot {
|
|||||||
self.inventory == resolved_inventory(manifest)
|
self.inventory == resolved_inventory(manifest)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether the snapshot is worth re-scanning. Note that a stale snapshot is
|
||||||
|
/// still displayed: every entry is keyed by its exact installed version, so
|
||||||
|
/// content that changed since the scan simply stops matching instead of
|
||||||
|
/// invalidating the labels of everything else.
|
||||||
|
pub fn is_stale(&self, manifest: &ContentManifest) -> bool {
|
||||||
|
!self.matches_manifest(manifest)
|
||||||
|
|| chrono::Utc::now()
|
||||||
|
.timestamp()
|
||||||
|
.saturating_sub(self.checked_at)
|
||||||
|
>= RECHECK_AFTER_SECONDS
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Keeps known updates for entries whose check failed this round so a flaky
|
||||||
|
/// network or a rate limited provider does not drop labels that were correct.
|
||||||
|
fn carry_over(&mut self, previous: &Self) {
|
||||||
|
for failure in &self.failures {
|
||||||
|
if let Some(update) = previous.update_for(&failure.installed) {
|
||||||
|
self.updates.push(update.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sort_updates(&mut self.updates);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn update_for(&self, installed: &ProviderProject) -> Option<&AvailableUpdate> {
|
pub fn update_for(&self, installed: &ProviderProject) -> Option<&AvailableUpdate> {
|
||||||
self.updates.iter().find(|update| {
|
self.updates.iter().find(|update| {
|
||||||
update.installed.provider == installed.provider
|
update.installed.provider == installed.provider
|
||||||
@@ -98,7 +128,12 @@ impl UpdateSnapshot {
|
|||||||
|
|
||||||
pub fn spawn(instance: InstanceConfig, manifest: ContentManifest, path: std::path::PathBuf) {
|
pub fn spawn(instance: InstanceConfig, manifest: ContentManifest, path: std::path::PathBuf) {
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let snapshot = scan(&instance, &manifest).await;
|
let previous =
|
||||||
|
UpdateSnapshot::load(&path).filter(|previous| previous.applies_to(&instance));
|
||||||
|
let mut snapshot = scan(&instance, &manifest).await;
|
||||||
|
if let Some(previous) = previous {
|
||||||
|
snapshot.carry_over(&previous);
|
||||||
|
}
|
||||||
if let Ok(bytes) = serde_json::to_vec_pretty(&snapshot)
|
if let Ok(bytes) = serde_json::to_vec_pretty(&snapshot)
|
||||||
&& let Err(error) = crate::storage::write_atomic(&path, &bytes)
|
&& let Err(error) = crate::storage::write_atomic(&path, &bytes)
|
||||||
{
|
{
|
||||||
@@ -144,9 +179,16 @@ pub async fn scan(instance: &InstanceConfig, manifest: &ContentManifest) -> Upda
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let slots = Arc::new(tokio::sync::Semaphore::new(8));
|
let slots = Arc::new(tokio::sync::Semaphore::new(8));
|
||||||
|
// one registry (and therefore one pooled http client) for the whole scan
|
||||||
|
let registry = Arc::new(
|
||||||
|
crate::instance::content::provider::ProviderRegistry::configured(
|
||||||
|
crate::net::HttpClient::new(),
|
||||||
|
),
|
||||||
|
);
|
||||||
let mut tasks = tokio::task::JoinSet::new();
|
let mut tasks = tokio::task::JoinSet::new();
|
||||||
for (installed, kind) in projects {
|
for (installed, kind) in projects {
|
||||||
let slots = slots.clone();
|
let slots = slots.clone();
|
||||||
|
let registry = registry.clone();
|
||||||
let game_version = instance.game_version.clone();
|
let game_version = instance.game_version.clone();
|
||||||
let loader = instance.loader;
|
let loader = instance.loader;
|
||||||
tasks.spawn(async move {
|
tasks.spawn(async move {
|
||||||
@@ -155,9 +197,6 @@ pub async fn scan(instance: &InstanceConfig, manifest: &ContentManifest) -> Upda
|
|||||||
.acquire_owned()
|
.acquire_owned()
|
||||||
.await
|
.await
|
||||||
.map_err(|error| error.to_string())?;
|
.map_err(|error| error.to_string())?;
|
||||||
let registry = crate::instance::content::provider::ProviderRegistry::configured(
|
|
||||||
crate::net::HttpClient::new(),
|
|
||||||
);
|
|
||||||
let provider = registry.get(&installed.provider).ok_or_else(|| {
|
let provider = registry.get(&installed.provider).ok_or_else(|| {
|
||||||
format!("{} content provider is unavailable", installed.provider)
|
format!("{} content provider is unavailable", installed.provider)
|
||||||
})?;
|
})?;
|
||||||
@@ -165,17 +204,27 @@ pub async fn scan(instance: &InstanceConfig, manifest: &ContentManifest) -> Upda
|
|||||||
.compatible_versions(&installed.project_id, kind, &game_version, loader)
|
.compatible_versions(&installed.project_id, kind, &game_version, loader)
|
||||||
.await
|
.await
|
||||||
.map_err(|error| error.to_string())?;
|
.map_err(|error| error.to_string())?;
|
||||||
let current = versions
|
let Some(newest) = crate::instance::content::provider::newest_version(&versions)
|
||||||
|
else {
|
||||||
|
return Ok(None);
|
||||||
|
};
|
||||||
|
// a modpack pins files that are often not tagged for the exact
|
||||||
|
// game version of the instance, so the installed version can be
|
||||||
|
// missing from the compatible list. asking the provider for it
|
||||||
|
// directly is the only way to tell "up to date" from "unknown".
|
||||||
|
let current = match versions
|
||||||
.iter()
|
.iter()
|
||||||
.find(|version| version.id == installed.version_id)
|
.find(|version| version.id == installed.version_id)
|
||||||
.cloned();
|
{
|
||||||
let target = versions.first().cloned().filter(|_| {
|
Some(current) => current.clone(),
|
||||||
crate::instance::content::provider::has_newer_compatible_version(
|
None => provider
|
||||||
&versions,
|
.version(&installed.version_id)
|
||||||
&installed.version_id,
|
.await
|
||||||
)
|
.map_err(|error| error.to_string())?,
|
||||||
});
|
};
|
||||||
Ok::<_, String>(target.map(|target| (current, target)))
|
let target = crate::instance::content::provider::is_newer(newest, ¤t)
|
||||||
|
.then(|| newest.clone());
|
||||||
|
Ok::<_, String>(target.map(|target| (Some(current), target)))
|
||||||
}
|
}
|
||||||
.await;
|
.await;
|
||||||
(installed, kind, result)
|
(installed, kind, result)
|
||||||
@@ -201,19 +250,24 @@ pub async fn scan(instance: &InstanceConfig, manifest: &ContentManifest) -> Upda
|
|||||||
Err(error) => tracing::debug!("Content update task failed: {error}"),
|
Err(error) => tracing::debug!("Content update task failed: {error}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updates.sort_by(|left, right| {
|
sort_updates(&mut updates);
|
||||||
(&left.installed.provider, &left.installed.project_id)
|
|
||||||
.cmp(&(&right.installed.provider, &right.installed.project_id))
|
|
||||||
});
|
|
||||||
UpdateSnapshot {
|
UpdateSnapshot {
|
||||||
game_version: instance.game_version.clone(),
|
game_version: instance.game_version.clone(),
|
||||||
loader: instance.loader,
|
loader: instance.loader,
|
||||||
inventory,
|
inventory,
|
||||||
|
checked_at: chrono::Utc::now().timestamp(),
|
||||||
updates,
|
updates,
|
||||||
failures,
|
failures,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn sort_updates(updates: &mut [AvailableUpdate]) {
|
||||||
|
updates.sort_by(|left, right| {
|
||||||
|
(&left.installed.provider, &left.installed.project_id)
|
||||||
|
.cmp(&(&right.installed.provider, &right.installed.project_id))
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
fn resolved_inventory(manifest: &ContentManifest) -> Vec<ProviderProject> {
|
fn resolved_inventory(manifest: &ContentManifest) -> Vec<ProviderProject> {
|
||||||
let mut inventory = manifest
|
let mut inventory = manifest
|
||||||
.files
|
.files
|
||||||
@@ -375,6 +429,7 @@ mod tests {
|
|||||||
game_version: "1.21.1".to_owned(),
|
game_version: "1.21.1".to_owned(),
|
||||||
loader: ModLoader::Fabric,
|
loader: ModLoader::Fabric,
|
||||||
inventory: vec![installed.clone()],
|
inventory: vec![installed.clone()],
|
||||||
|
checked_at: chrono::Utc::now().timestamp(),
|
||||||
updates: vec![AvailableUpdate {
|
updates: vec![AvailableUpdate {
|
||||||
installed: installed.clone(),
|
installed: installed.clone(),
|
||||||
current: Some(version("old")),
|
current: Some(version("old")),
|
||||||
@@ -396,7 +451,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn cached_updates_require_the_same_content_inventory() {
|
fn a_changed_content_inventory_only_schedules_a_rescan() {
|
||||||
let project = ProviderProject {
|
let project = ProviderProject {
|
||||||
provider: "modrinth".to_owned(),
|
provider: "modrinth".to_owned(),
|
||||||
project_id: "project".to_owned(),
|
project_id: "project".to_owned(),
|
||||||
@@ -406,6 +461,7 @@ mod tests {
|
|||||||
game_version: "1.21.1".to_owned(),
|
game_version: "1.21.1".to_owned(),
|
||||||
loader: ModLoader::Fabric,
|
loader: ModLoader::Fabric,
|
||||||
inventory: vec![project.clone()],
|
inventory: vec![project.clone()],
|
||||||
|
checked_at: chrono::Utc::now().timestamp(),
|
||||||
updates: Vec::new(),
|
updates: Vec::new(),
|
||||||
failures: Vec::new(),
|
failures: Vec::new(),
|
||||||
};
|
};
|
||||||
@@ -427,12 +483,58 @@ mod tests {
|
|||||||
cleanup_eligible: false,
|
cleanup_eligible: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
assert!(snapshot.matches_manifest(&manifest));
|
assert!(!snapshot.is_stale(&manifest));
|
||||||
manifest.files[0].resolution = crate::instance::Resolution::Unmatched {
|
manifest.files[0].resolution = crate::instance::Resolution::Unmatched {
|
||||||
checked_at: 0,
|
checked_at: 0,
|
||||||
providers: Vec::new(),
|
providers: Vec::new(),
|
||||||
};
|
};
|
||||||
assert!(!snapshot.matches_manifest(&manifest));
|
assert!(snapshot.is_stale(&manifest));
|
||||||
|
|
||||||
|
let expired = UpdateSnapshot {
|
||||||
|
checked_at: chrono::Utc::now().timestamp() - RECHECK_AFTER_SECONDS,
|
||||||
|
..snapshot
|
||||||
|
};
|
||||||
|
assert!(expired.is_stale(&manifest));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn failed_checks_keep_the_previously_known_update() {
|
||||||
|
let installed = ProviderProject {
|
||||||
|
provider: "modrinth".to_owned(),
|
||||||
|
project_id: "project".to_owned(),
|
||||||
|
version_id: "old".to_owned(),
|
||||||
|
};
|
||||||
|
let previous = UpdateSnapshot {
|
||||||
|
game_version: "1.21.1".to_owned(),
|
||||||
|
loader: ModLoader::Fabric,
|
||||||
|
inventory: vec![installed.clone()],
|
||||||
|
checked_at: 0,
|
||||||
|
updates: vec![AvailableUpdate {
|
||||||
|
installed: installed.clone(),
|
||||||
|
current: Some(version("old")),
|
||||||
|
target: version("new"),
|
||||||
|
kind: ContentKind::Mod,
|
||||||
|
}],
|
||||||
|
failures: Vec::new(),
|
||||||
|
};
|
||||||
|
let mut offline = UpdateSnapshot {
|
||||||
|
updates: Vec::new(),
|
||||||
|
failures: vec![UpdateCheckFailure {
|
||||||
|
installed: installed.clone(),
|
||||||
|
kind: ContentKind::Mod,
|
||||||
|
reason: "request timed out".to_owned(),
|
||||||
|
}],
|
||||||
|
..previous.clone()
|
||||||
|
};
|
||||||
|
|
||||||
|
offline.carry_over(&previous);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
offline
|
||||||
|
.update_for(&installed)
|
||||||
|
.map(|update| &update.target.id),
|
||||||
|
Some(&"new".to_owned())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -6,9 +6,8 @@ fn registry_falls_back_to_first_capable_provider() {
|
|||||||
assert_eq!(registry.preferred("unknown").unwrap().id(), "modrinth");
|
assert_eq!(registry.preferred("unknown").unwrap().id(), "modrinth");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
fn version(id: &str, date_published: &str) -> VersionInfo {
|
||||||
fn update_check_requires_the_installed_version_behind_a_newer_result() {
|
VersionInfo {
|
||||||
let version = |id: &str| VersionInfo {
|
|
||||||
id: id.to_owned(),
|
id: id.to_owned(),
|
||||||
project_id: "project".to_owned(),
|
project_id: "project".to_owned(),
|
||||||
name: id.to_owned(),
|
name: id.to_owned(),
|
||||||
@@ -17,12 +16,43 @@ fn update_check_requires_the_installed_version_behind_a_newer_result() {
|
|||||||
loaders: vec!["fabric".to_owned()],
|
loaders: vec!["fabric".to_owned()],
|
||||||
version_type: crate::net::modrinth::VersionType::Release,
|
version_type: crate::net::modrinth::VersionType::Release,
|
||||||
dependencies: Vec::new(),
|
dependencies: Vec::new(),
|
||||||
date_published: String::new(),
|
date_published: date_published.to_owned(),
|
||||||
files: Vec::new(),
|
files: Vec::new(),
|
||||||
};
|
}
|
||||||
let versions = vec![version("new"), version("installed")];
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn update_check_requires_the_installed_version_behind_a_newer_result() {
|
||||||
|
let versions = vec![version("new", ""), version("installed", "")];
|
||||||
|
|
||||||
assert!(has_newer_compatible_version(&versions, "installed"));
|
assert!(has_newer_compatible_version(&versions, "installed"));
|
||||||
assert!(!has_newer_compatible_version(&versions, "new"));
|
assert!(!has_newer_compatible_version(&versions, "new"));
|
||||||
assert!(!has_newer_compatible_version(&versions, "missing"));
|
assert!(!has_newer_compatible_version(&versions, "missing"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn update_check_uses_publish_dates_not_response_order() {
|
||||||
|
// curseforge does not promise a newest-first ordering
|
||||||
|
let versions = vec![
|
||||||
|
version("installed", "2024-01-01T00:00:00Z"),
|
||||||
|
version("new", "2024-06-01T00:00:00.500Z"),
|
||||||
|
];
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
newest_version(&versions).map(|v| v.id.as_str()),
|
||||||
|
Some("new")
|
||||||
|
);
|
||||||
|
assert!(has_newer_compatible_version(&versions, "installed"));
|
||||||
|
assert!(!has_newer_compatible_version(&versions, "new"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_version_missing_from_the_compatible_list_can_still_be_outdated() {
|
||||||
|
// a modpack pins files that are not tagged for the instance's exact game
|
||||||
|
// version, so the installed version never shows up in the filtered list
|
||||||
|
let compatible = vec![version("new", "2024-06-01T00:00:00Z")];
|
||||||
|
let pinned = version("pinned", "2023-01-01T00:00:00Z");
|
||||||
|
|
||||||
|
assert!(is_newer(newest_version(&compatible).unwrap(), &pinned));
|
||||||
|
assert!(!has_newer_compatible_version(&compatible, &pinned.id));
|
||||||
|
}
|
||||||
+23
-32
@@ -402,19 +402,23 @@ impl App {
|
|||||||
.instances_dir
|
.instances_dir
|
||||||
.join(&result.instance_name),
|
.join(&result.instance_name),
|
||||||
);
|
);
|
||||||
self.content_update_snapshot =
|
let cached =
|
||||||
crate::instance::content::updates::UpdateSnapshot::load(&paths.content_updates())
|
crate::instance::content::updates::UpdateSnapshot::load(&paths.content_updates())
|
||||||
.filter(|snapshot| {
|
.filter(|snapshot| snapshot.applies_to(&selected));
|
||||||
snapshot.applies_to(&selected) && snapshot.matches_manifest(&result.manifest)
|
let stale = cached
|
||||||
})
|
.as_ref()
|
||||||
.map(|snapshot| (result.instance_name.clone(), snapshot));
|
.is_none_or(|snapshot| snapshot.is_stale(&result.manifest));
|
||||||
|
self.content_update_snapshot =
|
||||||
|
cached.map(|snapshot| (result.instance_name.clone(), snapshot));
|
||||||
self.content_manifest = Some((result.instance_name.clone(), result.manifest.clone()));
|
self.content_manifest = Some((result.instance_name.clone(), result.manifest.clone()));
|
||||||
self.apply_content_update_snapshot();
|
self.apply_content_update_snapshot();
|
||||||
crate::instance::content::updates::spawn(
|
if stale {
|
||||||
selected,
|
crate::instance::content::updates::spawn(
|
||||||
result.manifest,
|
selected,
|
||||||
paths.content_updates(),
|
result.manifest,
|
||||||
);
|
paths.content_updates(),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply_cached_content_manifest(&mut self) {
|
fn apply_cached_content_manifest(&mut self) {
|
||||||
@@ -458,36 +462,30 @@ impl App {
|
|||||||
};
|
};
|
||||||
let snapshot = match crate::instance::content::updates::PENDING_UPDATE_SNAPSHOTS.lock() {
|
let snapshot = match crate::instance::content::updates::PENDING_UPDATE_SNAPSHOTS.lock() {
|
||||||
Ok(mut pending) => {
|
Ok(mut pending) => {
|
||||||
pending.retain(|pending| {
|
let latest = pending
|
||||||
pending.instance_name != selected.name
|
|
||||||
|| pending.instance_created == selected.created
|
|
||||||
});
|
|
||||||
pending
|
|
||||||
.iter()
|
.iter()
|
||||||
.rposition(|pending| {
|
.rposition(|pending| {
|
||||||
pending.instance_name == selected.name
|
pending.instance_name == selected.name
|
||||||
&& pending.instance_created == selected.created
|
&& pending.instance_created == selected.created
|
||||||
})
|
})
|
||||||
.map(|index| pending.remove(index))
|
.map(|index| pending.remove(index));
|
||||||
|
// every scan also writes its result to disk, so whatever is left
|
||||||
|
// here is recovered on the next reconciliation of that instance
|
||||||
|
pending.clear();
|
||||||
|
latest
|
||||||
}
|
}
|
||||||
Err(_) => return,
|
Err(_) => return,
|
||||||
};
|
};
|
||||||
let Some(snapshot) = snapshot else {
|
let Some(snapshot) = snapshot else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let current_manifest = self
|
|
||||||
.content_manifest
|
|
||||||
.as_ref()
|
|
||||||
.filter(|(name, _)| name == &snapshot.instance_name)
|
|
||||||
.map(|(_, manifest)| manifest);
|
|
||||||
if current_manifest.is_none_or(|manifest| !snapshot.snapshot.matches_manifest(manifest)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
self.content_update_snapshot = Some((snapshot.instance_name, snapshot.snapshot));
|
self.content_update_snapshot = Some((snapshot.instance_name, snapshot.snapshot));
|
||||||
self.apply_content_update_snapshot();
|
self.apply_content_update_snapshot();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply_content_update_snapshot(&mut self) {
|
fn apply_content_update_snapshot(&mut self) {
|
||||||
|
// matched per entry by exact installed version, so a snapshot that no
|
||||||
|
// longer covers the whole manifest still labels everything it does cover
|
||||||
let snapshot = self
|
let snapshot = self
|
||||||
.content_update_snapshot
|
.content_update_snapshot
|
||||||
.as_ref()
|
.as_ref()
|
||||||
@@ -495,14 +493,7 @@ impl App {
|
|||||||
self.instances_state
|
self.instances_state
|
||||||
.selected_instance()
|
.selected_instance()
|
||||||
.filter(|instance| instance.name == *name && snapshot.applies_to(instance))
|
.filter(|instance| instance.name == *name && snapshot.applies_to(instance))
|
||||||
.and_then(|_| {
|
.map(|_| snapshot)
|
||||||
self.content_manifest
|
|
||||||
.as_ref()
|
|
||||||
.filter(|(manifest_name, manifest)| {
|
|
||||||
manifest_name == name && snapshot.matches_manifest(manifest)
|
|
||||||
})
|
|
||||||
.map(|_| snapshot)
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
self.mods_state.apply_update_snapshot(snapshot);
|
self.mods_state.apply_update_snapshot(snapshot);
|
||||||
self.resource_packs_state.apply_update_snapshot(snapshot);
|
self.resource_packs_state.apply_update_snapshot(snapshot);
|
||||||
|
|||||||
+1
-5
@@ -1158,11 +1158,7 @@ impl App {
|
|||||||
let cached_snapshot = self
|
let cached_snapshot = self
|
||||||
.content_update_snapshot
|
.content_update_snapshot
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.filter(|(name, snapshot)| {
|
.filter(|(name, snapshot)| name == &instance.name && snapshot.applies_to(&instance))
|
||||||
name == &instance.name
|
|
||||||
&& snapshot.applies_to(&instance)
|
|
||||||
&& snapshot.matches_manifest(&manifest)
|
|
||||||
})
|
|
||||||
.map(|(_, snapshot)| snapshot.clone());
|
.map(|(_, snapshot)| snapshot.clone());
|
||||||
if cached_snapshot
|
if cached_snapshot
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ fn snapshot() -> UpdateSnapshot {
|
|||||||
game_version: "1.21.1".to_owned(),
|
game_version: "1.21.1".to_owned(),
|
||||||
loader: crate::instance::ModLoader::Fabric,
|
loader: crate::instance::ModLoader::Fabric,
|
||||||
inventory: Vec::new(),
|
inventory: Vec::new(),
|
||||||
|
checked_at: 0,
|
||||||
updates: Vec::new(),
|
updates: Vec::new(),
|
||||||
failures: Vec::new(),
|
failures: Vec::new(),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,12 +50,14 @@ pub fn spawn_modpack_update_check(instance: &InstanceConfig) {
|
|||||||
let Ok(versions) = crate::instance::import::provider_versions(&source).await else {
|
let Ok(versions) = crate::instance::import::provider_versions(&source).await else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let update = versions.first().cloned().filter(|_| {
|
let update = crate::instance::content::provider::newest_version(&versions)
|
||||||
crate::instance::content::provider::has_newer_compatible_version(
|
.cloned()
|
||||||
&versions,
|
.filter(|_| {
|
||||||
&source.version_id,
|
crate::instance::content::provider::has_newer_compatible_version(
|
||||||
)
|
&versions,
|
||||||
});
|
&source.version_id,
|
||||||
|
)
|
||||||
|
});
|
||||||
if let Ok(mut pending) = PENDING_MODPACK_UPDATES.lock() {
|
if let Ok(mut pending) = PENDING_MODPACK_UPDATES.lock() {
|
||||||
pending.push((instance.name, source, update));
|
pending.push((instance.name, source, update));
|
||||||
crate::feedback::request_redraw();
|
crate::feedback::request_redraw();
|
||||||
|
|||||||
Reference in new issue
Block a user