diff --git a/CHANGELOG.md b/CHANGELOG.md index b6ddedda..fd70a111 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ ## [2.0.1] ### 🔄 Updated 🔄 * `PushButton` has received a facelift. It now mimics the look and feel of native macOS buttons more closely. - * **Note:** As a result, its `pressedOpacity` property and the `PushButtonTheme` class have been deprecated. + * **Note:** As a result, its `pressedOpacity` property and the `PushButtonTheme` class have been deprecated. ## [2.0.0] ### 🚨 Breaking Changes 🚨 diff --git a/lib/src/utils/utils.dart b/lib/src/utils/utils.dart index 3d63855c..29be5e12 100644 --- a/lib/src/utils/utils.dart +++ b/lib/src/utils/utils.dart @@ -1,3 +1,6 @@ +import 'dart:io'; + +import 'package:flutter/foundation.dart'; import 'package:macos_ui/macos_ui.dart'; import 'package:macos_ui/src/library.dart'; @@ -66,3 +69,24 @@ class Unsupported { final String message; } + +/// A class that ensures that the application's macOS window's brightness +/// matches the given brightness. +class MacOSBrightnessOverrideHandler { + static Brightness? _lastBrightness; + + /// Ensures that the application's macOS window's brightness matches + /// [currentBrightness]. + /// + /// For performance reasons, the brightness setting will only be overridden if + /// [currentBrightness] differs from the value it had when this method was + /// previously called. Therefore, it is safe to call this method frequently. + static void ensureMatchingBrightness(Brightness currentBrightness) { + if (kIsWeb) return; + if (!Platform.isMacOS) return; + if (currentBrightness == _lastBrightness) return; + + WindowManipulator.overrideMacOSBrightness(dark: currentBrightness.isDark); + _lastBrightness = currentBrightness; + } +}