Add private window entry point

This commit is contained in:
2026-05-09 00:31:40 -04:00
parent 97a06d7b52
commit 7797203bbf
6 changed files with 139 additions and 29 deletions
+55 -24
View File
@@ -19,6 +19,7 @@ actions!(
OpenDownloads,
OpenHistory,
OpenNewTab,
OpenPrivateWindow,
OpenSettings,
OpenTaskManager,
Quit,
@@ -39,6 +40,7 @@ fn main() {
gpui_component::init(cx);
cx.on_action(quit);
bind_shortcuts(cx);
cx.on_action(open_private_window);
cx.set_menus(vec![
Menu {
name: "ELY Browser".into(),
@@ -52,6 +54,7 @@ fn main() {
name: "File".into(),
items: vec![
MenuItem::action("New Tab", OpenNewTab),
MenuItem::action("New Private Window", OpenPrivateWindow),
MenuItem::action("Split Right", SplitRight),
MenuItem::separator(),
MenuItem::action("Command Mode", FocusCommandMode),
@@ -78,30 +81,7 @@ fn main() {
},
]);
let bounds = Bounds::centered(None, size(px(1240.0), px(780.0)), cx);
let opened = cx.open_window(
WindowOptions {
titlebar: Some(TitlebarOptions {
title: Some("ELY Browser".into()),
appears_transparent: true,
traffic_light_position: Some(point(px(18.0), px(24.0))),
}),
window_bounds: Some(WindowBounds::Windowed(bounds)),
..WindowOptions::default()
},
|window, cx| {
let shell = cx.new(|cx| ElyShell::new(window, cx));
let focus_handle = shell.focus_handle(cx);
window.defer(cx, move |window, cx| {
if window.focused(cx).is_none() {
focus_handle.focus(window);
}
});
cx.new(|cx| gpui_component::Root::new(shell, window, cx))
},
);
if opened.is_ok() {
if open_browser_window(cx, BrowserWindowMode::Standard) {
cx.activate(true);
} else {
cx.quit();
@@ -109,6 +89,57 @@ fn main() {
});
}
#[derive(Clone, Copy)]
enum BrowserWindowMode {
Standard,
Private,
}
impl BrowserWindowMode {
fn title(self) -> &'static str {
match self {
Self::Standard => "ELY Browser",
Self::Private => "ELY Browser - Private",
}
}
}
fn open_browser_window(cx: &mut App, mode: BrowserWindowMode) -> bool {
let bounds = Bounds::centered(None, size(px(1240.0), px(780.0)), cx);
let opened = cx.open_window(
WindowOptions {
titlebar: Some(TitlebarOptions {
title: Some(mode.title().into()),
appears_transparent: true,
traffic_light_position: Some(point(px(18.0), px(24.0))),
}),
window_bounds: Some(WindowBounds::Windowed(bounds)),
..WindowOptions::default()
},
|window, cx| {
let shell = cx.new(|cx| match mode {
BrowserWindowMode::Standard => ElyShell::new(window, cx),
BrowserWindowMode::Private => ElyShell::new_private(window, cx),
});
let focus_handle = shell.focus_handle(cx);
window.defer(cx, move |window, cx| {
if window.focused(cx).is_none() {
focus_handle.focus(window);
}
});
cx.new(|cx| gpui_component::Root::new(shell, window, cx))
},
);
opened.is_ok()
}
fn quit(_: &Quit, cx: &mut App) {
cx.quit();
}
fn open_private_window(_: &OpenPrivateWindow, cx: &mut App) {
if open_browser_window(cx, BrowserWindowMode::Private) {
cx.activate(true);
}
}