include full appmetadata object in user status broadcasts
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
use crate::services::active_app::AppMetadata;
|
||||
use crate::services::ws::UserStatusPayload;
|
||||
use crate::services::ws::report_user_status;
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn send_user_status_cmd(active_app: String, state: String) -> Result<(), String> {
|
||||
let payload = UserStatusPayload { active_app, state };
|
||||
pub async fn send_user_status_cmd(app_metadata: AppMetadata, state: String) -> Result<(), String> {
|
||||
let payload = UserStatusPayload { app_metadata, state };
|
||||
report_user_status(payload).await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ pub static ACTIVE_APP_CHANGED: &str = "active-app-changed";
|
||||
/// Used for app to emit user foreground app to peers.
|
||||
pub fn init_foreground_app_change_listener() {
|
||||
let app_handle = get_app_handle();
|
||||
listen_for_active_app_changes(|app_names: AppMetadata| {
|
||||
listen_for_active_app_changes(|app_metadata: AppMetadata| {
|
||||
{
|
||||
let guard = lock_r!(FDOLL);
|
||||
if guard
|
||||
@@ -62,15 +62,17 @@ pub fn init_foreground_app_change_listener() {
|
||||
.map(|c| c.is_ws_initialized)
|
||||
.unwrap_or(false)
|
||||
{
|
||||
let active_app_value = app_names
|
||||
// Check if app metadata has valid data
|
||||
let has_valid_name = app_metadata
|
||||
.localized
|
||||
.as_ref()
|
||||
.or(app_names.unlocalized.as_ref())
|
||||
.unwrap_or(&String::new())
|
||||
.clone();
|
||||
if !active_app_value.trim().is_empty() {
|
||||
.or(app_metadata.unlocalized.as_ref())
|
||||
.map(|s| !s.trim().is_empty())
|
||||
.unwrap_or(false);
|
||||
|
||||
if has_valid_name {
|
||||
let payload = crate::services::ws::UserStatusPayload {
|
||||
active_app: active_app_value,
|
||||
app_metadata: app_metadata.clone(),
|
||||
state: "idle".to_string(),
|
||||
};
|
||||
tauri::async_runtime::spawn(async move {
|
||||
@@ -79,7 +81,7 @@ pub fn init_foreground_app_change_listener() {
|
||||
}
|
||||
}
|
||||
};
|
||||
if let Err(e) = app_handle.emit(ACTIVE_APP_CHANGED, app_names) {
|
||||
if let Err(e) = app_handle.emit(ACTIVE_APP_CHANGED, app_metadata) {
|
||||
error!("Failed to emit active app changed event: {}", e);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -7,13 +7,14 @@ use tokio::time::Duration;
|
||||
use tracing::error;
|
||||
|
||||
use crate::{init::lifecycle::handle_disasterous_failure, lock_r, state::FDOLL};
|
||||
use crate::services::active_app::AppMetadata;
|
||||
|
||||
use super::WS_EVENT;
|
||||
|
||||
#[derive(Clone, serde::Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct UserStatusPayload {
|
||||
pub active_app: String,
|
||||
pub app_metadata: AppMetadata,
|
||||
pub state: String,
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { listen, type UnlistenFn } from "@tauri-apps/api/event";
|
||||
import { writable } from "svelte/store";
|
||||
import type { AppMetadata } from "../types/bindings/AppMetadata";
|
||||
|
||||
export type FriendUserStatus = {
|
||||
activeApp: string;
|
||||
appMetadata: AppMetadata;
|
||||
state: "idle" | "resting";
|
||||
};
|
||||
|
||||
@@ -31,13 +32,20 @@ export async function initUserStatusListeners() {
|
||||
const status = payload?.status as FriendUserStatus | undefined;
|
||||
|
||||
if (!userId || !status) return;
|
||||
if (typeof status.activeApp !== "string" || status.activeApp.trim() === "") return;
|
||||
if (!status.appMetadata) return;
|
||||
|
||||
// Validate that appMetadata has at least one valid name
|
||||
const hasValidName =
|
||||
(typeof status.appMetadata.localized === "string" && status.appMetadata.localized.trim() !== "") ||
|
||||
(typeof status.appMetadata.unlocalized === "string" && status.appMetadata.unlocalized.trim() !== "");
|
||||
if (!hasValidName) return;
|
||||
|
||||
if (status.state !== "idle" && status.state !== "resting") return;
|
||||
|
||||
friendsUserStatuses.update((current) => ({
|
||||
...current,
|
||||
[userId]: {
|
||||
activeApp: status.activeApp,
|
||||
appMetadata: status.appMetadata,
|
||||
state: status.state,
|
||||
},
|
||||
}));
|
||||
|
||||
@@ -106,8 +106,17 @@
|
||||
)})
|
||||
</span>
|
||||
{#if status}
|
||||
<span>
|
||||
{status.state} in {status.activeApp}
|
||||
<span class="flex items-center gap-1">
|
||||
{status.state} in
|
||||
{#if status.appMetadata.appIconB64}
|
||||
<img
|
||||
src={`data:image/png;base64,${status.appMetadata.appIconB64}`}
|
||||
alt="Friend's active app icon"
|
||||
class="size-4"
|
||||
/>
|
||||
{/if}
|
||||
{status.appMetadata.localized ||
|
||||
status.appMetadata.unlocalized}
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user