app.rs

 1use super::{BoolExt as _, Dispatcher, Window};
 2use crate::{executor, platform, FontCache};
 3use anyhow::Result;
 4use cocoa::base::id;
 5use objc::{class, msg_send, sel, sel_impl};
 6use std::{rc::Rc, sync::Arc};
 7
 8pub struct App {
 9    dispatcher: Arc<Dispatcher>,
10}
11
12impl App {
13    pub fn new() -> Self {
14        Self {
15            dispatcher: Arc::new(Dispatcher),
16        }
17    }
18}
19
20impl platform::App for App {
21    fn dispatcher(&self) -> Arc<dyn platform::Dispatcher> {
22        self.dispatcher.clone()
23    }
24
25    fn activate(&self, ignoring_other_apps: bool) {
26        unsafe {
27            let app: id = msg_send![class!(NSApplication), sharedApplication];
28            let _: () = msg_send![app, activateIgnoringOtherApps: ignoring_other_apps.to_objc()];
29        }
30    }
31
32    fn open_window(
33        &self,
34        options: platform::WindowOptions,
35        executor: Rc<executor::Foreground>,
36        font_cache: Arc<FontCache>,
37    ) -> Result<Box<dyn platform::Window>> {
38        Ok(Box::new(Window::open(options, executor, font_cache)?))
39    }
40}