From b56508c55c3622e673dc4c8371be90209f858ffa Mon Sep 17 00:00:00 2001 From: Lukhnos Liu Date: Tue, 4 Mar 2014 23:53:45 -0800 Subject: [PATCH] Add a debug menu item for checking updates --- Source/AppDelegate.h | 1 + Source/AppDelegate.m | 21 ++++++++++++++------- Source/InputMethodController.mm | 10 ++++++++++ Source/en.lproj/Localizable.strings | 2 ++ Source/zh-Hant.lproj/Localizable.strings | 3 +++ 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/Source/AppDelegate.h b/Source/AppDelegate.h index 2f505cc4..19796d7e 100644 --- a/Source/AppDelegate.h +++ b/Source/AppDelegate.h @@ -46,6 +46,7 @@ } - (void)checkForUpdate; +- (void)checkForUpdateForced:(BOOL)forced; @property (assign, nonatomic) IBOutlet NSWindow *window; @end diff --git a/Source/AppDelegate.m b/Source/AppDelegate.m index 5a353cf5..4b45f069 100644 --- a/Source/AppDelegate.m +++ b/Source/AppDelegate.m @@ -70,6 +70,11 @@ static const NSTimeInterval kTimeoutInterval = 60.0; } - (void)checkForUpdate +{ + [self checkForUpdateForced:NO]; +} + +- (void)checkForUpdateForced:(BOOL)forced { if (_updateCheckConnection) { // busy @@ -77,14 +82,16 @@ static const NSTimeInterval kTimeoutInterval = 60.0; } // time for update? - NSDate *now = [NSDate date]; - NSDate *date = [[NSUserDefaults standardUserDefaults] objectForKey:kNextUpdateCheckDateKey]; - if (![date isKindOfClass:[NSDate class]]) { - date = now; - } + if (!forced) { + NSDate *now = [NSDate date]; + NSDate *date = [[NSUserDefaults standardUserDefaults] objectForKey:kNextUpdateCheckDateKey]; + if (![date isKindOfClass:[NSDate class]]) { + date = now; + } - if ([now compare:date] == NSOrderedAscending) { - return; + if ([now compare:date] == NSOrderedAscending) { + return; + } } NSDate *nextUpdateDate = [NSDate dateWithTimeInterval:kNextCheckInterval sinceDate:[NSDate date]]; diff --git a/Source/InputMethodController.mm b/Source/InputMethodController.mm index d172cb51..bbccadb5 100644 --- a/Source/InputMethodController.mm +++ b/Source/InputMethodController.mm @@ -234,6 +234,11 @@ public: } #endif //DEBUG + #if DEBUG + NSMenuItem *updateCheckItem = [[[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Check for Updates…", @"") action:@selector(checkForUpdate:) keyEquivalent:@""] autorelease]; + [menu addItem:updateCheckItem]; + #endif + NSMenuItem *aboutMenuItem = [[[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"About McBopomofo…", @"") action:@selector(showAbout:) keyEquivalent:@""] autorelease]; [menu addItem:aboutMenuItem]; @@ -1360,6 +1365,11 @@ public: [[NSApplication sharedApplication] activateIgnoringOtherApps:YES]; } +- (void)checkForUpdate:(id)sender +{ + [(AppDelegate *)[[NSApplication sharedApplication] delegate] checkForUpdateForced:YES]; +} + - (void)showAbout:(id)sender { [[NSApplication sharedApplication] orderFrontStandardAboutPanel:sender]; diff --git a/Source/en.lproj/Localizable.strings b/Source/en.lproj/Localizable.strings index 47533e49..8024204c 100644 --- a/Source/en.lproj/Localizable.strings +++ b/Source/en.lproj/Localizable.strings @@ -25,3 +25,5 @@ /* No comment provided by engineer. */ "You are running version %@ (%@), and the new version %@ (%@) is now available.\n\nVisit the website to download it?" = "You are running version %1$@ (%2$@), and the new version %3$@ (%4$@) is now available.\n\nVisit the website to download it?"; +/* No comment provided by engineer. */ +"Check for Updates…" = "Check for Updates…"; diff --git a/Source/zh-Hant.lproj/Localizable.strings b/Source/zh-Hant.lproj/Localizable.strings index 937e3015..2ebe96de 100644 --- a/Source/zh-Hant.lproj/Localizable.strings +++ b/Source/zh-Hant.lproj/Localizable.strings @@ -24,3 +24,6 @@ /* No comment provided by engineer. */ "You are running version %@ (%@), and the new version %@ (%@) is now available.\n\nVisit the website to download it?" = "目前的輸入法版本是 %1$@ 版 (%2$@),目前最新版本已經到第 %3$@ 版 (%4$@)。\n\n是否要前往輸入法網站,下載最新版本?"; + +/* No comment provided by engineer. */ +"Check for Updates…" = "檢查是否有新版…";