From a78fdd386f93db366d7327aa736624ad8bc1aa6f Mon Sep 17 00:00:00 2001 From: KnightMurloc <44520059+KnightMurloc@users.noreply.github.com> Date: Fri, 9 Sep 2022 12:03:55 +0700 Subject: add opt-in hide to system tray icon (#99) --- src/abaddon.cpp | 29 +++++++++++++++++++++++++++++ src/abaddon.hpp | 9 ++++++++- src/settings.cpp | 2 ++ src/settings.hpp | 2 ++ src/windows/mainwindow.cpp | 2 +- src/windows/mainwindow.hpp | 1 + 6 files changed, 43 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/abaddon.cpp b/src/abaddon.cpp index 343dff7..02dcd08 100644 --- a/src/abaddon.cpp +++ b/src/abaddon.cpp @@ -248,11 +248,25 @@ int Abaddon::StartGTK() { m_main_window->GetChatWindow()->signal_action_reaction_remove().connect(sigc::mem_fun(*this, &Abaddon::ActionReactionRemove)); ActionReloadCSS(); + if (m_settings.GetSettings().HideToTray) { + m_tray = Gtk::StatusIcon::create("discord"); + m_tray->signal_activate().connect(sigc::mem_fun(*this, &Abaddon::on_tray_click)); + m_tray->signal_popup_menu().connect(sigc::mem_fun(*this, &Abaddon::on_tray_popup_menu)); + } + m_tray_menu = Gtk::make_managed(); + m_tray_exit = Gtk::make_managed("Quit", false); + + m_tray_exit->signal_activate().connect(sigc::mem_fun(*this, &Abaddon::on_tray_menu_click)); + + m_tray_menu->append(*m_tray_exit); + m_tray_menu->show_all(); + m_main_window->signal_hide().connect(sigc::mem_fun(*this, &Abaddon::on_window_hide)); m_gtk_app->signal_shutdown().connect(sigc::mem_fun(*this, &Abaddon::OnShutdown), false); m_main_window->UpdateMenus(); + m_gtk_app->hold(); m_main_window->show(); RunFirstTimeDiscordStartup(); @@ -937,6 +951,21 @@ EmojiResource &Abaddon::GetEmojis() { return m_emojis; } +void Abaddon::on_tray_click() { + m_main_window->set_visible(!m_main_window->is_visible()); +} +void Abaddon::on_tray_menu_click() { + m_gtk_app->quit(); +} +void Abaddon::on_tray_popup_menu(int button, int activate_time) { + m_tray->popup_menu_at_position(*m_tray_menu, button, activate_time); +} +void Abaddon::on_window_hide() { + if (!m_settings.GetSettings().HideToTray) { + m_gtk_app->quit(); + } +} + int main(int argc, char **argv) { if (std::getenv("ABADDON_NO_FC") == nullptr) Platform::SetupFonts(); diff --git a/src/abaddon.hpp b/src/abaddon.hpp index ab80c46..b067324 100644 --- a/src/abaddon.hpp +++ b/src/abaddon.hpp @@ -117,6 +117,8 @@ protected: Gtk::MenuItem *m_user_menu_roles; Gtk::MenuItem *m_user_menu_remove_recipient; Gtk::Menu *m_user_menu_roles_submenu; + Gtk::Menu *m_tray_menu; + Gtk::MenuItem *m_tray_exit; void on_user_menu_insert_mention(); void on_user_menu_ban(); @@ -124,6 +126,10 @@ protected: void on_user_menu_copy_id(); void on_user_menu_open_dm(); void on_user_menu_remove_recipient(); + void on_tray_click(); + void on_tray_popup_menu(int button, int activate_time); + void on_tray_menu_click(); + void on_window_hide(); private: SettingsManager m_settings; @@ -142,5 +148,6 @@ private: Glib::RefPtr m_gtk_app; Glib::RefPtr m_css_provider; Glib::RefPtr m_css_low_provider; // registered with a lower priority to allow better customization - std::unique_ptr m_main_window; // wah wah cant create a gtkstylecontext fuck you + Glib::RefPtr m_tray; + std::unique_ptr m_main_window; // wah wah cant create a gtkstylecontext fuck you }; diff --git a/src/settings.cpp b/src/settings.cpp index 242bd7c..dd1fe83 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -48,6 +48,7 @@ void SettingsManager::ReadSettings() { SMBOOL("gui", "save_state", SaveState); SMBOOL("gui", "stock_emojis", ShowStockEmojis); SMBOOL("gui", "unreads", Unreads); + SMBOOL("gui", "hide_to_tray", HideToTray); SMINT("http", "concurrent", CacheHTTPConcurrency); SMSTR("http", "user_agent", UserAgent); SMSTR("style", "expandercolor", ChannelsExpanderColor); @@ -101,6 +102,7 @@ void SettingsManager::Close() { SMBOOL("gui", "save_state", SaveState); SMBOOL("gui", "stock_emojis", ShowStockEmojis); SMBOOL("gui", "unreads", Unreads); + SMBOOL("gui", "hide_to_tray", HideToTray); SMINT("http", "concurrent", CacheHTTPConcurrency); SMSTR("http", "user_agent", UserAgent); SMSTR("style", "expandercolor", ChannelsExpanderColor); diff --git a/src/settings.hpp b/src/settings.hpp index 3c9aebb..7f5e015 100644 --- a/src/settings.hpp +++ b/src/settings.hpp @@ -28,6 +28,8 @@ public: #endif bool Unreads { true }; + bool HideToTray { false }; + // [http] int CacheHTTPConcurrency { 20 }; std::string UserAgent { "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36" }; diff --git a/src/windows/mainwindow.cpp b/src/windows/mainwindow.cpp index 17edfa3..7f4395c 100644 --- a/src/windows/mainwindow.cpp +++ b/src/windows/mainwindow.cpp @@ -401,4 +401,4 @@ MainWindow::type_signal_action_view_pins MainWindow::signal_action_view_pins() { MainWindow::type_signal_action_view_threads MainWindow::signal_action_view_threads() { return m_signal_action_view_threads; -} +} \ No newline at end of file diff --git a/src/windows/mainwindow.hpp b/src/windows/mainwindow.hpp index b5b6fc1..534df1b 100644 --- a/src/windows/mainwindow.hpp +++ b/src/windows/mainwindow.hpp @@ -83,6 +83,7 @@ private: Gtk::MenuItem m_menu_view_go_back; Gtk::MenuItem m_menu_view_go_forward; #endif + void OnViewSubmenuPopup(); public: -- cgit v1.2.3 From f3e5dcbe6521413344091004641feaa2906efb0f Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Fri, 9 Sep 2022 02:40:33 -0400 Subject: fix some potential crashes because of optionals --- src/components/chatmessage.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/components/chatmessage.cpp b/src/components/chatmessage.cpp index 1aca81d..89c924e 100644 --- a/src/components/chatmessage.cpp +++ b/src/components/chatmessage.cpp @@ -655,13 +655,19 @@ Gtk::Widget *ChatMessageItemContainer::CreateReplyComponent(const Message &data) const auto role = discord.GetRole(role_id); if (role.has_value()) { const auto author = discord.GetUser(author_id); - return "Color) + "\">" + author->GetEscapedString() + ""; + if (author.has_value()) { + return "Color) + "\">" + author->GetEscapedString() + ""; + } } } } const auto author = discord.GetUser(author_id); - return author->GetEscapedBoldString(); + if (author.has_value()) { + return author->GetEscapedBoldString(); + } + + return "Unknown User"; }; // if the message wasnt fetched from store it might have an un-fetched reference @@ -673,15 +679,15 @@ Gtk::Widget *ChatMessageItemContainer::CreateReplyComponent(const Message &data) } if (data.Interaction.has_value()) { - const auto user = *discord.GetUser(data.Interaction->User.ID); - if (data.GuildID.has_value()) { - lbl->set_markup(get_author_markup(user.ID, *data.GuildID) + + lbl->set_markup(get_author_markup(data.Interaction->User.ID, *data.GuildID) + " used /" + Glib::Markup::escape_text(data.Interaction->Name) + ""); + } else if (const auto user = discord.GetUser(data.Interaction->User.ID); user.has_value()) { + lbl->set_markup(user->GetEscapedBoldString()); } else { - lbl->set_markup(user.GetEscapedBoldString()); + lbl->set_markup("Unknown User"); } } else if (referenced_message.has_value()) { if (referenced_message.value() == nullptr) { -- cgit v1.2.3 From 84eb56d6b1f6d0fee4b909e3a96c66b6ad1311f7 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Fri, 9 Sep 2022 02:51:59 -0400 Subject: store user from interaction even if member is not present --- src/discord/discord.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/discord/discord.cpp b/src/discord/discord.cpp index 561b25b..e1b7a48 100644 --- a/src/discord/discord.cpp +++ b/src/discord/discord.cpp @@ -2441,9 +2441,11 @@ void DiscordClient::StoreMessageData(Message &msg) { if (msg.Member.has_value()) m_store.SetGuildMember(*msg.GuildID, msg.Author.ID, *msg.Member); - if (msg.Interaction.has_value() && msg.Interaction->Member.has_value()) { + if (msg.Interaction.has_value()) { m_store.SetUser(msg.Interaction->User.ID, msg.Interaction->User); - m_store.SetGuildMember(*msg.GuildID, msg.Interaction->User.ID, *msg.Interaction->Member); + if (msg.Interaction->Member.has_value()) { + m_store.SetGuildMember(*msg.GuildID, msg.Interaction->User.ID, *msg.Interaction->Member); + } } m_store.EndTransaction(); -- cgit v1.2.3 From 3027e00905b19282a4f501a26f7a4f71bc6940ea Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Sun, 25 Sep 2022 01:44:09 -0400 Subject: open browser on mouse release (fixes #108) --- src/components/chatmessage.cpp | 8 ++++---- src/windows/guildsettings/infopane.cpp | 7 +++---- src/windows/profile/userinfopane.cpp | 4 ++-- src/windows/profilewindow.cpp | 4 ++-- 4 files changed, 11 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/components/chatmessage.cpp b/src/components/chatmessage.cpp index 89c924e..3afdf9f 100644 --- a/src/components/chatmessage.cpp +++ b/src/components/chatmessage.cpp @@ -150,8 +150,8 @@ void ChatMessageItemContainer::UpdateAttributes() { void ChatMessageItemContainer::AddClickHandler(Gtk::Widget *widget, const std::string &url) { // clang-format off - widget->signal_button_press_event().connect([url](GdkEventButton *event) -> bool { - if (event->type == GDK_BUTTON_PRESS && event->button == GDK_BUTTON_PRIMARY) { + widget->signal_button_release_event().connect([url](GdkEventButton *event) -> bool { + if (event->type == GDK_BUTTON_RELEASE && event->button == GDK_BUTTON_PRIMARY) { LaunchBrowser(url); return true; } @@ -357,8 +357,8 @@ Gtk::Widget *ChatMessageItemContainer::CreateEmbedComponent(const EmbedData &emb if (embed.URL.has_value()) { AddPointerCursor(*title_ev); auto url = *embed.URL; - title_ev->signal_button_press_event().connect([url = std::move(url)](GdkEventButton *event) -> bool { - if (event->button == GDK_BUTTON_PRIMARY) { + title_ev->signal_button_release_event().connect([url = std::move(url)](GdkEventButton *event) -> bool { + if (event->type == GDK_BUTTON_RELEASE && event->button == GDK_BUTTON_PRIMARY) { LaunchBrowser(url); return true; } diff --git a/src/windows/guildsettings/infopane.cpp b/src/windows/guildsettings/infopane.cpp index 578aaac..a27c1a8 100644 --- a/src/windows/guildsettings/infopane.cpp +++ b/src/windows/guildsettings/infopane.cpp @@ -56,10 +56,9 @@ GuildSettingsInfoPane::GuildSettingsInfoPane(Snowflake id) guild_icon_url = guild.GetIconURL("gif", "512"); else guild_icon_url = guild.GetIconURL("png", "512"); - m_guild_icon_ev.signal_button_press_event().connect([guild_icon_url](GdkEventButton *event) -> bool { - if (event->type == GDK_BUTTON_PRESS) - if (event->button == GDK_BUTTON_PRIMARY) - LaunchBrowser(guild_icon_url); + m_guild_icon_ev.signal_button_release_event().connect([guild_icon_url](GdkEventButton *event) -> bool { + if (event->type == GDK_BUTTON_RELEASE && event->button == GDK_BUTTON_PRIMARY) + LaunchBrowser(guild_icon_url); return false; }); diff --git a/src/windows/profile/userinfopane.cpp b/src/windows/profile/userinfopane.cpp index a17dbff..b62da93 100644 --- a/src/windows/profile/userinfopane.cpp +++ b/src/windows/profile/userinfopane.cpp @@ -41,13 +41,13 @@ ConnectionItem::ConnectionItem(const ConnectionData &conn) m_box.add(m_name); if (!url.empty()) { auto cb = [url](GdkEventButton *event) -> bool { - if (event->type == GDK_BUTTON_PRESS && event->button == GDK_BUTTON_PRIMARY) { + if (event->type == GDK_BUTTON_RELEASE && event->button == GDK_BUTTON_PRIMARY) { LaunchBrowser(url); return true; } return false; }; - signal_button_press_event().connect(sigc::track_obj(cb, *this)); + signal_button_release_event().connect(sigc::track_obj(cb, *this)); AddPointerCursor(*this); } m_overlay.add(m_box); diff --git a/src/windows/profilewindow.cpp b/src/windows/profilewindow.cpp index aff98c5..d73731d 100644 --- a/src/windows/profilewindow.cpp +++ b/src/windows/profilewindow.cpp @@ -34,8 +34,8 @@ ProfileWindow::ProfileWindow(Snowflake user_id) if (user.HasAvatar()) AddPointerCursor(m_avatar_ev); - m_avatar_ev.signal_button_press_event().connect([user](GdkEventButton *event) -> bool { - if (event->type == GDK_BUTTON_PRESS && event->button == GDK_BUTTON_PRIMARY) { + m_avatar_ev.signal_button_release_event().connect([user](GdkEventButton *event) -> bool { + if (event->type == GDK_BUTTON_RELEASE && event->button == GDK_BUTTON_PRIMARY) { if (user.HasAnimatedAvatar()) LaunchBrowser(user.GetAvatarURL("gif", "512")); else -- cgit v1.2.3