feat: added migrations to the new discord rpc values
This commit is contained in:
parent
7ee8294d3a
commit
9d1ec0907d
3 changed files with 56 additions and 30 deletions
|
@ -25,8 +25,6 @@ impl From<DiscordRpc> 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();
|
||||
|
||||
Self {
|
||||
app_id: match value.get("app_id") {
|
||||
// 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,
|
||||
|
||||
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(),
|
||||
|
|
|
@ -25,8 +25,6 @@ impl From<DiscordRpc> for DiscordRpcParams {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: add honkers-specific discord rpc
|
||||
|
||||
impl Default for DiscordRpc {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
|
|
|
@ -43,26 +43,41 @@ impl From<&JsonValue> for DiscordRpc {
|
|||
fn from(value: &JsonValue) -> Self {
|
||||
let default = Self::default();
|
||||
|
||||
Self {
|
||||
app_id: match value.get("app_id") {
|
||||
// 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,
|
||||
|
||||
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(),
|
||||
|
|
Loading…
Reference in a new issue