diff --git a/Poedit.xcodeproj/project.pbxproj b/Poedit.xcodeproj/project.pbxproj index cd639d690c..93470c392d 100644 --- a/Poedit.xcodeproj/project.pbxproj +++ b/Poedit.xcodeproj/project.pbxproj @@ -120,7 +120,6 @@ B28F1CF116F629D30018AF7E /* findframe.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B28F1CC216F629D30018AF7E /* findframe.cpp */; }; B28F1CF216F629D30018AF7E /* gexecute.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B28F1CC416F629D30018AF7E /* gexecute.cpp */; }; B28F1CF516F629D30018AF7E /* manager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B28F1CCA16F629D30018AF7E /* manager.cpp */; }; - B28F1CF616F629D30018AF7E /* macos_helpers.mm in Sources */ = {isa = PBXBuildFile; fileRef = B28F1CCD16F629D30018AF7E /* macos_helpers.mm */; }; B28F1CF816F629D30018AF7E /* prefsdlg.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B28F1CD016F629D30018AF7E /* prefsdlg.cpp */; }; B28F1CF916F629D30018AF7E /* progressinfo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B28F1CD216F629D30018AF7E /* progressinfo.cpp */; }; B28F1CFA16F629D30018AF7E /* propertiesdlg.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B28F1CD416F629D30018AF7E /* propertiesdlg.cpp */; }; @@ -202,6 +201,7 @@ B2EC60A41812D9D40059756A /* icudt57l.dat in Resources */ = {isa = PBXBuildFile; fileRef = B2EC60A31812D9D40059756A /* icudt57l.dat */; }; B2F25F0D199E327C00127FF9 /* spellchecking.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B2F25F0C199E327C00127FF9 /* spellchecking.cpp */; }; B2F287C0170DCC63004C1F41 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B248B2DF170D765100EBA58E /* CoreFoundation.framework */; }; + B2F3C2912B891644008E0593 /* app_updates.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B2F3C28F2B891644008E0593 /* app_updates.cpp */; }; B2FE296B1AC85FFF005588E4 /* keytar_mac.cc in Sources */ = {isa = PBXBuildFile; fileRef = B2FE29691AC85FFF005588E4 /* keytar_mac.cc */; }; /* End PBXBuildFile section */ @@ -470,8 +470,6 @@ B28F1CC516F629D30018AF7E /* gexecute.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = gexecute.h; sourceTree = ""; }; B28F1CCA16F629D30018AF7E /* manager.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; path = manager.cpp; sourceTree = ""; }; B28F1CCB16F629D30018AF7E /* manager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = manager.h; sourceTree = ""; }; - B28F1CCC16F629D30018AF7E /* macos_helpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = macos_helpers.h; sourceTree = ""; }; - B28F1CCD16F629D30018AF7E /* macos_helpers.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = macos_helpers.mm; sourceTree = ""; }; B28F1CD016F629D30018AF7E /* prefsdlg.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; path = prefsdlg.cpp; sourceTree = ""; }; B28F1CD116F629D30018AF7E /* prefsdlg.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = prefsdlg.h; sourceTree = ""; }; B28F1CD216F629D30018AF7E /* progressinfo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = progressinfo.cpp; sourceTree = ""; }; @@ -618,6 +616,8 @@ B2EC60A31812D9D40059756A /* icudt57l.dat */ = {isa = PBXFileReference; lastKnownFileType = file; name = icudt57l.dat; path = deps/icu4c/source/data/in/icudt57l.dat; sourceTree = ""; }; B2F25F0B199E23B300127FF9 /* spellchecking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = spellchecking.h; sourceTree = ""; }; B2F25F0C199E327C00127FF9 /* spellchecking.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; path = spellchecking.cpp; sourceTree = ""; }; + B2F3C28F2B891644008E0593 /* app_updates.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; path = app_updates.cpp; sourceTree = ""; }; + B2F3C2902B891644008E0593 /* app_updates.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = app_updates.h; sourceTree = ""; }; B2F672D6197A83F900DBFDB0 /* da */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = da; path = da.lproj/MoveApplication.strings; sourceTree = ""; }; B2F672D7197A83FE00DBFDB0 /* de */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/MoveApplication.strings; sourceTree = ""; }; B2F672D8197A840400DBFDB0 /* es */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/MoveApplication.strings; sourceTree = ""; }; @@ -758,6 +758,8 @@ isa = PBXGroup; children = ( B25504A51A2201CC00EE2CEE /* Native */, + B2F3C28F2B891644008E0593 /* app_updates.cpp */, + B2F3C2902B891644008E0593 /* app_updates.h */, B28F1CB116F629D30018AF7E /* attentionbar.cpp */, B28F1CB216F629D30018AF7E /* attentionbar.h */, B28F1CD616F629D30018AF7E /* cat_update.cpp */, @@ -813,8 +815,6 @@ B28F1CCB16F629D30018AF7E /* manager.h */, B26E2C8425A24541008D6DF1 /* menus.cpp */, B26E2C8525A24541008D6DF1 /* menus.h */, - B28F1CCC16F629D30018AF7E /* macos_helpers.h */, - B28F1CCD16F629D30018AF7E /* macos_helpers.mm */, B28F1CD016F629D30018AF7E /* prefsdlg.cpp */, B28F1CD116F629D30018AF7E /* prefsdlg.h */, B2A3637A1E4B9DC800E96253 /* pretranslate.cpp */, @@ -1515,6 +1515,7 @@ B25504A81A2201E800EE2CEE /* main_toolbar.cpp in Sources */, B2D52B8F1DEC785700E27B35 /* custom_buttons.cpp in Sources */, B28F1CE616F629D30018AF7E /* catalog.cpp in Sources */, + B2F3C2912B891644008E0593 /* app_updates.cpp in Sources */, B2C21633251906CC002B144A /* recent_files.cpp in Sources */, B28602441DDB279400FCA617 /* colorscheme.cpp in Sources */, B28F1CE716F629D30018AF7E /* edapp.cpp in Sources */, @@ -1548,7 +1549,6 @@ B2A3637C1E4B9DC800E96253 /* pretranslate.cpp in Sources */, B28F1CF516F629D30018AF7E /* manager.cpp in Sources */, B212FEED20A7356300FAC68F /* pl_evaluate.cpp in Sources */, - B28F1CF616F629D30018AF7E /* macos_helpers.mm in Sources */, B240FFC719C6F1A600777AFE /* suggestions.cpp in Sources */, B2BC828B20A1F0DC007652D6 /* catalog_po.cpp in Sources */, B2380F9A1A9B821200B7D8C9 /* crowdin_gui.cpp in Sources */, @@ -1967,7 +1967,7 @@ "-licudata", "-licui18n", ); - POEDIT_FEATURES = "USE_SPARKLE HAVE_CLD2 HAVE_HTTP_CLIENT"; + POEDIT_FEATURES = "HAVE_CLD2 HAVE_HTTP_CLIENT"; PRODUCT_BUNDLE_IDENTIFIER = "net.poedit.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; @@ -1991,7 +1991,7 @@ "-licudata", "-licui18n", ); - POEDIT_FEATURES = "USE_SPARKLE HAVE_CLD2 HAVE_HTTP_CLIENT"; + POEDIT_FEATURES = "HAVE_CLD2 HAVE_HTTP_CLIENT"; PRODUCT_BUNDLE_IDENTIFIER = "net.poedit.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; diff --git a/src/macos_helpers.mm b/src/app_updates.cpp similarity index 57% rename from src/macos_helpers.mm rename to src/app_updates.cpp index 3fe6c6e66c..cc7b160d3f 100644 --- a/src/macos_helpers.mm +++ b/src/app_updates.cpp @@ -1,7 +1,7 @@ /* * This file is part of Poedit (https://poedit.net) * - * Copyright (C) 2007-2023 Vaclav Slavik + * Copyright (C) 2024 Vaclav Slavik * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -19,30 +19,20 @@ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. + * DEALINGS IN THE SOFTWARE. * */ -#include "macos_helpers.h" +#include "app_updates.h" -#include "edapp.h" +#ifdef HAS_UPDATES_CHECK -#import -#import -#import +#ifdef __WXOSX__ -#import -#import -#import +#include -#import "PFMoveApplication.h" - -#ifdef USE_SPARKLE #import -// -------------------------------------------------------------------------------- -// Sparkle helpers -// -------------------------------------------------------------------------------- @interface PoeditSparkleDelegate : NSObject @end @@ -52,7 +42,7 @@ @implementation PoeditSparkleDelegate - (NSArray *)feedParametersForUpdater:(SUUpdater *)updater sendingSystemProfile:(BOOL)sendingProfile { #pragma unused(updater, sendingProfile) - if (wxGetApp().CheckForBetaUpdates()) + if (Config::CheckForBetaUpdates()) { return @[ @{ @"key": @"beta", @@ -70,9 +60,19 @@ - (NSArray *)feedParametersForUpdater:(SUUpdater *)updater sendingSystemProfile: @end -NSObject *Sparkle_Initialize() +class AppUpdates::impl { - @autoreleasepool { +public: + impl() {} + + ~impl() + { + // Make sure that Sparkle's updates to plist preferences are saved: + [[NSUserDefaults standardUserDefaults] synchronize]; + } + + void Initialize() + { // Poedit < 2.0 stored this in preferences, which was wrong - it overrode // changes to Info.plist. Undo the damage: [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"SUFeedURL"]; @@ -81,79 +81,103 @@ - (NSArray *)feedParametersForUpdater:(SUUpdater *)updater sendingSystemProfile: NSDictionary *sparkleDefaults = @{ @"SUEnableAutomaticChecks": @YES }; [[NSUserDefaults standardUserDefaults] registerDefaults:sparkleDefaults]; - NSObject *delegate = [PoeditSparkleDelegate new]; - SUUpdater.sharedUpdater.delegate = delegate; - return delegate; + m_sparkleDelegate = [PoeditSparkleDelegate new]; + SUUpdater.sharedUpdater.delegate = m_sparkleDelegate; } -} + void EnableAutomaticChecks(bool enable) + { + SetBoolValue("SUEnableAutomaticChecks", enable); + } -void Sparkle_AddMenuItem(NSMenu *appmenu, const char *title) -{ - @autoreleasepool { - NSString *nstitle = [NSString stringWithUTF8String: title]; + bool AutomaticChecksEnabled() const + { + return GetBoolValue("SUEnableAutomaticChecks"); + } + + void AddMenuItem(wxMenu *appleMenu) + { + NSString *nstitle = [NSString stringWithUTF8String: _(L"Check for Updates…").utf8_str()]; NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:nstitle action:@selector(checkForUpdates:) keyEquivalent:@""]; SUUpdater *updater = [SUUpdater sharedUpdater]; [item setEnabled:YES]; [item setTarget:updater]; - [appmenu insertItem:item atIndex:1]; + [appleMenu->GetHMenu() insertItem:item atIndex:1]; } -} +private: + bool GetBoolValue(const char *key) const + { + NSString *nskey = [NSString stringWithUTF8String: key]; + return (bool)[[NSUserDefaults standardUserDefaults] boolForKey:nskey]; + } -void Sparkle_Cleanup() -{ - /* Make sure that Sparkle's updates to plist preferences are saved: */ - @autoreleasepool { + void SetBoolValue(const char *key, int value) + { + NSString *nskey = [NSString stringWithUTF8String: key]; + + [[NSUserDefaults standardUserDefaults] setBool:value forKey:nskey]; [[NSUserDefaults standardUserDefaults] synchronize]; } -} -#endif // USE_SPARKLE +private: + NSObject *m_sparkleDelegate = nullptr; +}; + +#endif // __WXOSX__ -// -------------------------------------------------------------------------------- -// Native preferences -// -------------------------------------------------------------------------------- -int UserDefaults_GetBoolValue(const char *key) + +// Boilerplate: + +namespace { - @autoreleasepool { - NSString *nskey = [NSString stringWithUTF8String: key]; - return [[NSUserDefaults standardUserDefaults] boolForKey:nskey]; - } + static std::once_flag initializationFlag; + AppUpdates* gs_instance = nullptr; } - -void UserDefaults_SetBoolValue(const char *key, int value) +AppUpdates& AppUpdates::Get() { - @autoreleasepool { - NSString *nskey = [NSString stringWithUTF8String: key]; + std::call_once(initializationFlag, []() { + gs_instance = new AppUpdates; + }); + return *gs_instance; +} - [[NSUserDefaults standardUserDefaults] setBool:value forKey:nskey]; - [[NSUserDefaults standardUserDefaults] synchronize]; +void AppUpdates::CleanUp() +{ + if (gs_instance) + { + delete gs_instance; + gs_instance = nullptr; } } +AppUpdates::AppUpdates() : m_impl(new impl) {} +AppUpdates::~AppUpdates() {} -void UserDefaults_RemoveValue(const char *key) +void AppUpdates::Initialize() { - @autoreleasepool { - NSString *nskey = [NSString stringWithUTF8String: key]; - - [[NSUserDefaults standardUserDefaults] removeObjectForKey:nskey]; - [[NSUserDefaults standardUserDefaults] synchronize]; - } + m_impl->Initialize(); } +void AppUpdates::EnableAutomaticChecks(bool enable) +{ + m_impl->EnableAutomaticChecks(enable); +} -// -------------------------------------------------------------------------------- -// Misc UI helpers -// -------------------------------------------------------------------------------- +bool AppUpdates::AutomaticChecksEnabled() const +{ + return m_impl->AutomaticChecksEnabled(); +} -void MoveToApplicationsFolderIfNecessary() +#ifdef __WXOSX__ +void AppUpdates::AddMenuItem(wxMenu *appleMenu) { - PFMoveToApplicationsFolderIfNecessary(); + m_impl->AddMenuItem(appleMenu); } +#endif +#endif // HAS_UPDATES_CHECK diff --git a/src/macos_helpers.h b/src/app_updates.h similarity index 54% rename from src/macos_helpers.h rename to src/app_updates.h index 5495eb673e..190e32987b 100644 --- a/src/macos_helpers.h +++ b/src/app_updates.h @@ -1,7 +1,7 @@ /* * This file is part of Poedit (https://poedit.net) * - * Copyright (C) 2007-2023 Vaclav Slavik + * Copyright (C) 2024 Vaclav Slavik * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -19,29 +19,51 @@ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. + * DEALINGS IN THE SOFTWARE. * */ -#ifndef Poedit_macos_helpers_h -#define Poedit_macos_helpers_h +#ifndef Poedit_app_updates_h +#define Poedit_app_updates_h -// FIXME: This is a hack to work around Automake's lack of support for ObjC++. -// Remove it after switching build system to Bakefile. +#if defined(__WXMSW__) || defined(__WXOSX__) + #define HAS_UPDATES_CHECK +#endif -#ifdef USE_SPARKLE -// Sparkle helpers -NSObject *Sparkle_Initialize(); -void Sparkle_AddMenuItem(NSMenu *appmenu, const char *title); -void Sparkle_Cleanup(); -#endif // USE_SPARKLE +class WXDLLIMPEXP_FWD_CORE wxMenu; -// Native preferences -void UserDefaults_SetBoolValue(const char *key, int value); -int UserDefaults_GetBoolValue(const char *key); -void UserDefaults_RemoveValue(const char *key); +#include -// Misc UI helpers -void MoveToApplicationsFolderIfNecessary(); +#ifdef HAS_UPDATES_CHECK -#endif // Poedit_macos_helpers_h +/// Management of app updates. +class AppUpdates +{ +public: + /// Return singleton instance of the manager. + static AppUpdates& Get(); + + // Initialize and start checking for updates (if allowed by the user). + void Initialize(); + + /// Destroys the singleton, must be called (only) on app shutdown. + static void CleanUp(); + + void EnableAutomaticChecks(bool enable); + bool AutomaticChecksEnabled() const; + +#ifdef __WXOSX__ + void AddMenuItem(wxMenu *appleMenu); +#endif + +private: + AppUpdates(); + ~AppUpdates(); + + class impl; + std::unique_ptr m_impl; +}; + +#endif // HAS_UPDATES_CHECK + +#endif // Poedit_app_updates_h diff --git a/src/attentionbar.cpp b/src/attentionbar.cpp index d1618572ed..85e5947e12 100644 --- a/src/attentionbar.cpp +++ b/src/attentionbar.cpp @@ -42,10 +42,6 @@ #include #include -#ifdef __WXOSX__ -#include "macos_helpers.h" -#endif - #ifdef __WXOSX__ #define SMALL_BORDER PX(7) #define BUTTONS_SPACE PX(10) diff --git a/src/configuration.h b/src/configuration.h index 9888913f3e..26cf54586e 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -57,6 +57,9 @@ class Config static bool UseTM() { return Read("/use_tm", true); } static void UseTM(bool use) { Write("/use_tm", use); } + static bool CheckForBetaUpdates() { return Read("/check_for_beta_updates", false); } + static void CheckForBetaUpdates(bool use) { Write("/check_for_beta_updates", use); } + static ::PretranslateSettings PretranslateSettings(); static void PretranslateSettings(::PretranslateSettings s); diff --git a/src/edapp.cpp b/src/edapp.cpp index 38853cec43..fadc3ddec6 100644 --- a/src/edapp.cpp +++ b/src/edapp.cpp @@ -54,7 +54,7 @@ #include #ifdef __WXOSX__ -#include "macos_helpers.h" +#import "PFMoveApplication.h" #endif #ifdef __WXMSW__ @@ -75,6 +75,7 @@ #error "Unicode build of wxWidgets is required by Poedit" #endif +#include "app_updates.h" #include "colorscheme.h" #include "concurrency.h" #include "configuration.h" @@ -106,9 +107,6 @@ #ifdef __WXOSX__ struct PoeditApp::NativeMacAppData { -#ifdef USE_SPARKLE - NSObject *sparkleDelegate = nullptr; -#endif }; #endif @@ -325,11 +323,6 @@ wxString PoeditApp::GetAppBuildNumber() const #endif } -bool PoeditApp::CheckForBetaUpdates() const -{ - return wxConfigBase::Get()->ReadBool("check_for_beta_updates", false); -} - #ifndef __WXOSX__ static wxArrayString gs_filesToOpen; @@ -385,7 +378,7 @@ bool PoeditApp::OnInit() InitHiDPIHandling(); #ifdef __WXOSX__ - MoveToApplicationsFolderIfNecessary(); + PFMoveToApplicationsFolderIfNecessary(); wxSystemOptions::SetOption(wxMAC_TEXTCONTROL_USE_SPELL_CHECKER, 1); @@ -470,10 +463,6 @@ bool PoeditApp::OnInit() s_macHelpMenuTitleName = _("&Help"); #endif -#ifdef USE_SPARKLE - m_nativeMacAppData->sparkleDelegate = Sparkle_Initialize(); -#endif // USE_SPARKLE - #ifdef __WXMSW__ if (CheckForBetaUpdates()) win_sparkle_set_appcast_url("https://poedit.net/updates_v2/win/appcast/beta"); @@ -550,6 +539,7 @@ int PoeditApp::OnExit() ColorScheme::CleanUp(); RecentFiles::CleanUp(); TranslationMemory::CleanUp(); + AppUpdates::CleanUp(); #ifdef HAVE_HTTP_CLIENT CloudAccountClient::CleanUp(); @@ -557,9 +547,6 @@ int PoeditApp::OnExit() dispatch::cleanup(); -#ifdef USE_SPARKLE - Sparkle_Cleanup(); -#endif // USE_SPARKLE #ifdef __WXMSW__ win_sparkle_cleanup(); #endif diff --git a/src/edapp.h b/src/edapp.h index 0097721771..143d41f754 100644 --- a/src/edapp.h +++ b/src/edapp.h @@ -65,7 +65,6 @@ class PoeditApp : public wxApp, public MenusManager wxString GetAppVersion() const; // e.g. "3.4.2" wxString GetMajorAppVersion() const; // e.g. "3.4" wxString GetAppBuildNumber() const; - bool CheckForBetaUpdates() const; // opens files in new frame, returns count of succesfully opened int OpenFiles(const wxArrayString& filenames, int lineno = 0); diff --git a/src/edframe.cpp b/src/edframe.cpp index f8945aa501..0c1acc44e8 100644 --- a/src/edframe.cpp +++ b/src/edframe.cpp @@ -49,7 +49,6 @@ #ifdef __WXOSX__ #import -#include "macos_helpers.h" #endif #include diff --git a/src/menus.cpp b/src/menus.cpp index 320b7f49c8..3d5bcbf3d7 100644 --- a/src/menus.cpp +++ b/src/menus.cpp @@ -25,10 +25,7 @@ #include "menus.h" -#ifdef __WXOSX__ -#include "macos_helpers.h" -#endif - +#include "app_updates.h" #include "recent_files.h" #include "str_helpers.h" @@ -142,9 +139,7 @@ void MenusManager::TweakOSXMenuBar(wxMenuBar *bar) apple->InsertSeparator(3); } -#if USE_SPARKLE - Sparkle_AddMenuItem(apple->GetHMenu(), _(L"Check for Updates…").utf8_str()); -#endif + AppUpdates::Get().AddMenuItem(apple); if (@available(macOS 13.0, *)) { diff --git a/src/prefsdlg.cpp b/src/prefsdlg.cpp index c0a04b9ec3..f2c5e4937b 100644 --- a/src/prefsdlg.cpp +++ b/src/prefsdlg.cpp @@ -52,6 +52,7 @@ #include #include +#include "app_updates.h" #include "edapp.h" #include "edframe.h" #include "catalog.h" @@ -74,14 +75,6 @@ #include #endif -#ifdef USE_SPARKLE -#include "macos_helpers.h" -#endif // USE_SPARKLE - -#if defined(USE_SPARKLE) || defined(__WXMSW__) - #define HAS_UPDATES_CHECK -#endif - // Handling of different page icons #ifdef __WXOSX__ inline wxBitmap MacPageIcon(const char *macos10, const char *macos11) @@ -1118,18 +1111,19 @@ class UpdatesPageWindow : public PrefsPanel void InitValues(const wxConfigBase&) override { -#ifdef USE_SPARKLE - m_updates->SetValue((bool)UserDefaults_GetBoolValue("SUEnableAutomaticChecks")); -#endif + 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 - m_beta->SetValue(wxGetApp().CheckForBetaUpdates()); } - void SaveValues(wxConfigBase& cfg) override + void SaveValues(wxConfigBase&) override { - cfg.Write("check_for_beta_updates", m_beta->GetValue()); + // 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() @@ -1138,9 +1132,7 @@ class UpdatesPageWindow : public PrefsPanel else win_sparkle_set_appcast_url("https://poedit.net/updates_v2/win/appcast"); #endif -#ifdef USE_SPARKLE - UserDefaults_SetBoolValue("SUEnableAutomaticChecks", m_updates->GetValue()); -#endif + AppUpdates::Get().EnableAutomaticChecks(m_beta->GetValue()); } private: