Skip to content

Commit

Permalink
Add utility to help format the code (#247)
Browse files Browse the repository at this point in the history
Signed-off-by: Aisuko <[email protected]>
  • Loading branch information
Aisuko authored Oct 11, 2022
1 parent fac5880 commit 40c55e5
Show file tree
Hide file tree
Showing 39 changed files with 414 additions and 420 deletions.
9 changes: 9 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ If you want to revert back to the original name, just clear the name and click r

### How can I help/contribute?
If you are a coder, you are very welcome! You can fork this repo and then create a pull request.

To check formats and errors of code before run the code:

```shell
cargo fmt

cargo check
```

To run BoilR just write:

```shell
Expand Down
38 changes: 19 additions & 19 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,39 +52,39 @@ pub fn get_boilr_links_path() -> PathBuf {
get_config_folder().join("links")
}


#[cfg(test)]
mod tests{
mod tests {
use std::path::PathBuf;

use super::get_config_folder;

#[test]

#[cfg(target_family = "unix")]
fn check_return_xdg_config_path(){

fn check_return_xdg_config_path() {
// Parameters for set environment 'XDG_CONFIG_HOME'
std::env::set_var("XDG_CONFIG_HOME", std::env::var("HOME").unwrap()+"/.config/boilr");
std::env::set_var(
"XDG_CONFIG_HOME",
std::env::var("HOME").unwrap() + "/.config/boilr",
);

let xdg_config_home=std::env::var("XDG_CONFIG_HOME").unwrap();
let config_path=get_config_folder();
let test_path=PathBuf::from(xdg_config_home);
let xdg_config_home = std::env::var("XDG_CONFIG_HOME").unwrap();
let config_path = get_config_folder();
let test_path = PathBuf::from(xdg_config_home);

assert_eq!(config_path,test_path);
assert_eq!(config_path, test_path);
}


#[test]

#[cfg(target_family = "unix")]
fn check_return_config_path(){
fn check_return_config_path() {
std::env::set_var(
"XDG_CONFIG_HOME",
std::env::var("HOME").unwrap() + "/.config/boilr",
);

std::env::set_var("XDG_CONFIG_HOME", std::env::var("HOME").unwrap()+"/.config/boilr");

let config_path=get_config_folder();
let current_path=std::env::var("HOME").unwrap()+"/.config/boilr";
let config_path = get_config_folder();
let current_path = std::env::var("HOME").unwrap() + "/.config/boilr";

assert_eq!(config_path,PathBuf::from(current_path));
assert_eq!(config_path, PathBuf::from(current_path));
}
}
}
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod ui;

use color_eyre::eyre::Result;

fn main() -> Result<()>{
fn main() -> Result<()> {
color_eyre::install()?;
ensure_config_folder();
migration::migrate_config();
Expand Down
2 changes: 1 addition & 1 deletion src/migration.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::path::Path;

use crate::{settings::save_settings, platforms::get_platforms};
use crate::{platforms::get_platforms, settings::save_settings};

pub fn migrate_config() {
let version = &crate::settings::Settings::new()
Expand Down
30 changes: 16 additions & 14 deletions src/platforms/amazon/amazon_platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ use sqlite::State;
use std::path::{Path, PathBuf};
use steam_shortcuts_util::{shortcut::ShortcutOwned, Shortcut};

use crate::platforms::{to_shortcuts_simple, ShortcutToImport, FromSettingsString, load_settings, GamesPlatform};
use crate::platforms::{
load_settings, to_shortcuts_simple, FromSettingsString, GamesPlatform, ShortcutToImport,
};

#[derive(Clone)]
pub struct AmazonPlatform {
pub settings: AmazonSettings,
}


impl FromSettingsString for AmazonPlatform{
fn from_settings_string<S:AsRef<str>>(s:S) -> Self {
AmazonPlatform { settings: load_settings(s) }
impl FromSettingsString for AmazonPlatform {
fn from_settings_string<S: AsRef<str>>(s: S) -> Self {
AmazonPlatform {
settings: load_settings(s),
}
}
}

Expand Down Expand Up @@ -51,26 +54,24 @@ fn get_launcher_path() -> eyre::Result<PathBuf> {
}
}

impl GamesPlatform for AmazonPlatform{
impl GamesPlatform for AmazonPlatform {
fn name(&self) -> &str {
"Amazon"
}


fn enabled(&self) -> bool {
self.settings.enabled
}

fn get_shortcut_info(&self) -> eyre::Result<Vec<ShortcutToImport>> {
to_shortcuts_simple(self.get_amazon_games())

}

fn render_ui(&mut self, ui: &mut egui::Ui) {
ui.heading("Amazon");
ui.checkbox(&mut self.settings.enabled, "Import from Amazon");
}

fn get_settings_serilizable(&self) -> String {
toml::to_string(&self.settings).unwrap_or_default()
}
Expand All @@ -80,9 +81,7 @@ impl GamesPlatform for AmazonPlatform{
}
}


impl AmazonPlatform {

fn get_amazon_games(&self) -> eyre::Result<Vec<AmazonGame>> {
let sqllite_path = get_sqlite_path()?;
let launcher_path = get_launcher_path()?;
Expand Down Expand Up @@ -141,14 +140,17 @@ pub struct AmazonSettings {
pub launcher_location: Option<String>,
}

impl Default for AmazonSettings{
impl Default for AmazonSettings {
fn default() -> Self {
#[cfg(target_family = "unix")]
let enabled = false;

#[cfg(not(target_family = "unix"))]
let enabled = true;

Self { enabled, launcher_location: Default::default() }
Self {
enabled,
launcher_location: Default::default(),
}
}
}
}
2 changes: 1 addition & 1 deletion src/platforms/amazon/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mod amazon_platform;

pub use amazon_platform::AmazonGame;
pub use amazon_platform::AmazonPlatform;
pub use amazon_platform::AmazonGame;
19 changes: 11 additions & 8 deletions src/platforms/bottles/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ use serde::{Deserialize, Serialize};

use steam_shortcuts_util::{shortcut::ShortcutOwned, Shortcut};

use crate::platforms::{to_shortcuts_simple, ShortcutToImport, FromSettingsString, load_settings, GamesPlatform};
use crate::platforms::{
load_settings, to_shortcuts_simple, FromSettingsString, GamesPlatform, ShortcutToImport,
};

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct BottlesPlatform {
pub settings: BottlesSettings,
}

impl FromSettingsString for BottlesPlatform{
impl FromSettingsString for BottlesPlatform {
fn from_settings_string<S: AsRef<str>>(s: S) -> Self {
BottlesPlatform { settings: load_settings(s) }
BottlesPlatform {
settings: load_settings(s),
}
}
}

Expand All @@ -29,7 +33,7 @@ pub struct BottlesSettings {
pub enabled: bool,
}

impl Default for BottlesSettings{
impl Default for BottlesSettings {
fn default() -> Self {
#[cfg(target_family = "unix")]
let enabled = true;
Expand Down Expand Up @@ -124,8 +128,7 @@ impl BottlesPlatform {
}
}


impl GamesPlatform for BottlesPlatform{
impl GamesPlatform for BottlesPlatform {
fn name(&self) -> &str {
"Bottles"
}
Expand All @@ -142,12 +145,12 @@ impl GamesPlatform for BottlesPlatform{
ui.heading("Bottles");
ui.checkbox(&mut self.settings.enabled, "Import from Bottles");
}

fn get_settings_serilizable(&self) -> String {
toml::to_string(&self.settings).unwrap_or_default()
}

fn code_name(&self) -> &str {
"bottles"
}
}
}
8 changes: 4 additions & 4 deletions src/platforms/egs/epic_platform.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::platforms::{
load_settings, to_shortcuts, FromSettingsString, NeedsPorton, ShortcutToImport, GamesPlatform,
load_settings, to_shortcuts, FromSettingsString, GamesPlatform, NeedsPorton, ShortcutToImport,
};

use super::{get_egs_manifests, settings::EpicGamesLauncherSettings, ManifestItem};
Expand Down Expand Up @@ -32,7 +32,7 @@ impl NeedsPorton<EpicPlatform> for ManifestItem {
}
}

impl GamesPlatform for EpicPlatform{
impl GamesPlatform for EpicPlatform {
fn name(&self) -> &str {
"Epic"
}
Expand All @@ -52,8 +52,8 @@ impl GamesPlatform for EpicPlatform{
fn render_ui(&mut self, ui: &mut egui::Ui) {
self.render_epic_settings(ui)
}

fn get_settings_serilizable(&self) -> String {
toml::to_string(&self.settings).unwrap_or_default()
}
}
}
3 changes: 1 addition & 2 deletions src/platforms/egs/get_manifests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub(crate) fn get_egs_manifests(
}
}
}
let mut manifests :Vec<ManifestItem> = all_manifests
let mut manifests: Vec<ManifestItem> = all_manifests
.filter(is_game_installed)
.filter(is_game_launchable)
.collect();
Expand Down Expand Up @@ -71,7 +71,6 @@ pub(crate) fn get_egs_manifests(
}
}


fn is_game_installed(manifest: &ManifestItem) -> bool {
Path::new(manifest.manifest_location.as_str()).exists()
}
Expand Down
5 changes: 2 additions & 3 deletions src/platforms/egs/manifest_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ fn launcher_shortcut(manifest: ManifestItem) -> ShortcutOwned {
.to_owned()
}


impl From<ManifestItem> for ShortcutOwned {
fn from(manifest: ManifestItem) -> Self {
let mut owned_shortcut = if manifest.needs_launcher() {
Expand Down Expand Up @@ -163,8 +162,8 @@ impl ManifestItem {
self.catalog_namespace, self.catalog_item_id, self.app_name
)
}
pub fn dedupe_key(&self)-> String {

pub fn dedupe_key(&self) -> String {
format!(
"{}-{}-{}",
self.install_location, self.launch_executable, self.is_managed
Expand Down
3 changes: 1 addition & 2 deletions src/platforms/egs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
mod epic_platform;
mod epic_ui;
mod get_manifests;
mod manifest_item;
mod paths;
mod settings;
mod epic_ui;

pub use epic_platform::*;
use get_manifests::get_egs_manifests;
pub(crate) use manifest_item::*;
use paths::*;

19 changes: 9 additions & 10 deletions src/platforms/flatpak/platform.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use serde::{Deserialize, Serialize};

use crate::platforms::{NeedsPorton, to_shortcuts, ShortcutToImport, GamesPlatform, FromSettingsString, load_settings};
use crate::platforms::{
load_settings, to_shortcuts, FromSettingsString, GamesPlatform, NeedsPorton, ShortcutToImport,
};

use super::FlatpakSettings;
use steam_shortcuts_util::{shortcut::ShortcutOwned, Shortcut};
Expand All @@ -23,7 +25,7 @@ impl From<FlatpakApp> for ShortcutOwned {
}
}

impl NeedsPorton<FlatpakPlatform> for FlatpakApp{
impl NeedsPorton<FlatpakPlatform> for FlatpakApp {
fn needs_proton(&self, _platform: &FlatpakPlatform) -> bool {
false
}
Expand All @@ -34,7 +36,6 @@ impl NeedsPorton<FlatpakPlatform> for FlatpakApp{
}

impl FlatpakPlatform {

fn get_flatpak_apps(&self) -> eyre::Result<Vec<FlatpakApp>> {
use std::process::Command;
let mut command = Command::new("flatpak");
Expand All @@ -60,20 +61,18 @@ impl FlatpakPlatform {
}
}


impl FromSettingsString for FlatpakPlatform{
impl FromSettingsString for FlatpakPlatform {
fn from_settings_string<S: AsRef<str>>(s: S) -> Self {
FlatpakPlatform {
settings: load_settings(s),
}
}
}
}

impl GamesPlatform for FlatpakPlatform{
impl GamesPlatform for FlatpakPlatform {
fn name(&self) -> &str {
"Flatpak"
}


fn enabled(&self) -> bool {
self.settings.enabled
Expand All @@ -87,12 +86,12 @@ impl GamesPlatform for FlatpakPlatform{
ui.heading("Flatpak");
ui.checkbox(&mut self.settings.enabled, "Import from Flatpak");
}

fn get_settings_serilizable(&self) -> String {
toml::to_string(&self.settings).unwrap_or_default()
}

fn code_name(&self) -> &str {
"flatpak"
}
}
}
Loading

0 comments on commit 40c55e5

Please sign in to comment.