Skip to content

Commit

Permalink
MainWindow: Add home button and demo banner
Browse files Browse the repository at this point in the history
  • Loading branch information
cassidyjames committed Jan 6, 2024
1 parent 8c098a7 commit bed9919
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

public class Butler.MainWindow : Adw.ApplicationWindow {
public Adw.AboutWindow about_window;
public Adw.Banner demo_banner;
public Adw.Toast fullscreen_toast;
public Adw.ToastOverlay toast_overlay;
public Gtk.Revealer header_revealer;
public Gtk.Revealer home_revealer;

private const GLib.ActionEntry[] ACTION_ENTRIES = {
{ "toggle_fullscreen", toggle_fullscreen },
Expand Down Expand Up @@ -54,6 +56,15 @@ public class Butler.MainWindow : Adw.ApplicationWindow {
icon_name = about_window.application_icon;
title = about_window.application_name;

var home_button = new Gtk.Button.from_icon_name ("go-home-symbolic") {
tooltip_text = _("Go Home")
};

home_revealer = new Gtk.Revealer () {
child = home_button,
transition_type = Gtk.RevealerTransitionType.SLIDE_RIGHT
};

var site_menu = new Menu ();
site_menu.append (_("_Log Out…"), "win.log_out");

Expand All @@ -74,13 +85,19 @@ public class Butler.MainWindow : Adw.ApplicationWindow {
};

var header = new Adw.HeaderBar ();
header.pack_start (home_revealer);
header.pack_end (menu_button);

header_revealer = new Gtk.Revealer () {
child = header,
reveal_child = !fullscreened
};

demo_banner = new Adw.Banner (_("Browsing Home Assistant Demo")) {
action_name = "win.set_server",
button_label = _("Set _Server…")
};

fullscreen_toast = new Adw.Toast (_("Press <b>Ctrl F</b> or <b>F11</b> to toggle fullscreen")) {
action_name = "win.toggle_fullscreen",
button_label = _("Exit _Fullscreen")
Expand Down Expand Up @@ -120,6 +137,7 @@ public class Butler.MainWindow : Adw.ApplicationWindow {
};
grid.attach (header_revealer, 0, 0);
grid.attach (toast_overlay, 0, 1);
grid.attach (demo_banner, 0, 2);

set_content (grid);

Expand All @@ -128,6 +146,10 @@ public class Butler.MainWindow : Adw.ApplicationWindow {

set_default_size (window_width, window_height);

home_button.clicked.connect (() => {
web_view.load_uri (server);
});

close_request.connect (() => {
save_window_state ();
return Gdk.EVENT_PROPAGATE;
Expand Down Expand Up @@ -169,7 +191,20 @@ public class Butler.MainWindow : Adw.ApplicationWindow {
if (web_view.is_loading) {
// TODO: Add a loading progress bar or spinner somewhere?
} else {
App.settings.set_string ("current-url", web_view.uri);
string default_server = App.settings.get_default_value ("server").get_string ();
string server = App.settings.get_string ("server");
string current_url = web_view.uri;

App.settings.set_string ("current-url", current_url);

if (current_url.has_prefix (default_server)) {
demo_banner.revealed = true;
} else if (current_url.has_prefix (server)) {
demo_banner.revealed = false;
} else {
demo_banner.revealed = false;
home_revealer.set_reveal_child (true);
}
}
}

Expand Down

0 comments on commit bed9919

Please sign in to comment.