Skip to content

Commit

Permalink
feat: deleted discord rpc support
Browse files Browse the repository at this point in the history
It became too annoying to maintain and after making a public poll
most of people agreed to drop its support. We can re-think this
change in the future universal launcher.
  • Loading branch information
krypt0nn committed Oct 9, 2024
1 parent 44a2c74 commit 4707505
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 245 deletions.
31 changes: 4 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ opt-level = "s"
glib-build-tools = "0.20"

[dependencies.anime-launcher-sdk]
git = "https://github.com/an-anime-team/anime-launcher-sdk"
tag = "1.20.3"
# git = "https://github.com/an-anime-team/anime-launcher-sdk"
# tag = "1.20.3"
features = ["all", "genshin"]

# path = "../anime-launcher-sdk" # ! for dev purposes only
path = "../anime-launcher-sdk" # ! for dev purposes only

[dependencies]
relm4 = { version = "0.9.0", features = ["macros", "libadwaita"] }
Expand Down
216 changes: 1 addition & 215 deletions src/ui/preferences/enhancements/mod.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
use relm4::prelude::*;

use relm4::factory::{
AsyncFactoryComponent,
AsyncFactorySender,
AsyncFactoryVecDeque
};

use adw::prelude::*;

use anime_launcher_sdk::config::ConfigExt;
use anime_launcher_sdk::genshin::config::Config;
use anime_launcher_sdk::config::schema_blanks::prelude::*;

use anime_launcher_sdk::anime_game_core::installer::downloader::Downloader;

use anime_launcher_sdk::discord_rpc::DiscordRpc;
use anime_launcher_sdk::is_available;

use enum_ordinalize::Ordinalize;
Expand All @@ -32,64 +22,7 @@ use crate::*;
use super::gamescope::*;
use super::main::PreferencesAppMsg;

#[derive(Debug)]
struct DiscordRpcIcon {
pub check_button: gtk::CheckButton,

pub name: String,
pub path: PathBuf
}

#[relm4::factory(async)]
impl AsyncFactoryComponent for DiscordRpcIcon {
type Init = Self;
type Input = EnhancementsAppMsg;
type Output = EnhancementsAppMsg;
type CommandOutput = ();
type ParentWidget = adw::ExpanderRow;

view! {
root = adw::ActionRow {
set_title: &self.name,
// set_subtitle: &self.name,

// Don't even try to understand
add_prefix = &self.check_button.clone(),

add_suffix = &gtk::Picture {
set_margin_start: 4,
set_margin_top: 4,
set_margin_end: 4,
set_margin_bottom: 4,

add_css_class: "round-bin",

set_filename: Some(&self.path)
},

set_activatable: true,

connect_activated[sender, index] => move |_| {
sender.output(EnhancementsAppMsg::SetDiscordRpcIcon(index.clone()))
.unwrap();
}
}
}

#[inline]
async fn init_model(
init: Self::Init,
_index: &DynamicIndex,
_sender: AsyncFactorySender<Self>,
) -> Self {
init
}
}

