diff --git a/src/main.rs b/src/main.rs index b4cd353..f4d8548 100644 --- a/src/main.rs +++ b/src/main.rs @@ -57,7 +57,7 @@ fn main() { title: Some("PicoForge".into()), appears_transparent: true, // TODO: This option needs to be tested and adjusted on macos - traffic_light_position: Some(gpui::point(px(12.0), px(12.0))), + traffic_light_position: Some(gpui::point(px(9.0), px(9.0))), }), // Render our own window decorations(shadows and resize attack area) for linux/bsd. @@ -82,5 +82,12 @@ fn main() { Ok::<_, anyhow::Error>(()) }) .detach(); + + // Quit the application when the window is closed (specifically needed for macOS) + #[cfg(target_os = "macos")] + { + cx.on_window_closed(|cx| cx.quit()) + .detach(); + } }); } diff --git a/src/ui/components/sidebar.rs b/src/ui/components/sidebar.rs index 5fae191..aa41cd7 100644 --- a/src/ui/components/sidebar.rs +++ b/src/ui/components/sidebar.rs @@ -73,13 +73,7 @@ impl AppSidebar { .border_color(border_color) .w(width) .child({ - let header = h_flex() - .w_full() - .items_center() - .bg(sidebar_bg) - // .border_r_1() - // .border_color(border_color) - .pt_4(); + let header = h_flex().w_full().items_center().bg(sidebar_bg).pt_4(); let current_width = width; let t = ((current_width - px(48.)) / (px(255.) - px(48.))).clamp(0.0, 1.0); diff --git a/src/ui/rootview.rs b/src/ui/rootview.rs index 68ef8dd..ada02ea 100644 --- a/src/ui/rootview.rs +++ b/src/ui/rootview.rs @@ -117,122 +117,110 @@ impl Render for ApplicationRoot { let dialog_layer = Root::render_dialog_layer(window, cx); let sheet_layer = Root::render_sheet_layer(window, cx); - div().size_full().overflow_hidden().child( + let title_bar = TitleBar::new().bg(cx.theme().title_bar).child( + h_flex() + .w_full() + .justify_between() + .bg(cx.theme().title_bar) + .items_center() + .cursor(gpui::CursorStyle::OpenHand) + .child( + Button::new("sidebar_toggle") + .ghost() + .icon(IconName::PanelLeft) + .on_click(cx.listener(|this, _, _, _| { + this.is_sidebar_collapsed = !this.is_sidebar_collapsed; + })) + .tooltip("Toggle Sidebar"), + ), + ); + + let content_area = v_flex() + .min_h(px(0.)) + .min_w(px(0.)) + .overflow_y_scrollbar() + .flex_grow() + .bg(cx.theme().background) + .child(match self.active_view { + ActiveView::Home => { + HomeView::build(&self.state, cx.theme(), window.bounds().size.width) + .into_any_element() + } + ActiveView::Passkeys => { + let view = self.passkeys_view.get_or_insert_with(|| { + let view = cx.new(|cx| { + PasskeysView::new( + window, + cx, + self.state.device_status.clone(), + self.state.fido_info.clone(), + ) + }); + cx.subscribe_in( + &view, + window, + |_, _, event: &PasskeysEvent, window, cx| match event { + PasskeysEvent::Notification(msg) => { + window.push_notification(msg.to_string(), cx); + } + PasskeysEvent::CloseDialog => { + window.close_dialog(cx); + } + }, + ) + .detach(); + view + }); + view.clone().into_any_element() + } + ActiveView::Configuration => { + let view = self.config_view.get_or_insert_with(|| { + cx.new(|cx| ConfigView::new(window, cx, self.state.device_status.clone())) + }); + view.clone().into_any_element() + } + ActiveView::Security => SecurityView::build(cx).into_any_element(), + ActiveView::Logs => { + let view = self + .logs_view + .get_or_insert_with(|| cx.new(|cx| LogsView::new(window, cx))); + view.clone().into_any_element() + } + ActiveView::About => AboutView::build(cx.theme()).into_any_element(), + }); + + let sidebar = AppSidebar::new( + self.active_view, + self.sidebar_width, + is_sidebar_collapsed, + self.state.clone(), + ) + .on_select(|this: &mut Self, view, _, _| { + this.active_view = view; + }) + .on_refresh(|this, window, cx| { + this.refresh_device_status(Some(window), cx); + }); + + #[cfg(target_os = "macos")] + let body = v_flex().size_full().child(title_bar).child( h_flex() .size_full() - .child( - AppSidebar::new( - self.active_view, - self.sidebar_width, - is_sidebar_collapsed, - self.state.clone(), - ) - .on_select(|this: &mut Self, view, _, _| { - this.active_view = view; - }) - .on_refresh(|this, window, cx| { - this.refresh_device_status(Some(window), cx); - }) - .render(cx), - ) - .child( - v_flex() - .size_full() - .child( - TitleBar::new().bg(cx.theme().title_bar).child( - h_flex() - .w_full() - .justify_between() - .bg(cx.theme().title_bar) - .items_center() - .cursor(gpui::CursorStyle::OpenHand) - .child( - Button::new("sidebar_toggle") - .ghost() - .icon(IconName::PanelLeft) - .on_click(cx.listener(|this, _, _, _| { - this.is_sidebar_collapsed = - !this.is_sidebar_collapsed; - })) - .tooltip("Toggle Sidebar"), - ), - ), - ) - .child( - v_flex() - .min_h(px(0.)) - .min_w(px(0.)) - .overflow_y_scrollbar() - .flex_grow() - .bg(cx.theme().background) - .child(match self.active_view { - ActiveView::Home => HomeView::build( - &self.state, - cx.theme(), - window.bounds().size.width, - ) - .into_any_element(), - ActiveView::Passkeys => { - let view = self.passkeys_view.get_or_insert_with(|| { - let view = cx.new(|cx| { - PasskeysView::new( - window, - cx, - self.state.device_status.clone(), - self.state.fido_info.clone(), - ) - }); - cx.subscribe_in( - &view, - window, - |_, _, event: &PasskeysEvent, window, cx| { - match event { - PasskeysEvent::Notification(msg) => { - window.push_notification( - msg.to_string(), - cx, - ); - } - PasskeysEvent::CloseDialog => { - window.close_dialog(cx); - } - } - }, - ) - .detach(); - view - }); - view.clone().into_any_element() - } - ActiveView::Configuration => { - let view = self.config_view.get_or_insert_with(|| { - cx.new(|cx| { - ConfigView::new( - window, - cx, - self.state.device_status.clone(), - ) - }) - }); - view.clone().into_any_element() - } - ActiveView::Security => { - SecurityView::build(cx).into_any_element() - } - ActiveView::Logs => { - let view = self.logs_view.get_or_insert_with(|| { - cx.new(|cx| LogsView::new(window, cx)) - }); - view.clone().into_any_element() - } - ActiveView::About => { - AboutView::build(cx.theme()).into_any_element() - } - }), - ), - ) - .children(dialog_layer) - .children(sheet_layer), - ) + .child(sidebar.render(cx)) + .child(content_area), + ); + + #[cfg(not(target_os = "macos"))] + let body = h_flex() + .size_full() + .child(sidebar.render(cx)) + .child(v_flex().size_full().child(title_bar).child(content_area)); + + div() + .size_full() + .overflow_hidden() + .child(body) + .children(dialog_layer) + .children(sheet_layer) } }