Show
Ignore:
Timestamp:
07/29/08 16:35:01 (4 months ago)
Author:
astrange
Message:

Delete progress indicators from the prefpane, they're ugly and pointless.
Get rid of alert panels in the update checker and use IPC to show them in the prefpane instead.
Fix the update checker never cleaning up its locks.
Synchronize user defaults more often since it seems necessary.
Delete code for not running too often in the update checker, it's a duplicate of the same more-maintained code in Perian.

This requires merging the nib into release branch again...

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Update Checker Sources/UpdateCheckerAppDelegate.h

    r624 r917  
    1818#define UPDATE_URL_KEY @"UpdateFeedURL" 
    1919#define SKIPPED_VERSION_KEY @"SkippedVersion" 
     20#define UPDATE_STATUS_NOTIFICATION @"org.perian.UpdateCheckStatus" 
    2021#define TIME_INTERVAL_TIL_NEXT_RUN 7*24*60*60 
    2122 
  • trunk/Update Checker Sources/UpdateCheckerAppDelegate.m

    r913 r917  
    3535        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
    3636        lastRunDate = [[defaults objectForKey:NEXT_RUN_KEY] retain]; 
    37         if (lastRunDate == nil || [lastRunDate laterDate:[NSDate date]] != lastRunDate) { 
    38                 //this means we should in fact run 
    39                 [defaults setObject:[NSDate dateWithTimeIntervalSinceNow:TIME_INTERVAL_TIL_NEXT_RUN] forKey:NEXT_RUN_KEY]; 
    40                 manualRun = [defaults boolForKey:MANUAL_RUN_KEY]; 
    41                 [defaults removeObjectForKey:MANUAL_RUN_KEY]; 
    42                 [self doUpdateCheck]; 
    43         } else { 
    44                 //another instance was already started and therefore we don't need to do this again 
    45                 [[NSApplication sharedApplication] terminate:self]; 
    46         } 
     37         
     38        [defaults setObject:[NSDate dateWithTimeIntervalSinceNow:TIME_INTERVAL_TIL_NEXT_RUN] forKey:NEXT_RUN_KEY]; 
     39        manualRun = [defaults boolForKey:MANUAL_RUN_KEY]; 
     40        [defaults removeObjectForKey:MANUAL_RUN_KEY]; 
     41        [defaults synchronize]; 
     42        [self doUpdateCheck]; 
    4743} 
    4844 
     
    5652        updateUrlString = [[updateUrlString substringToIndex:[updateUrlString length]-4] stringByAppendingFormat:@"-%@.xml", betaAppcastUrl]; 
    5753#endif 
     54        if(manualRun) 
     55                [[NSDistributedNotificationCenter defaultCenter] postNotificationName:UPDATE_STATUS_NOTIFICATION object:@"Starting"]; 
    5856         
    5957        SUAppcast *appcast = [[SUAppcast alloc] init]; 
     
    8179    NSString *panePath = [[[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent] stringByDeletingLastPathComponent] stringByDeletingLastPathComponent]; 
    8280        updateAvailable = (updateAvailable && (SUStandardVersionComparison([latest fileVersion], [[NSBundle bundleWithPath:panePath] objectForInfoDictionaryKey:@"CFBundleVersion"]) == NSOrderedAscending)); 
     81         
     82        if (![panePath isEqualToString:@"Perian.prefPane"]) { 
     83                NSLog(@"The update checker needs to be run from inside the preference pane, quitting..."); 
     84                updateAvailable = 0; 
     85        } 
     86         
    8387        NSString *skippedVersion = [[NSUserDefaults standardUserDefaults] objectForKey:SKIPPED_VERSION_KEY]; 
    8488        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
    8589        if (updateAvailable && (!skippedVersion ||  
    8690                (skippedVersion && ![skippedVersion isEqualToString:[latest versionString]]))) { 
     91                if(manualRun) 
     92                        [[NSDistributedNotificationCenter defaultCenter] postNotificationName:UPDATE_STATUS_NOTIFICATION object:@"YesUpdates"]; 
    8793                [self showUpdatePanelForItem:latest]; 
    8894        } else { 
    8995                if(manualRun) 
    90                         NSRunAlertPanel(SULocalizedString(@"No Update Found!", nil), SULocalizedString(@"Your copy of Perian is up to date", nil), nil, nil, nil)
     96                        [[NSDistributedNotificationCenter defaultCenter] postNotificationName:UPDATE_STATUS_NOTIFICATION object:@"NoUpdates"]
    9197                [[NSApplication sharedApplication] terminate:self]; 
    9298        } 
     
    99105        [self updateFailed]; 
    100106        if(manualRun) 
    101                 [self showUpdateErrorAlertWithInfo:SULocalizedString(@"An error occurred while trying to load Perian's version info. Please try again later.", nil)]; 
     107                [[NSDistributedNotificationCenter defaultCenter] postNotificationName:UPDATE_STATUS_NOTIFICATION object:@"Error"]; 
    102108    [appcast release]; 
    103109        [[NSApplication sharedApplication] terminate:self];      
  • trunk/Update Checker Sources/main.m

    r913 r917  
    1313#define lockPath "/tmp/PerianUpdateLock" 
    1414 
     15static int fp = -1; 
     16 
     17static void deleteLock() 
     18{ 
     19        close(fp); 
     20        unlink(lockPath); 
     21} 
     22 
    1523int main(int argc, char *argv[]) 
    1624{ 
    17         int fp = open(lockPath, O_CREAT | O_EXCL); 
     25        fp = open(lockPath, O_CREAT | O_EXCL); 
    1826        if(fp == -1) 
    1927        { 
     
    3139        if(fp == -1) 
    3240                return 0; 
     41         
     42        atexit(deleteLock); 
    3343 
    3444        int ret = NSApplicationMain(argc,  (const char **) argv); 
    3545         
    36     close(fp); 
    37         unlink(lockPath); 
    38          
    3946        return ret; 
    4047}