<reference key="NSOnImage" ref="35465992"/>
<reference key="NSMixedImage" ref="502551668"/>
</object>
+ <object class="NSMenuItem" id="97798140">
+ <reference key="NSMenu" ref="110575045"/>
+ <string key="NSTitle">Check for Updates...</string>
+ <string key="NSKeyEquiv"/>
+ <int key="NSMnemonicLoc">2147483647</int>
+ <reference key="NSOnImage" ref="35465992"/>
+ <reference key="NSMixedImage" ref="502551668"/>
+ </object>
+ <object class="NSMenuItem" id="150364400">
+ <reference key="NSMenu" ref="110575045"/>
+ <bool key="NSIsDisabled">YES</bool>
+ <bool key="NSIsSeparator">YES</bool>
+ <string key="NSTitle"/>
+ <string key="NSKeyEquiv"/>
+ <int key="NSKeyEquivModMask">1048576</int>
+ <int key="NSMnemonicLoc">2147483647</int>
+ <reference key="NSOnImage" ref="35465992"/>
+ <reference key="NSMixedImage" ref="502551668"/>
+ </object>
<object class="NSMenuItem" id="1046388886">
<reference key="NSMenu" ref="110575045"/>
<string key="NSTitle">Services</string>
<int key="connectionID">622</int>
</object>
<object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">menuCheckForUpdates:</string>
+ <reference key="source" ref="976324537"/>
+ <reference key="destination" ref="97798140"/>
+ </object>
+ <int key="connectionID">629</int>
+ </object>
+ <object class="IBConnectionRecord">
<object class="IBBindingConnection" key="connection">
<string key="label">enabled: delegate.alwaysNo</string>
<reference key="source" ref="629835270"/>
</object>
<int key="connectionID">619</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBBindingConnection" key="connection">
+ <string key="label">enabled: checkForUpdatesNotRunning</string>
+ <reference key="source" ref="97798140"/>
+ <reference key="destination" ref="976324537"/>
+ <object class="NSNibBindingConnector" key="connector">
+ <reference key="NSSource" ref="97798140"/>
+ <reference key="NSDestination" ref="976324537"/>
+ <string key="NSLabel">enabled: checkForUpdatesNotRunning</string>
+ <string key="NSBinding">enabled</string>
+ <string key="NSKeyPath">checkForUpdatesNotRunning</string>
+ <int key="NSNibBindingConnectorVersion">2</int>
+ </object>
+ </object>
+ <int key="connectionID">630</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
<reference ref="1046388886"/>
<reference ref="1056857174"/>
<reference ref="342932134"/>
+ <reference ref="150364400"/>
+ <reference ref="97798140"/>
</object>
<reference key="parent" ref="694149608"/>
</object>
<reference key="object" ref="1005268357"/>
<reference key="parent" ref="789758025"/>
</object>
+ <object class="IBObjectRecord">
+ <int key="objectID">626</int>
+ <reference key="object" ref="150364400"/>
+ <reference key="parent" ref="110575045"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">627</int>
+ <reference key="object" ref="97798140"/>
+ <reference key="parent" ref="110575045"/>
+ </object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
<string>606.IBPluginDependency</string>
<string>607.IBPluginDependency</string>
<string>623.IBPluginDependency</string>
+ <string>626.IBPluginDependency</string>
+ <string>627.IBPluginDependency</string>
<string>73.IBPluginDependency</string>
<string>74.IBPluginDependency</string>
<string>77.IBPluginDependency</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
</object>
</object>
<object class="NSMutableDictionary" key="unlocalizedProperties">
<reference key="dict.values" ref="0"/>
</object>
<nil key="sourceID"/>
- <int key="maxID">625</int>
- </object>
- <object class="IBClassDescriber" key="IBDocument.Classes">
- <object class="NSMutableArray" key="referencedPartialClassDescriptions">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <object class="IBPartialClassDescription">
- <string key="className">pithos_macosAppDelegate</string>
- <string key="superclassName">NSObject</string>
- <object class="NSMutableDictionary" key="actions">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <object class="NSArray" key="dict.sortedKeys">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <string>showPithosAbout:</string>
- <string>showPithosBrowser:</string>
- <string>showPithosPreferences:</string>
- </object>
- <object class="NSArray" key="dict.values">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <string>id</string>
- <string>id</string>
- <string>id</string>
- </object>
- </object>
- <object class="NSMutableDictionary" key="actionInfosByName">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <object class="NSArray" key="dict.sortedKeys">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <string>showPithosAbout:</string>
- <string>showPithosBrowser:</string>
- <string>showPithosPreferences:</string>
- </object>
- <object class="NSArray" key="dict.values">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <object class="IBActionInfo">
- <string key="name">showPithosAbout:</string>
- <string key="candidateClassName">id</string>
- </object>
- <object class="IBActionInfo">
- <string key="name">showPithosBrowser:</string>
- <string key="candidateClassName">id</string>
- </object>
- <object class="IBActionInfo">
- <string key="name">showPithosPreferences:</string>
- <string key="candidateClassName">id</string>
- </object>
- </object>
- </object>
- <object class="NSMutableDictionary" key="outlets">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <object class="NSArray" key="dict.sortedKeys">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <string>accountsMenu</string>
- <string>lastSyncMenu</string>
- <string>statusMenu</string>
- </object>
- <object class="NSArray" key="dict.values">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <string>NSMenu</string>
- <string>NSMenu</string>
- <string>NSMenu</string>
- </object>
- </object>
- <object class="NSMutableDictionary" key="toOneOutletInfosByName">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <object class="NSArray" key="dict.sortedKeys">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <string>accountsMenu</string>
- <string>lastSyncMenu</string>
- <string>statusMenu</string>
- </object>
- <object class="NSArray" key="dict.values">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <object class="IBToOneOutletInfo">
- <string key="name">accountsMenu</string>
- <string key="candidateClassName">NSMenu</string>
- </object>
- <object class="IBToOneOutletInfo">
- <string key="name">lastSyncMenu</string>
- <string key="candidateClassName">NSMenu</string>
- </object>
- <object class="IBToOneOutletInfo">
- <string key="name">statusMenu</string>
- <string key="candidateClassName">NSMenu</string>
- </object>
- </object>
- </object>
- <object class="IBClassDescriptionSource" key="sourceIdentifier">
- <string key="majorKey">IBProjectSource</string>
- <string key="minorKey">./Classes/pithos_macosAppDelegate.h</string>
- </object>
- </object>
- </object>
+ <int key="maxID">630</int>
</object>
+ <object class="IBClassDescriber" key="IBDocument.Classes"/>
<int key="IBDocument.localizationMode">0</int>
<string key="IBDocument.TargetRuntimeIdentifier">IBCocoaFramework</string>
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDevelopmentDependencies">
@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
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/
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
// [self savePithosAccounts:self];
//}
+- (IBAction)menuCheckForUpdates:(NSMenuItem *)sender {
+ @synchronized(self) {
+ checkForUpdatesCalledFromMenu = YES;
+ }
+ [self checkForUpdates];
+}
+
@end