feat: added discord rpc icons support
This commit is contained in:
parent
6e7dcefd99
commit
b744e5d595
5 changed files with 105 additions and 20 deletions
|
@ -1,12 +1,31 @@
|
|||
use std::thread::JoinHandle;
|
||||
use std::sync::mpsc::{self, Sender, SendError};
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
use anime_game_core::minreq;
|
||||
|
||||
use discord_rich_presence::{
|
||||
activity::*,
|
||||
DiscordIpc,
|
||||
DiscordIpcClient
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct DiscordRpcAsset {
|
||||
pub app_id: u64,
|
||||
pub id: String,
|
||||
pub r#type: u64,
|
||||
pub name: String
|
||||
}
|
||||
|
||||
impl DiscordRpcAsset {
|
||||
#[inline]
|
||||
pub fn get_uri(&self) -> String {
|
||||
format!("https://cdn.discordapp.com/app-assets/{}/{}.png", self.app_id, self.id)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct DiscordRpcParams {
|
||||
pub app_id: u64,
|
||||
|
@ -106,6 +125,20 @@ impl DiscordRpc {
|
|||
pub fn update(&self, update: RpcUpdates) -> Result<(), SendError<RpcUpdates>> {
|
||||
self.sender.send(update)
|
||||
}
|
||||
|
||||
pub fn get_assets(app_id: u64) -> anyhow::Result<Vec<DiscordRpcAsset>> {
|
||||
Ok(minreq::get(format!("https://discord.com/api/v9/oauth2/applications/{app_id}/assets"))
|
||||
.send()?
|
||||
.json::<Vec<serde_json::Value>>()?
|
||||
.into_iter()
|
||||
.map(|value| DiscordRpcAsset {
|
||||
app_id,
|
||||
id: value["id"].as_str().unwrap().to_string(),
|
||||
r#type: value["type"].as_u64().unwrap(),
|
||||
name: value["name"].as_str().unwrap().to_string()
|
||||
})
|
||||
.collect())
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for DiscordRpc {
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
pub const FOLDER_NAME: &str = "anime-game-launcher";
|
||||
|
||||
/// Get default launcher dir path
|
||||
///
|
||||
/// If `LAUNCHER_FOLDER` variable is set, then its value will be returned. Otherwise return `$HOME/.local/share/anime-game-launcher`
|
||||
#[inline]
|
||||
pub fn launcher_dir() -> anyhow::Result<PathBuf> {
|
||||
if let Ok(folder) = std::env::var("LAUNCHER_FOLDER") {
|
||||
return Ok(folder.into());
|
||||
|
@ -11,13 +12,25 @@ pub fn launcher_dir() -> anyhow::Result<PathBuf> {
|
|||
|
||||
Ok(std::env::var("XDG_DATA_HOME")
|
||||
.or_else(|_| std::env::var("HOME").map(|home| home + "/.local/share"))
|
||||
.map(|home| PathBuf::from(home).join("anime-game-launcher"))?)
|
||||
.map(|home| PathBuf::from(home).join(FOLDER_NAME))?)
|
||||
}
|
||||
|
||||
/// Get default config file path
|
||||
/// Get launcher's cache dir path
|
||||
///
|
||||
/// `$HOME/.local/share/anime-game-launcher/config.json`
|
||||
#[inline]
|
||||
/// If `CACHE_FOLDER` variable is set, then its value will be returned. Otherwise return `$HOME/.cache/anime-game-launcher`
|
||||
pub fn cache_dir() -> anyhow::Result<PathBuf> {
|
||||
if let Ok(folder) = std::env::var("CACHE_FOLDER") {
|
||||
return Ok(folder.into());
|
||||
}
|
||||
|
||||
Ok(std::env::var("XDG_CACHE_HOME")
|
||||
.or_else(|_| std::env::var("HOME").map(|home| home + "/.cache"))
|
||||
.map(|home| PathBuf::from(home).join(FOLDER_NAME))?)
|
||||
}
|
||||
|
||||
/// Get config file path
|
||||
///
|
||||
/// Default is `$HOME/.local/share/anime-game-launcher/config.json`
|
||||
pub fn config_file() -> anyhow::Result<PathBuf> {
|
||||
launcher_dir().map(|dir| dir.join("config.json"))
|
||||
}
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
pub const FOLDER_NAME: &str = "honkers-launcher";
|
||||
|
||||
/// Get default launcher dir path
|
||||
///
|
||||
/// If `LAUNCHER_FOLDER` variable is set, then its value will be returned. Otherwise return `$HOME/.local/share/honkers-launcher`
|
||||
#[inline]
|
||||
pub fn launcher_dir() -> anyhow::Result<PathBuf> {
|
||||
if let Ok(folder) = std::env::var("LAUNCHER_FOLDER") {
|
||||
return Ok(folder.into());
|
||||
|
@ -11,13 +12,25 @@ pub fn launcher_dir() -> anyhow::Result<PathBuf> {
|
|||
|
||||
Ok(std::env::var("XDG_DATA_HOME")
|
||||
.or_else(|_| std::env::var("HOME").map(|home| home + "/.local/share"))
|
||||
.map(|home| PathBuf::from(home).join("honkers-launcher"))?)
|
||||
.map(|home| PathBuf::from(home).join(FOLDER_NAME))?)
|
||||
}
|
||||
|
||||
/// Get default config file path
|
||||
/// Get launcher's cache dir path
|
||||
///
|
||||
/// `$HOME/.local/share/honkers-launcher/config.json`
|
||||
#[inline]
|
||||
/// If `CACHE_FOLDER` variable is set, then its value will be returned. Otherwise return `$HOME/.cache/honkers-launcher`
|
||||
pub fn cache_dir() -> anyhow::Result<PathBuf> {
|
||||
if let Ok(folder) = std::env::var("CACHE_FOLDER") {
|
||||
return Ok(folder.into());
|
||||
}
|
||||
|
||||
Ok(std::env::var("XDG_CACHE_HOME")
|
||||
.or_else(|_| std::env::var("HOME").map(|home| home + "/.cache"))
|
||||
.map(|home| PathBuf::from(home).join(FOLDER_NAME))?)
|
||||
}
|
||||
|
||||
/// Get config file path
|
||||
///
|
||||
/// Default is `$HOME/.local/share/honkers-launcher/config.json`
|
||||
pub fn config_file() -> anyhow::Result<PathBuf> {
|
||||
launcher_dir().map(|dir| dir.join("config.json"))
|
||||
}
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
pub const FOLDER_NAME: &str = "anime-borb-launcher";
|
||||
|
||||
/// Get default launcher dir path
|
||||
///
|
||||
/// If `LAUNCHER_FOLDER` variable is set, then its value will be returned. Otherwise return `$HOME/.local/share/anime-borb-launcher`
|
||||
#[inline]
|
||||
pub fn launcher_dir() -> anyhow::Result<PathBuf> {
|
||||
if let Ok(folder) = std::env::var("LAUNCHER_FOLDER") {
|
||||
return Ok(folder.into());
|
||||
|
@ -11,13 +12,25 @@ pub fn launcher_dir() -> anyhow::Result<PathBuf> {
|
|||
|
||||
Ok(std::env::var("XDG_DATA_HOME")
|
||||
.or_else(|_| std::env::var("HOME").map(|home| home + "/.local/share"))
|
||||
.map(|home| PathBuf::from(home).join("anime-borb-launcher"))?)
|
||||
.map(|home| PathBuf::from(home).join(FOLDER_NAME))?)
|
||||
}
|
||||
|
||||
/// Get default config file path
|
||||
/// Get launcher's cache dir path
|
||||
///
|
||||
/// `$HOME/.local/share/anime-borb-launcher/config.json`
|
||||
#[inline]
|
||||
/// If `CACHE_FOLDER` variable is set, then its value will be returned. Otherwise return `$HOME/.cache/anime-borb-launcher`
|
||||
pub fn cache_dir() -> anyhow::Result<PathBuf> {
|
||||
if let Ok(folder) = std::env::var("CACHE_FOLDER") {
|
||||
return Ok(folder.into());
|
||||
}
|
||||
|
||||
Ok(std::env::var("XDG_CACHE_HOME")
|
||||
.or_else(|_| std::env::var("HOME").map(|home| home + "/.cache"))
|
||||
.map(|home| PathBuf::from(home).join(FOLDER_NAME))?)
|
||||
}
|
||||
|
||||
/// Get config file path
|
||||
///
|
||||
/// Default is `$HOME/.local/share/anime-borb-launcher/config.json`
|
||||
pub fn config_file() -> anyhow::Result<PathBuf> {
|
||||
launcher_dir().map(|dir| dir.join("config.json"))
|
||||
}
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
pub const FOLDER_NAME: &str = "honkers-railway-launcher";
|
||||
|
||||
/// Get default launcher dir path
|
||||
///
|
||||
/// If `LAUNCHER_FOLDER` variable is set, then its value will be returned. Otherwise return `$HOME/.local/share/honkers-railway-launcher`
|
||||
#[inline]
|
||||
pub fn launcher_dir() -> anyhow::Result<PathBuf> {
|
||||
if let Ok(folder) = std::env::var("LAUNCHER_FOLDER") {
|
||||
return Ok(folder.into());
|
||||
|
@ -11,13 +12,25 @@ pub fn launcher_dir() -> anyhow::Result<PathBuf> {
|
|||
|
||||
Ok(std::env::var("XDG_DATA_HOME")
|
||||
.or_else(|_| std::env::var("HOME").map(|home| home + "/.local/share"))
|
||||
.map(|home| PathBuf::from(home).join("honkers-railway-launcher"))?)
|
||||
.map(|home| PathBuf::from(home).join(FOLDER_NAME))?)
|
||||
}
|
||||
|
||||
/// Get default config file path
|
||||
/// Get launcher's cache dir path
|
||||
///
|
||||
/// `$HOME/.local/share/honkers-railway-launcher/config.json`
|
||||
#[inline]
|
||||
/// If `CACHE_FOLDER` variable is set, then its value will be returned. Otherwise return `$HOME/.cache/honkers-railway-launcher`
|
||||
pub fn cache_dir() -> anyhow::Result<PathBuf> {
|
||||
if let Ok(folder) = std::env::var("CACHE_FOLDER") {
|
||||
return Ok(folder.into());
|
||||
}
|
||||
|
||||
Ok(std::env::var("XDG_CACHE_HOME")
|
||||
.or_else(|_| std::env::var("HOME").map(|home| home + "/.cache"))
|
||||
.map(|home| PathBuf::from(home).join(FOLDER_NAME))?)
|
||||
}
|
||||
|
||||
/// Get config file path
|
||||
///
|
||||
/// Default is `$HOME/.local/share/honkers-railway-launcher/config.json`
|
||||
pub fn config_file() -> anyhow::Result<PathBuf> {
|
||||
launcher_dir().map(|dir| dir.join("config.json"))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue