diff --git a/src/games/honkai/config/schema/launcher/discord_rpc.rs b/src/games/honkai/config/schema/launcher/discord_rpc.rs index a5022a7..81c720f 100644 --- a/src/games/honkai/config/schema/launcher/discord_rpc.rs +++ b/src/games/honkai/config/schema/launcher/discord_rpc.rs @@ -25,8 +25,6 @@ impl From for DiscordRpcParams { } } -// TODO: add honkers-specific discord rpc - impl Default for DiscordRpc { #[inline] fn default() -> Self { @@ -45,26 +43,41 @@ impl From<&JsonValue> for DiscordRpc { fn from(value: &JsonValue) -> Self { let default = Self::default(); + // Migration: Update old Discord RPC values + // This will be removed in future updates + + let mut app_id = match value.get("app_id") { + Some(value) => value.as_u64().unwrap_or(default.app_id), + None => default.app_id + }; + + let mut title = match value.get("title") { + Some(value) => value.as_str().unwrap_or(&default.title).to_string(), + None => default.title + }; + + let mut subtitle = match value.get("subtitle") { + Some(value) => value.as_str().unwrap_or(&default.subtitle).to_string(), + None => default.subtitle + }; + + // If old values are detected - replace them by new + if app_id == 901534333360304168 { + app_id = defualt.app_id; + title = default.title; + subtitle = default.subtitle; + } + Self { - app_id: match value.get("app_id") { - Some(value) => value.as_u64().unwrap_or(default.app_id), - None => default.app_id - }, + app_id, enabled: match value.get("enabled") { Some(value) => value.as_bool().unwrap_or(default.enabled), None => default.enabled }, - title: match value.get("title") { - Some(value) => value.as_str().unwrap_or(&default.title).to_string(), - None => default.title - }, - - subtitle: match value.get("subtitle") { - Some(value) => value.as_str().unwrap_or(&default.subtitle).to_string(), - None => default.subtitle - }, + title, + subtitle, icon: match value.get("icon") { Some(value) => value.as_str().unwrap_or(&default.icon).to_string(), diff --git a/src/games/pgr/config/schema/launcher/discord_rpc.rs b/src/games/pgr/config/schema/launcher/discord_rpc.rs index 48126f5..9b7cd47 100644 --- a/src/games/pgr/config/schema/launcher/discord_rpc.rs +++ b/src/games/pgr/config/schema/launcher/discord_rpc.rs @@ -25,8 +25,6 @@ impl From for DiscordRpcParams { } } -// TODO: add honkers-specific discord rpc - impl Default for DiscordRpc { #[inline] fn default() -> Self { diff --git a/src/games/star_rail/config/schema/launcher/discord_rpc.rs b/src/games/star_rail/config/schema/launcher/discord_rpc.rs index 0b5ecd2..b7c2113 100644 --- a/src/games/star_rail/config/schema/launcher/discord_rpc.rs +++ b/src/games/star_rail/config/schema/launcher/discord_rpc.rs @@ -43,26 +43,41 @@ impl From<&JsonValue> for DiscordRpc { fn from(value: &JsonValue) -> Self { let default = Self::default(); + // Migration: Update old Discord RPC values + // This will be removed in future updates + + let mut app_id = match value.get("app_id") { + Some(value) => value.as_u64().unwrap_or(default.app_id), + None => default.app_id + }; + + let mut title = match value.get("title") { + Some(value) => value.as_str().unwrap_or(&default.title).to_string(), + None => default.title + }; + + let mut subtitle = match value.get("subtitle") { + Some(value) => value.as_str().unwrap_or(&default.subtitle).to_string(), + None => default.subtitle + }; + + // If old values are detected - replace them by new + if app_id == 901534333360304168 { + app_id = defualt.app_id; + title = default.title; + subtitle = default.subtitle; + } + Self { - app_id: match value.get("app_id") { - Some(value) => value.as_u64().unwrap_or(default.app_id), - None => default.app_id - }, + app_id, enabled: match value.get("enabled") { Some(value) => value.as_bool().unwrap_or(default.enabled), None => default.enabled }, - title: match value.get("title") { - Some(value) => value.as_str().unwrap_or(&default.title).to_string(), - None => default.title - }, - - subtitle: match value.get("subtitle") { - Some(value) => value.as_str().unwrap_or(&default.subtitle).to_string(), - None => default.subtitle - }, + title, + subtitle, icon: match value.get("icon") { Some(value) => value.as_str().unwrap_or(&default.icon).to_string(),