main window: made action button to follow launcher's state

- also added "open debug file" option to the header menu
This commit is contained in:
Observer KRypt0n_ 2023-02-22 22:28:28 +02:00
parent f2a04f5ebe
commit 9497136ac6
No known key found for this signature in database
GPG key ID: 844DA47BA25FE1E2
4 changed files with 49 additions and 1 deletions

View file

@ -1,6 +1,7 @@
launcher-folder-opening-error = Failed to open launcher folder
game-folder-opening-error = Failed to open game folder
config-file-opening-error = Failed to open config file
debug-file-opening-error = Failed to open debug file
game-launching-failed = Failed to launch game

View file

@ -20,6 +20,11 @@ unpacking = Unpacking
launch = Launch
apply-patch = Apply patch
download-wine = Download wine
create-prefix = Create prefix
update = Update
download = Download
preferences = Preferences

View file

@ -1,6 +1,7 @@
launcher-folder-opening-error = Не удалось открыть папку лаунчера
game-folder-opening-error = Не удалось открыть папку игры
config-file-opening-error = Не удалось открыть файл настроек
debug-file-opening-error = Не удалось открыть файл отладки
game-launching-failed = Не удалось запустить игру

View file

@ -24,6 +24,7 @@ relm4::new_action_group!(WindowActionGroup, "win");
relm4::new_stateless_action!(LauncherFolder, WindowActionGroup, "launcher_folder");
relm4::new_stateless_action!(GameFolder, WindowActionGroup, "game_folder");
relm4::new_stateless_action!(ConfigFile, WindowActionGroup, "config_file");
relm4::new_stateless_action!(DebugFile, WindowActionGroup, "debug_file");
relm4::new_stateless_action!(About, WindowActionGroup, "about");
@ -76,6 +77,7 @@ impl SimpleComponent for App {
"Launcher folder" => LauncherFolder,
"Game folder" => GameFolder,
"Config file" => ConfigFile,
"Debug file" => DebugFile,
},
section! {
@ -209,8 +211,36 @@ impl SimpleComponent for App {
set_margin_top: 64,
set_spacing: 8,
// TODO: add tooltips
gtk::Button {
set_label: &tr("launch"),
#[watch]
set_label: &match model.state {
Some(LauncherState::Launch) => tr("launch"),
Some(LauncherState::PredownloadAvailable { .. }) => tr("launch"),
Some(LauncherState::PatchAvailable(_)) => tr("apply-patch"),
Some(LauncherState::WineNotInstalled) => tr("download-wine"),
Some(LauncherState::PrefixNotExists) => tr("create-prefix"),
Some(LauncherState::VoiceUpdateAvailable(_)) => tr("update"),
Some(LauncherState::VoiceOutdated(_)) => tr("update"),
Some(LauncherState::VoiceNotInstalled(_)) => tr("download"),
Some(LauncherState::GameUpdateAvailable(_)) => tr("update"),
Some(LauncherState::GameOutdated(_)) => tr("update"),
Some(LauncherState::GameNotInstalled(_)) => tr("download"),
None => String::from("...")
},
#[watch]
set_sensitive: match model.state {
Some(LauncherState::GameOutdated { .. }) => false,
Some(LauncherState::VoiceOutdated(_)) => false,
Some(_) => true,
None => false
},
set_hexpand: false,
set_width_request: 200,
add_css_class: "suggested-action",
@ -316,6 +346,17 @@ impl SimpleComponent for App {
}
})));
group.add_action::<DebugFile>(&RelmAction::new_stateless(clone!(@strong sender => move |_| {
if let Err(err) = std::process::Command::new("xdg-open").arg(DEBUG_FILE.as_os_str()).spawn() {
sender.input(AppMsg::Toast {
title: tr("debug-file-opening-error"),
description: Some(err.to_string())
});
tracing::error!("Failed to open debug file: {err}");
}
})));
group.add_action::<About>(&RelmAction::new_stateless(move |_| {
about_dialog_broker.send(AboutDialogMsg::Show);
}));