mirror of
https://github.com/ow-mods/ow-mod-man.git
synced 2025-12-11 20:15:50 +01:00
[GUI] More strict log spam protection
This commit is contained in:
parent
98df12b051
commit
cc461dceb0
@ -34,7 +34,7 @@ use owmods_core::{
|
|||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use tauri::FileDropEvent;
|
use tauri::FileDropEvent;
|
||||||
use tauri::{api::dialog, async_runtime, AppHandle, Manager, WindowEvent};
|
use tauri::{api::dialog, async_runtime, AppHandle, Manager, WindowEvent};
|
||||||
use tokio::{sync::mpsc, try_join};
|
use tokio::{select, sync::mpsc, try_join};
|
||||||
use typeshare::typeshare;
|
use typeshare::typeshare;
|
||||||
|
|
||||||
use crate::events::{CustomEventEmitter, CustomEventEmitterAll, CustomEventTriggerGlobal, Event};
|
use crate::events::{CustomEventEmitter, CustomEventEmitterAll, CustomEventTriggerGlobal, Event};
|
||||||
@ -761,10 +761,24 @@ pub async fn run_game(
|
|||||||
let (tx, mut rx) = mpsc::channel(32);
|
let (tx, mut rx) = mpsc::channel(32);
|
||||||
|
|
||||||
let log_handler = async {
|
let log_handler = async {
|
||||||
while let Some(msg) = rx.recv().await {
|
loop {
|
||||||
let mut game_log = state.game_log.write().await;
|
select! {
|
||||||
if let Some(log_data) = game_log.get_mut(&port) {
|
msg = rx.recv() => {
|
||||||
log_data.take_message(msg);
|
if let Some(msg) = msg {
|
||||||
|
let mut game_log = state.game_log.write().await;
|
||||||
|
if let Some(log_data) = game_log.get_mut(&port) {
|
||||||
|
log_data.take_message(msg);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ = tokio::time::sleep(tokio::time::Duration::from_secs(5)) => {
|
||||||
|
let mut game_log = state.game_log.write().await;
|
||||||
|
if let Some(log_data) = game_log.get_mut(&port) {
|
||||||
|
log_data.process_emit_queue();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@ -68,7 +68,7 @@ pub struct LogData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl LogData {
|
impl LogData {
|
||||||
const LOG_LIMIT_PER_SECOND: u32 = 25;
|
const LOG_LIMIT_PER_SECOND: u32 = 5;
|
||||||
const LOG_TIME_UNTIL_FORCED_EMIT_SEC: u64 = 1;
|
const LOG_TIME_UNTIL_FORCED_EMIT_SEC: u64 = 1;
|
||||||
|
|
||||||
pub fn new(port: LogPort, handle: &AppHandle) -> Result<Self> {
|
pub fn new(port: LogPort, handle: &AppHandle) -> Result<Self> {
|
||||||
|
|||||||
@ -26,12 +26,13 @@ export const useTauri = <T, E extends Event["name"]>(
|
|||||||
const errorBound = useErrorBoundary();
|
const errorBound = useErrorBoundary();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const subscriptions: (() => void)[] = [];
|
||||||
if (status !== "Loading") {
|
if (status !== "Loading") {
|
||||||
for (const eventToSubscribe of events) {
|
for (const eventToSubscribe of events) {
|
||||||
listen(eventToSubscribe, (params) => {
|
subscriptions.push(listen(eventToSubscribe, (params) => {
|
||||||
if (shouldChangeFn && !shouldChangeFn(params)) return;
|
if (shouldChangeFn && !shouldChangeFn(params)) return;
|
||||||
setStatus("Loading");
|
setStatus("Loading");
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
commandFn()
|
commandFn()
|
||||||
@ -44,6 +45,11 @@ export const useTauri = <T, E extends Event["name"]>(
|
|||||||
})
|
})
|
||||||
.finally(() => setStatus("Done"));
|
.finally(() => setStatus("Done"));
|
||||||
}
|
}
|
||||||
|
return () => {
|
||||||
|
for (const unsub of subscriptions) {
|
||||||
|
unsub();
|
||||||
|
}
|
||||||
|
};
|
||||||
}, [commandFn, shouldChangeFn, errorBound, events, status]);
|
}, [commandFn, shouldChangeFn, errorBound, events, status]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@ -12,7 +12,7 @@ pub fn spam_logs(port: u16) -> Result<()> {
|
|||||||
println!("Message {i}, {}", i == usize::MAX);
|
println!("Message {i}, {}", i == usize::MAX);
|
||||||
// I just want to easily change stuff when testing so im leaving the format here
|
// I just want to easily change stuff when testing so im leaving the format here
|
||||||
#[allow(clippy::useless_format)]
|
#[allow(clippy::useless_format)]
|
||||||
let msg = format!("{{\"type\": 0, \"message\": \"Line 1\", \"senderName\": \"xtask\", \"senderType\": \"log_spammer\"}}\n");
|
let msg = format!("{{\"type\": 0, \"message\": \"Line {i}\", \"senderName\": \"xtask\", \"senderType\": \"log_spammer\"}}\n");
|
||||||
stream.write_all(msg.as_bytes())?;
|
stream.write_all(msg.as_bytes())?;
|
||||||
i += 1;
|
i += 1;
|
||||||
std::thread::sleep(Duration::from_secs_f32(
|
std::thread::sleep(Duration::from_secs_f32(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user