Fix GrowlSafari under Safari 4 by updating the download stage numbers. For simplicity and ease of fixage, I've ripped out all the Safari 2 and 3 support—GrowlSafari requires Safari 4 now. For clarity, I've also added an enumeration to name all the stages.
authorPeter Hosey <hg@boredzo.org>
Thu Jul 02 06:31:09 2009 -0700 (2009-07-02)
changeset 4226a6eb28fcc0b7
parent 4225 22ffbf7ae378
child 4230 7de4cf9ccf4d
Fix GrowlSafari under Safari 4 by updating the download stage numbers. For simplicity and ease of fixage, I've ripped out all the Safari 2 and 3 support—GrowlSafari requires Safari 4 now. For clarity, I've also added an enumeration to name all the stages.
Extras/GrowlSafari/English.lproj/Localizable.strings
Extras/GrowlSafari/GrowlSafari.m
Extras/GrowlSafari/de.lproj/Localizable.strings
Extras/GrowlSafari/ja.lproj/Localizable.strings
Extras/GrowlSafari/nl.lproj/Localizable.strings
Extras/GrowlSafari/pt_BR.lproj/Localizable.strings
Extras/GrowlSafari/ru.lproj/Localizable.strings
Extras/GrowlSafari/sv.lproj/Localizable.strings
     1.1 --- a/Extras/GrowlSafari/English.lproj/Localizable.strings	Thu Jul 02 06:30:46 2009 -0700
     1.2 +++ b/Extras/GrowlSafari/English.lproj/Localizable.strings	Thu Jul 02 06:31:09 2009 -0700
     1.3 @@ -14,9 +14,6 @@
     1.4  "Compression Status" = "Compression Status";
     1.5  
     1.6  /* No comment provided by engineer. */
     1.7 -"Copying Disk Image" = "Copying Disk Image";
     1.8 -
     1.9 -/* No comment provided by engineer. */
    1.10  "Decompressing File" = "Decompressing File";
    1.11  
    1.12  /* No comment provided by engineer. */
     2.1 --- a/Extras/GrowlSafari/GrowlSafari.m	Thu Jul 02 06:30:46 2009 -0700
     2.2 +++ b/Extras/GrowlSafari/GrowlSafari.m	Thu Jul 02 06:31:09 2009 -0700
     2.3 @@ -34,8 +34,19 @@
     2.4  #import <objc/objc-runtime.h>
     2.5  
     2.6  
     2.7 -#define SAFARI_VERSION_2_0	412
     2.8 -#define SAFARI_VERSION_3_0  523
     2.9 +#define SAFARI_VERSION_4_0  5530
    2.10 +
    2.11 +enum {
    2.12 +	GrowlSafariDownloadStageActive = 1,
    2.13 +	GrowlSafariDownloadStageDecompressing = 2,
    2.14 +	GrowlSafariDownloadStageDiskImagePreparing = 4,
    2.15 +	GrowlSafariDownloadStageDiskImageVerifying = 7,
    2.16 +	GrowlSafariDownloadStageDiskImageVerified = 8,
    2.17 +	GrowlSafariDownloadStageDiskImageMounting = 9,
    2.18 +	GrowlSafariDownloadStageDiskImageCleanup = 12,
    2.19 +	GrowlSafariDownloadStageInactive = 13,
    2.20 +	GrowlSafariDownloadStageFinished = 14
    2.21 +};
    2.22  
    2.23  // How long should we wait (in seconds) before it's a long download?
    2.24  static double longDownload = 15.0;
    2.25 @@ -127,28 +138,29 @@
    2.26  		safariVersion = [[[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleVersionKey] intValue];
    2.27  		//  NSLog(@"%d",safariVersion);
    2.28  
    2.29 -		//	NSLog(@"Patching DownloadProgressEntry...");
    2.30 -		Class class = NSClassFromString(@"DownloadProgressEntry");
    2.31 -		PerformSwizzle(class, @selector(setDownloadStage:), @selector(mySetDownloadStage:), YES);
    2.32 -				
    2.33 -		if (safariVersion<SAFARI_VERSION_3_0) 
    2.34 -			PerformSwizzle(class, @selector(updateDiskImageStatus:), @selector(myUpdateDiskImageStatus:), YES);
    2.35 -		else
    2.36 +		if (safariVersion >= SAFARI_VERSION_4_0) {
    2.37 +			//	NSLog(@"Patching DownloadProgressEntry...");
    2.38 +			Class class = NSClassFromString(@"DownloadProgressEntry");
    2.39 +			PerformSwizzle(class, @selector(setDownloadStage:), @selector(mySetDownloadStage:), YES);
    2.40 +					
    2.41  			PerformSwizzle(class, @selector(_updateDiskImageStatus:), @selector(myUpdateDiskImageStatus:), YES);
    2.42 -		
    2.43 -		PerformSwizzle(class, @selector(initWithDownload:mayOpenWhenDone:allowOverwrite:),
    2.44 -					   @selector(myInitWithDownload:mayOpenWhenDone:allowOverwrite:),
    2.45 -					   YES);
    2.46 -		
    2.47 -		Class webBookmarkClass = NSClassFromString(@"WebBookmark");
    2.48 -		if (webBookmarkClass)
    2.49 -			[[GSWebBookmark class] poseAsClass:webBookmarkClass];
    2.50 -
    2.51 -		NSLog(@"Loaded GrowlSafari %@", [GrowlSafari bundleVersion]);
    2.52 -		NSDictionary *infoDictionary = [GrowlApplicationBridge frameworkInfoDictionary];
    2.53 -		NSLog(@"Using Growl.framework %@ (%@)",
    2.54 -			  [infoDictionary objectForKey:@"CFBundleShortVersionString"],
    2.55 -			  [infoDictionary objectForKey:(NSString *)kCFBundleVersionKey]);
    2.56 +			
    2.57 +			PerformSwizzle(class, @selector(initWithDownload:mayOpenWhenDone:allowOverwrite:),
    2.58 +						   @selector(myInitWithDownload:mayOpenWhenDone:allowOverwrite:),
    2.59 +						   YES);
    2.60 +			
    2.61 +			Class webBookmarkClass = NSClassFromString(@"WebBookmark");
    2.62 +			if (webBookmarkClass)
    2.63 +				[[GSWebBookmark class] poseAsClass:webBookmarkClass];
    2.64 +
    2.65 +			NSLog(@"Loaded GrowlSafari %@", [GrowlSafari bundleVersion]);
    2.66 +			NSDictionary *infoDictionary = [GrowlApplicationBridge frameworkInfoDictionary];
    2.67 +			NSLog(@"Using Growl.framework %@ (%@)",
    2.68 +				  [infoDictionary objectForKey:@"CFBundleShortVersionString"],
    2.69 +				  [infoDictionary objectForKey:(NSString *)kCFBundleVersionKey]);
    2.70 +		} else {
    2.71 +			NSLog(@"Safari too old (4.0 required); GrowlSafari disabled.");
    2.72 +		}
    2.73  	} else {
    2.74  		NSLog(@"Could not load Growl.framework, GrowlSafari disabled");
    2.75  	}
    2.76 @@ -212,12 +224,12 @@
    2.77  
    2.78  @implementation NSObject (GrowlSafariPatch)
    2.79  - (void) mySetDownloadStage:(int)stage {
    2.80 -	int oldStage = [self downloadStage];
    2.81 +	//int oldStage = [self downloadStage];
    2.82  	
    2.83  	//NSLog(@"mySetDownloadStage:%d -> %d", oldStage, stage);
    2.84  	[self mySetDownloadStage:stage];
    2.85  	if (dateStarted(self)) {
    2.86 -		if ( (safariVersion < SAFARI_VERSION_3_0 && stage == 2) || (safariVersion >= SAFARI_VERSION_3_0 && stage == 1) ) {
    2.87 +		if ( stage == GrowlSafariDownloadStageDecompressing ) {
    2.88  			NSBundle *bundle = [GrowlSafari bundle];
    2.89  			NSString *description = [[NSString alloc] initWithFormat:
    2.90  				NSLocalizedStringFromTableInBundle(@"%@", nil, bundle, @""),
    2.91 @@ -230,13 +242,12 @@
    2.92  										   isSticky:NO
    2.93  									   clickContext:nil];
    2.94  			[description release];
    2.95 -		} else if ( (safariVersion < SAFARI_VERSION_3_0 && stage == 9 && oldStage != 9) || 
    2.96 -			        (safariVersion >= SAFARI_VERSION_3_0 && stage == 8 && oldStage != 8) ) {
    2.97 +		} else if ( stage == GrowlSafariDownloadStageDiskImageVerifying ) {
    2.98  			NSBundle *bundle = [GrowlSafari bundle];
    2.99  			NSString *description = [[NSString alloc] initWithFormat:
   2.100 -				NSLocalizedStringFromTableInBundle(@"%@", nil, bundle, @""),
   2.101 -				[[self gsDownloadPath] lastPathComponent]];
   2.102 -			[GrowlApplicationBridge notifyWithTitle:NSLocalizedStringFromTableInBundle(@"Copying Disk Image", nil, bundle, @"")
   2.103 +									 NSLocalizedStringFromTableInBundle(@"%@", nil, bundle, @""),
   2.104 +									 [[self gsDownloadPath] lastPathComponent]];
   2.105 +			[GrowlApplicationBridge notifyWithTitle:NSLocalizedStringFromTableInBundle(@"Verifying Disk Image", nil, bundle, @"")
   2.106  										description:description
   2.107  								   notificationName:NSLocalizedStringFromTableInBundle(@"Disk Image Status", nil, bundle, @"")
   2.108  										   iconData:nil
   2.109 @@ -244,9 +255,7 @@
   2.110  										   isSticky:NO
   2.111  									   clickContext:nil];
   2.112  			[description release];
   2.113 -		} else if ( (safariVersion < SAFARI_VERSION_2_0 && stage == 13) || 
   2.114 -		            ((safariVersion >= SAFARI_VERSION_2_0 && safariVersion < SAFARI_VERSION_3_0) && stage == 15) ||
   2.115 -				    (safariVersion >= SAFARI_VERSION_3_0 && stage == 13) ) {
   2.116 +		} else if ( stage == GrowlSafariDownloadStageFinished ) {
   2.117  			NSBundle *bundle = [GrowlSafari bundle];
   2.118  			NSString *notificationName = isLongDownload(self) ? NSLocalizedStringFromTableInBundle(@"Download Complete", nil, bundle, @"") : NSLocalizedStringFromTableInBundle(@"Short Download Complete", nil, bundle, @"");
   2.119  			setDownloadFinished(self);
   2.120 @@ -262,7 +271,7 @@
   2.121  									   clickContext:nil];
   2.122  			[description release];
   2.123  		}
   2.124 -	} else if (stage == 0) {
   2.125 +	} else if (stage == GrowlSafariDownloadStageActive) {
   2.126  		setDownloadStarted(self);
   2.127  	}
   2.128  }
   2.129 @@ -273,8 +282,8 @@
   2.130  	//NSLog(@"myUpdateDiskImageStatus:%@ stage=%d -> %d", status, oldStage, [self downloadStage]);
   2.131  
   2.132  	if (dateStarted(self)
   2.133 -			&& ( (safariVersion < SAFARI_VERSION_3_0 && oldStage == 3) || (safariVersion >= SAFARI_VERSION_3_0 && oldStage == 7) )
   2.134 -			&& [self downloadStage] == 8
   2.135 +			&& oldStage == GrowlSafariDownloadStageDiskImageVerified
   2.136 +			&& [self downloadStage] == GrowlSafariDownloadStageDiskImageMounting
   2.137  			&& [[status objectForKey:@"status-stage"] isEqualToString:@"attach"]) {
   2.138  		NSBundle *bundle = [GrowlSafari bundle];
   2.139  		NSString *description = [[NSString alloc] initWithFormat:
   2.140 @@ -299,10 +308,7 @@
   2.141  }
   2.142  
   2.143  - (NSString*) gsDownloadPath {
   2.144 -	if (safariVersion<SAFARI_VERSION_3_0)
   2.145 -		return [self downloadPath];
   2.146 -	else
   2.147 -		return [self currentPath];
   2.148 +	return [self currentPath];
   2.149  }
   2.150  
   2.151  @end
     3.1 --- a/Extras/GrowlSafari/de.lproj/Localizable.strings	Thu Jul 02 06:30:46 2009 -0700
     3.2 +++ b/Extras/GrowlSafari/de.lproj/Localizable.strings	Thu Jul 02 06:31:09 2009 -0700
     3.3 @@ -12,4 +12,3 @@
     3.4  "%d new entry" = "%d neuer Eintrag";
     3.5  "Compression Status" = "Compression Status";
     3.6  "Decompressing File" = "Entpacke Datei";
     3.7 -"Copying Disk Image" = "Kopiere Disk Image";
     4.1 --- a/Extras/GrowlSafari/ja.lproj/Localizable.strings	Thu Jul 02 06:30:46 2009 -0700
     4.2 +++ b/Extras/GrowlSafari/ja.lproj/Localizable.strings	Thu Jul 02 06:31:09 2009 -0700
     4.3 @@ -11,4 +11,3 @@
     4.4  "%d new entry" = "%d new entry";
     4.5  "Compression Status" = "圧縮状況";
     4.6  "Decompressing File" = "ファイルの解凍中";
     4.7 -"Copying Disk Image" = "ディスクイメージのコピー";
     5.1 --- a/Extras/GrowlSafari/nl.lproj/Localizable.strings	Thu Jul 02 06:30:46 2009 -0700
     5.2 +++ b/Extras/GrowlSafari/nl.lproj/Localizable.strings	Thu Jul 02 06:31:09 2009 -0700
     5.3 @@ -20,9 +20,6 @@
     5.4  "Copying application from %@" = "Kopieert programma van %@";
     5.5  
     5.6  /* No comment provided by engineer. */
     5.7 -"Copying Disk Image" = "Kopieert schijfkopiebestand";
     5.8 -
     5.9 -/* No comment provided by engineer. */
    5.10  "Decompressing File" = "Decomprimeert bestand";
    5.11  
    5.12  /* No comment provided by engineer. */
     6.1 --- a/Extras/GrowlSafari/pt_BR.lproj/Localizable.strings	Thu Jul 02 06:30:46 2009 -0700
     6.2 +++ b/Extras/GrowlSafari/pt_BR.lproj/Localizable.strings	Thu Jul 02 06:31:09 2009 -0700
     6.3 @@ -12,4 +12,3 @@
     6.4  "%d new entry" = "%d nova entrada";
     6.5  "Compression Status" = "Estado da Compressão";
     6.6  "Decompressing File" = "Descomprimindo Arquivo";
     6.7 -"Copying Disk Image" = "Copiando imagem de disco";
     7.1 --- a/Extras/GrowlSafari/ru.lproj/Localizable.strings	Thu Jul 02 06:30:46 2009 -0700
     7.2 +++ b/Extras/GrowlSafari/ru.lproj/Localizable.strings	Thu Jul 02 06:31:09 2009 -0700
     7.3 @@ -13,8 +13,6 @@
     7.4  	<key>%d new entry</key>
     7.5  	<string>новое сообщение - %d</string>
     7.6  	<key>Compression Status</key>
     7.7 -	<string>Архивация</string>
     7.8 -	<key>Copying Disk Image</key>
     7.9  	<string>Копирую образ диска</string>
    7.10  	<key>Copying application from %@</key>
    7.11  	<string>Копирую приложение из %@</string>
     8.1 --- a/Extras/GrowlSafari/sv.lproj/Localizable.strings	Thu Jul 02 06:30:46 2009 -0700
     8.2 +++ b/Extras/GrowlSafari/sv.lproj/Localizable.strings	Thu Jul 02 06:31:09 2009 -0700
     8.3 @@ -12,4 +12,3 @@
     8.4  "%d new entry" = "%d ny post";
     8.5  "Compression Status" = "Komprimeringsstatus";
     8.6  "Decompressing File" = "Packar upp fil";
     8.7 -"Copying Disk Image" = "Kopierar skivavbild";