|
| 1 | +use crate::messages::app_window::AppWindowMessage; |
| 2 | +use crate::messages::prelude::*; |
| 3 | +use graphite_proc_macros::{ExtractField, message_handler_data}; |
| 4 | + |
| 5 | +#[derive(Debug, Clone, Default, ExtractField)] |
| 6 | +pub struct AppWindowMessageHandler { |
| 7 | + platform: AppWindowPlatform, |
| 8 | + maximized: bool, |
| 9 | + viewport_hole_punch_active: bool, |
| 10 | +} |
| 11 | + |
| 12 | +#[message_handler_data] |
| 13 | +impl MessageHandler<AppWindowMessage, ()> for AppWindowMessageHandler { |
| 14 | + fn process_message(&mut self, message: AppWindowMessage, responses: &mut std::collections::VecDeque<Message>, _: ()) { |
| 15 | + match message { |
| 16 | + AppWindowMessage::AppWindowMinimize => { |
| 17 | + self.platform = if self.platform == AppWindowPlatform::Mac { |
| 18 | + AppWindowPlatform::Windows |
| 19 | + } else { |
| 20 | + AppWindowPlatform::Mac |
| 21 | + }; |
| 22 | + responses.add(FrontendMessage::UpdatePlatform { platform: self.platform }); |
| 23 | + } |
| 24 | + AppWindowMessage::AppWindowMaximize => { |
| 25 | + self.maximized = !self.maximized; |
| 26 | + responses.add(FrontendMessage::UpdateMaximized { maximized: self.maximized }); |
| 27 | + |
| 28 | + self.viewport_hole_punch_active = !self.viewport_hole_punch_active; |
| 29 | + responses.add(FrontendMessage::UpdateViewportHolePunch { |
| 30 | + active: self.viewport_hole_punch_active, |
| 31 | + }); |
| 32 | + } |
| 33 | + AppWindowMessage::AppWindowClose => { |
| 34 | + self.platform = AppWindowPlatform::Web; |
| 35 | + responses.add(FrontendMessage::UpdatePlatform { platform: self.platform }); |
| 36 | + } |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + fn actions(&self) -> ActionList { |
| 41 | + actions!(AppWindowMessageDiscriminant;) |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +#[derive(PartialEq, Eq, Clone, Copy, Default, Debug, serde::Serialize, serde::Deserialize, specta::Type)] |
| 46 | +pub enum AppWindowPlatform { |
| 47 | + #[default] |
| 48 | + Web, |
| 49 | + Windows, |
| 50 | + Mac, |
| 51 | + Linux, |
| 52 | +} |
0 commit comments