mirror of
https://github.com/textmate/textmate.git
synced 2026-04-28 03:00:34 -04:00
Rework about window
We now perform the content hash (to see if release notes have changed) on a background thread.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
@interface AboutWindowController : NSWindowController <NSWindowDelegate, NSToolbarDelegate>
|
||||
+ (BOOL)shouldShowChangesWindow;
|
||||
@interface AboutWindowController : NSWindowController
|
||||
+ (AboutWindowController*)sharedInstance;
|
||||
+ (void)showChangesIfUpdated;
|
||||
- (void)showAboutWindow:(id)sender;
|
||||
- (void)showChangesWindow:(id)sender;
|
||||
@end
|
||||
|
||||
@@ -49,28 +49,36 @@ static NSData* Digest (NSString* someString)
|
||||
|
||||
// ============================
|
||||
|
||||
@interface AboutWindowController ()
|
||||
@interface AboutWindowController () <NSWindowDelegate, NSToolbarDelegate>
|
||||
@property (nonatomic, strong) NSToolbar* toolbar;
|
||||
@property (nonatomic, strong) WebView* webView;
|
||||
@property (nonatomic) NSString* selectedPage;
|
||||
@end
|
||||
|
||||
@implementation AboutWindowController
|
||||
+ (BOOL)shouldShowChangesWindow
|
||||
+ (AboutWindowController*)sharedInstance
|
||||
{
|
||||
static AboutWindowController* instance = [AboutWindowController new];
|
||||
return instance;
|
||||
}
|
||||
|
||||
+ (void)showChangesIfUpdated
|
||||
{
|
||||
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)
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
|
||||
if(NSString* releaseNotes = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:NULL])
|
||||
{
|
||||
if(![lastDigest isEqualToData:currentDigest])
|
||||
return YES;
|
||||
NSData* lastDigest = [[NSUserDefaults standardUserDefaults] dataForKey:kUserDefaultsReleaseNotesDigestKey];
|
||||
NSData* currentDigest = Digest(releaseNotes);
|
||||
if(lastDigest && ![lastDigest isEqualToData:currentDigest])
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[[AboutWindowController sharedInstance] showChangesWindow:self];
|
||||
});
|
||||
}
|
||||
[[NSUserDefaults standardUserDefaults] setObject:currentDigest forKey:kUserDefaultsReleaseNotesDigestKey];
|
||||
}
|
||||
[[NSUserDefaults standardUserDefaults] setObject:currentDigest forKey:kUserDefaultsReleaseNotesDigestKey];
|
||||
}
|
||||
return NO;
|
||||
});
|
||||
}
|
||||
|
||||
- (id)init
|
||||
|
||||
@@ -79,7 +79,6 @@ BOOL HasDocumentWindow (NSArray* windows)
|
||||
|
||||
@interface AppController ()
|
||||
@property (nonatomic) OakFilterWindowController* filterWindowController;
|
||||
@property (nonatomic) AboutWindowController* aboutWindowController;
|
||||
@property (nonatomic) BOOL didFinishLaunching;
|
||||
@end
|
||||
|
||||
@@ -179,8 +178,6 @@ BOOL HasDocumentWindow (NSArray* windows)
|
||||
[NSURL URLWithString:REST_API @"/releases/nightly"], kSoftwareUpdateChannelNightly,
|
||||
nil]];
|
||||
|
||||
[TerminalPreferences updateMateIfRequired];
|
||||
|
||||
[self userDefaultsDidChange:nil]; // setup mate/rmate server
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(userDefaultsDidChange:) name:NSUserDefaultsDidChangeNotification object:[NSUserDefaults standardUserDefaults]];
|
||||
|
||||
@@ -188,11 +185,8 @@ BOOL HasDocumentWindow (NSArray* windows)
|
||||
themesMenu.delegate = self;
|
||||
spellingMenu.delegate = self;
|
||||
|
||||
if([AboutWindowController shouldShowChangesWindow])
|
||||
{
|
||||
self.aboutWindowController = [[AboutWindowController alloc] init];
|
||||
[self.aboutWindowController performSelector:@selector(showChangesWindow:) withObject:self afterDelay:0];
|
||||
}
|
||||
[TerminalPreferences updateMateIfRequired];
|
||||
[AboutWindowController showChangesIfUpdated];
|
||||
|
||||
self.didFinishLaunching = YES;
|
||||
}
|
||||
@@ -225,9 +219,7 @@ BOOL HasDocumentWindow (NSArray* windows)
|
||||
|
||||
- (IBAction)orderFrontAboutPanel:(id)sender
|
||||
{
|
||||
if(!self.aboutWindowController)
|
||||
self.aboutWindowController = [[AboutWindowController alloc] init];
|
||||
[self.aboutWindowController showAboutWindow:self];
|
||||
[[AboutWindowController sharedInstance] showAboutWindow:self];
|
||||
}
|
||||
|
||||
- (IBAction)orderFrontFindPanel:(id)sender
|
||||
|
||||
Reference in New Issue
Block a user