From: Miltiadis Vasilakis Date: Sun, 15 Apr 2012 09:58:16 +0000 (+0300) Subject: Add simple check for updates mechanism using the info.plist in the repository. Update... X-Git-Tag: v0.9.5 X-Git-Url: https://code.grnet.gr/git/pithos-macos/commitdiff_plain/66aeb3c9111493f1b4674f6a4550887b59dd68d8 Add simple check for updates mechanism using the info.plist in the repository. Update version. --- diff --git a/pithos-macos/en.lproj/MainMenu.xib b/pithos-macos/en.lproj/MainMenu.xib index f4f6ed2..812b027 100644 --- a/pithos-macos/en.lproj/MainMenu.xib +++ b/pithos-macos/en.lproj/MainMenu.xib @@ -97,6 +97,25 @@ + + + Check for Updates... + + 2147483647 + + + + + + YES + YES + + + 1048576 + 2147483647 + + + Services @@ -703,6 +722,14 @@ 622 + + menuCheckForUpdates: + + + + 629 + + enabled: delegate.alwaysNo @@ -799,6 +826,22 @@ 619 + + + enabled: checkForUpdatesNotRunning + + + + + + enabled: checkForUpdatesNotRunning + enabled + checkForUpdatesNotRunning + 2 + + + 630 + @@ -923,6 +966,8 @@ + + @@ -1182,6 +1227,16 @@ + + 626 + + + + + 627 + + + @@ -1238,6 +1293,8 @@ 606.IBPluginDependency 607.IBPluginDependency 623.IBPluginDependency + 626.IBPluginDependency + 627.IBPluginDependency 73.IBPluginDependency 74.IBPluginDependency 77.IBPluginDependency @@ -1313,6 +1370,8 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin @@ -1327,99 +1386,9 @@ - 625 - - - - YES - - pithos_macosAppDelegate - NSObject - - YES - - YES - showPithosAbout: - showPithosBrowser: - showPithosPreferences: - - - YES - id - id - id - - - - YES - - YES - showPithosAbout: - showPithosBrowser: - showPithosPreferences: - - - YES - - showPithosAbout: - id - - - showPithosBrowser: - id - - - showPithosPreferences: - id - - - - - YES - - YES - accountsMenu - lastSyncMenu - statusMenu - - - YES - NSMenu - NSMenu - NSMenu - - - - YES - - YES - accountsMenu - lastSyncMenu - statusMenu - - - YES - - accountsMenu - NSMenu - - - lastSyncMenu - NSMenu - - - statusMenu - NSMenu - - - - - IBProjectSource - ./Classes/pithos_macosAppDelegate.h - - - + 630 + 0 IBCocoaFramework diff --git a/pithos-macos/pithos-macos-Info.plist b/pithos-macos/pithos-macos-Info.plist index e2aaf40..b135d48 100644 --- a/pithos-macos/pithos-macos-Info.plist +++ b/pithos-macos/pithos-macos-Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.9 + 0.9.5 CFBundleSignature ???? CFBundleURLTypes @@ -32,12 +32,14 @@ CFBundleVersion - 20120410.0 + 20120415.0 LSMinimumSystemVersion ${MACOSX_DEPLOYMENT_TARGET} NSMainNibFile MainMenu NSPrincipalClass NSApplication + PithosDistributionURL + https://code.grnet.gr/projects/pithos-macos/files diff --git a/pithos-macos/pithos_macosAppDelegate.h b/pithos-macos/pithos_macosAppDelegate.h index 9798748..dc3731d 100644 --- a/pithos-macos/pithos_macosAppDelegate.h +++ b/pithos-macos/pithos_macosAppDelegate.h @@ -67,6 +67,9 @@ PithosAccount *syncPithosAccount; NSTimeInterval activityFacilityTimeInterval; + + BOOL checkForUpdatesNotRunning; + BOOL checkForUpdatesCalledFromMenu; } @property (nonatomic, readonly) PithosBrowserController *pithosBrowserController; @@ -80,6 +83,7 @@ @property (nonatomic, readonly) NSMutableDictionary *pithosAccountsDictionary; @property (nonatomic, retain) PithosAccount *syncPithosAccount; @property (nonatomic, readonly) NSTimeInterval activityFacilityTimeInterval; +@property (nonatomic, assign) BOOL checkForUpdatesNotRunning; - (void)handleAppleEvent:(NSAppleEventDescriptor *)event withReplyEvent: (NSAppleEventDescriptor *)replyEvent; - (IBAction)showPithosBrowser:(id)sender; @@ -88,5 +92,6 @@ - (void)sync; - (void)savePithosAccounts:(id)sender; - (void)removedPithosAccount:(PithosAccount *)removedPithosAccount; +- (IBAction)menuCheckForUpdates:(NSMenuItem *)sender; @end diff --git a/pithos-macos/pithos_macosAppDelegate.m b/pithos-macos/pithos_macosAppDelegate.m index 5048895..acb89a0 100644 --- a/pithos-macos/pithos_macosAppDelegate.m +++ b/pithos-macos/pithos_macosAppDelegate.m @@ -46,7 +46,7 @@ @implementation pithos_macosAppDelegate @synthesize pithosBrowserController, pithosPreferencesController, alwaysNo, openAtLoginEnabled, openAtLogin, activated, -currentPithosAccount, pithosAccounts, pithosAccountsDictionary, syncPithosAccount, activityFacilityTimeInterval; +currentPithosAccount, pithosAccounts, pithosAccountsDictionary, syncPithosAccount, activityFacilityTimeInterval, checkForUpdatesNotRunning; - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { [[NSAppleEventManager sharedAppleEventManager] setEventHandler:self @@ -117,6 +117,11 @@ currentPithosAccount, pithosAccounts, pithosAccountsDictionary, syncPithosAccoun userInfo:nil repeats:YES] retain]; [syncTimer fire]; + + @synchronized(self) { + self.checkForUpdatesNotRunning = YES; + } + [self checkForUpdates]; } // Based on: http://cocoatutorial.grapewave.com/2010/01/creating-a-status-bar-application/ @@ -458,6 +463,79 @@ void LSSharedFileListChanged(LSSharedFileListRef inList, void *context) { self.syncPithosAccount = nil; } +- (void)checkForUpdates { + @synchronized(self) { + if (!checkForUpdatesNotRunning) + return; + self.checkForUpdatesNotRunning = NO; + } + ASIHTTPRequest *checkForUpdatesRequest = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"https://code.grnet.gr/projects/pithos-macos/repository/revisions/master/raw/pithos-macos/pithos-macos-Info.plist"]]; + checkForUpdatesRequest.delegate = self; + checkForUpdatesRequest.didFinishSelector = @selector(checkForUpdatesRequestFinished:); + checkForUpdatesRequest.didFailSelector = @selector(checkForUpdatesRequestFailed:); + checkForUpdatesRequest.timeOutSeconds = 60; + checkForUpdatesRequest.numberOfTimesToRetryOnTimeout = 10; + [checkForUpdatesRequest startAsynchronous]; +} + +#pragma mark - +#pragma mark ASIHTTPRequestDelegate + +- (void)checkForUpdatesRequestFinished:(ASIHTTPRequest *)request { + if (request.responseStatusCode == 200) { + NSError *error; + NSDictionary *plistDictionary = [NSPropertyListSerialization propertyListWithData:[request.responseString dataUsingEncoding:NSUTF8StringEncoding] + options:NSPropertyListImmutable + format:NULL + error:&error]; + if (!error) { + NSString *currentVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]; + NSString *newVersion = [plistDictionary objectForKey:@"CFBundleVersion"]; + NSURL *distributionURL = [NSURL URLWithString:[plistDictionary objectForKey:@"PithosDistributionURL"]]; + if (newVersion && currentVersion && distributionURL && ([newVersion doubleValue] > [currentVersion doubleValue])) { + NSAlert *alert = [[[NSAlert alloc] init] autorelease]; + [alert setMessageText:@"Updates Available"]; + [alert setInformativeText:@"An updated version is available"]; + [alert addButtonWithTitle:@"Download"]; + [alert runModal]; + [[NSWorkspace sharedWorkspace] openURL:distributionURL]; + } else if (checkForUpdatesCalledFromMenu) { + NSAlert *alert = [[[NSAlert alloc] init] autorelease]; + [alert setMessageText:@"No Updates Available"]; + [alert setInformativeText:@"You are running the latest version"]; + [alert addButtonWithTitle:@"OK"]; + [alert runModal]; + checkForUpdatesCalledFromMenu = NO; + } + [NSTimer scheduledTimerWithTimeInterval:86400 + target:self + selector:@selector(checkForUpdates) + userInfo:nil + repeats:YES]; + self.checkForUpdatesNotRunning = YES; + return; + } + NSLog(@"Check for update plist error: %@", error); + } +} + +- (void)checkForUpdatesRequestFailed:(ASIHTTPRequest *)request { + if (checkForUpdatesCalledFromMenu) { + NSAlert *alert = [[[NSAlert alloc] init] autorelease]; + [alert setMessageText:@"Check for Updates Error"]; + [alert setInformativeText:@"Cannot check for updates now, try again later"]; + [alert addButtonWithTitle:@"OK"]; + [alert runModal]; + checkForUpdatesCalledFromMenu = NO; + } + [NSTimer scheduledTimerWithTimeInterval:600 + target:self + selector:@selector(checkForUpdates) + userInfo:nil + repeats:YES]; + self.checkForUpdatesNotRunning = YES; +} + #pragma mark - #pragma mark Menu Actions @@ -492,4 +570,11 @@ void LSSharedFileListChanged(LSSharedFileListRef inList, void *context) { // [self savePithosAccounts:self]; //} +- (IBAction)menuCheckForUpdates:(NSMenuItem *)sender { + @synchronized(self) { + checkForUpdatesCalledFromMenu = YES; + } + [self checkForUpdates]; +} + @end