LunaKit: The Night Realm

⚠️ This post is an unfinished draft, and published from archives.
It was originally intended to be published May 2, 2023.

Let us skip an introduction and begin with a question: How do Apple's video apps have a blue tint?

Blue Tint?

If you've used any of Apple's Pro Apps video-editing tools, you'll quickly notice all three (Final Cut Pro, Motion, and Compressor) utilize a non-standard UI with blue hues. For example, consider Final Cut Pro's General Settings:

The General tab within Final Cut Pro Settings. Five settings are present. For the context of this article, only three of these settings have pop-up menus:

Note that the pop-up menus do not respect the system accent color, and instead utilize a darker blue/purple-y color. Additionally, the view's background is a far darker color than the standard tint for dark mode windows. It's clear that Apple is doing something custom here.

How can we figure out what they're doing?

Investigating

We can first utilize the AppKit debugging menu to see what class is handling this window. One defaults write -g _NS_4445425547 -bool TRUE1 later, and we have some insight:

Within the menu bar, the AppKit debugging menu is open. The submenu

Our window is provided by a LKPanel, instead of a normal NSPanel! Some rapid greping around, and we can find this symbol inside LunaKit.framework - tucked away within the application's bundle.

Functionality

Next, we can use nm for a quick glimpse into what is provided. We can quickly many classes with names similar to their AppKit parents:

and so on, and so forth. These classes have a superclass of their AppKit namesakes. Let's take a quick peek at functions within the panel we previously saw.

-[LKPanel awakeFromNib]
-[LKPanel _commonInit]
-[LKPanel _disableDesktopTinting]
-[LKPanel _installEffectView]
-[LKPanel setUseHUDStyle:]

Custom awake behavior? Let's look at awakeFromNib:

/* -[LKPanel awakeFromNib] */
-(void) awakeFromNib {
  if ([self _useHUDStyle]) {
    [self _commonInit];
  }
}

Hmm... what's "HUD" in this context? Is this our custom styling?

What does _commonInit do?

/* -[LKPanel _commonInit] */
-(void)_commonInit {
  [self setAppearance:[LunaKit mainAppearance]];
  [[self standardWindowButton:NSWindowCloseButton] setAppearance:[LunaKit mainAppearance]];
  [[self standardWindowButton:NSWindowMiniaturizeButton] setAppearance:[LunaKit mainAppearance]];
  [[self standardWindowButton:NSWindowZoomButton] setAppearance:[LunaKit mainAppearance]];
  [self _disableDesktopTinting];
  [self setDfrController:nil]; // in which DFR is "device function row", or Touch Bar
}

Ah, sure enough. Indeed, if we search for HUD, we see several functions related to setting this custom apperance.

Let's take a look at mainAppearance:

/* +[LunaKit mainAppearance] */
/* Somewhat abbreviated to allow for content */
-(NSAppearance*)mainAppearance {
  if ([LunaKit _wantsConsumerLook]) {
    return [NSAppearance appearanceNamed:NSAppearanceNameDarkAqua];
  }

  // in which LKBundle is the bundle of LumaKit.framework
  LKAppearance* primary = [LKAppearance initWithAppearanceNamed:@"NOX" bundle:[LKBundle bundle]];
  LKAppearance* bigButton = [LKAppearance initWithAppearanceNamed:@"NOXLargePushButton" bundle:[LKBundle bundle]];

  return [[NSClassFromString(@"NSCompositeAppearance") alloc] initWithAppearances:@[primary, bigButton]];
}

...wait, _wantsConsumerLook?

iMovie

Of course, iMovie is the consumer version of Final Cut Pro. It, as well, utilizes LunaKit. We can find a NOXConsumer.car present within all variants of the framework, full of iMovie's general appearance.

_wantsConsumerLook targets it, and it alone:

/* [LunaKit _wantsConsumerLook] */
+(BOOL)_wantsConsumerLook {
  static BOOL checkedBundle = false;
  static BOOL appISIMOVIE = false;

  if (checkedBundle == false) {
    CFBundle mainBundle = CFBundleGetMainBundle();
    if (mainBundle != NULL) {
      CFString bundleIdentifier = CFBundleGetIdentifier(mainBundle);
      if (bundleIdentifier != NULL && CFStringCompare(bundleIdentifier, @"com.apple.iMovieApp", NULL)) {
        appISIMOVIE = true;
      }
    }
    checkedBundle = true;
  }

  return appISIMOVIE;
}

Poor iMovie, stuck with that dreary light grey :(

Due to this, we can simply change the bundle identifier of the applications to view what they look like.

Comparisons

Drag the slider to compare between the two.

iMovie - Normal UI vs. Pro Apps/HUD UI
iMovie with the normal, a.k.a. consumer, UI. It inherits the system's hues - in this case, a pink color. iMovie with the Final Cut Pro coloring. All UI elements have a general blue hue.
Final Cut Pro - Normal UI vs. iMovie/consumer UI
Final Cut Pro with its normal blue hue. Final Cut Pro with the consumer UI. It inherits the system's pink hue for many elements. (Some continue to use the blue hue.)

I don't know what to feel about that.

To conclude:

Jumping back

Let's attempt to make a simple application utilizing these classes.

/* +[LunaKit mainAppearance] */
/* Somewhat abbreviated to allow for content */
-(NSAppearance*)mainAppearance {
  if ([LunaKit _wantsConsumerLook]) {
    return [NSAppearance appearanceNamed:NSAppearanceNameDarkAqua];
  }

  // in which LKBundle is the bundle of LumaKit.framework...
  LKAppearance* primary = [LKAppearance initWithAppearanceNamed:@"NOX" bundle:[LKBundle bundle]];
  LKAppearance* bigButton = [LKAppearance initWithAppearanceNamed:@"NOXLargePushButton" bundle:[LKBundle bundle]];

  return [[NSClassFromString(@"NSCompositeAppearance") alloc] initWithAppearances:@[primary, bigButton]];
}

This blog post was not completed beyond this point.

Conclusion

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in these bullet points are to be interpreted as described in RFC 2119:


Footnotes

1

Is this trick really not known? As of writing, on Google, there are 7 results matching _NS_4445425547. Two of them are tweets regarding the menu, and remaining four are logs where cfprefsd looked up the key's value. It's a very valuable resource for poking around :)