Skip to content

Commit

Permalink
feat: now able to set logo position
Browse files Browse the repository at this point in the history
  • Loading branch information
Tormak9970 committed May 13, 2023
1 parent 0afcd81 commit 0fc0d48
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
31 changes: 29 additions & 2 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod appinfo_vdf_parser;
mod shortcuts_vdf_parser;
mod vdf_reader;

use std::{path::PathBuf, collections::HashMap, fs::{self, File}, io::Write};
use std::{path::PathBuf, collections::HashMap, fs::{self, File, write}, io::Write};

use appinfo_vdf_parser::open_appinfo_vdf;
use serde_json::{Map, Value};
Expand Down Expand Up @@ -291,7 +291,34 @@ async fn save_changes(app_handle: AppHandle, steam_active_user_id: String, curre
}
}

let should_change_shortcuts = check_for_shortcut_changes(&shortcut_icons, &original_shortcut_icons);
let grids_directory: PathBuf = PathBuf::from(steam::get_grids_directory(app_handle.to_owned(), steam_active_user_id.clone()));
for (appid, steam_logo_str_val) in changed_logo_positions.into_iter() {
let steam_logo_str: &str = steam_logo_str_val.as_str().expect("Should have been able to convert steamLogo pos into str.");
let logo_config_path: PathBuf = grids_directory.join(format!("{}.json", appid));

if steam_logo_str == "Remove" {
let remove_res = fs::remove_file(logo_config_path);
if remove_res.is_err() {
let err = remove_res.err().unwrap();
return format!("{{ \"error\": \"{}\"}}", err.to_string());
}
logger::log_to_file(app_handle.to_owned(), format!("Removed logo position config for {}.", appid).as_str(), 0);
} else {
// let config_file = fs::File::create(&logo_config_path).expect("Should have been able to create or truncate logo pos config file.");

let write_res = write(&logo_config_path, steam_logo_str);

if write_res.is_ok() {
logger::log_to_file(app_handle.to_owned(), format!("Wrote logo pos to config for {}.", appid).as_str(), 0);
} else {
logger::log_to_file(app_handle.to_owned(), format!("Failed to write logo pos to config for {}.", appid).as_str(), 2);
let err = write_res.err().unwrap();
return format!("{{ \"error\": \"{}\"}}", err.to_string());
}
}
}

let should_change_shortcuts: bool = check_for_shortcut_changes(&shortcut_icons, &original_shortcut_icons);

if should_change_shortcuts {
logger::log_to_file(app_handle.to_owned(), "Changes to shortcuts detected. Writing shortcuts.vdf...", 0);
Expand Down
2 changes: 1 addition & 1 deletion src/components/core/games/Game.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
$: originalLogoPos = $originalLogoPositions[game.appid]?.logoPosition;
$: steamLogoPos = $steamLogoPositions[game.appid]?.logoPosition;
$: canDiscard = (($currentPlatform == Platforms.STEAM && $appLibraryCache[game.appid]) ? $appLibraryCache[game.appid][$gridType] != $originalAppLibraryCache[game.appid][$gridType] : false)
|| (steamLogoPos ? (steamLogoPos.nHeightPct != originalLogoPos.nHeightPct || steamLogoPos.nWidthPct != originalLogoPos.nWidthPct || steamLogoPos.pinnedPosition != originalLogoPos.pinnedPosition) : false);
|| (steamLogoPos ? (steamLogoPos.nHeightPct != originalLogoPos?.nHeightPct || steamLogoPos.nWidthPct != originalLogoPos?.nWidthPct || steamLogoPos.pinnedPosition != originalLogoPos?.pinnedPosition) : false);
$: hasCustomArt = ($currentPlatform == Platforms.STEAM && $unfilteredLibraryCache[game.appid]) ? $appLibraryCache[game.appid][$gridType] != $unfilteredLibraryCache[game.appid][$gridType] : false;
/**
Expand Down
6 changes: 3 additions & 3 deletions src/lib/controllers/AppController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,10 @@ export class AppController {
const logoPosStrings = {};

for (const [appid, steamLogo] of Object.entries(steamLogoPos)) {
const originalPos = originalLogoPos[appid].logoPosition;
const originalPos = originalLogoPos[appid]?.logoPosition;
const logoPos = steamLogo.logoPosition;

if (logoPos.nHeightPct != originalPos.nHeightPct || logoPos.nWidthPct != originalPos.nWidthPct || logoPos.pinnedPosition != originalPos.pinnedPosition) {
if (logoPos.nHeightPct != originalPos?.nHeightPct || logoPos.nWidthPct != originalPos?.nWidthPct || logoPos.pinnedPosition != originalPos?.pinnedPosition) {
logoPosStrings[appid] = logoPos.pinnedPosition == "REMOVE" ? "REMOVE" : JSON.stringify(steamLogo);
}
}
Expand Down Expand Up @@ -680,7 +680,7 @@ export class AppController {

const currentPos = logoPositions[appId];
logoPositions[appId] = {
nVersion: currentPos.nVersion,
nVersion: currentPos?.nVersion ?? 1,
logoPosition: {
pinnedPosition: pinPosition,
nHeightPct: heightPct,
Expand Down

0 comments on commit 0fc0d48

Please sign in to comment.