Skip to content

Commit

Permalink
Potentially address the problem in #144
Browse files Browse the repository at this point in the history
  • Loading branch information
p0ryae committed Apr 19, 2024
1 parent aaff68e commit 86469c4
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 54 deletions.
4 changes: 2 additions & 2 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ strip = true
[features]
# by default Tauri runs in production mode
# when `tauri dev` runs it is executed with `cargo run --no-default-features` if `devPath` is an URL
default = [ "custom-protocol" ]
default = ["custom-protocol"]
# this feature is used used for production builds where `devPath` points to the filesystem
# DO NOT remove this
custom-protocol = [ "tauri/custom-protocol" ]
custom-protocol = ["tauri/custom-protocol"]
4 changes: 2 additions & 2 deletions src-tauri/src/addons/spotify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ const CUSTOM_ENGINE: engine::GeneralPurpose =
#[actix_web::main]
pub async fn main() -> std::io::Result<()> {
unsafe {
// SPOTIFY_CLIENT_ID = "".to_string();
// SPOTIFY_CLIENT_SECRET = "".to_string();
// SPOTIFY_CLIENT_ID = String::new();
// SPOTIFY_CLIENT_SECRET = String::new();

if SPOTIFY_CLIENT_ID.is_empty() || SPOTIFY_CLIENT_SECRET.is_empty() {
let spotify_client_id = option_env!("SPOTIFY_CLIENT_ID");
Expand Down
10 changes: 5 additions & 5 deletions src-tauri/src/launchers/custom_games.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ pub async fn get_installed_games() -> Vec<GameObject> {
#[tauri::command]
pub async fn add_custom_game(location: String, display_name: String) {
let mut obj: GameData = GameData {
banner_path: "".to_string(),
executable: "".to_string(),
location: "".to_string(),
banner_path: String::new(),
executable: String::new(),
location: String::new(),
display_name: display_name,
game_id: "CustomGame".to_string(),
launch_id: "".to_string(),
launch_id: String::new(),
size: 0,
launch_command: "".to_string(),
launch_command: String::new(),
launcher_name: "CustomGame".to_string(),
args: vec![],
lastlaunch: 0,
Expand Down
4 changes: 2 additions & 2 deletions src-tauri/src/launchers/gog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ pub async fn get_installed_games() -> Vec<GameObject> {
let img_data: ImageData = serde_json::from_str(&game_data.banner).unwrap();
gameobjects.push(GameObject::new(
banners::get_banner(&game_data.title, &(product_id.to_string()), "GOG", &img_data.icon).await,
"".to_string(),
String::new(),
game.installation_path.to_string(),
game_data.title.to_string(),
product_id.to_string(),
format!("\"{}\"", launcher_location) + " /command=runGame" + &format!(" /gameId={}", game.product_id) + &format!(" /path=\"{}\"", game.installation_path),
0,
"".to_string(),
String::new(),
"GOG".to_string(),
vec![],
));
Expand Down
6 changes: 3 additions & 3 deletions src-tauri/src/launchers/minecraft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async fn get_minecraft_launcher() -> Option<GameObject> {
"Minecraft".to_string(),
"0".to_string(),
0,
"".to_string(),
String::new(),
"Minecraft".to_string(),
args,
));
Expand Down Expand Up @@ -114,7 +114,7 @@ async fn get_minecraft_launcher() -> Option<GameObject> {
"Minecraft".to_string(),
"0".to_string(),
0,
"".to_string(),
String::new(),
"Minecraft".to_string(),
vec![],
));
Expand Down Expand Up @@ -151,7 +151,7 @@ async fn get_minecraft_launcher() -> Option<GameObject> {
"Minecraft".to_string(),
"0".to_string(),
0,
"".to_string(),
String::new(),
"Minecraft".to_string(),
vec![],
));
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/launchers/riot_games.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub async fn parse_game_object(path: &str, game: &str) -> GameObject {
game.to_string(),
0.to_string(),
0,
"".to_string(),
String::new(),
"RiotGames".to_string(),
args,
);
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/launchers/rockstar_games.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ async fn parse_game_object(path: &str, name: &str) -> Option<GameObject> {
format!("{}-{}", game.title_id, game.ros_title_id),
"0".to_string(),
0,
"".to_string(),
String::new(),
"RockstarGames".to_string(),
vec![],
));
Expand Down
14 changes: 7 additions & 7 deletions src-tauri/src/launchers/steam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,41 +131,41 @@ pub async fn get_installed_games() -> Vec<GameObject> {
#[cfg(target_os = "macos")]
temp_all_games.push(GameObject::new(
banners::get_banner(&game_file_parsed.name, &game_file_parsed.appid, "Steam", "").await,
"".to_string(),
String::new(),
game_file_parsed.installdir.to_string(),
game_file_parsed.name,
game_file_parsed.appid.parse().unwrap(),
"0".to_string(),
game_file_parsed.size_on_disk.parse().unwrap(),
"".to_string(),
String::new(),
"Steam".to_string(),
vec![],
));

#[cfg(target_os = "windows")]
temp_all_games.push(GameObject::new(
banners::get_banner(&game_file_parsed.name, &game_file_parsed.appid, "Steam", "").await,
"".to_string(),
String::new(),
game_file_parsed.launcherpath.to_string(),
game_file_parsed.name,
game_file_parsed.appid.parse().unwrap(),
"0".to_string(),
game_file_parsed.size_on_disk.parse().unwrap(),
"".to_string(),
String::new(),
"Steam".to_string(),
vec![],
));

#[cfg(target_os = "linux")]
temp_all_games.push(GameObject::new(
banners::get_banner(&game_file_parsed.name, &game_file_parsed.appid, "Steam", "").await,
"".to_string(),
"".to_string(),
String::new(),
String::new(),
game_file_parsed.name,
game_file_parsed.appid.parse().unwrap(),
"0".to_string(),
game_file_parsed.size_on_disk.parse().unwrap(),
"".to_string(),
String::new(),
"Steam".to_string(),
vec![],
));
Expand Down
6 changes: 3 additions & 3 deletions src-tauri/src/launchers/uplay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ pub async fn get_installed_games() -> Vec<GameObject> {
if !game_res_loc.is_empty() {
all_games.push(GameObject::new(
banners::get_banner(&y, "", "Uplay", "").await,
"".to_string(),
String::new(),
game_res_loc,
y,
123.to_string(),
"".to_string(),
String::new(),
0,
"".to_string(),
String::new(),
"Uplay".to_string(),
vec![],
));
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/launchers/wine_managers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async fn get_lutris_games() -> Option<Vec<GameObject>> {
game.game_id,
game.launch_id.to_string(),
game.size,
"".to_string(),
String::new(),
"Lutris".to_string(),
vec![],
))
Expand Down
4 changes: 2 additions & 2 deletions src-tauri/src/launchers/xbox_games.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ pub fn parse_game_object(game: XboxGame) -> Option<GameObject> {
location.to_string(),
game.name,
game.package_full_name,
"".to_string(),
String::new(),
0,
"".to_string(),
String::new(),
"XboxGames".to_string(),
vec![],
);
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn main() {
if !window.is_visible().unwrap() {
window.show().unwrap()
}

window.open_devtools();
app.emit_all("single-instance", Payload { args: argv, cwd })
.unwrap();
}))
Expand Down
51 changes: 27 additions & 24 deletions src-tauri/src/modules/banners.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@ use std::{
use reqwest::header::{ACCEPT, CONTENT_TYPE};
use serde::Deserialize;

use crate::{operations::{custom_fs::d_f_exists, misc::sha256}, CONFIG_DIR};
use crate::{
operations::{custom_fs::d_f_exists, misc::sha256},
CONFIG_DIR,
};

pub async fn get_banner(display_name: &str, game_id: &str, launcher_name: &str, url: &str) -> String {
pub async fn get_banner(
display_name: &str,
game_id: &str,
launcher_name: &str,
url: &str,
) -> String {
match launcher_name {
"Steam" => {
return fetch_banner(
Expand Down Expand Up @@ -53,7 +61,7 @@ pub async fn get_banner(display_name: &str, game_id: &str, launcher_name: &str,
if display_name.replace(" ", "_") == "Rockstar_Games_Launcher" {
return fetch_banner(format!("https://cdn.player.one/sites/player.one/files/2019/08/26/rockstar-games.png"), display_name).await;
}
return "".to_string();
return String::new();
}
// "XboxGames" => {
// return fetch_banner(url.to_string(), display_name).await;
Expand All @@ -79,10 +87,7 @@ pub async fn get_banner(display_name: &str, game_id: &str, launcher_name: &str,
}

async fn fetch_banner(url: String, display_name: &str) -> String {
let banners_dir = format!(
"{}/cache/games/banners",
CONFIG_DIR.lock().unwrap()
);
let banners_dir = format!("{}/cache/games/banners", CONFIG_DIR.lock().unwrap());

let dispsha256 = sha256(display_name.replace(" ", "_")).await.unwrap();
let file_path: String = format!("{}/{}.png", banners_dir, dispsha256);
Expand Down Expand Up @@ -110,10 +115,7 @@ struct GameWithinRawg {
}

async fn rawg_fetch_banner(display_name: &str) -> String {
let banners_dir = format!(
"{}/cache/games/banners",
CONFIG_DIR.lock().unwrap()
);
let banners_dir = format!("{}/cache/games/banners", CONFIG_DIR.lock().unwrap());

let dispsha256 = sha256(display_name.replace(" ", "_")).await.unwrap();
let file_path: String = format!("{}/{}.png", banners_dir, dispsha256);
Expand All @@ -132,18 +134,19 @@ async fn rawg_fetch_banner(display_name: &str) -> String {

match response.status() {
reqwest::StatusCode::OK => {
let banner_response = reqwest::get(
&response
.json::<RAWGApi>()
.await
.unwrap()
.results
.get(0)
.unwrap()
.background_image,
)
.await
.unwrap();
let background_image_url =
match response.json::<RAWGApi>().await.unwrap().results.get(0) {
Some(result) => result.background_image.clone(),
None => return String::new(),
};

let banner_response = match reqwest::get(&background_image_url).await {
Ok(response) => response,
Err(err) => {
eprintln!("Error fetching background image: {}", err);
return String::new();
}
};
let mut file = File::create(&file_path).unwrap();

let mut content = Cursor::new(banner_response.bytes().await.unwrap());
Expand All @@ -153,7 +156,7 @@ async fn rawg_fetch_banner(display_name: &str) -> String {
}
_ => {
println!("Something unexpected happened... Trace -> init_reqwest");
return "".to_string();
return String::new();
}
}
}

0 comments on commit 86469c4

Please sign in to comment.