1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// SPDX-License-Identifier: Apache-2.0
//! Event emission trait — shared by daemon (NoopEmitter) and Tauri app (TauriEmitter).
//!
//! Allows wenlan-core to emit UI events without depending on tauri.
//! The Tauri app supplies its own implementation that wraps `tauri::Emitter`;
//! tests and headless operation use `NoopEmitter`.
use anyhow::Result;
/// Trait for emitting events from core to external consumers.
///
/// Replaces `Option<tauri::AppHandle>` in MemoryDB and other modules that
/// previously needed to push updates to the Tauri frontend.
pub trait EventEmitter: Send + Sync {
/// Emit a named event with a string payload (typically JSON).
fn emit(&self, event: &str, payload: &str) -> Result<()>;
}
/// No-op emitter for testing and headless operation.
///
/// Always returns `Ok(())` without doing anything.
pub struct NoopEmitter;
impl EventEmitter for NoopEmitter {
fn emit(&self, _event: &str, _payload: &str) -> Result<()> {
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn noop_emitter_always_ok() {
let emitter = NoopEmitter;
assert!(emitter.emit("test-event", "{}").is_ok());
assert!(emitter.emit("", "").is_ok());
}
#[test]
fn noop_emitter_is_send_sync() {
fn assert_send_sync<T: Send + Sync>() {}
assert_send_sync::<NoopEmitter>();
}
}