From 0915586b791b64ada93db6d5ab562fdd21b8d04a Mon Sep 17 00:00:00 2001 From: Andre Meyering Date: Tue, 23 Apr 2024 19:53:00 +0200 Subject: [PATCH] fix(macOS): Support building and running on macOS 10.13 again We don't support darkmode on macOS 10.x anymore. Users can use our Qt6 build instead. --- CMakePresets.json | 16 ++++++++++++++++ src/ui/MacUiUtilities.mm | 10 +++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CMakePresets.json b/CMakePresets.json index 3fe035729f..182a7c1587 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -13,6 +13,18 @@ "ENABLE_LTO": "ON" } }, + { + "name": "release-macOS-qt5", + "displayName": "release macOS Qt5", + "generator": "Unix Makefiles", + "binaryDir": "${sourceDir}/build/${presetName}", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release", + "ENABLE_COLOR_OUTPUT": "ON", + "CMAKE_EXPORT_COMPILE_COMMANDS": "ON", + "ENABLE_LTO": "ON" + } + }, { "name": "debug", "displayName": "Debug", @@ -99,6 +111,10 @@ "name": "release", "configurePreset": "release" }, + { + "name": "release-macOS-qt5", + "configurePreset": "release-macOS-qt5" + }, { "name": "asan", "configurePreset": "asan" diff --git a/src/ui/MacUiUtilities.mm b/src/ui/MacUiUtilities.mm index c74a0778d8..98a6338324 100644 --- a/src/ui/MacUiUtilities.mm +++ b/src/ui/MacUiUtilities.mm @@ -2,19 +2,27 @@ #undef slots #import +#include namespace mediaelch { namespace ui { bool macIsInDarkTheme() { +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + // macOS 10.13 doesn't support NSAppearanceNameDarkAqua and we can't build it on it. + // The easiest way I found was to just drop support for dark mode on macOS 10.X. + // With macOS 11 and later, users can use our Qt6 version. + return false; +#else // See tutorial at if (__builtin_available(macOS 10.14, *)) { auto appearance = [NSApp.effectiveAppearance - bestMatchFromAppearancesWithNames:@[NSAppearanceNameAqua, NSAppearanceNameDarkAqua]]; + bestMatchFromAppearancesWithNames:@[ NSAppearanceNameAqua, NSAppearanceNameDarkAqua ]]; return [appearance isEqualToString:NSAppearanceNameDarkAqua]; } return false; +#endif } } // namespace ui