app.rs

 1use super::{BoolExt as _, Dispatcher, FontSystem, Window};
 2use crate::{executor, platform};
 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    fonts: Arc<FontSystem>,
11}
12
13impl App {
14    pub fn new() -> Self {
15        Self {
16            dispatcher: Arc::new(Dispatcher),
17            fonts: Arc::new(FontSystem::new()),
18        }
19    }
20}
21
22impl platform::App for App {
23    fn dispatcher(&self) -> Arc<dyn platform::Dispatcher> {
24        self.dispatcher.clone()
25    }
26
27    fn activate(&self, ignoring_other_apps: bool) {
28        unsafe {
29            let app: id = msg_send![class!(NSApplication), sharedApplication];
30            let _: () = msg_send![app, activateIgnoringOtherApps: ignoring_other_apps.to_objc()];
31        }
32    }
33
34    fn open_window(
35        &self,
36        options: platform::WindowOptions,
37        executor: Rc<executor::Foreground>,
38    ) -> Result<Box<dyn platform::Window>> {
39        Ok(Box::new(Window::open(options, executor, self.fonts())?))
40    }
41
42    fn fonts(&self) -> Arc<dyn platform::FontSystem> {
43        self.fonts.clone()
44    }
45}