Add utility to help format the code (#247)

Signed-off-by: Aisuko <urakiny@gmail.com>
This commit is contained in:
Aisuko
2022-10-11 06:17:10 +02:00
committed by GitHub
parent fac58803cc
commit 40c55e542d
39 changed files with 415 additions and 421 deletions
+4 -1
View File
@@ -57,7 +57,10 @@ impl MyEguiApp {
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() && disconnect_shortcut(&self.settings, shortcut.app_id).is_ok() {
if shortcut.is_boilr_shortcut()
&& ui.button(&shortcut.app_name).clicked()
&& disconnect_shortcut(&self.settings, shortcut.app_id).is_ok()
{
redraw = shortcut.app_id;
}
}
+49 -51
View File
@@ -13,7 +13,7 @@ use crate::sync;
use crate::sync::{download_images, SyncProgress};
use super::{backup_shortcuts, all_ready, get_all_games};
use super::{all_ready, backup_shortcuts, get_all_games};
use super::{
ui_colors::{BACKGROUND_COLOR, EXTRA_BACKGROUND_COLOR},
MyEguiApp,
@@ -60,7 +60,7 @@ impl MyEguiApp {
FetcStatus::NeedsFetched => {ui.label("Need to find games");},
FetcStatus::Fetching => {
ui.horizontal(|ui|{
ui.spinner();
ui.spinner();
ui.label("Finding installed games");
});
},
@@ -90,31 +90,29 @@ impl MyEguiApp {
}
}
}
} else {
let name = self.rename_map.get(&shortcut.app_id).unwrap_or(&shortcut.app_name);
let checkbox = egui::Checkbox::new(&mut import_game,name);
let response = ui.add(checkbox);
if response.double_clicked(){
self.rename_map.entry(shortcut.app_id).or_insert_with(|| shortcut.app_name.to_owned());
self.current_edit = Option::Some(shortcut.app_id);
}
if response.clicked(){
if !self.settings.blacklisted_games.contains(&shortcut.app_id){
self.settings.blacklisted_games.push(shortcut.app_id);
}else{
self.settings.blacklisted_games.retain(|id| *id != shortcut.app_id);
} else {
let name = self.rename_map.get(&shortcut.app_id).unwrap_or(&shortcut.app_name);
let checkbox = egui::Checkbox::new(&mut import_game,name);
let response = ui.add(checkbox);
if response.double_clicked(){
self.rename_map.entry(shortcut.app_id).or_insert_with(|| shortcut.app_name.to_owned());
self.current_edit = Option::Some(shortcut.app_id);
}
if response.clicked(){
if !self.settings.blacklisted_games.contains(&shortcut.app_id){
self.settings.blacklisted_games.push(shortcut.app_id);
} else {
self.settings.blacklisted_games.retain(|id| *id != shortcut.app_id);
}
}
}
}
});
});
}
},
Err(err) => {
ui.label("Failed finding games").on_hover_text(format!("Error message: {err}"));
},
};
},
}
@@ -125,8 +123,7 @@ impl MyEguiApp {
});
}
pub fn run_sync(&mut self, wait: bool ) {
pub fn run_sync(&mut self, wait: bool) {
let (sender, reciever) = watch::channel(SyncProgress::NotStarted);
let settings = self.settings.clone();
if settings.steam.stop_steam {
@@ -137,25 +134,26 @@ impl MyEguiApp {
self.status_reciever = reciever;
let renames = self.rename_map.clone();
let all_ready= all_ready(&self.games_to_sync);
let all_ready = all_ready(&self.games_to_sync);
let _ = sender.send(SyncProgress::Starting);
if all_ready{
let shortcuts_to_import = get_all_games(&self.games_to_sync);
if all_ready {
let shortcuts_to_import = get_all_games(&self.games_to_sync);
let handle = self.rt.spawn_blocking(move || {
#[cfg(target_family = "unix")]
setup_proton(shortcuts_to_import.iter());
let import_games = to_shortcut_owned(shortcuts_to_import);
let mut some_sender = Some(sender);
backup_shortcuts(&settings.steam);
let usersinfo = sync::sync_shortcuts(&settings, &import_games, &mut some_sender,&renames).unwrap();
let usersinfo =
sync::sync_shortcuts(&settings, &import_games, &mut some_sender, &renames)
.unwrap();
let task = download_images(&settings, &usersinfo, &mut some_sender);
block_on(task);
//Run a second time to fix up shortcuts after images are downloaded
sync::sync_shortcuts(&settings, &import_games, &mut some_sender,&renames).unwrap();
sync::sync_shortcuts(&settings, &import_games, &mut some_sender, &renames).unwrap();
if let Some(sender) = some_sender {
let _ = sender.send(SyncProgress::Done);
}
@@ -168,42 +166,42 @@ impl MyEguiApp {
}
}
}
}
fn to_shortcut_owned(shortcuts_to_import: Vec<(String, Vec<ShortcutToImport>)>) -> Vec<(String, Vec<ShortcutOwned>)> {
fn to_shortcut_owned(
shortcuts_to_import: Vec<(String, Vec<ShortcutToImport>)>,
) -> Vec<(String, Vec<ShortcutOwned>)> {
let mut import_games = vec![];
for(name,infos) in shortcuts_to_import{
for (name, infos) in shortcuts_to_import {
let mut shortcuts = vec![];
for info in infos{
for info in infos {
shortcuts.push(info.shortcut);
}
import_games.push((name,shortcuts));
import_games.push((name, shortcuts));
}
import_games
}
#[cfg(target_family = "unix")]
fn setup_proton<'a, I>(shortcut_infos: I)
where
I: IntoIterator<Item = &'a (String,Vec<ShortcutToImport>)>{
let mut shortcuts_to_proton = vec![];
for (name,shortcuts) in shortcut_infos {
for shortcut_info in shortcuts{
if shortcut_info.needs_proton {
crate::sync::symlinks::ensure_links_folder_created(name);
}
if shortcut_info.needs_proton {
shortcuts_to_proton.push(format!("{}", shortcut_info.shortcut.app_id));
}
I: IntoIterator<Item = &'a (String, Vec<ShortcutToImport>)>,
{
let mut shortcuts_to_proton = vec![];
if shortcut_info.needs_symlinks {
crate::sync::symlinks::create_sym_links(&shortcut_info.shortcut);
for (name, shortcuts) in shortcut_infos {
for shortcut_info in shortcuts {
if shortcut_info.needs_proton {
crate::sync::symlinks::ensure_links_folder_created(name);
}
if shortcut_info.needs_proton {
shortcuts_to_proton.push(format!("{}", shortcut_info.shortcut.app_id));
}
if shortcut_info.needs_symlinks {
crate::sync::symlinks::create_sym_links(&shortcut_info.shortcut);
}
}
setup_proton_games(&shortcuts_to_proton);
}
setup_proton_games(&shortcuts_to_proton);
}
}
+123 -125
View File
@@ -1,125 +1,123 @@
use copypasta::ClipboardProvider;
use eframe::egui;
use egui::ScrollArea;
use super::{
ui_colors::{BACKGROUND_COLOR, EXTRA_BACKGROUND_COLOR},
MyEguiApp,
};
pub const SECTION_SPACING: f32 = 25.0;
const VERSION: &str = env!("CARGO_PKG_VERSION");
impl MyEguiApp {
pub(crate) fn render_settings(&mut self, ui: &mut egui::Ui) {
ui.heading("Settings");
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.selection.bg_fill = EXTRA_BACKGROUND_COLOR;
scroll_style.visuals.widgets.hovered.bg_fill = EXTRA_BACKGROUND_COLOR;
ScrollArea::vertical()
.stick_to_right(true)
.auto_shrink([false, true])
.show(ui, |ui| {
ui.reset_style();
self.render_steamgriddb_settings(ui);
self.render_steam_settings(ui);
for platform in &mut self.platforms{
platform.render_ui(ui);
ui.add_space(SECTION_SPACING);
}
ui.label(format!("Version: {}", VERSION));
});
}
fn render_steam_settings(&mut self, ui: &mut egui::Ui) {
ui.heading("Steam");
ui.horizontal(|ui| {
let mut empty_string = "".to_string();
let steam_location = self
.settings
.steam
.location
.as_mut()
.unwrap_or(&mut empty_string);
ui.label("Steam Location: ");
if ui.text_edit_singleline(steam_location).changed() {
if steam_location.trim().is_empty(){
self.settings.steam.location = None;
}else{
self.settings.steam.location = Some(steam_location.to_string());
}
}
});
ui.checkbox(
&mut self.settings.steam.create_collections,
"Create collections",
)
.on_hover_text("Tries to create a games collection for each platform");
ui.checkbox(&mut self.settings.steam.optimize_for_big_picture, "Optimize for big picture").on_hover_text("Set icons to be larger horizontal images, this looks nice in steam big picture mode, but a bit off in desktop mode");
ui.checkbox(
&mut self.settings.steam.stop_steam,
"Stop Steam before import",
)
.on_hover_text("Stops Steam if it is running when import starts");
ui.checkbox(
&mut self.settings.steam.start_steam,
"Start Steam after import",
)
.on_hover_text("Starts Steam is it is not running after the import");
ui.add_space(SECTION_SPACING);
}
fn render_steamgriddb_settings(&mut self, ui: &mut egui::Ui) {
ui.heading("SteamGridDB");
ui.checkbox(&mut self.settings.steamgrid_db.enabled, "Download images");
if self.settings.steamgrid_db.enabled {
ui.horizontal(|ui| {
let mut auth_key = self
.settings
.steamgrid_db
.auth_key
.clone()
.unwrap_or_default();
ui.label("Authentication key: ");
if ui.text_edit_singleline(&mut auth_key).changed() {
if auth_key.is_empty() {
self.settings.steamgrid_db.auth_key = None;
} else {
self.settings.steamgrid_db.auth_key = Some(auth_key.to_string());
}
}
if auth_key.is_empty() && ui.button("Paste from clipboard").clicked(){
if let Ok(mut clipboard_ctx) = copypasta::ClipboardContext::new() {
if let Ok(content) = clipboard_ctx.get_contents() {
self.settings.steamgrid_db.auth_key = Some(content);
}
}
}
});
ui.horizontal(|ui| {
ui.label(
"To download images you need an API Key from SteamGridDB, you can find yours",
);
ui.hyperlink_to(
"here",
"https://www.steamgriddb.com/profile/preferences/api",
)
});
ui.checkbox(&mut self.settings.steamgrid_db.prefer_animated, "Prefer animated images").on_hover_text("Prefer downloading animated images over static images (this can slow Steam down but looks neat)");
ui.checkbox(
&mut self.settings.steamgrid_db.only_download_boilr_images,
"Only download images for BoilR shortcuts",
);
}
ui.add_space(SECTION_SPACING);
}
}
use copypasta::ClipboardProvider;
use eframe::egui;
use egui::ScrollArea;
use super::{
ui_colors::{BACKGROUND_COLOR, EXTRA_BACKGROUND_COLOR},
MyEguiApp,
};
pub const SECTION_SPACING: f32 = 25.0;
const VERSION: &str = env!("CARGO_PKG_VERSION");
impl MyEguiApp {
pub(crate) fn render_settings(&mut self, ui: &mut egui::Ui) {
ui.heading("Settings");
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.selection.bg_fill = EXTRA_BACKGROUND_COLOR;
scroll_style.visuals.widgets.hovered.bg_fill = EXTRA_BACKGROUND_COLOR;
ScrollArea::vertical()
.stick_to_right(true)
.auto_shrink([false, true])
.show(ui, |ui| {
ui.reset_style();
self.render_steamgriddb_settings(ui);
self.render_steam_settings(ui);
for platform in &mut self.platforms {
platform.render_ui(ui);
ui.add_space(SECTION_SPACING);
}
ui.label(format!("Version: {}", VERSION));
});
}
fn render_steam_settings(&mut self, ui: &mut egui::Ui) {
ui.heading("Steam");
ui.horizontal(|ui| {
let mut empty_string = "".to_string();
let steam_location = self
.settings
.steam
.location
.as_mut()
.unwrap_or(&mut empty_string);
ui.label("Steam Location: ");
if ui.text_edit_singleline(steam_location).changed() {
if steam_location.trim().is_empty() {
self.settings.steam.location = None;
} else {
self.settings.steam.location = Some(steam_location.to_string());
}
}
});
ui.checkbox(
&mut self.settings.steam.create_collections,
"Create collections",
)
.on_hover_text("Tries to create a games collection for each platform");
ui.checkbox(&mut self.settings.steam.optimize_for_big_picture, "Optimize for big picture").on_hover_text("Set icons to be larger horizontal images, this looks nice in steam big picture mode, but a bit off in desktop mode");
ui.checkbox(
&mut self.settings.steam.stop_steam,
"Stop Steam before import",
)
.on_hover_text("Stops Steam if it is running when import starts");
ui.checkbox(
&mut self.settings.steam.start_steam,
"Start Steam after import",
)
.on_hover_text("Starts Steam is it is not running after the import");
ui.add_space(SECTION_SPACING);
}
fn render_steamgriddb_settings(&mut self, ui: &mut egui::Ui) {
ui.heading("SteamGridDB");
ui.checkbox(&mut self.settings.steamgrid_db.enabled, "Download images");
if self.settings.steamgrid_db.enabled {
ui.horizontal(|ui| {
let mut auth_key = self
.settings
.steamgrid_db
.auth_key
.clone()
.unwrap_or_default();
ui.label("Authentication key: ");
if ui.text_edit_singleline(&mut auth_key).changed() {
if auth_key.is_empty() {
self.settings.steamgrid_db.auth_key = None;
} else {
self.settings.steamgrid_db.auth_key = Some(auth_key.to_string());
}
}
if auth_key.is_empty() && ui.button("Paste from clipboard").clicked() {
if let Ok(mut clipboard_ctx) = copypasta::ClipboardContext::new() {
if let Ok(content) = clipboard_ctx.get_contents() {
self.settings.steamgrid_db.auth_key = Some(content);
}
}
}
});
ui.horizontal(|ui| {
ui.label(
"To download images you need an API Key from SteamGridDB, you can find yours",
);
ui.hyperlink_to(
"here",
"https://www.steamgriddb.com/profile/preferences/api",
)
});
ui.checkbox(&mut self.settings.steamgrid_db.prefer_animated, "Prefer animated images").on_hover_text("Prefer downloading animated images over static images (this can slow Steam down but looks neat)");
ui.checkbox(
&mut self.settings.steamgrid_db.only_download_boilr_images,
"Only download images for BoilR shortcuts",
);
}
ui.add_space(SECTION_SPACING);
}
}