diff --git a/Poedit.xcodeproj/project.pbxproj b/Poedit.xcodeproj/project.pbxproj index e82d0603f8..7debfbed93 100644 --- a/Poedit.xcodeproj/project.pbxproj +++ b/Poedit.xcodeproj/project.pbxproj @@ -77,7 +77,7 @@ 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.m in Sources */ = {isa = PBXBuildFile; fileRef = B28F1CCD16F629D30018AF7E /* macos_helpers.m */; }; + 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 */; }; @@ -408,7 +408,7 @@ B28F1CCA16F629D30018AF7E /* manager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; 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.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = macos_helpers.m; sourceTree = ""; }; + B28F1CCD16F629D30018AF7E /* macos_helpers.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = macos_helpers.mm; sourceTree = ""; }; B28F1CD016F629D30018AF7E /* prefsdlg.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; 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 = ""; }; @@ -704,7 +704,7 @@ B28F1CCA16F629D30018AF7E /* manager.cpp */, B28F1CCB16F629D30018AF7E /* manager.h */, B28F1CCC16F629D30018AF7E /* macos_helpers.h */, - B28F1CCD16F629D30018AF7E /* macos_helpers.m */, + B28F1CCD16F629D30018AF7E /* macos_helpers.mm */, B28F1CD016F629D30018AF7E /* prefsdlg.cpp */, B28F1CD116F629D30018AF7E /* prefsdlg.h */, B2A3637A1E4B9DC800E96253 /* pretranslate.cpp */, @@ -1364,7 +1364,7 @@ B28F1CF216F629D30018AF7E /* gexecute.cpp in Sources */, B2A3637C1E4B9DC800E96253 /* pretranslate.cpp in Sources */, B28F1CF516F629D30018AF7E /* manager.cpp in Sources */, - B28F1CF616F629D30018AF7E /* macos_helpers.m in Sources */, + B28F1CF616F629D30018AF7E /* macos_helpers.mm in Sources */, B240FFC719C6F1A600777AFE /* suggestions.cpp in Sources */, B2380F9A1A9B821200B7D8C9 /* crowdin_gui.cpp in Sources */, B28F1CF816F629D30018AF7E /* prefsdlg.cpp in Sources */, diff --git a/src/edapp.cpp b/src/edapp.cpp index 78713c63f6..90edf4f9ca 100644 --- a/src/edapp.cpp +++ b/src/edapp.cpp @@ -90,6 +90,9 @@ struct PoeditApp::NativeMacAppData NSMenu *menu = nullptr; NSMenuItem *menuItem = nullptr; wxMenuBar *menuBar = nullptr; +#ifdef USE_SPARKLE + NSObject *sparkleDelegate = nullptr; +#endif }; #endif @@ -456,7 +459,7 @@ bool PoeditApp::OnInit() #endif // !__WXOSX__ #ifdef USE_SPARKLE - Sparkle_Initialize(CheckForBetaUpdates()); + m_nativeMacAppData->sparkleDelegate = Sparkle_Initialize(); #endif // USE_SPARKLE #ifdef __WXMSW__ diff --git a/src/macos_helpers.h b/src/macos_helpers.h index d7b1925b70..43edc62892 100644 --- a/src/macos_helpers.h +++ b/src/macos_helpers.h @@ -29,13 +29,9 @@ // FIXME: This is a hack to work around Automake's lack of support for ObjC++. // Remove it after switching build system to Bakefile. -#ifdef __cplusplus -extern "C" { -#endif - #ifdef USE_SPARKLE // Sparkle helpers -void Sparkle_Initialize(bool checkForBeta); +NSObject *Sparkle_Initialize(); void Sparkle_AddMenuItem(NSMenu *appmenu, const char *title); void Sparkle_Cleanup(); #endif // USE_SPARKLE @@ -50,8 +46,4 @@ void MakeButtonRounded(void *button); void MoveToApplicationsFolderIfNecessary(); -#ifdef __cplusplus -} -#endif - #endif // Poedit_macos_helpers_h diff --git a/src/macos_helpers.m b/src/macos_helpers.mm similarity index 80% rename from src/macos_helpers.m rename to src/macos_helpers.mm index 39ff990d73..e89cad8c83 100644 --- a/src/macos_helpers.m +++ b/src/macos_helpers.mm @@ -25,6 +25,8 @@ #include "macos_helpers.h" +#include "edapp.h" + #import #import #import @@ -42,20 +44,46 @@ // Sparkle helpers // -------------------------------------------------------------------------------- -void Sparkle_Initialize(bool checkForBeta) +@interface PoeditSparkleDelegate : NSObject +@end + +@implementation PoeditSparkleDelegate + +- (NSArray *)feedParametersForUpdater:(SUUpdater *)updater sendingSystemProfile:(BOOL)sendingProfile +{ + #pragma unused(updater, sendingProfile) + if (wxGetApp().CheckForBetaUpdates()) + { + return @[ @{ + @"key": @"beta", + @"value": @"1", + @"displayKey": @"Beta Versions", + @"displayValue": @"Yes" + } ]; + } + else + { + return @[]; + } +} + +@end + + +NSObject *Sparkle_Initialize() { @autoreleasepool { + // Poedit < 2.0 stored this in preferences, which was wrong - it overrode + // changes to Info.plist. Undo the damage: + [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"SUFeedURL"]; + // For Preferences window, have default in sync with Info.plist: NSDictionary *sparkleDefaults = @{ @"SUEnableAutomaticChecks": @YES }; [[NSUserDefaults standardUserDefaults] registerDefaults:sparkleDefaults]; - SUUpdater *updater = [SUUpdater sharedUpdater]; - - /* TODO: Use feedParametersForUpdater delegate method and append ?beta=1 instead. - This code puts SUFeedURL into user defaults! */ - NSString *url = checkForBeta ? @"https://poedit.net/updates/osx/appcast/beta" - : @"https://poedit.net/updates/osx/appcast"; - [updater setFeedURL:[NSURL URLWithString:url]]; + NSObject *delegate = [PoeditSparkleDelegate new]; + SUUpdater.sharedUpdater.delegate = delegate; + return delegate; } } diff --git a/src/prefsdlg.cpp b/src/prefsdlg.cpp index 304d092af7..7cad6aae4e 100644 --- a/src/prefsdlg.cpp +++ b/src/prefsdlg.cpp @@ -954,7 +954,6 @@ class UpdatesPageWindow : public PrefsPanel } #ifdef USE_SPARKLE UserDefaults_SetBoolValue("SUEnableAutomaticChecks", m_updates->GetValue()); - Sparkle_Initialize(wxGetApp().CheckForBetaUpdates()); #endif }