user's own doll color scheme in neko

This commit is contained in:
2026-03-09 19:04:53 +08:00
parent d582ea7fe8
commit 02f1119254
4 changed files with 36 additions and 4 deletions

View File

@@ -1,6 +1,6 @@
use crate::{ use crate::{
lock_r, lock_r,
models::app_data::UserData, models::{app_data::UserData, dolls::DollColorSchemeDto},
services::presence_modules::models::ModuleMetadata, services::presence_modules::models::ModuleMetadata,
state::{init_app_data_scoped, AppDataRefreshScope, FDOLL}, state::{init_app_data_scoped, AppDataRefreshScope, FDOLL},
}; };
@@ -26,3 +26,27 @@ pub fn get_modules() -> Result<Vec<ModuleMetadata>, String> {
let guard = lock_r!(FDOLL); let guard = lock_r!(FDOLL);
Ok(guard.modules.metadatas.clone()) Ok(guard.modules.metadatas.clone())
} }
#[tauri::command]
#[specta::specta]
pub fn get_active_doll_color_scheme() -> Result<Option<DollColorSchemeDto>, String> {
let guard = lock_r!(FDOLL);
let active_doll_id = guard
.user_data
.user
.as_ref()
.and_then(|u| u.active_doll_id.as_deref());
match active_doll_id {
Some(active_doll_id) => {
let color_scheme = guard
.user_data
.dolls
.as_ref()
.and_then(|dolls| dolls.iter().find(|d| d.id == active_doll_id))
.map(|d| d.configuration.color_scheme.clone());
Ok(color_scheme)
}
None => Ok(None),
}
}

View File

@@ -6,7 +6,7 @@ use crate::{
}, },
}; };
use commands::app::{quit_app, restart_app, retry_connection}; use commands::app::{quit_app, restart_app, retry_connection};
use commands::app_state::{get_app_data, refresh_app_data}; use commands::app_state::{get_app_data, get_active_doll_color_scheme, refresh_app_data};
use commands::auth::{change_password, login, logout_and_restart, register, reset_password}; use commands::auth::{change_password, login, logout_and_restart, register, reset_password};
use commands::config::{get_client_config, open_client_config_manager, save_client_config}; use commands::config::{get_client_config, open_client_config_manager, save_client_config};
use commands::dolls::{ use commands::dolls::{
@@ -65,6 +65,7 @@ pub fn run() {
.error_handling(ErrorHandlingMode::Throw) .error_handling(ErrorHandlingMode::Throw)
.commands(collect_commands![ .commands(collect_commands![
get_app_data, get_app_data,
get_active_doll_color_scheme,
refresh_app_data, refresh_app_data,
list_friends, list_friends,
search_users, search_users,

View File

@@ -8,6 +8,9 @@ export const commands = {
async getAppData() : Promise<UserData> { async getAppData() : Promise<UserData> {
return await TAURI_INVOKE("get_app_data"); return await TAURI_INVOKE("get_app_data");
}, },
async getActiveDollColorScheme() : Promise<DollColorSchemeDto | null> {
return await TAURI_INVOKE("get_active_doll_color_scheme");
},
async refreshAppData() : Promise<UserData> { async refreshAppData() : Promise<UserData> {
return await TAURI_INVOKE("refresh_app_data"); return await TAURI_INVOKE("refresh_app_data");
}, },

View File

@@ -15,10 +15,14 @@
let spriteUrl = $state(""); let spriteUrl = $state("");
$effect(() => { $effect(() => {
getSpriteSheetUrl().then((url) => { $appData;
if (!$appData) return;
commands.getActiveDollColorScheme().then((colorScheme) => {
getSpriteSheetUrl(colorScheme ?? undefined).then((url) => {
spriteUrl = url; spriteUrl = url;
}); });
}); });
});
</script> </script>
<div class="w-svw h-svh p-4 relative overflow-hidden"> <div class="w-svw h-svh p-4 relative overflow-hidden">