Skip to content

Commit

Permalink
Don't store Sparkle update feed in NSUserDefaults
Browse files Browse the repository at this point in the history
Don't modify the update URL at runtime depending on whether beta
updates are used or not. Instead, provide SUUpdaterDelegate
implementation that appends ?beta=1 in case of beta version.

Changing appcast feed URL would be impossible without this change.
  • Loading branch information
vslavik committed Mar 22, 2017
1 parent ec1affa commit 9b3a1a3
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 23 deletions.
8 changes: 4 additions & 4 deletions Poedit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -408,7 +408,7 @@
B28F1CCA16F629D30018AF7E /* manager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = manager.cpp; sourceTree = "<group>"; };
B28F1CCB16F629D30018AF7E /* manager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = manager.h; sourceTree = "<group>"; };
B28F1CCC16F629D30018AF7E /* macos_helpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = macos_helpers.h; sourceTree = "<group>"; };
B28F1CCD16F629D30018AF7E /* macos_helpers.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = macos_helpers.m; sourceTree = "<group>"; };
B28F1CCD16F629D30018AF7E /* macos_helpers.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = macos_helpers.mm; sourceTree = "<group>"; };
B28F1CD016F629D30018AF7E /* prefsdlg.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = prefsdlg.cpp; sourceTree = "<group>"; };
B28F1CD116F629D30018AF7E /* prefsdlg.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = prefsdlg.h; sourceTree = "<group>"; };
B28F1CD216F629D30018AF7E /* progressinfo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = progressinfo.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down
5 changes: 4 additions & 1 deletion src/edapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ struct PoeditApp::NativeMacAppData
NSMenu *menu = nullptr;
NSMenuItem *menuItem = nullptr;
wxMenuBar *menuBar = nullptr;
#ifdef USE_SPARKLE
NSObject *sparkleDelegate = nullptr;
#endif
};
#endif

Expand Down Expand Up @@ -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__
Expand Down
10 changes: 1 addition & 9 deletions src/macos_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -50,8 +46,4 @@ void MakeButtonRounded(void *button);

void MoveToApplicationsFolderIfNecessary();

#ifdef __cplusplus
}
#endif

#endif // Poedit_macos_helpers_h
44 changes: 36 additions & 8 deletions src/macos_helpers.m → src/macos_helpers.mm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

#include "macos_helpers.h"

#include "edapp.h"

#import <Foundation/NSString.h>
#import <Foundation/NSUserDefaults.h>
#import <Foundation/NSAutoreleasePool.h>
Expand All @@ -42,20 +44,46 @@
// Sparkle helpers
// --------------------------------------------------------------------------------

void Sparkle_Initialize(bool checkForBeta)
@interface PoeditSparkleDelegate : NSObject <SUUpdaterDelegate>
@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<SUUpdaterDelegate> *delegate = [PoeditSparkleDelegate new];
SUUpdater.sharedUpdater.delegate = delegate;
return delegate;
}
}

Expand Down
1 change: 0 additions & 1 deletion src/prefsdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,6 @@ class UpdatesPageWindow : public PrefsPanel
}
#ifdef USE_SPARKLE
UserDefaults_SetBoolValue("SUEnableAutomaticChecks", m_updates->GetValue());
Sparkle_Initialize(wxGetApp().CheckForBetaUpdates());
#endif
}

Expand Down

0 comments on commit 9b3a1a3

Please sign in to comment.