From 02092cfe96d7b577338a6edd5cc16d8a2c040a52 Mon Sep 17 00:00:00 2001 From: Yee Cheng Chin Date: Thu, 2 Feb 2023 17:02:44 -0800 Subject: [PATCH] Report better version in About MacVim, and store last used version Use a better format for the version reporting in the "About MacVim" page to be clear what's the Vim version, and what's specifically the MacVim release number. Also, store the last used MacVim version number. This isn't used right now but may be used later for showing up a "What's New" page when updating to a new version, primarily for non-Sparkle users (e.g. Homebrew builds) so they can still be notified when something changed. Storing this number now allows us to know in a later build whether the user has upgraded to the build or starting a new build from fresh (where we may not want to show the "What's New" page as everything would be new). Part of addressing #1293 --- src/MacVim/MMAppController.m | 46 ++++++++++++++++++++++++++++++++++++ src/MacVim/MMApplication.m | 2 +- src/MacVim/Miscellaneous.h | 1 + src/MacVim/Miscellaneous.m | 1 + 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/MacVim/MMAppController.m b/src/MacVim/MMAppController.m index 5aaaae931b..904db5c161 100644 --- a/src/MacVim/MMAppController.m +++ b/src/MacVim/MMAppController.m @@ -263,6 +263,7 @@ + (void)initialize [NSNumber numberWithBool:NO], MMRendererClipToRowKey, [NSNumber numberWithBool:YES], MMAllowForceClickLookUpKey, [NSNumber numberWithBool:NO], MMUpdaterPrereleaseChannelKey, + @"", MMLastUsedBundleVersionKey, nil]; [[NSUserDefaults standardUserDefaults] registerDefaults:dict]; @@ -459,6 +460,51 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification [self addInputSourceChangedObserver]; + NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; + + NSString *lastUsedVersion = [ud stringForKey:MMLastUsedBundleVersionKey]; + NSString *currentVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey: + @"CFBundleVersion"]; + // This will be used for showing a "What's New" dialog box in the future. For + // now, just update the stored version for future use so later versions will + // be able to tell whether to show this dialog box or not. + if (currentVersion && currentVersion.length != 0) { + if (!lastUsedVersion || [lastUsedVersion length] == 0) { + [ud setValue:currentVersion forKey:MMLastUsedBundleVersionKey]; + } else { + // If the current version is larger, set that to be stored. Don't + // want to do it otherwise to prevent testing older versions flipping + // the stored version back to an old one. + NSArray *lastUsedVersionItems = [lastUsedVersion componentsSeparatedByString:@"."]; + NSArray *currentVersionItems = [currentVersion componentsSeparatedByString:@"."]; + // Compare two arrays lexographically. We just assume that version + // numbers are also X.Y.Z… with no "beta" etc texts. + bool currentVersionLarger = NO; + for (int i = 0; i < currentVersionItems.count && i < lastUsedVersionItems.count; i++) { + if (i >= currentVersionItems.count) { + currentVersionLarger = NO; + break; + } + if (i >= lastUsedVersionItems.count) { + currentVersionLarger = YES; + break; + } + if (currentVersionItems[i].integerValue > lastUsedVersionItems[i].integerValue) { + currentVersionLarger = YES; + break; + } + else if (currentVersionItems[i].integerValue < lastUsedVersionItems[i].integerValue) { + currentVersionLarger = NO; + break; + } + } + + if (currentVersionLarger) { + [ud setValue:currentVersion forKey:MMLastUsedBundleVersionKey]; + } + } + } + ASLogInfo(@"MacVim finished launching"); } diff --git a/src/MacVim/MMApplication.m b/src/MacVim/MMApplication.m index e107753df8..ca8c5c5902 100644 --- a/src/MacVim/MMApplication.m +++ b/src/MacVim/MMApplication.m @@ -53,7 +53,7 @@ - (void)orderFrontStandardAboutPanel:(id)sender NSString *marketingVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]; NSString *title = [NSString stringWithFormat: - @"Custom Version %@ (%@)", marketingVersion, version]; + @"Vim %@ (MacVim r%@)", marketingVersion, version]; [self orderFrontStandardAboutPanelWithOptions: [NSDictionary dictionaryWithObjectsAndKeys: diff --git a/src/MacVim/Miscellaneous.h b/src/MacVim/Miscellaneous.h index b59aef25bd..9b51f277c8 100644 --- a/src/MacVim/Miscellaneous.h +++ b/src/MacVim/Miscellaneous.h @@ -64,6 +64,7 @@ extern NSString *MMCmdLineAlignBottomKey; extern NSString *MMRendererClipToRowKey; extern NSString *MMAllowForceClickLookUpKey; extern NSString *MMUpdaterPrereleaseChannelKey; +extern NSString *MMLastUsedBundleVersionKey; // The last used version of MacVim before this launch // Enum for MMUntitledWindowKey diff --git a/src/MacVim/Miscellaneous.m b/src/MacVim/Miscellaneous.m index 37054301e8..5a1eef0f43 100644 --- a/src/MacVim/Miscellaneous.m +++ b/src/MacVim/Miscellaneous.m @@ -60,6 +60,7 @@ NSString *MMRendererClipToRowKey = @"MMRendererClipToRow"; NSString *MMAllowForceClickLookUpKey = @"MMAllowForceClickLookUp"; NSString *MMUpdaterPrereleaseChannelKey = @"MMUpdaterPrereleaseChannel"; +NSString *MMLastUsedBundleVersionKey = @"MMLastUsedBundleVersion"; @implementation NSIndexSet (MMExtras)