moved send user request listener to rust side
This commit is contained in:
@@ -6,6 +6,7 @@ use tauri::Emitter;
|
|||||||
use tracing::error;
|
use tracing::error;
|
||||||
|
|
||||||
use crate::get_app_handle;
|
use crate::get_app_handle;
|
||||||
|
use crate::{lock_r, state::FDOLL};
|
||||||
|
|
||||||
const ICON_SIZE: u32 = 64;
|
const ICON_SIZE: u32 = 64;
|
||||||
const ICON_CACHE_LIMIT: usize = 50;
|
const ICON_CACHE_LIMIT: usize = 50;
|
||||||
@@ -762,8 +763,34 @@ pub static ACTIVE_APP_CHANGED: &str = "active-app-changed";
|
|||||||
pub fn init_foreground_app_change_listener() {
|
pub fn init_foreground_app_change_listener() {
|
||||||
let app_handle = get_app_handle();
|
let app_handle = get_app_handle();
|
||||||
listen_for_active_app_changes(|app_names: AppMetadata| {
|
listen_for_active_app_changes(|app_names: AppMetadata| {
|
||||||
if let Err(e) = app_handle.emit(ACTIVE_APP_CHANGED, app_names) {
|
{
|
||||||
error!("Failed to emit active app changed event: {}", e);
|
let guard = lock_r!(FDOLL);
|
||||||
}
|
if guard
|
||||||
|
.network
|
||||||
|
.clients
|
||||||
|
.as_ref()
|
||||||
|
.map(|c| c.is_ws_initialized)
|
||||||
|
.unwrap_or(false)
|
||||||
|
{
|
||||||
|
let active_app_value = app_names
|
||||||
|
.localized
|
||||||
|
.as_ref()
|
||||||
|
.or(app_names.unlocalized.as_ref())
|
||||||
|
.unwrap_or(&String::new())
|
||||||
|
.clone();
|
||||||
|
if !active_app_value.trim().is_empty() {
|
||||||
|
let payload = crate::services::ws::UserStatusPayload {
|
||||||
|
active_app: active_app_value,
|
||||||
|
state: "idle".to_string(),
|
||||||
|
};
|
||||||
|
tauri::async_runtime::spawn(async move {
|
||||||
|
crate::services::ws::report_user_status(payload).await;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if let Err(e) = app_handle.emit(ACTIVE_APP_CHANGED, app_names) {
|
||||||
|
error!("Failed to emit active app changed event: {}", e);
|
||||||
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
import Friends from "./tabs/friends.svelte";
|
import Friends from "./tabs/friends.svelte";
|
||||||
import Preferences from "./tabs/preferences.svelte";
|
import Preferences from "./tabs/preferences.svelte";
|
||||||
import YourDolls from "./tabs/your-dolls/index.svelte";
|
import YourDolls from "./tabs/your-dolls/index.svelte";
|
||||||
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
|
|
||||||
import { listen } from "@tauri-apps/api/event";
|
import { listen } from "@tauri-apps/api/event";
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
|
|
||||||
|
|||||||
@@ -7,9 +7,7 @@
|
|||||||
import { appData } from "../../events/app-data";
|
import { appData } from "../../events/app-data";
|
||||||
import { sceneInteractive } from "../../events/scene-interactive";
|
import { sceneInteractive } from "../../events/scene-interactive";
|
||||||
import { friendsUserStatuses } from "../../events/user-status";
|
import { friendsUserStatuses } from "../../events/user-status";
|
||||||
|
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
|
|
||||||
import DesktopPet from "./components/DesktopPet.svelte";
|
import DesktopPet from "./components/DesktopPet.svelte";
|
||||||
import { listen } from "@tauri-apps/api/event";
|
import { listen } from "@tauri-apps/api/event";
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
@@ -43,16 +41,6 @@
|
|||||||
onMount(() => {
|
onMount(() => {
|
||||||
const unlisten = listen<AppMetadata>("active-app-changed", (event) => {
|
const unlisten = listen<AppMetadata>("active-app-changed", (event) => {
|
||||||
appMetadata = event.payload;
|
appMetadata = event.payload;
|
||||||
const activeAppValue =
|
|
||||||
appMetadata?.localized ?? appMetadata?.unlocalized ?? "";
|
|
||||||
if (activeAppValue.trim()) {
|
|
||||||
invoke("send_user_status_cmd", {
|
|
||||||
activeApp: activeAppValue,
|
|
||||||
state: "idle",
|
|
||||||
}).catch((error) => {
|
|
||||||
console.error("Failed to send user status", error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user