Skip to content

Commit aa485a2

Browse files
authored
Merge pull request #1357 from ychin/store-last-used-version-macvim-better-about-version
Report better version in About MacVim, and store last used version
2 parents 17f3c3d + 02092cf commit aa485a2

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

src/MacVim/MMAppController.m

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ + (void)initialize
263263
[NSNumber numberWithBool:NO], MMRendererClipToRowKey,
264264
[NSNumber numberWithBool:YES], MMAllowForceClickLookUpKey,
265265
[NSNumber numberWithBool:NO], MMUpdaterPrereleaseChannelKey,
266+
@"", MMLastUsedBundleVersionKey,
266267
nil];
267268

268269
[[NSUserDefaults standardUserDefaults] registerDefaults:dict];
@@ -459,6 +460,51 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification
459460

460461
[self addInputSourceChangedObserver];
461462

463+
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
464+
465+
NSString *lastUsedVersion = [ud stringForKey:MMLastUsedBundleVersionKey];
466+
NSString *currentVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:
467+
@"CFBundleVersion"];
468+
// This will be used for showing a "What's New" dialog box in the future. For
469+
// now, just update the stored version for future use so later versions will
470+
// be able to tell whether to show this dialog box or not.
471+
if (currentVersion && currentVersion.length != 0) {
472+
if (!lastUsedVersion || [lastUsedVersion length] == 0) {
473+
[ud setValue:currentVersion forKey:MMLastUsedBundleVersionKey];
474+
} else {
475+
// If the current version is larger, set that to be stored. Don't
476+
// want to do it otherwise to prevent testing older versions flipping
477+
// the stored version back to an old one.
478+
NSArray<NSString*> *lastUsedVersionItems = [lastUsedVersion componentsSeparatedByString:@"."];
479+
NSArray<NSString*> *currentVersionItems = [currentVersion componentsSeparatedByString:@"."];
480+
// Compare two arrays lexographically. We just assume that version
481+
// numbers are also X.Y.Z… with no "beta" etc texts.
482+
bool currentVersionLarger = NO;
483+
for (int i = 0; i < currentVersionItems.count && i < lastUsedVersionItems.count; i++) {
484+
if (i >= currentVersionItems.count) {
485+
currentVersionLarger = NO;
486+
break;
487+
}
488+
if (i >= lastUsedVersionItems.count) {
489+
currentVersionLarger = YES;
490+
break;
491+
}
492+
if (currentVersionItems[i].integerValue > lastUsedVersionItems[i].integerValue) {
493+
currentVersionLarger = YES;
494+
break;
495+
}
496+
else if (currentVersionItems[i].integerValue < lastUsedVersionItems[i].integerValue) {
497+
currentVersionLarger = NO;
498+
break;
499+
}
500+
}
501+
502+
if (currentVersionLarger) {
503+
[ud setValue:currentVersion forKey:MMLastUsedBundleVersionKey];
504+
}
505+
}
506+
}
507+
462508
ASLogInfo(@"MacVim finished launching");
463509
}
464510

src/MacVim/MMApplication.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ - (void)orderFrontStandardAboutPanel:(id)sender
5353
NSString *marketingVersion = [[NSBundle mainBundle]
5454
objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
5555
NSString *title = [NSString stringWithFormat:
56-
@"Custom Version %@ (%@)", marketingVersion, version];
56+
@"Vim %@ (MacVim r%@)", marketingVersion, version];
5757

5858
[self orderFrontStandardAboutPanelWithOptions:
5959
[NSDictionary dictionaryWithObjectsAndKeys:

src/MacVim/Miscellaneous.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ extern NSString *MMCmdLineAlignBottomKey;
6464
extern NSString *MMRendererClipToRowKey;
6565
extern NSString *MMAllowForceClickLookUpKey;
6666
extern NSString *MMUpdaterPrereleaseChannelKey;
67+
extern NSString *MMLastUsedBundleVersionKey; // The last used version of MacVim before this launch
6768

6869

6970
// Enum for MMUntitledWindowKey

src/MacVim/Miscellaneous.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
NSString *MMRendererClipToRowKey = @"MMRendererClipToRow";
6161
NSString *MMAllowForceClickLookUpKey = @"MMAllowForceClickLookUp";
6262
NSString *MMUpdaterPrereleaseChannelKey = @"MMUpdaterPrereleaseChannel";
63+
NSString *MMLastUsedBundleVersionKey = @"MMLastUsedBundleVersion";
6364

6465

6566
@implementation NSIndexSet (MMExtras)

0 commit comments

Comments
 (0)