Add expiration date to TextMate

The user will get daily reminders when the application is more than a month old, and it will stop working when it’s two months old.

Normally not a fan of expiring software but a significant amount of the requests sent to api.textmate.org (posting crash reports, updating bundles) are from versions more than a month old. Adding to that, the expiration date serves as a fallback for potentially broken software update checking.
This commit is contained in:
Allan Odgaard
2013-04-28 10:03:51 +07:00
parent e1ff0ceaff
commit acaff3e352

View File

@@ -139,9 +139,37 @@ BOOL HasDocumentWindow (NSArray* windows)
setup_rmate_server(!disableRmate, [rmateInterface isEqualToString:kRMateServerListenRemote] ? INADDR_ANY : INADDR_LOOPBACK, rmatePort);
}
- (void)checkExpirationDate:(id)sender
{
NSTimeInterval const kSecondsPerDay = 24*60*60;
NSDate* currentDate = [NSDate date];
NSDate* compileDate = [NSDate dateWithString:@COMPILE_DATE @" 00:00:00 +0000"];
NSDate* warningDate = [compileDate dateByAddingTimeInterval:30*kSecondsPerDay];
NSDate* expirationDate = [compileDate dateByAddingTimeInterval:60*kSecondsPerDay];
if([currentDate laterDate:expirationDate] == currentDate)
{
NSInteger choice = NSRunAlertPanel(@"TextMate is Outdated!", @"You can get a new version from https://macromates.com/download.", @"Visit Website", nil, nil);
if(choice == NSAlertDefaultReturn) // "Visit Website"
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://macromates.com/download"]];
[NSApp terminate:self];
}
else if([currentDate laterDate:warningDate] == currentDate)
{
NSInteger daysUntilExpiration = floor([expirationDate timeIntervalSinceNow] / kSecondsPerDay);
NSInteger choice = NSRunAlertPanel(@"TextMate is Outdated!", @"You are using a preview of TextMate 2 which is more than a month old. It will stop working in %ld day%s.", @"Visit Website", @"Cancel", nil, daysUntilExpiration, daysUntilExpiration == 1 ? "" : "s");
if(choice == NSAlertDefaultReturn) // "Visit Website"
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://macromates.com/download"]];
}
[NSTimer scheduledTimerWithTimeInterval:kSecondsPerDay target:self selector:@selector(checkExpirationDate:) userInfo:nil repeats:NO];
}
- (void)applicationWillFinishLaunching:(NSNotification*)aNotification
{
D(DBF_AppController, bug("\n"););
[self checkExpirationDate:self];
settings_t::set_default_settings_path([[[NSBundle mainBundle] pathForResource:@"Default" ofType:@"tmProperties"] fileSystemRepresentation]);
settings_t::set_global_settings_path(path::join(path::home(), "Library/Application Support/TextMate/Global.tmProperties"));