diff --git a/src/account_switcher/mod.ui b/src/account_switcher/mod.ui index 8260bb78..3c65c93f 100644 --- a/src/account_switcher/mod.ui +++ b/src/account_switcher/mod.ui @@ -19,7 +19,7 @@ - app.new-session + win.new-session 10 diff --git a/src/application.rs b/src/application.rs index 6601bc41..cbe779e4 100644 --- a/src/application.rs +++ b/src/application.rs @@ -2,7 +2,6 @@ use std::{borrow::Cow, fmt}; use gettextrs::gettext; use gio::{ApplicationFlags, Settings}; -use glib::{clone, WeakRef}; use gtk::{gio, glib, prelude::*, subclass::prelude::*}; use ruma::{OwnedRoomId, RoomId}; use tracing::{debug, info}; @@ -16,7 +15,7 @@ mod imp { #[derive(Debug)] pub struct Application { - pub window: WeakRef, + pub window: glib::WeakRef, pub settings: Settings, } @@ -54,19 +53,6 @@ mod imp { app.setup_gactions(); app.setup_accels(); - let monitor = gio::NetworkMonitor::default(); - monitor.connect_network_changed(clone!(@weak app => move |monitor, _| { - app.lookup_action("show-login") - .and_downcast::() - .unwrap() - .set_enabled(monitor.is_network_available()); - })); - - app.lookup_action("show-login") - .and_downcast::() - .unwrap() - .set_enabled(monitor.is_network_available()); - app.main_window().present(); } @@ -119,16 +105,6 @@ impl Application { app.show_about_dialog(); }) .build(), - gio::ActionEntry::builder("new-session") - .activate(|app: &Application, _, _| { - app.main_window().switch_to_greeter_page(); - }) - .build(), - gio::ActionEntry::builder("show-login") - .activate(|app: &Application, _, _| { - app.main_window().switch_to_login_page(); - }) - .build(), gio::ActionEntry::builder("show-room") .parameter_type(Some(&AppShowRoomPayload::static_variant_type())) .activate(|app: &Application, _, v| { @@ -139,21 +115,6 @@ impl Application { }) .build(), ]); - - let show_session_action = gio::SimpleAction::new("show-session", None); - show_session_action.connect_activate(clone!(@weak self as app => move |_, _| { - app.main_window().switch_to_session_page(); - })); - self.add_action(&show_session_action); - - let win = self.main_window(); - let session_list = win.session_list(); - session_list.connect_is_empty_notify( - clone!(@weak show_session_action => move |session_list| { - show_session_action.set_enabled(!session_list.is_empty()); - }), - ); - show_session_action.set_enabled(!session_list.is_empty()); } /// Sets up keyboard shortcuts for application and window actions. diff --git a/src/greeter.ui b/src/greeter.ui index 73913b9f..2dd65849 100644 --- a/src/greeter.ui +++ b/src/greeter.ui @@ -7,7 +7,7 @@ - app.show-session + win.show-session go-previous-symbolic Back @@ -113,7 +113,7 @@ true _Log In true - app.show-login + win.show-login diff --git a/src/window.rs b/src/window.rs index d9288d61..223d23b5 100644 --- a/src/window.rs +++ b/src/window.rs @@ -95,6 +95,24 @@ mod imp { } }, ); + + klass.install_action("win.new-session", None, |obj, _, _| { + obj.switch_to_greeter_page(); + }); + klass.install_action("win.show-login", None, |obj, _, _| { + obj.switch_to_login_page(); + }); + klass.install_action("win.show-session", None, |obj, _, _| { + obj.switch_to_session_page(); + }); + + klass.install_action("win.toggle-fullscreen", None, |obj, _, _| { + if obj.is_fullscreened() { + obj.unfullscreen(); + } else { + obj.fullscreen(); + } + }); } fn instance_init(obj: &InitializingObject) { @@ -156,16 +174,11 @@ mod imp { obj.load_window_size(); - // Ask for the toggle fullscreen state - let fullscreen = gio::SimpleAction::new("toggle-fullscreen", None); - fullscreen.connect_activate(clone!(@weak obj as window => move |_, _| { - if window.is_fullscreened() { - window.unfullscreen(); - } else { - window.fullscreen(); - } - })); - obj.add_action(&fullscreen); + self.session_list + .connect_is_empty_notify(clone!(@weak obj => move |session_list| { + obj.action_set_enabled("win.show-session", !session_list.is_empty()); + })); + obj.action_set_enabled("win.show-session", !self.session_list.is_empty()); self.main_stack.connect_visible_child_notify( clone!(@weak obj => move |_| obj.set_default_by_child()), @@ -492,7 +505,10 @@ impl Window { let imp = self.imp(); let monitor = gio::NetworkMonitor::default(); - if !monitor.is_network_available() { + let is_network_available = monitor.is_network_available(); + self.action_set_enabled("win.show-login", is_network_available); + + if !is_network_available { imp.offline_banner .set_title(&gettext("No network connection")); imp.offline_banner.set_revealed(true);