mirror of
https://github.com/an-anime-team/an-anime-game-launcher.git
synced 2025-02-16 15:22:01 +03:00
Initial commit. Added discord-rpc option.
Modified `enhancements.blp` and `enhancements.rs` to load a discord-rpc swithbox. Added `discord-rpc.rs` in enhancements libs to parse JSON and created inital implementations. TODO: - Add support to change various discord-rpc component's values - Fix "disabled" status of the rpc - Actually make the thing work!
This commit is contained in:
parent
da37ea2103
commit
6e831811cc
6 changed files with 119 additions and 14 deletions
|
@ -55,7 +55,14 @@ Adw.PreferencesPage page {
|
|||
]
|
||||
};
|
||||
}
|
||||
|
||||
Adw.ComboRow discord_rpc_row
|
||||
{
|
||||
title: "Discord Rpc";
|
||||
subtitle: "placeholder";
|
||||
Gtk.Switch discord_rpc_switch {
|
||||
valign: center;
|
||||
}
|
||||
}
|
||||
Adw.ComboRow fsr_combo {
|
||||
title: "FSR";
|
||||
subtitle: "Upscales game to your monitor size. To use select lower\nresolution in the game's settings and press Alt+Enter";
|
||||
|
@ -74,6 +81,8 @@ Adw.PreferencesPage page {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Adw.ActionRow gamemode_row {
|
||||
title: "Gamemode";
|
||||
subtitle: "This prioritizes the game over the rest of the processes";
|
||||
|
|
73
src/lib/config/game/enhancements/discordrpc.rs
Normal file
73
src/lib/config/game/enhancements/discordrpc.rs
Normal file
|
@ -0,0 +1,73 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value as JsonValue;
|
||||
|
||||
use super::prelude::Fsr;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct DiscordRpc {
|
||||
pub enabled: bool,
|
||||
pub large_image_key: String,
|
||||
pub app_id: u64,
|
||||
pub description: String,
|
||||
pub state: String,
|
||||
}
|
||||
|
||||
impl Default for DiscordRpc {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
enabled: true,
|
||||
large_image_key: "gi-icon".to_string(),
|
||||
app_id: 901534333360304168,
|
||||
description: "Bullying Paimon".to_string(),
|
||||
state: "In the weeb game".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&JsonValue> for DiscordRpc {
|
||||
fn from(value: &JsonValue) -> Self {
|
||||
let default = Self::default();
|
||||
Self {
|
||||
enabled: match value.get("enabled") {
|
||||
Some(value) => value.as_bool().unwrap_or(default.enabled),
|
||||
None => default.enabled
|
||||
},
|
||||
|
||||
description: match value.get("description") {
|
||||
Some(value) => value.as_str().unwrap_or(&default.description).to_string(),
|
||||
None => default.description
|
||||
},
|
||||
|
||||
state: match value.get("state") {
|
||||
Some(value) => value.as_str().unwrap_or(&default.state).to_string(),
|
||||
None => default.state
|
||||
},
|
||||
|
||||
large_image_key: match value.get("large_image_key"){
|
||||
Some(value) => value.as_str().unwrap_or(&default.large_image_key).to_string(),
|
||||
None => default.large_image_key
|
||||
},
|
||||
app_id: match value.get("app_id"){
|
||||
Some(value) => value.as_u64().unwrap_or(default.app_id),
|
||||
None => default.app_id
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl DiscordRpc
|
||||
{
|
||||
pub fn toggle(&self)
|
||||
{
|
||||
println!("[Debug] RPC state changed!");
|
||||
if self.enabled
|
||||
{
|
||||
todo!();
|
||||
}
|
||||
else
|
||||
{
|
||||
todo!();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@ pub mod fsr;
|
|||
pub mod hud;
|
||||
pub mod fps_unlocker;
|
||||
pub mod gamescope;
|
||||
|
||||
pub mod discordrpc;
|
||||
pub mod prelude {
|
||||
pub use super::gamescope::prelude::*;
|
||||
pub use super::fps_unlocker::prelude::*;
|
||||
|
@ -14,17 +14,21 @@ pub mod prelude {
|
|||
pub use super::fsr::Fsr;
|
||||
pub use super::hud::HUD;
|
||||
pub use super::fps_unlocker::FpsUnlocker;
|
||||
pub use super::discordrpc::DiscordRpc;
|
||||
}
|
||||
|
||||
use prelude::*;
|
||||
|
||||
use crate::lib::config;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
pub struct Enhancements {
|
||||
pub fsr: Fsr,
|
||||
pub gamemode: bool,
|
||||
pub hud: HUD,
|
||||
pub fps_unlocker: FpsUnlocker,
|
||||
pub gamescope: Gamescope
|
||||
pub gamescope: Gamescope,
|
||||
pub discord_rpc: DiscordRpc,
|
||||
}
|
||||
|
||||
impl From<&JsonValue> for Enhancements {
|
||||
|
@ -55,7 +59,11 @@ impl From<&JsonValue> for Enhancements {
|
|||
gamescope: match value.get("gamescope") {
|
||||
Some(value) => Gamescope::from(value),
|
||||
None => default.gamescope
|
||||
}
|
||||
},
|
||||
discord_rpc: match value.get("discord_rpc") {
|
||||
Some(value) => DiscordRpc::from(value),
|
||||
None => default.discord_rpc
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -174,7 +174,6 @@ pub fn run() -> anyhow::Result<()> {
|
|||
command.envs(config.game.enhancements.hud.get_env_vars(&config));
|
||||
command.envs(config.game.enhancements.fsr.get_env_vars());
|
||||
command.envs(config.game.wine.language.get_env_vars());
|
||||
|
||||
command.envs(config.game.environment);
|
||||
|
||||
// Run command
|
||||
|
|
|
@ -878,7 +878,6 @@ impl App {
|
|||
};
|
||||
|
||||
self.actions.set(actions);
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use gtk::ffi::gtk_text_view_set_overwrite;
|
||||
use gtk::prelude::*;
|
||||
use adw::prelude::*;
|
||||
|
||||
|
@ -6,6 +7,7 @@ use gtk::glib::clone;
|
|||
|
||||
use crate::lib;
|
||||
use crate::lib::config;
|
||||
use crate::lib::config::game::enhancements::discordrpc;
|
||||
use crate::lib::config::prelude::*;
|
||||
|
||||
use crate::ui::*;
|
||||
|
@ -45,7 +47,10 @@ pub struct AppWidgets {
|
|||
pub fps_unlocker_power_saving_switcher: gtk::Switch,
|
||||
pub fps_unlocker_monitor_num: gtk::SpinButton,
|
||||
pub fps_unlocker_window_mode_combo: adw::ComboRow,
|
||||
pub fps_unlocker_priority_combo: adw::ComboRow
|
||||
pub fps_unlocker_priority_combo: adw::ComboRow,
|
||||
|
||||
pub discord_rpc_row: adw::ComboRow,
|
||||
pub discord_rpc: gtk::Switch,
|
||||
}
|
||||
|
||||
impl AppWidgets {
|
||||
|
@ -79,7 +84,9 @@ impl AppWidgets {
|
|||
fps_unlocker_power_saving_switcher: get_object(&builder, "fps_unlocker_power_saving_switcher")?,
|
||||
fps_unlocker_monitor_num: get_object(&builder, "fps_unlocker_monitor_num")?,
|
||||
fps_unlocker_window_mode_combo: get_object(&builder, "fps_unlocker_window_mode_combo")?,
|
||||
fps_unlocker_priority_combo: get_object(&builder, "fps_unlocker_priority_combo")?
|
||||
fps_unlocker_priority_combo: get_object(&builder, "fps_unlocker_priority_combo")?,
|
||||
discord_rpc: get_object(&builder,"discord_rpc_switch")?,
|
||||
discord_rpc_row: get_object(&builder, "discord_rpc_row")?
|
||||
};
|
||||
|
||||
// Set availale wine languages
|
||||
|
@ -102,6 +109,7 @@ impl AppWidgets {
|
|||
result.gamescope_row.set_sensitive(false);
|
||||
result.gamescope_row.set_tooltip_text(Some("Gamescope is not installed"));
|
||||
}
|
||||
result.discord_rpc.set_sensitive(true);
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
@ -157,8 +165,8 @@ impl App {
|
|||
self.widgets.borderless.connect_state_notify(move |switch| {
|
||||
if let Ok(mut config) = config::get() {
|
||||
config.game.wine.borderless = switch.state();
|
||||
|
||||
config::update(config);
|
||||
config::game::enhancements::discordrpc::rpc_start();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -207,7 +215,6 @@ impl App {
|
|||
self.widgets.fsr_combo.connect_selected_notify(move |row| {
|
||||
if let Ok(mut config) = config::get() {
|
||||
config.game.enhancements.fsr.strength = 5 - row.selected() as u64;
|
||||
|
||||
config::update(config);
|
||||
}
|
||||
});
|
||||
|
@ -220,12 +227,19 @@ impl App {
|
|||
config::update(config);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
self.widgets.discord_rpc.connect_state_notify(move |switch|{
|
||||
if let Ok(mut config) = config::get()
|
||||
{
|
||||
config.game.enhancements.discord_rpc.enabled = switch.state();
|
||||
config.game.enhancements.discord_rpc.toggle();
|
||||
config::update(config);
|
||||
}
|
||||
});
|
||||
// Gamemode switching
|
||||
self.widgets.gamemode_switcher.connect_state_notify(move |switch| {
|
||||
if let Ok(mut config) = config::get() {
|
||||
config.game.enhancements.gamemode = switch.state();
|
||||
|
||||
config::update(config);
|
||||
}
|
||||
});
|
||||
|
@ -286,7 +300,6 @@ impl App {
|
|||
self.widgets.fps_unlocker_window_mode_combo.connect_selected_notify(move |row| {
|
||||
if let Ok(mut config) = config::get() {
|
||||
config.game.enhancements.fps_unlocker.config.window_mode = row.selected() as u64;
|
||||
|
||||
config::update(config);
|
||||
}
|
||||
});
|
||||
|
@ -295,11 +308,12 @@ impl App {
|
|||
self.widgets.fps_unlocker_priority_combo.connect_selected_notify(move |row| {
|
||||
if let Ok(mut config) = config::get() {
|
||||
config.game.enhancements.fps_unlocker.config.priority = row.selected() as u64;
|
||||
|
||||
config::update(config);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -355,6 +369,9 @@ impl App {
|
|||
// FSR switching
|
||||
self.widgets.fsr_switcher.set_state(config.game.enhancements.fsr.enabled);
|
||||
|
||||
// Discord RPC
|
||||
self.widgets.discord_rpc.set_state(config.game.enhancements.discord_rpc.enabled);
|
||||
|
||||
// Gamemode switching
|
||||
self.widgets.gamemode_switcher.set_state(config.game.enhancements.gamemode);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue