Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ tauri-plugin-dialog = "2.1.0"
tauri-plugin-fs = "2.0.1"
tauri-plugin-log = "2"
structstruck = "0.4.1"
tauri-plugin-http = { version = "2", features = ["json", "stream"] }
tauri-plugin-http = { version = "2", features = ["json", "stream", "multipart"] }
tauri-plugin-os = "2"
tokio = { version = "1", features = ["full"] }
tokio-util = { version = "0.7.13", features = ["compat"] }
Expand Down
159 changes: 121 additions & 38 deletions src-tauri/src/account/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ use crate::account::helpers::authlib_injector::info::{
fetch_auth_server_info, fetch_auth_url, get_auth_server_info_by_url,
};
use crate::account::helpers::authlib_injector::jar::check_authlib_jar;
use crate::account::helpers::authlib_injector::texture::AuthlibInjectorTextureOperation;
use crate::account::helpers::authlib_injector::{self};
use crate::account::helpers::microsoft::texture::MicrosoftTextureOperation;
use crate::account::helpers::texture::{load_preset_skin_info, TextureOperation};
use crate::account::helpers::{microsoft, misc, offline};
use crate::account::models::{
AccountError, AccountInfo, AuthServer, DeviceAuthResponseInfo, Player, PlayerInfo, PlayerType,
PresetRole, SkinModel, TextureType,
PresetRole, SkinModel, Texture, TextureType,
};
use crate::error::SJMCLResult;
use crate::launcher_config::models::LauncherConfig;
use crate::storage::Storage;
use crate::utils::fs::get_app_resource_filepath;
use crate::utils::image::{load_image_from_dir, ImageWrapper};
use std::path::Path;
use std::sync::Mutex;
use tauri::{AppHandle, Manager};
Expand All @@ -33,7 +37,7 @@ pub fn retrieve_player_list(app: AppHandle) -> SJMCLResult<Vec<Player>> {

#[tauri::command]
pub async fn add_player_offline(app: AppHandle, username: String, uuid: String) -> SJMCLResult<()> {
let new_player = offline::login(&app, username, uuid).await?;
let new_player = offline::login::login(&app, username, uuid).await?;

let account_binding = app.state::<Mutex<AccountInfo>>();
let mut account_state = account_binding.lock()?;
Expand Down Expand Up @@ -360,70 +364,149 @@ pub async fn add_player_from_selection(app: AppHandle, player: Player) -> SJMCLR
}

#[tauri::command]
pub fn update_player_skin_offline_preset(
pub async fn update_player_texture_preset(
app: AppHandle,
player_id: String,
preset_role: PresetRole,
) -> SJMCLResult<()> {
let account_binding = app.state::<Mutex<AccountInfo>>();
let mut account_state = account_binding.lock()?;

let player = account_state
.get_player_by_id_mut(player_id.clone())
.ok_or(AccountError::NotFound)?;
let player = {
let account_state = account_binding.lock()?;
account_state
.get_player_by_id(player_id.clone())
.ok_or(AccountError::NotFound)?
.clone()
};

if player.player_type != PlayerType::Offline {
return Err(AccountError::Invalid.into());
}
let (skin_path, model) = load_preset_skin_info(&app, preset_role.clone())?;

player.textures = offline::load_preset_skin(&app, preset_role)?;
account_state.save()?;
match player.player_type {
PlayerType::Offline => {}
PlayerType::ThirdParty => {
let _ = AuthlibInjectorTextureOperation::delete_cape(&app, &player).await;
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Silently ignoring cape deletion errors with let _ could hide important issues. Consider logging the error or adding a comment explaining why failures are acceptable in this context.

Copilot uses AI. Check for mistakes.
AuthlibInjectorTextureOperation::upload_skin(&app, &player, &skin_path, model.clone())
.await?;
}
PlayerType::Microsoft => {
let _ = MicrosoftTextureOperation::delete_cape(&app, &player).await;
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Silently ignoring cape deletion errors with let _ could hide important issues. Consider logging the error or adding a comment explaining why failures are acceptable in this context.

Copilot uses AI. Check for mistakes.
MicrosoftTextureOperation::upload_skin(&app, &player, &skin_path, model.clone()).await?;
}
};

{
let mut account_state = account_binding.lock()?;

if let Some(stored_player) = account_state.players.iter_mut().find(|p| p.id == player_id) {
stored_player.textures.clear();
stored_player.textures.push(Texture {
texture_type: TextureType::Skin,
image: load_image_from_dir(&skin_path)
.ok_or(AccountError::TextureFormatIncorrect)?
.into(),
model,
preset: Some(preset_role),
});
account_state.save()?;
}
}
Ok(())
}

#[tauri::command]
pub fn update_player_skin_offline_local(
pub async fn update_player_texture_local(
app: AppHandle,
player_id: String,
image_path: String,
texture_type: TextureType,
skin_model: SkinModel,
) -> SJMCLResult<()> {
let account_binding = app.state::<Mutex<AccountInfo>>();

let player = {
let account_state = account_binding.lock()?;
account_state
.get_player_by_id(player_id.clone())
.ok_or(AccountError::NotFound)?
.clone()
};

let image_path = if image_path == "dummy" {
// this is an Easter Egg :)
get_app_resource_filepath(&app, "assets/skins/dummy.png")
.map_err(|_| AccountError::TextureError)?
.map_err(|_| AccountError::TextureFormatIncorrect)?
} else {
Path::new(&image_path).to_path_buf()
};
let texture_img =
crate::utils::image::load_image_from_dir(&image_path).ok_or(AccountError::TextureError)?;

let account_binding = app.state::<Mutex<AccountInfo>>();
let mut account_state = account_binding.lock()?;
let textures = match player.player_type {
PlayerType::Offline => {
let image: ImageWrapper = load_image_from_dir(&image_path)
.ok_or(AccountError::TextureFormatIncorrect)?
.into();
player
.textures
.iter()
.map(|texture| {
if texture.texture_type == texture_type {
Texture {
texture_type: texture_type.clone(),
image: image.clone(),
model: skin_model.clone(),
preset: None,
}
} else {
texture.clone()
}
})
.collect()
}
PlayerType::ThirdParty => {
AuthlibInjectorTextureOperation::parse_skin(
&app,
&match texture_type {
TextureType::Cape => {
AuthlibInjectorTextureOperation::upload_cape(&app, &player, &image_path).await?
}
TextureType::Skin => {
AuthlibInjectorTextureOperation::upload_skin(
&app,
&player,
&image_path,
skin_model.clone(),
)
.await?
}
},
)
.await?
}
PlayerType::Microsoft => {
MicrosoftTextureOperation::parse_skin(
&app,
&match texture_type {
TextureType::Cape => {
MicrosoftTextureOperation::upload_cape(&app, &player, &image_path).await?
}
TextureType::Skin => {
MicrosoftTextureOperation::upload_skin(&app, &player, &image_path, skin_model.clone())
.await?
}
},
)
.await?
}
};

let player = account_state
.get_player_by_id_mut(player_id.clone())
.ok_or(AccountError::NotFound)?;
{
let mut account_state = account_binding.lock()?;

if player.player_type != PlayerType::Offline {
return Err(AccountError::Invalid.into());
if let Some(stored_player) = account_state.players.iter_mut().find(|p| p.id == player_id) {
stored_player.textures.clear();
stored_player.textures.extend(textures);
account_state.save()?;
}
}

// remove existing texture of the same type
player
.textures
.retain(|texture| texture.texture_type != texture_type);

// add the new texture
player.textures.push(crate::account::models::Texture {
texture_type: texture_type.clone(),
image: texture_img.into(),
model: skin_model.clone(),
preset: None,
});

account_state.save()?;
Ok(())
}

Expand Down
54 changes: 5 additions & 49 deletions src-tauri/src/account/helpers/authlib_injector/common.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
use crate::account::helpers::authlib_injector::models::{MinecraftProfile, TextureInfo};
use crate::account::helpers::authlib_injector::models::MinecraftProfile;
use crate::account::helpers::authlib_injector::texture::AuthlibInjectorTextureOperation;
use crate::account::helpers::authlib_injector::{oauth, password};
use crate::account::helpers::misc::fetch_image;
use crate::account::helpers::offline::load_preset_skin;
use crate::account::models::{
AccountError, AuthServer, PlayerInfo, PlayerType, PresetRole, SkinModel, Texture, TextureType,
};
use crate::account::helpers::texture::TextureOperation;
use crate::account::models::{AccountError, AuthServer, PlayerInfo, PlayerType};
use crate::error::SJMCLResult;
use base64::engine::general_purpose;
use base64::Engine;
use serde_json::json;
use std::str::FromStr;
use strum::IntoEnumIterator;
use tauri::{AppHandle, Manager};
use tauri_plugin_http::reqwest;
use uuid::Uuid;
Expand Down Expand Up @@ -46,44 +40,6 @@ pub async fn parse_profile(
) -> SJMCLResult<PlayerInfo> {
let uuid = Uuid::parse_str(&profile.id).map_err(|_| AccountError::ParseError)?;
let name = profile.name.clone();
let mut textures: Vec<Texture> = vec![];

if let Some(texture_info_base64) = profile
.properties
.as_ref()
.and_then(|props| props.iter().find(|property| property.name == "textures"))
{
let texture_info = general_purpose::STANDARD
.decode(texture_info_base64.value.clone())
.map_err(|_| AccountError::ParseError)?
.into_iter()
.map(|b| b as char)
.collect::<String>();

let texture_info_value: TextureInfo =
serde_json::from_str(&texture_info).map_err(|_| AccountError::ParseError)?;

for texture_type in TextureType::iter() {
if let Some(skin) = texture_info_value.textures.get(&texture_type.to_string()) {
textures.push(Texture {
image: fetch_image(app, skin.url.clone()).await?,
texture_type,
model: skin
.metadata
.as_ref()
.and_then(|metadata| metadata.get("model").cloned())
.map(|model_str| SkinModel::from_str(&model_str).unwrap_or(SkinModel::Default))
.unwrap_or_default(),
preset: None,
});
}
}
}

if textures.is_empty() {
// this player didn't have a texture, use preset Steve skin instead
textures = load_preset_skin(app, PresetRole::Steve)?;
}

Ok(
PlayerInfo {
Expand All @@ -94,7 +50,7 @@ pub async fn parse_profile(
auth_account,
access_token,
refresh_token,
textures,
textures: AuthlibInjectorTextureOperation::parse_skin(app, profile).await?,
auth_server_url,
}
.with_generated_id(),
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/account/helpers/authlib_injector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ pub mod jar;
pub mod models;
pub mod oauth;
pub mod password;
pub mod texture;
Loading
Loading