diff --git a/Cargo.lock b/Cargo.lock index b6c224f..4e6134f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -76,6 +76,25 @@ dependencies = [ "backtrace", ] +[[package]] +name = "arboard" +version = "3.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df099ccb16cd014ff054ac1bf392c67feeef57164b05c42f037cd40f5d4357f4" +dependencies = [ + "clipboard-win", + "core-graphics", + "image", + "log", + "objc2", + "objc2-app-kit", + "objc2-foundation", + "parking_lot", + "windows-sys 0.48.0", + "wl-clipboard-rs", + "x11rb", +] + [[package]] name = "arrayref" version = "0.3.9" @@ -106,7 +125,7 @@ dependencies = [ "url", "wayland-backend", "wayland-client", - "wayland-protocols", + "wayland-protocols 0.32.6", "zbus", ] @@ -323,6 +342,7 @@ name = "babylonia-terminal-gui" version = "0.1.0" dependencies = [ "anyhow", + "arboard", "babylonia-terminal-sdk", "downloader", "glib-build-tools", @@ -447,12 +467,24 @@ version = "3.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf" +[[package]] +name = "bytemuck" +version = "1.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6b1fc10dbac614ebc03540c9dbd60e83887fda27794998c6528f1782047d540" + [[package]] name = "byteorder" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" +[[package]] +name = "byteorder-lite" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495" + [[package]] name = "bytes" version = "1.10.0" @@ -507,6 +539,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" + [[package]] name = "cfg_aliases" version = "0.2.1" @@ -599,6 +637,15 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" +[[package]] +name = "clipboard-win" +version = "5.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15efe7a882b08f34e38556b14f2fb3daa98769d06c7f0c1b076dfd0d983bc892" +dependencies = [ + "error-code", +] + [[package]] name = "colorchoice" version = "1.0.3" @@ -669,6 +716,30 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +[[package]] +name = "core-graphics" +version = "0.23.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c07782be35f9e1140080c6b96f0d44b739e2278479f64e02fdab4e32dfd8b081" +dependencies = [ + "bitflags 1.3.2", + "core-foundation 0.9.4", + "core-graphics-types", + "foreign-types 0.5.0", + "libc", +] + +[[package]] +name = "core-graphics-types" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45390e6114f68f718cc7a830514a96f903cccd70d02a8f6d9f643ac4ba45afaf" +dependencies = [ + "bitflags 1.3.2", + "core-foundation 0.9.4", + "libc", +] + [[package]] name = "cpufeatures" version = "0.2.17" @@ -718,6 +789,17 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72e3ae26c830a573f2e231fc2475f71fce4705609097cb9523abfc4007caed0b" +[[package]] +name = "derive-new" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d150dea618e920167e5973d70ae6ece4385b7164e0d799fe7c122dd0a5d912ad" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "dialoguer" version = "0.11.0" @@ -870,6 +952,12 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "error-code" +version = "3.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5d9305ccc6942a704f4335694ecd3de2ea531b114ac2d51f5f843750787a92f" + [[package]] name = "event-listener" version = "5.4.0" @@ -897,6 +985,15 @@ version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" +[[package]] +name = "fdeflate" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e6853b52649d4ac5c0bd02320cddc5ba956bdb407c4b75a2c6b75bf51500f8c" +dependencies = [ + "simd-adler32", +] + [[package]] name = "field-offset" version = "0.3.6" @@ -919,6 +1016,12 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "fixedbitset" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" + [[package]] name = "flate2" version = "1.0.35" @@ -953,7 +1056,28 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" dependencies = [ - "foreign-types-shared", + "foreign-types-shared 0.1.1", +] + +[[package]] +name = "foreign-types" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965" +dependencies = [ + "foreign-types-macros", + "foreign-types-shared 0.3.1", +] + +[[package]] +name = "foreign-types-macros" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742" +dependencies = [ + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -962,6 +1086,12 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" +[[package]] +name = "foreign-types-shared" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" + [[package]] name = "form_urlencoded" version = "1.2.1" @@ -1152,6 +1282,16 @@ dependencies = [ "version_check", ] +[[package]] +name = "gethostname" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0176e0459c2e4a1fe232f984bca6890e681076abb9934f6cea7c326f3fc47818" +dependencies = [ + "libc", + "windows-targets 0.48.5", +] + [[package]] name = "getrandom" version = "0.2.15" @@ -1767,6 +1907,19 @@ dependencies = [ "icu_properties", ] +[[package]] +name = "image" +version = "0.25.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd6f44aed642f18953a158afeb30206f4d50da59fbc66ecb53c66488de73563b" +dependencies = [ + "bytemuck", + "byteorder-lite", + "num-traits", + "png", + "tiff", +] + [[package]] name = "indexmap" version = "2.7.1" @@ -1808,6 +1961,12 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" +[[package]] +name = "jpeg-decoder" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5d4a7da358eff58addd2877a45865158f0d78c911d43a5784ceb7bbf52833b0" + [[package]] name = "js-sys" version = "0.3.77" @@ -1940,6 +2099,12 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "miniz_oxide" version = "0.8.4" @@ -1947,6 +2112,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3b1c9bd4fe1f0f8b387f6eb9eb3b4a1aa26185e5750efb9140301703f62cd1b" dependencies = [ "adler2", + "simd-adler32", ] [[package]] @@ -2000,6 +2166,18 @@ dependencies = [ "tempfile", ] +[[package]] +name = "nix" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab2156c4fce2f8df6c499cc1c763e4394b7482525bf2a9701c9d79d215f519e4" +dependencies = [ + "bitflags 2.8.0", + "cfg-if", + "cfg_aliases 0.1.1", + "libc", +] + [[package]] name = "nix" version = "0.29.0" @@ -2008,17 +2186,36 @@ checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46" dependencies = [ "bitflags 2.8.0", "cfg-if", - "cfg_aliases", + "cfg_aliases 0.2.1", "libc", "memoffset", ] +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + [[package]] name = "num-conv" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + [[package]] name = "num_cpus" version = "1.16.0" @@ -2167,7 +2364,7 @@ checksum = "5e14130c6a98cd258fdcb0fb6d744152343ff729cbfcb28c656a9d12b999fbcd" dependencies = [ "bitflags 2.8.0", "cfg-if", - "foreign-types", + "foreign-types 0.3.2", "libc", "once_cell", "openssl-macros", @@ -2219,6 +2416,16 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "os_pipe" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ffd2b0a5634335b135d5728d84c5e0fd726954b87111f7506a61c502280d982" +dependencies = [ + "libc", + "windows-sys 0.59.0", +] + [[package]] name = "pango" version = "0.20.9" @@ -2278,6 +2485,16 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" +[[package]] +name = "petgraph" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" +dependencies = [ + "fixedbitset", + "indexmap", +] + [[package]] name = "pin-project-lite" version = "0.2.16" @@ -2307,6 +2524,19 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" +[[package]] +name = "png" +version = "0.17.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82151a2fc869e011c153adc57cf2789ccb8d9906ce52c0b39a6b5697749d7526" +dependencies = [ + "bitflags 1.3.2", + "crc32fast", + "fdeflate", + "flate2", + "miniz_oxide", +] + [[package]] name = "polling" version = "3.7.4" @@ -2932,6 +3162,12 @@ dependencies = [ "libc", ] +[[package]] +name = "simd-adler32" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" + [[package]] name = "simple_logger" version = "4.3.3" @@ -3157,6 +3393,17 @@ dependencies = [ "syn", ] +[[package]] +name = "tiff" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba1310fcea54c6a9a4fd1aad794ecc02c31682f6bfbecdf460bf19533eed1e3e" +dependencies = [ + "flate2", + "jpeg-decoder", + "weezl", +] + [[package]] name = "time" version = "0.3.37" @@ -3374,6 +3621,19 @@ dependencies = [ "syn", ] +[[package]] +name = "tree_magic_mini" +version = "3.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aac5e8971f245c3389a5a76e648bfc80803ae066a1243a75db0064d7c1129d63" +dependencies = [ + "fnv", + "memchr", + "nom", + "once_cell", + "petgraph", +] + [[package]] name = "try-lock" version = "0.2.5" @@ -3600,6 +3860,18 @@ dependencies = [ "wayland-scanner", ] +[[package]] +name = "wayland-protocols" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f81f365b8b4a97f422ac0e8737c438024b5951734506b0e1d775c73030561f4" +dependencies = [ + "bitflags 2.8.0", + "wayland-backend", + "wayland-client", + "wayland-scanner", +] + [[package]] name = "wayland-protocols" version = "0.32.6" @@ -3612,6 +3884,19 @@ dependencies = [ "wayland-scanner", ] +[[package]] +name = "wayland-protocols-wlr" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad1f61b76b6c2d8742e10f9ba5c3737f6530b4c243132c2a2ccc8aa96fe25cd6" +dependencies = [ + "bitflags 2.8.0", + "wayland-backend", + "wayland-client", + "wayland-protocols 0.31.2", + "wayland-scanner", +] + [[package]] name = "wayland-scanner" version = "0.31.6" @@ -3660,6 +3945,12 @@ version = "0.25.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" +[[package]] +name = "weezl" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082" + [[package]] name = "winapi" version = "0.3.9" @@ -3908,6 +4199,26 @@ dependencies = [ "bitflags 2.8.0", ] +[[package]] +name = "wl-clipboard-rs" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12b41773911497b18ca8553c3daaf8ec9fe9819caf93d451d3055f69de028adb" +dependencies = [ + "derive-new", + "libc", + "log", + "nix 0.28.0", + "os_pipe", + "tempfile", + "thiserror", + "tree_magic_mini", + "wayland-backend", + "wayland-client", + "wayland-protocols 0.31.2", + "wayland-protocols-wlr", +] + [[package]] name = "write16" version = "1.0.0" @@ -3920,6 +4231,23 @@ version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" +[[package]] +name = "x11rb" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d91ffca73ee7f68ce055750bf9f6eca0780b8c85eff9bc046a3b0da41755e12" +dependencies = [ + "gethostname", + "rustix", + "x11rb-protocol", +] + +[[package]] +name = "x11rb-protocol" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec107c4503ea0b4a98ef47356329af139c0a4f7750e621cf2973cd3385ebcb3d" + [[package]] name = "xattr" version = "1.4.0" @@ -3986,7 +4314,7 @@ dependencies = [ "futures-core", "futures-lite", "hex", - "nix", + "nix 0.29.0", "ordered-stream", "serde", "serde_repr", diff --git a/babylonia-terminal-gui/Cargo.toml b/babylonia-terminal-gui/Cargo.toml index 51baef4..c350218 100644 --- a/babylonia-terminal-gui/Cargo.toml +++ b/babylonia-terminal-gui/Cargo.toml @@ -13,6 +13,7 @@ relm4 = { version = "0.9.1", features = ["libadwaita"] } libadwaita = { version = "0.7.1", features = ["v1_4"] } downloader = { git = "https://github.com/ALEZ-DEV/downloader" } # version = "0.2.7", rfd = "0.15.2" +arboard = { version = "3.4.1", features = ["wayland-data-control"] } [build-dependencies] glib-build-tools = "0.20.0" diff --git a/babylonia-terminal-gui/src/manager.rs b/babylonia-terminal-gui/src/manager.rs index c38e4f7..db1849d 100644 --- a/babylonia-terminal-gui/src/manager.rs +++ b/babylonia-terminal-gui/src/manager.rs @@ -14,7 +14,10 @@ use wincompatlib::prelude::Proton; use crate::ui::{ self, - pages::steps::{self, download_components}, + pages::steps::{ + self, + download_components::{self, DownloadComponentsPageWidgets}, + }, }; static PROTON: OnceCell = OnceCell::const_new(); @@ -140,8 +143,9 @@ impl Worker for HandleComponentInstallation { GameConfig::get_config_directory().await }; - GameManager::install_wine(game_dir.clone(), proton_release, Some(progress_bar.clone())) - .await; + if let Err(error) = GameManager::install_wine(game_dir.clone(), proton_release, Some(progress_bar.clone())).await { + sender.output(download_components::DownloadComponentsMsg::ShowError(format!("Failed to install proton : {}", error))).unwrap(); + } let _ = sender .output(download_components::DownloadComponentsMsg::UpdateProgressBarMsg(String::from("Starting download for DXVK"), Some(String::from("Installing DXVK")))); @@ -150,7 +154,9 @@ impl Worker for HandleComponentInstallation { let _ = sender.output(download_components::DownloadComponentsMsg::UpdateDownloadedComponentName(String::from("DXVK"))); - GameManager::install_dxvk(&get_proton().await, game_dir, dxvk_release, Some(progress_bar.clone())).await; + if let Err(error) = GameManager::install_dxvk(&get_proton().await, game_dir, dxvk_release, Some(progress_bar.clone())).await { + sender.output(download_components::DownloadComponentsMsg::ShowError(format!("Failed to install DXVK : {}", error))).unwrap(); + } let _ = sender .output(download_components::DownloadComponentsMsg::UpdateProgressBarMsg(String::from("Downloading and installing fonts"), Some(String::from("Fonts installed")))); @@ -159,7 +165,9 @@ impl Worker for HandleComponentInstallation { let _ = sender.output(download_components::DownloadComponentsMsg::UpdateDownloadedComponentName(String::from("fonts"))); - GameManager::install_font(&get_proton().await, Some(progress_bar.clone())).await; + if let Err(error) = GameManager::install_font(&get_proton().await, Some(progress_bar.clone())).await { + sender.output(download_components::DownloadComponentsMsg::ShowError(format!("Failed to install fonts : {}", error))).unwrap(); + } let _ = sender .output(download_components::DownloadComponentsMsg::UpdateProgressBarMsg(String::from("Download and installing denpendecies"), None)); @@ -168,7 +176,10 @@ impl Worker for HandleComponentInstallation { let _ = sender.output(download_components::DownloadComponentsMsg::UpdateDownloadedComponentName(String::from("denpendecies"))); - GameManager::install_dependencies(&get_proton().await).await; + if let Err(error) = GameManager::install_dependencies(&get_proton().await).await { + sender.output(download_components::DownloadComponentsMsg::ShowError(format!("Failed to install dependencies : {}", error))).unwrap(); + + } debug!("Finished to installing the components!"); diff --git a/babylonia-terminal-gui/src/ui/mod.rs b/babylonia-terminal-gui/src/ui/mod.rs index 8a404b9..527915d 100644 --- a/babylonia-terminal-gui/src/ui/mod.rs +++ b/babylonia-terminal-gui/src/ui/mod.rs @@ -8,6 +8,7 @@ use relm4::{ self, gtk::{self, prelude::*}, loading_widgets::LoadingWidgets, + once_cell::sync::OnceCell, prelude::*, *, }; @@ -19,6 +20,8 @@ use crate::APP_RESOURCE_PATH; pub mod pages; +pub static mut MAIN_WINDOW: Option = None; + pub fn run(app: RelmApp) { app.run_async::(None); } @@ -69,7 +72,7 @@ impl SimpleAsyncComponent for MainWindow { view! { #[root] - adw::ApplicationWindow { + main_window = adw::ApplicationWindow { set_default_size: (700, 560), add_css_class?: IS_DEVEL.then_some("devel"), @@ -211,6 +214,10 @@ impl SimpleAsyncComponent for MainWindow { let widgets = view_output!(); + unsafe { + MAIN_WINDOW = Some(widgets.main_window.clone()); + } + debug!("current GameState : {:?}", model.game_state); AsyncComponentParts { model, widgets } diff --git a/babylonia-terminal-gui/src/ui/pages/steps/download_components.rs b/babylonia-terminal-gui/src/ui/pages/steps/download_components.rs index 9fd8b1b..68a1057 100644 --- a/babylonia-terminal-gui/src/ui/pages/steps/download_components.rs +++ b/babylonia-terminal-gui/src/ui/pages/steps/download_components.rs @@ -1,5 +1,6 @@ use std::{convert::identity, usize}; +use arboard::Clipboard; use babylonia_terminal_sdk::{ components::{ dxvk_component::{self, DXVKComponent}, @@ -22,7 +23,7 @@ use relm4::{ use adw::prelude::*; use libadwaita as adw; -use crate::{manager, ui::MainWindowMsg}; +use crate::{manager, ui::MAIN_WINDOW}; use super::SetupPageMsg; @@ -33,7 +34,9 @@ pub enum DownloadComponentsMsg { ShowDoneMsg, UpdateDownloadedComponentName(String), UpdateCurrentlyInstalling(CurrentlyInstalling), + ShowError(String), // error message Finish, + Quit, } #[derive(Debug, PartialEq, Eq)] @@ -50,6 +53,7 @@ pub struct DownloadComponentsPage { // widgets proton_combo: adw::ComboRow, dxvk_combo: adw::ComboRow, + //error_dialog: Controller, // values proton_versions: Vec, @@ -137,6 +141,16 @@ impl SimpleAsyncComponent for DownloadComponentsPage { connect_clicked => DownloadComponentsMsg::UpdateCurrentlyInstalling(CurrentlyInstalling::Proton), }, + + gtk::Button { + set_css_classes: &["suggested-action", "pill"], + + set_label: "Test dialog", + set_hexpand: false, + set_width_request: 200, + + connect_clicked => DownloadComponentsMsg::ShowError(String::from("Test dialog")), + }, }, }, @@ -269,7 +283,12 @@ impl SimpleAsyncComponent for DownloadComponentsPage { let model = DownloadComponentsPage { proton_combo: adw::ComboRow::new(), dxvk_combo: adw::ComboRow::new(), - + //error_dialog: CopyDialog::builder() + // .transient_for(&root) + // .launch(()) + // .forward(sender.input_sender(), move |msg| match msg { + // DialogOutput::Close => DownloadComponentsMsg::Quit, + // }), proton_versions: proton_releases, dxvk_versions: dxvk_releases, selected_proton_version: None, @@ -326,9 +345,32 @@ impl SimpleAsyncComponent for DownloadComponentsPage { DownloadComponentsMsg::UpdateCurrentlyInstalling(currently_installing) => { self.currently_installing = currently_installing; } + DownloadComponentsMsg::ShowError(message) => { + let dialog = unsafe { + adw::MessageDialog::new( + MAIN_WINDOW.as_ref(), + Some("Error while downloading components"), + Some(&message), + ) + }; + + dialog.add_response("close", "Close"); + dialog.add_response("copy", "Copy"); + + dialog.set_response_appearance("copy", adw::ResponseAppearance::Suggested); + + dialog.connect_response(Some("copy"), move |_, _| { + if let Err(err) = Clipboard::new().unwrap().set_text(&message.clone()) { + error!("Failed to copy the error to the clipboard : {}", err); + } + }); + + dialog.present(); + } DownloadComponentsMsg::Finish => { let _ = sender.output(SetupPageMsg::Finish); } + DownloadComponentsMsg::Quit => relm4::main_application().quit(), } if self.selected_proton_version.is_none()