Add simple check for updates mechanism using the info.plist in the repository. Update... v0.9.5
authorMiltiadis Vasilakis <mvasilak@gmail.com>
Sun, 15 Apr 2012 09:58:16 +0000 (12:58 +0300)
committerMiltiadis Vasilakis <mvasilak@gmail.com>
Sun, 15 Apr 2012 09:58:16 +0000 (12:58 +0300)
pithos-macos/en.lproj/MainMenu.xib
pithos-macos/pithos-macos-Info.plist
pithos-macos/pithos_macosAppDelegate.h
pithos-macos/pithos_macosAppDelegate.m

index f4f6ed2..812b027 100644 (file)
                                                                        <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">
index e2aaf40..b135d48 100644 (file)
@@ -17,7 +17,7 @@
        <key>CFBundlePackageType</key>
        <string>APPL</string>
        <key>CFBundleShortVersionString</key>
-       <string>0.9</string>
+       <string>0.9.5</string>
        <key>CFBundleSignature</key>
        <string>????</string>
        <key>CFBundleURLTypes</key>
                </dict>
        </array>
        <key>CFBundleVersion</key>
-       <string>20120410.0</string>
+       <string>20120415.0</string>
        <key>LSMinimumSystemVersion</key>
        <string>${MACOSX_DEPLOYMENT_TARGET}</string>
        <key>NSMainNibFile</key>
        <string>MainMenu</string>
        <key>NSPrincipalClass</key>
        <string>NSApplication</string>
+       <key>PithosDistributionURL</key>
+       <string>https://code.grnet.gr/projects/pithos-macos/files</string>
 </dict>
 </plist>
index 9798748..dc3731d 100644 (file)
@@ -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
index 5048895..acb89a0 100644 (file)
@@ -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