From 7af2a71de0a541af80fc6c586eb773f9ce1705ff Mon Sep 17 00:00:00 2001 From: Allan Odgaard Date: Sat, 29 Sep 2012 00:38:40 +0200 Subject: [PATCH] Conditionally show release notes during startup --- .../TextMate/src/AboutWindowController.h | 2 + .../TextMate/src/AboutWindowController.mm | 37 +++++++++++++++++++ Applications/TextMate/src/AppController.mm | 6 +++ 3 files changed, 45 insertions(+) diff --git a/Applications/TextMate/src/AboutWindowController.h b/Applications/TextMate/src/AboutWindowController.h index 10bdbc6c..659d66b2 100644 --- a/Applications/TextMate/src/AboutWindowController.h +++ b/Applications/TextMate/src/AboutWindowController.h @@ -1,3 +1,5 @@ @interface AboutWindowController : NSWindowController ++ (BOOL)shouldShowChangesWindow; - (void)showAboutWindow:(id)sender; +- (void)showChangesWindow:(id)sender; @end diff --git a/Applications/TextMate/src/AboutWindowController.mm b/Applications/TextMate/src/AboutWindowController.mm index 214cd5ee..d30fc1c6 100644 --- a/Applications/TextMate/src/AboutWindowController.mm +++ b/Applications/TextMate/src/AboutWindowController.mm @@ -2,6 +2,16 @@ #import #import +static NSString* const kUserDefaultsReleaseNotesDigestKey = @"releaseNotesDigest"; + +static NSData* Digest (NSString* someString) +{ + char const* str = [someString UTF8String]; + char md[SHA_DIGEST_LENGTH]; + CC_SHA1((unsigned char*)str, strlen(str), (unsigned char*)md); + return [NSData dataWithBytes:md length:sizeof(md)]; +} + // ============================ // = JavaScript Bridge Object = // ============================ @@ -33,6 +43,23 @@ @end @implementation AboutWindowController ++ (BOOL)shouldShowChangesWindow +{ + NSURL* url = [[NSBundle mainBundle] URLForResource:@"Changes" withExtension:@"html"]; + if(NSString* releaseNotes = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:NULL]) + { + NSData* lastDigest = [[NSUserDefaults standardUserDefaults] dataForKey:kUserDefaultsReleaseNotesDigestKey]; + NSData* currentDigest = Digest(releaseNotes); + if(lastDigest) + { + if(![lastDigest isEqualToData:currentDigest]) + return YES; + } + [[NSUserDefaults standardUserDefaults] setObject:currentDigest forKey:kUserDefaultsReleaseNotesDigestKey]; + } + return NO; +} + - (id)init { NSRect visibleRect = [[NSScreen mainScreen] visibleFrame]; @@ -88,6 +115,16 @@ [self showWindow:self]; } +- (void)showChangesWindow:(id)sender +{ + [self didClickToolbarItem:@"Changes"]; + [self showWindow:self]; + + NSURL* url = [[NSBundle mainBundle] URLForResource:@"Changes" withExtension:@"html"]; + if(NSString* releaseNotes = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:NULL]) + [[NSUserDefaults standardUserDefaults] setObject:Digest(releaseNotes) forKey:kUserDefaultsReleaseNotesDigestKey]; +} + // ==================== // = Toolbar Delegate = // ==================== diff --git a/Applications/TextMate/src/AppController.mm b/Applications/TextMate/src/AppController.mm index 32b0be3b..29151454 100644 --- a/Applications/TextMate/src/AppController.mm +++ b/Applications/TextMate/src/AppController.mm @@ -53,6 +53,12 @@ void OakOpenDocuments (NSArray* paths) spellingMenu.delegate = self; [NSApp setDelegate:self]; + + if([AboutWindowController shouldShowChangesWindow]) + { + self.aboutWindowController = [[[AboutWindowController alloc] init] autorelease]; + [self.aboutWindowController performSelector:@selector(showChangesWindow:) withObject:self afterDelay:0]; + } } - (IBAction)newDocumentAndActivate:(id)sender