mirror of
https://github.com/djibux/BoilR.git
synced 2026-09-01 05:53:41 +02:00
Add feature to disconnect a shortcut (#160)
This commit is contained in:
@@ -0,0 +1 @@
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
mod defines;
|
||||
mod ui_backup;
|
||||
mod ui_disconnect;
|
||||
mod ui_image_download;
|
||||
mod ui_import_games;
|
||||
mod ui_settings;
|
||||
@@ -7,6 +8,7 @@ mod uiapp;
|
||||
|
||||
pub use defines::*;
|
||||
pub use ui_backup::*;
|
||||
pub use ui_disconnect::*;
|
||||
pub use ui_image_download::*;
|
||||
pub use ui_import_games::*;
|
||||
pub use ui_settings::*;
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
use egui::ScrollArea;
|
||||
|
||||
use super::ui_colors::*;
|
||||
use super::MyEguiApp;
|
||||
use crate::steam::get_shortcuts_for_user;
|
||||
use crate::steam::get_shortcuts_paths;
|
||||
use crate::steam::ShortcutInfo;
|
||||
use crate::sync::disconnect_shortcut;
|
||||
use crate::sync::IsBoilRShortcut;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct DiconnectState {
|
||||
pub connected_shortcuts: Option<Result<Vec<ShortcutInfo>, String>>,
|
||||
}
|
||||
|
||||
impl MyEguiApp {
|
||||
pub fn render_disconnect(&mut self, ui: &mut egui::Ui) {
|
||||
let steam_settings = self.settings.steam.clone();
|
||||
let users_info = self
|
||||
.disconect_state
|
||||
.connected_shortcuts
|
||||
.get_or_insert_with(|| {
|
||||
let users = get_shortcuts_paths(&steam_settings)
|
||||
.map_err(|e| format!("Getting shortcut paths failed: {e}"));
|
||||
users.map(|users| {
|
||||
let mut user_info = vec![];
|
||||
for user in users {
|
||||
let shortcut_info = get_shortcuts_for_user(&user);
|
||||
user_info.push(shortcut_info);
|
||||
}
|
||||
user_info
|
||||
})
|
||||
});
|
||||
|
||||
ui.heading("Add a disconnected Shortcuts");
|
||||
ui.label("In this section you can add a shortcut that BoilR is not in control of.");
|
||||
ui.label("This prevents BoilR from deleting or updating a shortcut it orignally added.");
|
||||
ui.label(
|
||||
"This is useful if you want to manully edit a shortcut after BoilR has imported it.",
|
||||
);
|
||||
|
||||
ui.add_space(super::SECTION_SPACING);
|
||||
|
||||
match users_info.as_mut() {
|
||||
Ok(users) => {
|
||||
let has_multiple_users = users.len() > 1;
|
||||
let mut redraw = 0;
|
||||
set_scroll_style(ui);
|
||||
ScrollArea::vertical()
|
||||
.stick_to_right()
|
||||
.auto_shrink([false, true])
|
||||
.show(ui, |ui| {
|
||||
ui.reset_style();
|
||||
|
||||
for user in users.iter_mut() {
|
||||
if has_multiple_users {
|
||||
ui.heading(&user.path.to_string_lossy().to_string());
|
||||
}
|
||||
for shortcut in user.shortcuts.iter() {
|
||||
if shortcut.is_boilr_shortcut()
|
||||
&& ui.button(&shortcut.app_name).clicked()
|
||||
{
|
||||
if disconnect_shortcut(&self.settings, shortcut.app_id).is_ok()
|
||||
{
|
||||
redraw = shortcut.app_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
if redraw != 0 {
|
||||
self.disconect_state.connected_shortcuts = None;
|
||||
self.settings.blacklisted_games.push(redraw);
|
||||
}
|
||||
}
|
||||
Err(msg) => {
|
||||
ui.label(&*msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn set_scroll_style(ui: &mut egui::Ui) {
|
||||
let mut scroll_style = ui.style_mut();
|
||||
scroll_style.visuals.extreme_bg_color = BACKGROUND_COLOR;
|
||||
scroll_style.visuals.widgets.inactive.bg_fill = EXTRA_BACKGROUND_COLOR;
|
||||
scroll_style.visuals.widgets.active.bg_fill = EXTRA_BACKGROUND_COLOR;
|
||||
scroll_style.visuals.widgets.hovered.bg_fill = EXTRA_BACKGROUND_COLOR;
|
||||
}
|
||||
@@ -149,13 +149,12 @@ impl MyEguiApp {
|
||||
return value;
|
||||
}
|
||||
} else if let Some(image_type) = state.image_type_selected.as_ref() {
|
||||
if let Some(action) = self.render_possible_images(ui, image_type, state) {
|
||||
return action;
|
||||
}
|
||||
} else if let Some(action) = render_shortcut_images(ui, state) {
|
||||
if let Some(action) = self.render_possible_images(ui, image_type, state) {
|
||||
return action;
|
||||
}
|
||||
} else if let Some(action) = render_shortcut_images(ui, state) {
|
||||
return action;
|
||||
}
|
||||
|
||||
} else {
|
||||
let is_shortcut = state.game_mode.is_shortcuts();
|
||||
if ui
|
||||
@@ -176,9 +175,8 @@ impl MyEguiApp {
|
||||
return action;
|
||||
}
|
||||
} else if let Some(action) = render_steam_game_select(ui, state) {
|
||||
return action;
|
||||
return action;
|
||||
}
|
||||
|
||||
}
|
||||
UserAction::NoAction
|
||||
}
|
||||
@@ -660,13 +658,10 @@ fn render_shortcut_images(ui: &mut egui::Ui, state: &ImageSelectState) -> Option
|
||||
for image_type in ImageType::all() {
|
||||
ui.label(image_type.name());
|
||||
let (_path, key) = shortcut.key(image_type, Path::new(&user_path));
|
||||
let texture = state
|
||||
.image_handles
|
||||
.get(&key)
|
||||
.and_then(|k| match k.value() {
|
||||
TextureState::Loaded(texture) => Some(texture.clone()),
|
||||
_ => None,
|
||||
});
|
||||
let texture = state.image_handles.get(&key).and_then(|k| match k.value() {
|
||||
TextureState::Loaded(texture) => Some(texture.clone()),
|
||||
_ => None,
|
||||
});
|
||||
let clicked = render_thumbnail(ui, texture);
|
||||
if clicked {
|
||||
return Some(UserAction::ImageTypeSelected(*image_type));
|
||||
|
||||
@@ -9,7 +9,7 @@ use crate::sync;
|
||||
|
||||
use crate::sync::{download_images, SyncProgress};
|
||||
|
||||
use super::{ImageSelectState, backup_shortcuts};
|
||||
use super::{backup_shortcuts, ImageSelectState};
|
||||
use super::{
|
||||
ui_colors::{BACKGROUND_COLOR, EXTRA_BACKGROUND_COLOR},
|
||||
MyEguiApp,
|
||||
@@ -42,9 +42,6 @@ impl<T> FetcStatus<T> {
|
||||
}
|
||||
|
||||
impl MyEguiApp {
|
||||
|
||||
|
||||
|
||||
pub(crate) fn render_import_games(&mut self, ui: &mut egui::Ui) {
|
||||
ui.heading("Import Games");
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ use super::{
|
||||
ui_colors::{BACKGROUND_COLOR, EXTRA_BACKGROUND_COLOR},
|
||||
MyEguiApp,
|
||||
};
|
||||
const SECTION_SPACING: f32 = 25.0;
|
||||
pub const SECTION_SPACING: f32 = 25.0;
|
||||
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
impl MyEguiApp {
|
||||
@@ -49,6 +49,9 @@ impl MyEguiApp {
|
||||
{
|
||||
self.render_amazon_settings(ui);
|
||||
}
|
||||
|
||||
self.render_disconnect(ui);
|
||||
|
||||
ui.add_space(SECTION_SPACING);
|
||||
ui.label(format!("Version: {}", VERSION));
|
||||
});
|
||||
|
||||
+12
-1
@@ -17,7 +17,7 @@ use super::{
|
||||
},
|
||||
ui_images::{get_import_image, get_logo, get_logo_icon},
|
||||
ui_import_games::FetcStatus,
|
||||
BackupState, ImageSelectState,
|
||||
BackupState, DiconnectState, ImageSelectState,
|
||||
};
|
||||
|
||||
const SECTION_SPACING: f32 = 25.0;
|
||||
@@ -39,6 +39,7 @@ pub struct MyEguiApp {
|
||||
pub(crate) heroic_games: Option<Vec<HeroicGame>>,
|
||||
pub(crate) image_selected_state: ImageSelectState,
|
||||
pub(crate) backup_state: BackupState,
|
||||
pub(crate) disconect_state: DiconnectState,
|
||||
}
|
||||
|
||||
impl MyEguiApp {
|
||||
@@ -55,6 +56,7 @@ impl MyEguiApp {
|
||||
heroic_games: None,
|
||||
image_selected_state: ImageSelectState::default(),
|
||||
backup_state: BackupState::default(),
|
||||
disconect_state: DiconnectState::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -65,6 +67,7 @@ enum Menues {
|
||||
Settings,
|
||||
Images,
|
||||
Backup,
|
||||
Disconnect,
|
||||
}
|
||||
|
||||
impl Default for Menues {
|
||||
@@ -106,6 +109,11 @@ impl App for MyEguiApp {
|
||||
.selectable_value(&mut self.selected_menu, Menues::Backup, "Backup")
|
||||
.changed();
|
||||
|
||||
changed = changed
|
||||
|| ui
|
||||
.selectable_value(&mut self.selected_menu, Menues::Disconnect, "Disconnect")
|
||||
.changed();
|
||||
|
||||
if changed {
|
||||
self.backup_state.available_backups = None;
|
||||
}
|
||||
@@ -172,6 +180,9 @@ impl App for MyEguiApp {
|
||||
Menues::Backup => {
|
||||
self.render_backup(ui);
|
||||
}
|
||||
Menues::Disconnect => {
|
||||
self.render_disconnect(ui);
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user