From 5971a233375b0b549ec9e2b42f83fc73be8a9881 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Tue, 27 Feb 2024 18:14:56 +0100 Subject: [PATCH] app_updates for winsparkle --- Poedit.vcxproj | 2 + Poedit.vcxproj.filters | 6 +++ src/app_updates.cpp | 96 +++++++++++++++++++++++++++++++++++++++++- src/app_updates.h | 5 +++ src/edapp.cpp | 34 +-------------- src/edapp.h | 2 - src/prefsdlg.cpp | 15 ------- 7 files changed, 110 insertions(+), 50 deletions(-) diff --git a/Poedit.vcxproj b/Poedit.vcxproj index 7aef937d4f..c992f30660 100644 --- a/Poedit.vcxproj +++ b/Poedit.vcxproj @@ -107,6 +107,7 @@ + @@ -177,6 +178,7 @@ + diff --git a/Poedit.vcxproj.filters b/Poedit.vcxproj.filters index ba4f74c999..c78cd7bf16 100644 --- a/Poedit.vcxproj.filters +++ b/Poedit.vcxproj.filters @@ -207,6 +207,9 @@ Source Files + + Source Files + @@ -416,6 +419,9 @@ Header Files + + Header Files + diff --git a/src/app_updates.cpp b/src/app_updates.cpp index cc7b160d3f..64288a0628 100644 --- a/src/app_updates.cpp +++ b/src/app_updates.cpp @@ -27,12 +27,21 @@ #ifdef HAS_UPDATES_CHECK -#ifdef __WXOSX__ +#include "edapp.h" +#include "edframe.h" #include +#ifdef __WXOSX__ #import +#endif +#ifdef __WXMSW__ +#include +#endif + + +#ifdef __WXOSX__ @interface PoeditSparkleDelegate : NSObject @end @@ -129,6 +138,79 @@ class AppUpdates::impl #endif // __WXOSX__ +#ifdef __WXMSW__ + +class AppUpdates::impl +{ +public: + impl() {} + + ~impl() + { + win_sparkle_cleanup(); + } + + void Initialize() + { + if (Config::CheckForBetaUpdates()) + win_sparkle_set_appcast_url("https://poedit.net/updates_v2/win/appcast/beta"); + else + win_sparkle_set_appcast_url("https://poedit.net/updates_v2/win/appcast"); + + win_sparkle_set_can_shutdown_callback(&impl::WinSparkle_CanShutdown); + win_sparkle_set_shutdown_request_callback(&impl::WinSparkle_Shutdown); + auto buildnum = wxGetApp().GetAppBuildNumber(); + if (!buildnum.empty()) + win_sparkle_set_app_build_version(buildnum.wc_str()); + win_sparkle_init(); + } + + void SetLanguage(const std::string& lang) + { + win_sparkle_set_lang(lang.c_str()); + } + + void CheckForUpdatesWithUI() + { + win_sparkle_check_update_with_ui(); + } + + void EnableAutomaticChecks(bool enable) + { + if (enable) + SetupAppcastURL(); + win_sparkle_set_automatic_check_for_updates(enable); + } + + bool AutomaticChecksEnabled() const + { + return win_sparkle_get_automatic_check_for_updates(); + } + +private: + void SetupAppcastURL() + { + if (Config::CheckForBetaUpdates()) + win_sparkle_set_appcast_url("https://poedit.net/updates_v2/win/appcast/beta"); + else + win_sparkle_set_appcast_url("https://poedit.net/updates_v2/win/appcast"); + } + + // WinSparkle callbacks: + static int WinSparkle_CanShutdown() + { + return !PoeditFrame::AnyWindowIsModified(); + } + + static void WinSparkle_Shutdown() + { + wxCommandEvent evt(wxEVT_COMMAND_MENU_SELECTED, wxID_EXIT); + wxGetApp().AddPendingEvent(evt); + } +}; + +#endif // __WXMSW__ + // Boilerplate: @@ -173,6 +255,18 @@ bool AppUpdates::AutomaticChecksEnabled() const return m_impl->AutomaticChecksEnabled(); } +#ifdef __WXMSW__ +void AppUpdates::SetLanguage(const std::string& lang) +{ + m_impl->SetLanguage(lang); +} + +void AppUpdates::CheckForUpdatesWithUI() +{ + m_impl->CheckForUpdatesWithUI(); +} +#endif // __WXMSW__ + #ifdef __WXOSX__ void AppUpdates::AddMenuItem(wxMenu *appleMenu) { diff --git a/src/app_updates.h b/src/app_updates.h index 190e32987b..f342d1ec38 100644 --- a/src/app_updates.h +++ b/src/app_updates.h @@ -52,6 +52,11 @@ class AppUpdates void EnableAutomaticChecks(bool enable); bool AutomaticChecksEnabled() const; +#ifdef __WXMSW__ + void SetLanguage(const std::string& lang); + void CheckForUpdatesWithUI(); +#endif + #ifdef __WXOSX__ void AddMenuItem(wxMenu *appleMenu); #endif diff --git a/src/edapp.cpp b/src/edapp.cpp index 61c4c497da..e4e3d9fe8b 100644 --- a/src/edapp.cpp +++ b/src/edapp.cpp @@ -60,7 +60,6 @@ #ifdef __WXMSW__ #include #include -#include #endif #ifdef __WXGTK__ @@ -465,20 +464,6 @@ bool PoeditApp::OnInit() AppUpdates::Get().Initialize(); -#ifdef __WXMSW__ - if (CheckForBetaUpdates()) - win_sparkle_set_appcast_url("https://poedit.net/updates_v2/win/appcast/beta"); - else - win_sparkle_set_appcast_url("https://poedit.net/updates_v2/win/appcast"); - - win_sparkle_set_can_shutdown_callback(&PoeditApp::WinSparkle_CanShutdown); - win_sparkle_set_shutdown_request_callback(&PoeditApp::WinSparkle_Shutdown); - auto buildnum = GetAppBuildNumber(); - if (!buildnum.empty()) - win_sparkle_set_app_build_version(buildnum.wc_str()); - win_sparkle_init(); -#endif - #ifndef __WXOSX__ // NB: opening files or creating empty window is handled differently on // Macs, using MacOpenFiles() and MacNewFile(), so don't create empty @@ -549,10 +534,6 @@ int PoeditApp::OnExit() dispatch::cleanup(); -#ifdef __WXMSW__ - win_sparkle_cleanup(); -#endif - u_cleanup(); return wxApp::OnExit(); @@ -635,7 +616,7 @@ void PoeditApp::SetupLanguage() g_layoutDirection = info ? info->LayoutDirection : wxLayout_Default; #ifdef __WXMSW__ - win_sparkle_set_lang(bestTrans.utf8_str()); + AppUpdates::Get().SetLanguage(bestTrans.utf8_string()); #endif #ifdef SUPPORTS_OTA_UPDATES @@ -1395,18 +1376,7 @@ void PoeditApp::OnCloseWindowCommand(wxCommandEvent&) void PoeditApp::OnWinsparkleCheck(wxCommandEvent& event) { - win_sparkle_check_update_with_ui(); -} - -// WinSparkle callbacks: -int PoeditApp::WinSparkle_CanShutdown() -{ - return !PoeditFrame::AnyWindowIsModified(); -} - -void PoeditApp::WinSparkle_Shutdown() -{ - wxGetApp().OnQuit(wxCommandEvent()); + AppUpdates::Get().CheckForUpdatesWithUI(); } #endif // __WXMSW__ diff --git a/src/edapp.h b/src/edapp.h index 143d41f754..a8a41acf6a 100644 --- a/src/edapp.h +++ b/src/edapp.h @@ -127,8 +127,6 @@ class PoeditApp : public wxApp, public MenusManager #ifdef __WXMSW__ void OnWinsparkleCheck(wxCommandEvent& event); - static int WinSparkle_CanShutdown(); - static void WinSparkle_Shutdown(); #endif DECLARE_EVENT_TABLE() diff --git a/src/prefsdlg.cpp b/src/prefsdlg.cpp index f2c5e4937b..80b7131a8a 100644 --- a/src/prefsdlg.cpp +++ b/src/prefsdlg.cpp @@ -71,9 +71,6 @@ #include "customcontrols.h" #include "unicode_helpers.h" -#ifdef __WXMSW__ -#include -#endif // Handling of different page icons #ifdef __WXOSX__ @@ -1113,10 +1110,6 @@ class UpdatesPageWindow : public PrefsPanel { m_updates->SetValue(AppUpdates::Get().AutomaticChecksEnabled()); m_beta->SetValue(Config::CheckForBetaUpdates()); - -#ifdef __WXMSW__ - m_updates->SetValue(win_sparkle_get_automatic_check_for_updates() != 0); -#endif } void SaveValues(wxConfigBase&) override @@ -1124,14 +1117,6 @@ class UpdatesPageWindow : public PrefsPanel // NB: Must be done first, before calling AppUpdates methods! Config::CheckForBetaUpdates(m_beta->GetValue()); -#ifdef __WXMSW__ - win_sparkle_set_automatic_check_for_updates(m_updates->GetValue()); - // FIXME: don't duplicate this code from PoeditApp::OnInit() - if (m_beta->GetValue()) - win_sparkle_set_appcast_url("https://poedit.net/updates_v2/win/appcast/beta"); - else - win_sparkle_set_appcast_url("https://poedit.net/updates_v2/win/appcast"); -#endif AppUpdates::Get().EnableAutomaticChecks(m_beta->GetValue()); }