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.
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 + PerformSwizzle(class, @selector(initWithDownload:mayOpenWhenDone:allowOverwrite:),
2.52 + @selector(myInitWithDownload:mayOpenWhenDone:allowOverwrite:),
2.53 + YES);
2.54 +
2.55 + Class webBookmarkClass = NSClassFromString(@"WebBookmark");
2.56 + if (webBookmarkClass)
2.57 + [[GSWebBookmark class] poseAsClass:webBookmarkClass];
2.58
2.59 - NSLog(@"Loaded GrowlSafari %@", [GrowlSafari bundleVersion]);
2.60 - NSDictionary *infoDictionary = [GrowlApplicationBridge frameworkInfoDictionary];
2.61 - NSLog(@"Using Growl.framework %@ (%@)",
2.62 - [infoDictionary objectForKey:@"CFBundleShortVersionString"],
2.63 - [infoDictionary objectForKey:(NSString *)kCFBundleVersionKey]);
2.64 + NSLog(@"Loaded GrowlSafari %@", [GrowlSafari bundleVersion]);
2.65 + NSDictionary *infoDictionary = [GrowlApplicationBridge frameworkInfoDictionary];
2.66 + NSLog(@"Using Growl.framework %@ (%@)",
2.67 + [infoDictionary objectForKey:@"CFBundleShortVersionString"],
2.68 + [infoDictionary objectForKey:(NSString *)kCFBundleVersionKey]);
2.69 + } else {
2.70 + NSLog(@"Safari too old (4.0 required); GrowlSafari disabled.");
2.71 + }
2.72 } else {
2.73 NSLog(@"Could not load Growl.framework, GrowlSafari disabled");
2.74 }
2.75 @@ -212,12 +224,12 @@
2.76
2.77 @implementation NSObject (GrowlSafariPatch)
2.78 - (void) mySetDownloadStage:(int)stage {
2.79 - int oldStage = [self downloadStage];
2.80 + //int oldStage = [self downloadStage];
2.81
2.82 //NSLog(@"mySetDownloadStage:%d -> %d", oldStage, stage);
2.83 [self mySetDownloadStage:stage];
2.84 if (dateStarted(self)) {
2.85 - if ( (safariVersion < SAFARI_VERSION_3_0 && stage == 2) || (safariVersion >= SAFARI_VERSION_3_0 && stage == 1) ) {
2.86 + if ( stage == GrowlSafariDownloadStageDecompressing ) {
2.87 NSBundle *bundle = [GrowlSafari bundle];
2.88 NSString *description = [[NSString alloc] initWithFormat:
2.89 NSLocalizedStringFromTableInBundle(@"%@", nil, bundle, @""),
2.90 @@ -230,13 +242,12 @@
2.91 isSticky:NO
2.92 clickContext:nil];
2.93 [description release];
2.94 - } else if ( (safariVersion < SAFARI_VERSION_3_0 && stage == 9 && oldStage != 9) ||
2.95 - (safariVersion >= SAFARI_VERSION_3_0 && stage == 8 && oldStage != 8) ) {
2.96 + } else if ( stage == GrowlSafariDownloadStageDiskImageVerifying ) {
2.97 NSBundle *bundle = [GrowlSafari bundle];
2.98 NSString *description = [[NSString alloc] initWithFormat:
2.99 - NSLocalizedStringFromTableInBundle(@"%@", nil, bundle, @""),
2.100 - [[self gsDownloadPath] lastPathComponent]];
2.101 - [GrowlApplicationBridge notifyWithTitle:NSLocalizedStringFromTableInBundle(@"Copying Disk Image", nil, bundle, @"")
2.102 + NSLocalizedStringFromTableInBundle(@"%@", nil, bundle, @""),
2.103 + [[self gsDownloadPath] lastPathComponent]];
2.104 + [GrowlApplicationBridge notifyWithTitle:NSLocalizedStringFromTableInBundle(@"Verifying Disk Image", nil, bundle, @"")
2.105 description:description
2.106 notificationName:NSLocalizedStringFromTableInBundle(@"Disk Image Status", nil, bundle, @"")
2.107 iconData:nil
2.108 @@ -244,9 +255,7 @@
2.109 isSticky:NO
2.110 clickContext:nil];
2.111 [description release];
2.112 - } else if ( (safariVersion < SAFARI_VERSION_2_0 && stage == 13) ||
2.113 - ((safariVersion >= SAFARI_VERSION_2_0 && safariVersion < SAFARI_VERSION_3_0) && stage == 15) ||
2.114 - (safariVersion >= SAFARI_VERSION_3_0 && stage == 13) ) {
2.115 + } else if ( stage == GrowlSafariDownloadStageFinished ) {
2.116 NSBundle *bundle = [GrowlSafari bundle];
2.117 NSString *notificationName = isLongDownload(self) ? NSLocalizedStringFromTableInBundle(@"Download Complete", nil, bundle, @"") : NSLocalizedStringFromTableInBundle(@"Short Download Complete", nil, bundle, @"");
2.118 setDownloadFinished(self);
2.119 @@ -262,7 +271,7 @@
2.120 clickContext:nil];
2.121 [description release];
2.122 }
2.123 - } else if (stage == 0) {
2.124 + } else if (stage == GrowlSafariDownloadStageActive) {
2.125 setDownloadStarted(self);
2.126 }
2.127 }
2.128 @@ -273,8 +282,8 @@
2.129 //NSLog(@"myUpdateDiskImageStatus:%@ stage=%d -> %d", status, oldStage, [self downloadStage]);
2.130
2.131 if (dateStarted(self)
2.132 - && ( (safariVersion < SAFARI_VERSION_3_0 && oldStage == 3) || (safariVersion >= SAFARI_VERSION_3_0 && oldStage == 7) )
2.133 - && [self downloadStage] == 8
2.134 + && oldStage == GrowlSafariDownloadStageDiskImageVerified
2.135 + && [self downloadStage] == GrowlSafariDownloadStageDiskImageMounting
2.136 && [[status objectForKey:@"status-stage"] isEqualToString:@"attach"]) {
2.137 NSBundle *bundle = [GrowlSafari bundle];
2.138 NSString *description = [[NSString alloc] initWithFormat:
2.139 @@ -299,10 +308,7 @@
2.140 }
2.141
2.142 - (NSString*) gsDownloadPath {
2.143 - if (safariVersion<SAFARI_VERSION_3_0)
2.144 - return [self downloadPath];
2.145 - else
2.146 - return [self currentPath];
2.147 + return [self currentPath];
2.148 }
2.149
2.150 @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";