Skip to content

Commit

Permalink
UPDATES: Check that we're running in a bundle, and skip Sparkle initi…
Browse files Browse the repository at this point in the history
…alization otherwise

This was leading to an unhandled exception within Sparkle code
which was hanging the application. This feature is good only for development
purposes, as convenient users are supposed to run ScummVM from the
supplied bundle.
  • Loading branch information
sev- committed Apr 10, 2016
1 parent ef5e63a commit 6b2eab6
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions backends/updates/macosx/macosx-updates.mm
Expand Up @@ -49,14 +49,22 @@
*
*/
MacOSXUpdateManager::MacOSXUpdateManager() {
NSBundle* mainBundle = [NSBundle mainBundle];

NSString *version = [mainBundle objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey];
if (!version || [version isEqualToString:@""]) {
warning("Running not in bundle, skipping Sparkle initialization");

sparkleUpdater = nullptr;
return;
}

NSMenuItem *menuItem = [[NSApp mainMenu] itemAtIndex:0];
NSMenu *applicationMenu = [menuItem submenu];

// Init Sparkle
sparkleUpdater = [SUUpdater sharedUpdater];

NSBundle* mainBundle = [NSBundle mainBundle];

NSString* feedbackURL = [mainBundle objectForInfoDictionaryKey:@"SUFeedURL"];

// Set appcast URL
Expand Down Expand Up @@ -92,24 +100,36 @@
}

void MacOSXUpdateManager::checkForUpdates() {
if (sparkleUpdater == nullptr)
return;

[sparkleUpdater checkForUpdatesInBackground];
}

void MacOSXUpdateManager::setAutomaticallyChecksForUpdates(UpdateManager::UpdateState state) {
if (state == kUpdateStateNotSupported)
return;

if (sparkleUpdater == nullptr)
return;

[sparkleUpdater setAutomaticallyChecksForUpdates:(state == kUpdateStateEnabled ? YES : NO)];
}

Common::UpdateManager::UpdateState MacOSXUpdateManager::getAutomaticallyChecksForUpdates() {
if (sparkleUpdater == nullptr)
return kUpdateStateDisabled;

if ([sparkleUpdater automaticallyChecksForUpdates])
return kUpdateStateEnabled;
else
return kUpdateStateDisabled;
}

void MacOSXUpdateManager::setUpdateCheckInterval(int interval) {
if (sparkleUpdater == nullptr)
return;

if (interval == kUpdateIntervalNotSupported)
return;

Expand All @@ -119,6 +139,9 @@
}

int MacOSXUpdateManager::getUpdateCheckInterval() {
if (sparkleUpdater == nullptr)
return kUpdateIntervalOneDay;

// This is kind of a hack but necessary, as the value stored by Sparkle
// might have been changed outside of ScummVM (in which case we return the
// default interval of one day)
Expand All @@ -137,6 +160,9 @@
}

bool MacOSXUpdateManager::getLastUpdateCheckTimeAndDate(TimeDate &t) {
if (sparkleUpdater == nullptr)
return false;

NSDate *date = [sparkleUpdater lastUpdateCheckDate];
#ifdef MAC_OS_X_VERSION_10_10
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
Expand Down

0 comments on commit 6b2eab6

Please sign in to comment.