text_document_frontend/
app_context.rs1use common::database::db_context::DbContext;
4use common::event::EventHub;
5use common::long_operation::LongOperationManager;
6use common::undo_redo::UndoRedoManager;
7use std::sync::{Arc, Mutex};
8
9#[derive(Clone)]
11pub struct AppContext {
12 pub db_context: DbContext,
13 pub event_hub: Arc<EventHub>,
14 pub quit_signal: Arc<std::sync::atomic::AtomicBool>,
15 pub undo_redo_manager: Arc<Mutex<UndoRedoManager>>,
16 pub long_operation_manager: Arc<Mutex<LongOperationManager>>,
17}
18
19impl AppContext {
20 pub fn new() -> Self {
21 let db_context = DbContext::new().expect("Failed to create database context");
22
23 let event_hub = Arc::new(EventHub::new());
24 let quit_signal = Arc::new(std::sync::atomic::AtomicBool::new(false));
25
26 let undo_redo_manager = Arc::new(Mutex::new(UndoRedoManager::new()));
27 let long_operation_manager = Arc::new(Mutex::new(LongOperationManager::new()));
28
29 {
31 let mut lom = long_operation_manager.lock().unwrap();
32 lom.set_event_hub(&event_hub);
33 }
34
35 Self {
36 db_context,
37 event_hub,
38 quit_signal,
39 undo_redo_manager,
40 long_operation_manager,
41 }
42 }
43
44 pub fn shutdown(&self) {
46 self.quit_signal
47 .store(true, std::sync::atomic::Ordering::Relaxed);
48 }
49}
50
51impl Default for AppContext {
52 fn default() -> Self {
53 Self::new()
54 }
55}