[vlc-commits] [Git][videolan/vlc][master] 3 commits: macosx: VLCApplication: add vlcAppIconImage property

Hugo Beauzée-Luyssen (@chouquette) gitlab at videolan.org
Wed Sep 22 08:18:53 UTC 2021



Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / VLC


Commits:
52980312 by Marvin Scholz at 2021-09-22T07:56:52+00:00
macosx: VLCApplication: add vlcAppIconImage property

Add a property that returns the NSImage that is currently used as
application icon for VLC. This is not always the same as
NSImageNameApplicationIcon due to easter eggs like the Christmas cone.

- - - - -
68a6b68b by Marvin Scholz at 2021-09-22T07:56:52+00:00
macosx: VLCMain: use VLCApplication's vlcAppIconImage

- - - - -
5f8f5299 by Marvin Scholz at 2021-09-22T07:56:52+00:00
macosx: About: use VLCApplication's vlcAppIconImage

- - - - -


4 changed files:

- modules/gui/macosx/main/VLCApplication.h
- modules/gui/macosx/main/VLCApplication.m
- modules/gui/macosx/main/VLCMain.m
- modules/gui/macosx/windows/VLCAboutWindowController.m


Changes:

=====================================
modules/gui/macosx/main/VLCApplication.h
=====================================
@@ -31,4 +31,17 @@
 
 @interface VLCApplication : NSApplication
 
+/**
+ * The current VLC App icon image
+ * 
+ * This is adjusted accordingly to return the special
+ * image on occasions like christmas. Contrary to the
+ * applicationIconImage property though, the image is
+ * not scaled down, so it remains suitable when it is
+ * displayed for example in the About window.
+ * 
+ * Must be called from the main thread only.
+ */
+ at property(strong, readonly) NSImage *vlcAppIconImage;
+
 @end


=====================================
modules/gui/macosx/main/VLCApplication.m
=====================================
@@ -37,6 +37,7 @@
 @interface VLCApplication ()
 {
     NSURL *_appLocationURL;
+    NSImage *_vlcAppIconImage;
 }
 
 @end
@@ -64,6 +65,32 @@
     [[NSNotificationCenter defaultCenter] removeObserver:self];
 }
 
+- (NSImage *)vlcAppIconImage
+{
+    NSAssert(NSThread.isMainThread, @"I must be called from the main thread only!");
+
+    // If we already have an image, immediately return that
+    if (_vlcAppIconImage != nil)
+        return _vlcAppIconImage;
+
+    if (config_GetInt("macosx-icon-change")) {
+        /* After day 354 of the year, the usual VLC cone is replaced by another cone
+         * wearing a Father Xmas hat.
+         * Note: this icon doesn't represent an endorsement of The Coca-Cola Company.
+         */
+        NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
+        NSUInteger dayOfYear = [gregorian ordinalityOfUnit:NSCalendarUnitDay inUnit:NSCalendarUnitYear forDate:[NSDate date]];
+
+        if (dayOfYear >= 354)
+            _vlcAppIconImage = [NSImage imageNamed:@"VLC-Xmas"];
+    }
+
+    if (_vlcAppIconImage == nil)
+        _vlcAppIconImage = [NSImage imageNamed:@"VLC"];
+
+    return _vlcAppIconImage;
+}
+
 - (void)appBecameActive:(NSNotification *)aNotification
 {
     if ([[[NSBundle mainBundle] bundleURL] checkResourceIsReachableAndReturnError:nil]) {


=====================================
modules/gui/macosx/main/VLCMain.m
=====================================
@@ -245,20 +245,9 @@ static VLCMain *sharedInstance = nil;
     [[SUUpdater sharedUpdater] setDelegate:self];
 #endif
 
-    if (var_InheritInteger(_p_intf, "macosx-icon-change")) {
-        /* After day 354 of the year, the usual VLC cone is replaced by another cone
-         * wearing a Father Xmas hat.
-         * Note: this icon doesn't represent an endorsement of The Coca-Cola Company.
-         */
-        NSCalendar *gregorian =
-        [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
-        NSUInteger dayOfYear = [gregorian ordinalityOfUnit:NSCalendarUnitDay inUnit:NSCalendarUnitYear forDate:[NSDate date]];
-
-        if (dayOfYear >= 354)
-            [[VLCApplication sharedApplication] setApplicationIconImage: [NSImage imageNamed:@"VLC-Xmas"]];
-        else
-            [[VLCApplication sharedApplication] setApplicationIconImage: [NSImage imageNamed:@"VLC"]];
-    }
+    NSImage *appIconImage = [[VLCApplication sharedApplication] vlcAppIconImage];
+    [[VLCApplication sharedApplication]
+        setApplicationIconImage:appIconImage];
 }
 
 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification


=====================================
modules/gui/macosx/windows/VLCAboutWindowController.m
=====================================
@@ -33,6 +33,7 @@
 #import "extensions/NSString+Helpers.h"
 #import "main/CompatibilityFixes.h"
 #import "main/VLCMain.h"
+#import "main/VLCApplication.h"
 
 #import "views/VLCScrollingClipView.h"
 
@@ -155,18 +156,8 @@
     [[self window] setExcludedFromWindowsMenu:YES];
     [[self window] setMenu:nil];
 
-    if (config_GetInt("macosx-icon-change")) {
-        /* After day 354 of the year, the usual VLC cone is replaced by another cone
-         * wearing a Father Xmas hat.
-         * Note: this icon doesn't represent an endorsement of The Coca-Cola Company.
-         */
-        NSCalendar *gregorian =
-        [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
-        NSUInteger dayOfYear = [gregorian ordinalityOfUnit:NSCalendarUnitDay inUnit:NSCalendarUnitYear forDate:[NSDate date]];
-
-        if (dayOfYear >= 354)
-            [o_icon_view setImage: [NSImage imageNamed:@"VLC-Xmas"]];
-    }
+    [o_icon_view setImage:
+        [[VLCApplication sharedApplication] vlcAppIconImage]];
 }
 
 - (void)windowDidBecomeKey:(NSNotification *)notification



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/cc9d9444fbdf7e8a4d4d5884d6fb97925408d7cf...5f8f52991601290d6c37d74e3e3d4d98349127bc

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/cc9d9444fbdf7e8a4d4d5884d6fb97925408d7cf...5f8f52991601290d6c37d74e3e3d4d98349127bc
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list