Skip to content

Commit

Permalink
Conditionally show release notes during startup
Browse files Browse the repository at this point in the history
  • Loading branch information
sorbits committed Sep 28, 2012
1 parent fcfec66 commit 7af2a71
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Applications/TextMate/src/AboutWindowController.h
@@ -1,3 +1,5 @@
@interface AboutWindowController : NSWindowController <NSWindowDelegate, NSToolbarDelegate>
+ (BOOL)shouldShowChangesWindow;
- (void)showAboutWindow:(id)sender;
- (void)showChangesWindow:(id)sender;
@end
37 changes: 37 additions & 0 deletions Applications/TextMate/src/AboutWindowController.mm
Expand Up @@ -2,6 +2,16 @@
#import <OakFoundation/NSString Additions.h>
#import <updater/updater.h>

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 =
// ============================
Expand Down Expand Up @@ -33,6 +43,23 @@ - (void)didClickToolbarItem:(id)sender;
@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];
Expand Down Expand Up @@ -88,6 +115,16 @@ - (void)showAboutWindow:(id)sender
[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 =
// ====================
Expand Down
6 changes: 6 additions & 0 deletions Applications/TextMate/src/AppController.mm
Expand Up @@ -53,6 +53,12 @@ - (void)setup
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
Expand Down

0 comments on commit 7af2a71

Please sign in to comment.