anki/qt/mac/theme.swift
Damien Elmes d9c8addbc1 switch AnkiHelper to Swift
More pleasant to work with than ObjectiveC, which will help with the
following commit.

Swift libraries weren't added to macOS until 10.14.4, so theme
autodetection will fail on 10.14.0-10.14.3. The Qt6 build will have its
minimum version bumped to 10.14.4; the Qt5 build will remain on 10.13.4.

Bazel's rules_swift doesn't currently support building Swift dylibs, so
we need to invoke swiftc directly via a genrule().
2021-12-07 18:48:24 +10:00

19 lines
601 B
Swift

// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import AppKit
import Foundation
/// Force our app to be either light or dark mode.
@_cdecl("set_darkmode_enabled")
public func setDarkmodeEnabled(_ enabled: Bool) {
NSApplication.shared.appearance = NSAppearance(named: enabled ? .darkAqua : .aqua)
}
/// True if the system is set to dark mode.
@_cdecl("system_is_dark")
public func systemIsDark() -> Bool {
let styleSet = UserDefaults.standard.object(forKey: "AppleInterfaceStyle") != nil
return styleSet
}