2021-02-08 18:37:25 +11:00
|
|
|
//! Implements the start of the App lifecycle. Handles creating the required menu and window
|
|
|
|
//! components and message dispatching.
|
|
|
|
|
2021-08-08 15:31:48 +10:00
|
|
|
use cacao::appkit::{App, AppDelegate};
|
2021-02-08 18:37:25 +11:00
|
|
|
use cacao::notification_center::Dispatcher;
|
|
|
|
|
|
|
|
use crate::menu::menu;
|
|
|
|
use crate::storage::{Defaults, Message};
|
|
|
|
use crate::windows::WindowManager;
|
|
|
|
|
|
|
|
/// This handles routing lifecycle events, and maintains our `WindowManager`.
|
|
|
|
#[derive(Default)]
|
|
|
|
pub struct TodosApp {
|
2022-08-27 00:40:31 +10:00
|
|
|
pub window_manager: WindowManager
|
2021-02-08 18:37:25 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
impl AppDelegate for TodosApp {
|
|
|
|
/// Sets the menu, activates the app, opens the main window and requests notification
|
|
|
|
/// permissions.
|
|
|
|
fn did_finish_launching(&self) {
|
|
|
|
Defaults::register();
|
|
|
|
|
|
|
|
App::set_menu(menu());
|
|
|
|
App::activate();
|
2022-07-11 01:15:29 +10:00
|
|
|
|
2021-02-08 18:37:25 +11:00
|
|
|
self.window_manager.open_main();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Dispatcher for TodosApp {
|
|
|
|
type Message = Message;
|
|
|
|
|
|
|
|
/// Handles a message that came over on the main (UI) thread.
|
|
|
|
fn on_ui_message(&self, message: Self::Message) {
|
|
|
|
self.window_manager.on_ui_message(message);
|
|
|
|
}
|
|
|
|
}
|