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 tauri::FileDropEvent;
|
||||
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 crate::events::{CustomEventEmitter, CustomEventEmitterAll, CustomEventTriggerGlobal, Event};
|
||||
@ -761,10 +761,24 @@ pub async fn run_game(
|
||||
let (tx, mut rx) = mpsc::channel(32);
|
||||
|
||||
let log_handler = async {
|
||||
while let Some(msg) = rx.recv().await {
|
||||
let mut game_log = state.game_log.write().await;
|
||||
if let Some(log_data) = game_log.get_mut(&port) {
|
||||
log_data.take_message(msg);
|
||||
loop {
|
||||
select! {
|
||||
msg = rx.recv() => {
|
||||
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(())
|
||||
|
||||
@ -68,7 +68,7 @@ pub struct 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;
|
||||
|
||||
pub fn new(port: LogPort, handle: &AppHandle) -> Result<Self> {
|
||||
|
||||
@ -26,12 +26,13 @@ export const useTauri = <T, E extends Event["name"]>(
|
||||
const errorBound = useErrorBoundary();
|
||||
|
||||
useEffect(() => {
|
||||
const subscriptions: (() => void)[] = [];
|
||||
if (status !== "Loading") {
|
||||
for (const eventToSubscribe of events) {
|
||||
listen(eventToSubscribe, (params) => {
|
||||
subscriptions.push(listen(eventToSubscribe, (params) => {
|
||||
if (shouldChangeFn && !shouldChangeFn(params)) return;
|
||||
setStatus("Loading");
|
||||
});
|
||||
}));
|
||||
}
|
||||
} else {
|
||||
commandFn()
|
||||
@ -44,6 +45,11 @@ export const useTauri = <T, E extends Event["name"]>(
|
||||
})
|
||||
.finally(() => setStatus("Done"));
|
||||
}
|
||||
return () => {
|
||||
for (const unsub of subscriptions) {
|
||||
unsub();
|
||||
}
|
||||
};
|
||||
}, [commandFn, shouldChangeFn, errorBound, events, status]);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@ -12,7 +12,7 @@ pub fn spam_logs(port: u16) -> Result<()> {
|
||||
println!("Message {i}, {}", i == usize::MAX);
|
||||
// I just want to easily change stuff when testing so im leaving the format here
|
||||
#[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())?;
|
||||
i += 1;
|
||||
std::thread::sleep(Duration::from_secs_f32(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user