refactor: polish codebase, clean clippy lints, and ensure test suite passes
This commit is contained in:
parent
cea98e9923
commit
a3a3d74fd6
10 changed files with 45 additions and 65 deletions
|
|
@ -69,12 +69,8 @@ fn get_or_compose_head(skin_bytes: &Bytes) -> Option<ImageHandle> {
|
|||
}
|
||||
let src_ptr = skin_bytes.as_ptr() as usize;
|
||||
let cache = AVATAR_HEAD_CACHE.get_or_init(|| Mutex::new(HashMap::new()));
|
||||
{
|
||||
if let Ok(guard) = cache.lock() {
|
||||
if let Some(handle) = guard.get(&src_ptr) {
|
||||
return Some(handle.clone());
|
||||
}
|
||||
}
|
||||
if let Some(handle) = cache.lock().ok().and_then(|g| g.get(&src_ptr).cloned()) {
|
||||
return Some(handle);
|
||||
}
|
||||
|
||||
let composed = compose_head(skin_bytes)?;
|
||||
|
|
|
|||
|
|
@ -461,9 +461,8 @@ fn offline_mode_dialog_body(on_close: impl FnMut() + Clone + 'static) -> impl In
|
|||
let mut close_cb = on_close_btn.clone();
|
||||
spawn(async move {
|
||||
if let Ok(state) = crate::launcher::state() {
|
||||
if let Ok(acc) =
|
||||
state.auth.add_offline_account("Player".to_string()).await
|
||||
{
|
||||
let res = state.auth.add_offline_account("Player".to_string()).await;
|
||||
if let Ok(acc) = res {
|
||||
let _ = state.auth.set_default_account(Some(acc.id)).await;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,8 @@ impl QueryCapability for FetchPlayerProfileQuery {
|
|||
}
|
||||
|
||||
if let Ok(u) = uuid::Uuid::parse_str(uuid_str) {
|
||||
if u.get_version() == Some(uuid::Version::Md5) || u.is_nil() {
|
||||
let is_offline = u.get_version() == Some(uuid::Version::Md5) || u.is_nil();
|
||||
if is_offline {
|
||||
return Ok(PlayerProfileView {
|
||||
uuid: uuid_str.clone(),
|
||||
..Default::default()
|
||||
|
|
|
|||
|
|
@ -117,12 +117,11 @@ pub fn use_player_skin(uuid: String) -> (Bytes, bool) {
|
|||
|
||||
let default_slim = (java_string_hash(&uuid) & 1) == 1;
|
||||
|
||||
if let Some(custom) = custom_data {
|
||||
if custom.has_custom {
|
||||
if let Some(bytes) = custom.bytes {
|
||||
return (bytes, custom.is_slim);
|
||||
}
|
||||
}
|
||||
if let Some((bytes, is_slim)) = custom_data
|
||||
.filter(|c| c.has_custom)
|
||||
.and_then(|c| c.bytes.map(|b| (b, c.is_slim)))
|
||||
{
|
||||
return (bytes, is_slim);
|
||||
}
|
||||
|
||||
match crate::hooks::loaded_image(skin_url.as_deref(), &skin_query) {
|
||||
|
|
@ -190,10 +189,8 @@ pub async fn save_account_skin(
|
|||
.await
|
||||
.map_err(|e| format!("Failed to write skin metadata: {e}"))?;
|
||||
|
||||
if let Some(uname) = username {
|
||||
if !uname.is_empty() {
|
||||
let _ = sync_custom_skin_loader(uname, &png_bytes).await;
|
||||
}
|
||||
if let Some(uname) = username.filter(|u| !u.is_empty()) {
|
||||
let _ = sync_custom_skin_loader(uname, &png_bytes).await;
|
||||
}
|
||||
|
||||
invalidate_skin_queries(Some(uuid)).await;
|
||||
|
|
@ -212,10 +209,8 @@ pub async fn delete_account_skin(uuid: &str, username: Option<&str>) -> Result<(
|
|||
let _ = polyio::remove_file(&meta_path).await;
|
||||
}
|
||||
|
||||
if let Some(uname) = username {
|
||||
if !uname.is_empty() {
|
||||
let _ = remove_custom_skin_loader(uname).await;
|
||||
}
|
||||
if let Some(uname) = username.filter(|u| !u.is_empty()) {
|
||||
let _ = remove_custom_skin_loader(uname).await;
|
||||
}
|
||||
|
||||
invalidate_skin_queries(Some(uuid)).await;
|
||||
|
|
|
|||
|
|
@ -40,10 +40,8 @@ impl Component for RootLayout {
|
|||
ctx.windows.get(&id).map(|w| w.window().is_maximized())
|
||||
})
|
||||
.await;
|
||||
if let Ok(Some(is_max)) = is_max {
|
||||
if *maximized.peek() != is_max {
|
||||
maximized.set(is_max);
|
||||
}
|
||||
if let Ok(Some(is_max)) = is_max.map(|opt| opt.filter(|&m| *maximized.peek() != m)) {
|
||||
maximized.set(is_max);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ impl Component for SettingsAccounts {
|
|||
let username = use_state(String::new);
|
||||
let mut show_offline = use_state(|| false);
|
||||
let edit_account = use_state(|| None::<(Uuid, String)>);
|
||||
let edit_name = use_state(|| String::new());
|
||||
let edit_name = use_state(String::new);
|
||||
|
||||
let accounts = try_accounts(&accounts_query).unwrap_or_default();
|
||||
let default_account = try_default_account(&default_query);
|
||||
|
|
@ -123,7 +123,6 @@ impl Component for SettingsAccounts {
|
|||
.maybe_child(edit_account.read().as_ref().map(|(id, _)| {
|
||||
let id = *id;
|
||||
let mut edit_account = edit_account;
|
||||
let edit_name = edit_name;
|
||||
OverlayPopup::new()
|
||||
.on_close(move |()| edit_account.set(None))
|
||||
.child(
|
||||
|
|
|
|||
|
|
@ -73,8 +73,8 @@ impl Component for PreviewPanel {
|
|||
let account_uuid = self.account_uuid.clone();
|
||||
let custom_query = use_custom_skin(account_uuid.clone().unwrap_or_default());
|
||||
let custom_data = crate::hooks::settled_or_loading(&custom_query);
|
||||
let is_slim = custom_data.as_ref().map_or(false, |d| d.is_slim);
|
||||
let has_custom = custom_data.as_ref().map_or(false, |d| d.has_custom);
|
||||
let is_slim = custom_data.as_ref().is_some_and(|d| d.is_slim);
|
||||
let has_custom = custom_data.as_ref().is_some_and(|d| d.has_custom);
|
||||
|
||||
let acc_id_copy = self.account_id;
|
||||
let username_copy = self.username.clone();
|
||||
|
|
|
|||
|
|
@ -57,9 +57,9 @@ impl Component for OnboardingAccount {
|
|||
))
|
||||
.child(if show_entry {
|
||||
let start = msa.clone();
|
||||
let add_offline_click = add_offline.clone();
|
||||
let mut is_editing_save = is_editing.clone();
|
||||
let offline_name_read = offline_name.clone();
|
||||
let add_offline_click = add_offline;
|
||||
let mut is_editing_save = is_editing;
|
||||
let offline_name_read = offline_name;
|
||||
|
||||
rect()
|
||||
.vertical()
|
||||
|
|
@ -81,7 +81,7 @@ impl Component for OnboardingAccount {
|
|||
.spacing(8.)
|
||||
.cross_align(Alignment::Center)
|
||||
.child(
|
||||
TextInput::new(offline_name.clone())
|
||||
TextInput::new(offline_name)
|
||||
.placeholder("Enter username (e.g. Steve)")
|
||||
.width(Size::px(240.)),
|
||||
)
|
||||
|
|
@ -123,7 +123,7 @@ impl Component for OnboardingAccount {
|
|||
}))
|
||||
.into_element()
|
||||
} else {
|
||||
let mut is_editing_toggle = is_editing.clone();
|
||||
let mut is_editing_toggle = is_editing;
|
||||
let account = account.as_ref().unwrap();
|
||||
|
||||
rect()
|
||||
|
|
@ -147,10 +147,10 @@ impl Component for OnboardingAccount {
|
|||
})
|
||||
.into_element();
|
||||
|
||||
let add_offline_nav = add_offline.clone();
|
||||
let offline_name_nav = offline_name.clone();
|
||||
let is_editing_nav = is_editing.clone();
|
||||
let mut is_navigating_nav = is_navigating.clone();
|
||||
let add_offline_nav = add_offline;
|
||||
let offline_name_nav = offline_name;
|
||||
let is_editing_nav = is_editing;
|
||||
let mut is_navigating_nav = is_navigating;
|
||||
let account_clone = account.clone();
|
||||
|
||||
let on_next = move |_| {
|
||||
|
|
|
|||
|
|
@ -98,20 +98,14 @@ impl CredentialsStore {
|
|||
fn insert_offline_account(&mut self, username: String) -> AuthResult<MinecraftAccount> {
|
||||
validate_offline_username(&username)?;
|
||||
|
||||
if self
|
||||
if let Some(existing) = self
|
||||
.users
|
||||
.values()
|
||||
.any(|u| u.username.eq_ignore_ascii_case(&username))
|
||||
.find(|u| u.username.eq_ignore_ascii_case(&username))
|
||||
.cloned()
|
||||
{
|
||||
if let Some(existing) = self
|
||||
.users
|
||||
.values()
|
||||
.find(|u| u.username.eq_ignore_ascii_case(&username))
|
||||
.cloned()
|
||||
{
|
||||
self.default_user = Some(existing.id);
|
||||
return Ok(existing);
|
||||
}
|
||||
self.default_user = Some(existing.id);
|
||||
return Ok(existing);
|
||||
}
|
||||
|
||||
let account = offline_account(username);
|
||||
|
|
|
|||
|
|
@ -789,20 +789,18 @@ async fn inject_skin_resource_pack(game_dir: &Path, uuid: &str, username: &str)
|
|||
}
|
||||
|
||||
// Also sync to shared .minecraft if distinct from game_dir
|
||||
if let Ok(shared) = oneclient_common::paths::shared_minecraft_dir() {
|
||||
if shared != game_dir {
|
||||
let shared_targets = [
|
||||
shared.join("CustomSkinLoader").join("skins").join(format!("{username}.png")),
|
||||
shared.join("CustomSkinLoader").join("skins").join(format!("{uuid}.png")),
|
||||
shared.join("config").join("offlineskins").join(format!("{username}.png")),
|
||||
shared.join("config").join("offlineskins").join(format!("{uuid}.png")),
|
||||
];
|
||||
for target in shared_targets {
|
||||
if let Some(parent) = target.parent() {
|
||||
let _ = polyio::create_dir_all(parent).await;
|
||||
}
|
||||
let _ = polyio::write(&target, &skin_bytes).await;
|
||||
if let Some(shared) = oneclient_common::paths::shared_minecraft_dir().ok().filter(|s| s != game_dir) {
|
||||
let shared_targets = [
|
||||
shared.join("CustomSkinLoader").join("skins").join(format!("{username}.png")),
|
||||
shared.join("CustomSkinLoader").join("skins").join(format!("{uuid}.png")),
|
||||
shared.join("config").join("offlineskins").join(format!("{username}.png")),
|
||||
shared.join("config").join("offlineskins").join(format!("{uuid}.png")),
|
||||
];
|
||||
for target in shared_targets {
|
||||
if let Some(parent) = target.parent() {
|
||||
let _ = polyio::create_dir_all(parent).await;
|
||||
}
|
||||
let _ = polyio::write(&target, &skin_bytes).await;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue