mod arrangements;
mod cli_timer;
mod config_propagation;
mod config_renderer_apply;
mod coprocess;
mod menu_actions;
mod scripting;
mod settings_actions;
mod update_checker;
mod window_lifecycle;
mod window_session;
use crate::app::window_state::WindowState;
use crate::arrangements::ArrangementManager;
use crate::cli::RuntimeOptions;
use crate::config::Config;
use crate::menu::MenuManager;
use crate::settings_window::SettingsWindow;
use crate::update_checker::{UpdateCheckResult, UpdateChecker};
use std::collections::HashMap;
use std::sync::Arc;
use std::time::Instant;
use tokio::runtime::Runtime;
use winit::window::WindowId;
#[allow(dead_code)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum MoveDestination {
NewWindow,
ExistingWindow(WindowId),
}
#[allow(dead_code)]
#[derive(Debug, Clone, Copy)]
pub(crate) struct MoveTabRequest {
pub(crate) tab_id: crate::tab::TabId,
pub(crate) destination: MoveDestination,
}
pub(crate) struct WindowManager {
pub(crate) windows: HashMap<WindowId, WindowState>,
pub(crate) menu: Option<MenuManager>,
pub(crate) config: Config,
pub(crate) runtime: Arc<Runtime>,
pub(crate) should_exit: bool,
pending_window_count: usize,
pub(crate) settings_window: Option<SettingsWindow>,
pub(crate) runtime_options: RuntimeOptions,
pub(crate) start_time: Option<Instant>,
pub(crate) command_sent: bool,
pub(crate) screenshot_taken: bool,
pub(crate) update_checker: UpdateChecker,
pub(crate) next_update_check: Option<Instant>,
pub(crate) last_update_result: Option<UpdateCheckResult>,
pub(crate) arrangement_manager: ArrangementManager,
pub(crate) auto_restore_done: bool,
pub(crate) dynamic_profile_manager: crate::profile::DynamicProfileManager,
}
impl WindowManager {
pub fn new(config: Config, runtime: Arc<Runtime>, runtime_options: RuntimeOptions) -> Self {
let arrangement_manager = match crate::arrangements::storage::load_arrangements() {
Ok(manager) => manager,
Err(e) => {
log::warn!("Failed to load arrangements: {}", e);
ArrangementManager::new()
}
};
let mut dynamic_profile_manager = crate::profile::DynamicProfileManager::new();
if !config.dynamic_profile_sources.is_empty() {
let mut sources = config.dynamic_profile_sources.clone();
for src in &mut sources {
src.allow_http = config.allow_http_profiles;
}
dynamic_profile_manager.start(&sources, &runtime);
}
Self {
windows: HashMap::new(),
menu: None,
config,
runtime,
should_exit: false,
pending_window_count: 0,
settings_window: None,
runtime_options,
start_time: None,
command_sent: false,
screenshot_taken: false,
update_checker: UpdateChecker::new(env!("CARGO_PKG_VERSION")),
next_update_check: None,
last_update_result: None,
arrangement_manager,
auto_restore_done: false,
dynamic_profile_manager,
}
}
pub fn get_focused_window_id(&self) -> Option<WindowId> {
for (window_id, window_state) in &self.windows {
if window_state.focus_state.is_focused {
return Some(*window_id);
}
}
self.windows.keys().next().copied()
}
}