diff --git a/Cargo.lock b/Cargo.lock index 52a530d..231e168 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -74,11 +74,12 @@ dependencies = [ [[package]] name = "anime-launcher-sdk" -version = "0.1.1" +version = "0.2.1" dependencies = [ "anime-game-core", "anyhow", "dirs", + "discord-rich-presence", "enum-ordinalize", "lazy_static", "md-5", @@ -628,6 +629,18 @@ dependencies = [ "winapi", ] +[[package]] +name = "discord-rich-presence" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47fc4beffb85ee1461588499073a4d9c20dcc7728c4b13d6b282ab6c508947e5" +dependencies = [ + "serde", + "serde_derive", + "serde_json", + "uuid", +] + [[package]] name = "dispatch" version = "0.2.0" @@ -2702,6 +2715,15 @@ version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8db7427f936968176eaa7cdf81b7f98b980b18495ec28f1b5791ac3bfe3eea9" +[[package]] +name = "uuid" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" +dependencies = [ + "getrandom", +] + [[package]] name = "valuable" version = "0.1.0" diff --git a/anime-launcher-sdk b/anime-launcher-sdk index f1f8eb6..77f7e77 160000 --- a/anime-launcher-sdk +++ b/anime-launcher-sdk @@ -1 +1 @@ -Subproject commit f1f8eb6a2cc2d61dc8a2fa02051bd5ab2c400338 +Subproject commit 77f7e77aa222fcde9264a0df06f7588fa62df219 diff --git a/assets/locales/de/enhancements.ftl b/assets/locales/de/enhancements.ftl index ae856fd..2b810e9 100644 --- a/assets/locales/de/enhancements.ftl +++ b/assets/locales/de/enhancements.ftl @@ -27,6 +27,11 @@ gamemode-description = Dem Spiel den Vorrang vor den übrigen Prozessen geben gamescope = Gamescope gamescope-description = Gamescope ist ein Tool von Valve das es ermöglicht, Spiele in einer isolierten Xwayland-Instanz laufen zu lassen und unterstützt AMD-, Intel- und Nvidia-GPUs +discord-rpc = Discord RPC +discord-rpc-description = Discord RPC allows you to provide Discord the info that you are currently playing the game to let your friends know +title = Title +description = Description + fps-unlocker = FPS Freischalter enabled = Aktiviert diff --git a/assets/locales/en/enhancements.ftl b/assets/locales/en/enhancements.ftl index dbf44fc..30c847c 100644 --- a/assets/locales/en/enhancements.ftl +++ b/assets/locales/en/enhancements.ftl @@ -27,6 +27,11 @@ gamemode-description = Prioritize the game over the rest of the processes gamescope = Gamescope gamescope-description = Gamescope is a tool from Valve that allows for games to run in an isolated Xwayland instance and supports AMD, Intel, and Nvidia GPUs +discord-rpc = Discord RPC +discord-rpc-description = Discord RPC allows you to provide Discord the info that you are currently playing the game to let your friends know +title = Title +description = Description + fps-unlocker = FPS Unlocker enabled = Enabled diff --git a/assets/locales/ru/enhancements.ftl b/assets/locales/ru/enhancements.ftl index 96a34eb..c104649 100644 --- a/assets/locales/ru/enhancements.ftl +++ b/assets/locales/ru/enhancements.ftl @@ -27,6 +27,11 @@ gamemode-description = Выделять игре приоритет перед gamescope = Gamescope gamescope-description = Программа от Valve, позволяющая запускать игры в изолированном окружении Xwayland и поддерживает видеокарты от AMD, Intel, и Nvidia +discord-rpc = Discord RPC +discord-rpc-description = Discord RPC позволяет вам предоставлять Discord информацию об игре, в которую вы сейчас играете +title = Заголовок +description = Описание + fps-unlocker = FPS Unlocker enabled = Включен diff --git a/src/ui/main.rs b/src/ui/main.rs index d959a6d..802affc 100644 --- a/src/ui/main.rs +++ b/src/ui/main.rs @@ -810,29 +810,15 @@ impl SimpleComponent for App { std::thread::sleep(std::time::Duration::from_secs(2)); - /*if config.launcher.discord_rpc.enabled { - this.widgets.preferences_stack.enhancements_page.discord_rpc.update(RpcUpdates::Connect); - }*/ + while let Ok(output) = std::process::Command::new("ps").arg("-A").stdout(std::process::Stdio::piped()).output() { + let output = String::from_utf8_lossy(&output.stdout); - loop { - std::thread::sleep(std::time::Duration::from_secs(3)); - - match std::process::Command::new("ps").arg("-A").stdout(std::process::Stdio::piped()).output() { - Ok(output) => { - let output = String::from_utf8_lossy(&output.stdout); - - if !output.contains("GenshinImpact.e") && !output.contains("unlocker.exe") { - break; - } - } - - Err(_) => break + if !output.contains("GenshinImpact.e") && !output.contains("unlocker.exe") { + break; } - } - /*if config.launcher.discord_rpc.enabled { - this.widgets.preferences_stack.enhancements_page.discord_rpc.update(RpcUpdates::Disconnect); - }*/ + std::thread::sleep(std::time::Duration::from_secs(3)); + } MAIN_WINDOW.as_ref().unwrap_unchecked().show(); } diff --git a/src/ui/preferences/enhancements.rs b/src/ui/preferences/enhancements.rs index 5be9291..13ce900 100644 --- a/src/ui/preferences/enhancements.rs +++ b/src/ui/preferences/enhancements.rs @@ -50,7 +50,7 @@ impl SimpleAsyncComponent for EnhancementsApp { set_selected: CONFIG.game.wine.sync.ordinal() as u32, - connect_selected_notify => move |row| unsafe { + connect_selected_notify => |row| unsafe { if is_ready() { if let Ok(mut config) = config::get() { config.game.wine.sync = WineSync::from_ordinal_unsafe(row.selected() as i8); @@ -82,7 +82,7 @@ impl SimpleAsyncComponent for EnhancementsApp { set_selected: CONFIG.game.wine.language.ordinal() as u32, - connect_selected_notify => move |row| unsafe { + connect_selected_notify => |row| unsafe { if is_ready() { if let Ok(mut config) = config::get() { config.game.wine.language = WineLang::from_ordinal_unsafe(row.selected() as i8); @@ -101,7 +101,7 @@ impl SimpleAsyncComponent for EnhancementsApp { set_state: CONFIG.game.wine.borderless, - connect_state_notify => move |switch| { + connect_state_notify => |switch| { if is_ready() { if let Ok(mut config) = config::get() { config.game.wine.borderless = switch.state(); @@ -128,7 +128,7 @@ impl SimpleAsyncComponent for EnhancementsApp { set_selected: CONFIG.game.wine.virtual_desktop.get_resolution().into(), - connect_selected_notify => move |row| { + connect_selected_notify => |row| { if is_ready() { if let Ok(mut config) = config::get() { let (width, height) = Resolution::try_from(row.selected()).unwrap().get_pair(); @@ -146,7 +146,7 @@ impl SimpleAsyncComponent for EnhancementsApp { set_state: CONFIG.game.wine.virtual_desktop.enabled, - connect_state_notify => move |switch| { + connect_state_notify => |switch| { if is_ready() { if let Ok(mut config) = config::get() { config.game.wine.virtual_desktop.enabled = switch.state(); @@ -174,7 +174,7 @@ impl SimpleAsyncComponent for EnhancementsApp { set_selected: CONFIG.game.enhancements.hud.ordinal() as u32, - connect_selected_notify => move |row| unsafe { + connect_selected_notify => |row| unsafe { if is_ready() { if let Ok(mut config) = config::get() { config.game.enhancements.hud = HUD::from_ordinal_unsafe(row.selected() as i8); @@ -207,7 +207,7 @@ impl SimpleAsyncComponent for EnhancementsApp { // Source: Bottles (https://github.com/bottlesdevs/Bottles/blob/22fa3573a13f4e9b9c429e4cdfe4ca29787a2832/src/ui/details-preferences.ui#L88) set_selected: 5 - CONFIG.game.enhancements.fsr.strength as u32, - connect_selected_notify => move |row| { + connect_selected_notify => |row| { if is_ready() { if let Ok(mut config) = config::get() { config.game.enhancements.fsr.strength = 5 - row.selected() as u64; @@ -222,7 +222,7 @@ impl SimpleAsyncComponent for EnhancementsApp { set_state: CONFIG.game.enhancements.fsr.enabled, - connect_state_notify => move |switch| { + connect_state_notify => |switch| { if is_ready() { if let Ok(mut config) = config::get() { config.game.enhancements.fsr.enabled = switch.state(); @@ -245,7 +245,7 @@ impl SimpleAsyncComponent for EnhancementsApp { set_state: CONFIG.game.enhancements.gamemode, - connect_state_notify => move |switch| { + connect_state_notify => |switch| { if is_ready() { if let Ok(mut config) = config::get() { config.game.enhancements.gamemode = switch.state(); @@ -277,7 +277,7 @@ impl SimpleAsyncComponent for EnhancementsApp { set_state: CONFIG.game.enhancements.gamescope.enabled, - connect_state_notify => move |switch| { + connect_state_notify => |switch| { if is_ready() { if let Ok(mut config) = config::get() { config.game.enhancements.gamescope.enabled = switch.state(); @@ -290,6 +290,60 @@ 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 = >k::Switch { + set_valign: gtk::Align::Center, + set_state: 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.state(); + + config::update(config); + } + } + } + } + }, + + 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"), @@ -321,7 +375,7 @@ impl SimpleAsyncComponent for EnhancementsApp { Fps::Custom(_) => 7 }, - connect_selected_notify => move |row| { + connect_selected_notify => |row| { if is_ready() && row.selected() < Fps::list().len() as u32 - 1 { if let Ok(mut config) = config::get() { config.game.enhancements.fps_unlocker.config.fps = Fps::list()[row.selected() as usize].to_num(); @@ -336,7 +390,7 @@ impl SimpleAsyncComponent for EnhancementsApp { set_state: CONFIG.game.enhancements.fps_unlocker.enabled, - connect_state_notify => move |switch| { + connect_state_notify => |switch| { if is_ready() { if let Ok(mut config) = config::get() { config.game.enhancements.fps_unlocker.enabled = switch.state(); @@ -357,7 +411,7 @@ impl SimpleAsyncComponent for EnhancementsApp { set_state: CONFIG.game.enhancements.fps_unlocker.config.power_saving, - connect_state_notify => move |switch| { + connect_state_notify => |switch| { if is_ready() { if let Ok(mut config) = config::get() { config.game.enhancements.fps_unlocker.config.power_saving = switch.state(); @@ -379,7 +433,7 @@ impl SimpleAsyncComponent for EnhancementsApp { set_value: CONFIG.game.enhancements.fps_unlocker.config.monitor as f64, - connect_changed => move |row| { + connect_changed => |row| { if is_ready() { if let Ok(mut config) = config::get() { config.game.enhancements.fps_unlocker.config.monitor = row.value() as u64; @@ -403,7 +457,7 @@ impl SimpleAsyncComponent for EnhancementsApp { set_selected: CONFIG.game.enhancements.fps_unlocker.config.window_mode.ordinal() as u32, - connect_selected_notify => move |row| unsafe { + connect_selected_notify => |row| unsafe { if is_ready() { if let Ok(mut config) = config::get() { config.game.enhancements.fps_unlocker.config.window_mode = WindowMode::from_ordinal_unsafe(row.selected() as i8); @@ -430,7 +484,7 @@ impl SimpleAsyncComponent for EnhancementsApp { set_selected: CONFIG.game.enhancements.fps_unlocker.config.priority as u32, - connect_selected_notify => move |row| { + connect_selected_notify => |row| { if is_ready() { if let Ok(mut config) = config::get() { config.game.enhancements.fps_unlocker.config.priority = row.selected() as u64; diff --git a/src/ui/preferences/gamescope.rs b/src/ui/preferences/gamescope.rs index bd66cc5..520d517 100644 --- a/src/ui/preferences/gamescope.rs +++ b/src/ui/preferences/gamescope.rs @@ -23,6 +23,8 @@ impl SimpleAsyncComponent for GamescopeApp { set_modal: true, set_hide_on_close: true, + + // FIXME: doesn't work for any reason set_search_enabled: false, add = &adw::PreferencesPage { @@ -40,10 +42,12 @@ impl SimpleAsyncComponent for GamescopeApp { }, connect_changed => |row| { - if let Ok(mut config) = config::get() { - config.game.enhancements.gamescope.game.width = row.text().parse().unwrap_or_default(); - - config::update(config); + if is_ready() { + if let Ok(mut config) = config::get() { + config.game.enhancements.gamescope.game.width = row.text().parse().unwrap_or_default(); + + config::update(config); + } } } }, @@ -59,10 +63,12 @@ impl SimpleAsyncComponent for GamescopeApp { }, connect_changed => |row| { - if let Ok(mut config) = config::get() { - config.game.enhancements.gamescope.game.height = row.text().parse().unwrap_or_default(); - - config::update(config); + if is_ready() { + if let Ok(mut config) = config::get() { + config.game.enhancements.gamescope.game.height = row.text().parse().unwrap_or_default(); + + config::update(config); + } } } } @@ -82,10 +88,12 @@ impl SimpleAsyncComponent for GamescopeApp { }, connect_changed => |row| { - if let Ok(mut config) = config::get() { - config.game.enhancements.gamescope.gamescope.width = row.text().parse().unwrap_or_default(); - - config::update(config); + if is_ready() { + if let Ok(mut config) = config::get() { + config.game.enhancements.gamescope.gamescope.width = row.text().parse().unwrap_or_default(); + + config::update(config); + } } } }, @@ -101,10 +109,12 @@ impl SimpleAsyncComponent for GamescopeApp { }, connect_changed => |row| { - if let Ok(mut config) = config::get() { - config.game.enhancements.gamescope.gamescope.height = row.text().parse().unwrap_or_default(); - - config::update(config); + if is_ready() { + if let Ok(mut config) = config::get() { + config.game.enhancements.gamescope.gamescope.height = row.text().parse().unwrap_or_default(); + + config::update(config); + } } } } @@ -126,10 +136,12 @@ impl SimpleAsyncComponent for GamescopeApp { }, connect_changed => |row| { - if let Ok(mut config) = config::get() { - config.game.enhancements.gamescope.framerate.focused = row.text().parse().unwrap_or_default(); - - config::update(config); + if is_ready() { + if let Ok(mut config) = config::get() { + config.game.enhancements.gamescope.framerate.focused = row.text().parse().unwrap_or_default(); + + config::update(config); + } } } }, @@ -145,10 +157,12 @@ impl SimpleAsyncComponent for GamescopeApp { }, connect_changed => |row| { - if let Ok(mut config) = config::get() { - config.game.enhancements.gamescope.framerate.unfocused = row.text().parse().unwrap_or_default(); - - config::update(config); + if is_ready() { + if let Ok(mut config) = config::get() { + config.game.enhancements.gamescope.framerate.unfocused = row.text().parse().unwrap_or_default(); + + config::update(config); + } } } }, @@ -161,10 +175,12 @@ impl SimpleAsyncComponent for GamescopeApp { set_state: CONFIG.game.enhancements.gamescope.integer_scaling, connect_state_notify => |switch| { - if let Ok(mut config) = config::get() { - config.game.enhancements.gamescope.integer_scaling = switch.state(); - - config::update(config); + if is_ready() { + if let Ok(mut config) = config::get() { + config.game.enhancements.gamescope.integer_scaling = switch.state(); + + config::update(config); + } } } } @@ -178,10 +194,12 @@ impl SimpleAsyncComponent for GamescopeApp { set_state: CONFIG.game.enhancements.gamescope.fsr, connect_state_notify => |switch| { - if let Ok(mut config) = config::get() { - config.game.enhancements.gamescope.fsr = switch.state(); - - config::update(config); + if is_ready() { + if let Ok(mut config) = config::get() { + config.game.enhancements.gamescope.fsr = switch.state(); + + config::update(config); + } } } } @@ -195,10 +213,12 @@ impl SimpleAsyncComponent for GamescopeApp { set_state: CONFIG.game.enhancements.gamescope.nis, connect_state_notify => |switch| { - if let Ok(mut config) = config::get() { - config.game.enhancements.gamescope.nis = switch.state(); - - config::update(config); + if is_ready() { + if let Ok(mut config) = config::get() { + config.game.enhancements.gamescope.nis = switch.state(); + + config::update(config); + } } } } @@ -216,10 +236,12 @@ impl SimpleAsyncComponent for GamescopeApp { set_selected: CONFIG.game.enhancements.gamescope.window_type.ordinal() as u32, connect_selected_notify => |row| unsafe { - if let Ok(mut config) = config::get() { - config.game.enhancements.gamescope.window_type = WindowType::from_ordinal_unsafe(row.selected() as i8); - - config::update(config); + if is_ready() { + if let Ok(mut config) = config::get() { + config.game.enhancements.gamescope.window_type = WindowType::from_ordinal_unsafe(row.selected() as i8); + + config::update(config); + } } } } diff --git a/src/ui/preferences/general.rs b/src/ui/preferences/general.rs index 9a676b7..0ef65d1 100644 --- a/src/ui/preferences/general.rs +++ b/src/ui/preferences/general.rs @@ -275,7 +275,7 @@ impl SimpleAsyncComponent for GeneralApp { .unwrap_or(0) as u32 }, - connect_selected_notify => move |row| { + connect_selected_notify => |row| { if is_ready() { if let Ok(mut config) = config::get() { config.launcher.language = crate::i18n::format_lang(SUPPORTED_LANGUAGES