mirror of
https://github.com/textmate/textmate.git
synced 2026-01-21 04:38:13 -05:00
Conditionally show release notes during startup
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
@interface AboutWindowController : NSWindowController <NSWindowDelegate, NSToolbarDelegate>
|
||||
+ (BOOL)shouldShowChangesWindow;
|
||||
- (void)showAboutWindow:(id)sender;
|
||||
- (void)showChangesWindow:(id)sender;
|
||||
@end
|
||||
|
||||
@@ -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 =
|
||||
// ============================
|
||||
@@ -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 =
|
||||
// ====================
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user