Skip to content

Commit

Permalink
fix(macOS): Support building and running on macOS 10.13 again
Browse files Browse the repository at this point in the history
We don't support darkmode on macOS 10.x anymore.  Users can use our Qt6
build instead.
  • Loading branch information
bugwelle committed Apr 23, 2024
1 parent 158143a commit 37a9f68
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
12 changes: 12 additions & 0 deletions CMakePresets.json
Expand Up @@ -13,6 +13,18 @@
"ENABLE_LTO": "ON"
}
},
{
"name": "release-macOS-qt5",
"displayName": "release macOS Qt5",
"generator": "Unix Makefile",
"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",
Expand Down
10 changes: 9 additions & 1 deletion src/ui/MacUiUtilities.mm
Expand Up @@ -2,19 +2,27 @@

#undef slots
#import <Cocoa/Cocoa.h>
#include <QtVersionChecks>

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 <https://successfulsoftware.net/2021/03/31/how-to-add-a-dark-theme-to-your-qt-application/>
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
Expand Down

0 comments on commit 37a9f68

Please sign in to comment.