pub struct EnhancementsApp {
discord_rpc_icons: AsyncFactoryVecDeque<DiscordRpcIcon>,
discord_rpc_root_check_button: gtk::CheckButton,

gamescope: AsyncController<GamescopeApp>,
game_page: AsyncController<GamePage>,
sandbox_page: AsyncController<SandboxPage>,
Expand All @@ -99,9 +32,6 @@ pub struct EnhancementsApp {
#[derive(Debug)]
pub enum EnhancementsAppMsg {
SetGamescopeParent,

SetDiscordRpcIcon(DynamicIndex),

OpenGamescope,
OpenMainPage,
OpenGameSettingsPage,
Expand Down Expand Up @@ -488,65 +418,6 @@ impl SimpleAsyncComponent for EnhancementsApp {
}
},

add = &adw::PreferencesGroup {
set_title: &tr!("discord-rpc"),

adw::ActionRow {
set_title: &tr!("enabled"),
set_subtitle: &tr!("discord-rpc-description"),

add_suffix = &gtk::Switch {
set_valign: gtk::Align::Center,
set_active: CONFIG.launcher.discord_rpc.enabled,

connect_state_notify => |switch| {
if is_ready() {
if let Ok(mut config) = Config::get() {
config.launcher.discord_rpc.enabled = switch.is_active();

Config::update(config);
}
}
}
}
},

#[local_ref]
discord_rpc_icons -> adw::ExpanderRow {
set_title: &tr!("icon")
},

adw::EntryRow {
set_title: &tr!("title"),
set_text: &CONFIG.launcher.discord_rpc.title,

connect_changed: |row| {
if is_ready() {
if let Ok(mut config) = Config::get() {
config.launcher.discord_rpc.title = row.text().to_string();

Config::update(config);
}
}
}
},

adw::EntryRow {
set_title: &tr!("description"),
set_text: &CONFIG.launcher.discord_rpc.subtitle,

connect_changed: |row| {
if is_ready() {
if let Ok(mut config) = Config::get() {
config.launcher.discord_rpc.subtitle = row.text().to_string();

Config::update(config);
}
}
}
}
},

add = &adw::PreferencesGroup {
set_title: &tr!("fps-unlocker"),

Expand Down Expand Up @@ -646,13 +517,7 @@ impl SimpleAsyncComponent for EnhancementsApp {
) -> AsyncComponentParts<Self> {
tracing::info!("Initializing enhancements settings");

let mut model = Self {
discord_rpc_icons: AsyncFactoryVecDeque::builder()
.launch_default()
.forward(sender.input_sender(), std::convert::identity),

discord_rpc_root_check_button: gtk::CheckButton::new(),

let model = Self {
gamescope: GamescopeApp::builder()
.launch(())
.detach(),
Expand All @@ -670,73 +535,6 @@ impl SimpleAsyncComponent for EnhancementsApp {
.forward(sender.input_sender(), std::convert::identity)
};

match DiscordRpc::get_assets(CONFIG.launcher.discord_rpc.app_id) {
Ok(icons) => {
for icon in icons {
let cache_file = CACHE_FOLDER
.join("discord-rpc")
.join(&icon.name)
.join(&icon.id);

// let sender = sender.clone();

// Workaround for old folder structure (pre 3.7.3)
let old_path = CACHE_FOLDER.join("discord-rpc").join(&icon.name);

if old_path.exists() {
if let Ok(metadata) = old_path.metadata() {
if metadata.is_file() {
std::fs::remove_file(old_path).expect("Failed to delete old discord rpc icon");
}
}
}

if !cache_file.exists() {
std::thread::spawn(move || {
Downloader::new(icon.get_uri())
.expect("Failed to init Discord RPC icon downloader")
.with_continue_downloading(false)
.with_free_space_check(false)
.download(cache_file, |_, _| {})
.expect("Failed to download Discord RPC icon");

/*if let Err(err) = result {
sender.input(EnhancementsAppMsg::Toast {
title: tr!("discord-rpc-icon-download-failed"),
description: Some(err.to_string())
});
}*/
});
}

// TODO: add icons after thread above finishes its work as well
else {
let check_button = gtk::CheckButton::new();

check_button.set_group(Some(&model.discord_rpc_root_check_button));

if CONFIG.launcher.discord_rpc.icon == icon.name {
check_button.set_active(true);
}

model.discord_rpc_icons.guard().push_back(DiscordRpcIcon {
check_button,

name: icon.name.clone(),
path: cache_file.clone()
});
}
}
}

Err(err) => sender.input(EnhancementsAppMsg::Toast {
title: tr!("discord-rpc-icons-fetch-failed"),
description: Some(err.to_string())
})
}

let discord_rpc_icons = model.discord_rpc_icons.widget();

let game_page = model.game_page.widget();
let sandbox_page = model.sandbox_page.widget();
let environment_page = model.environment_page.widget();
Expand All @@ -752,18 +550,6 @@ impl SimpleAsyncComponent for EnhancementsApp {
self.gamescope.widget().set_transient_for(super::main::PREFERENCES_WINDOW.as_ref());
}

EnhancementsAppMsg::SetDiscordRpcIcon(index) => {
if let Some(icon) = self.discord_rpc_icons.guard().get(index.current_index()) {
if let Ok(mut config) = Config::get() {
config.launcher.discord_rpc.icon.clone_from(&icon.name);

Config::update(config);

icon.check_button.set_active(true);
}
}
}

EnhancementsAppMsg::OpenGamescope => {
self.gamescope.widget().present();
}
Expand Down

0 comments on commit 4707505

Please sign in to comment.