Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(macOS): Support building and running on macOS 10.13 again #1742

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions CMakePresets.json
Expand Up @@ -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",
Expand Down Expand Up @@ -99,6 +111,10 @@
"name": "release",
"configurePreset": "release"
},
{
"name": "release-macOS-qt5",
"configurePreset": "release-macOS-qt5"
},
{
"name": "asan",
"configurePreset": "asan"
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 <QtGlobal>

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