Skip to content

Commit

Permalink
move MacOSBrightnessOverrideHandler to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian-Samoticha committed Aug 15, 2023
1 parent ef8c156 commit 7fa0f23
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
25 changes: 25 additions & 0 deletions lib/src/utils/macos_brightness_override_handler.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:macos_ui/macos_ui.dart';

/// 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;
}
}
25 changes: 1 addition & 24 deletions lib/src/utils/utils.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:macos_ui/macos_ui.dart';
import 'package:macos_ui/src/library.dart';

export 'window_main_state_listener.dart';
export 'accent_color_listener.dart';
export 'macos_brightness_override_handler.dart';

/// Asserts that the given context has a [MacosTheme] ancestor.
///
Expand Down Expand Up @@ -68,24 +66,3 @@ 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;
}
}

0 comments on commit 7fa0f23

Please sign in to comment.