Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions lib/app_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,21 @@ class _AppWidgetState extends State<AppWidget>
}
}

@override
Future<void> didChangePlatformBrightness() async {
super.didChangePlatformBrightness();
final ThemeProvider themeProvider = Provider.of<ThemeProvider>(context, listen: false);
KazumiLogger().i("Platform brightness changed, themeMode: ${themeProvider.themeMode}");

// Only update title bar theme when following system
// If user has forced a specific theme, keep title bar consistent with app content
if (themeProvider.themeMode == ThemeMode.system && Platform.isWindows) {
final brightness = WidgetsBinding.instance.platformDispatcher.platformBrightness;
KazumiLogger().i("Updating title bar brightness: $brightness");
await windowManager.setBrightness(brightness);
}
}

Future<void> _handleTray() async {
if (Platform.isWindows) {
await trayManager.setIcon('assets/images/logo/logo_lanczos.ico');
Expand Down Expand Up @@ -215,6 +230,12 @@ class _AppWidgetState extends State<AppWidget>
if (defaultThemeMode == 'system') {
themeProvider.setThemeMode(ThemeMode.system, notify: false);
}

// Set Windows title bar theme based on app theme
if (Platform.isWindows) {
windowManager.setBrightness(themeProvider.isEffectiveDark() ? Brightness.dark : Brightness.light);
}

themeProvider.setFontFamily(useSystemFont, notify: false);
var defaultDarkTheme = ThemeData(
useMaterial3: true,
Expand Down
10 changes: 10 additions & 0 deletions lib/bean/settings/theme_provider.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:kazumi/utils/constants.dart';

class ThemeProvider extends ChangeNotifier {
Expand All @@ -8,6 +9,15 @@ class ThemeProvider extends ChangeNotifier {
late ThemeData dark;
String? currentFontFamily = customAppFontFamily;

/// Returns true if the effective theme is dark mode.
/// Automatically gets platform brightness when themeMode is ThemeMode.system.
bool isEffectiveDark() {
if (themeMode == ThemeMode.dark) return true;
if (themeMode == ThemeMode.light) return false;
final platformBrightness = SchedulerBinding.instance.platformDispatcher.platformBrightness;
return platformBrightness == Brightness.dark;
}

void setTheme(ThemeData light, ThemeData dark, {bool notify = true}) {
this.light = light;
this.dark = dark;
Expand Down
6 changes: 6 additions & 0 deletions lib/pages/settings/theme_settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:kazumi/bean/settings/color_type.dart';
import 'package:kazumi/utils/utils.dart';
import 'package:card_settings_ui/card_settings_ui.dart';
import 'package:provider/provider.dart';
import 'package:window_manager/window_manager.dart';

class ThemeSettingsPage extends StatefulWidget {
const ThemeSettingsPage({super.key});
Expand Down Expand Up @@ -122,6 +123,11 @@ class _ThemeSettingsPageState extends State<ThemeSettingsPage> {
setState(() {
defaultThemeMode = theme;
});

// Update Windows title bar theme
if (Platform.isWindows) {
await windowManager.setBrightness(themeProvider.isEffectiveDark() ? Brightness.dark : Brightness.light);
}
}

void updateOledEnhance() {
Expand Down
7 changes: 4 additions & 3 deletions windows/runner/win32_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,10 @@ Win32Window::MessageHandler(HWND hwnd,
}
return 0;

case WM_DWMCOLORIZATIONCOLORCHANGED:
UpdateTheme(hwnd);
return 0;
// Theme state is now maintained by Flutter side (app_widget.dart).
// case WM_DWMCOLORIZATIONCOLORCHANGED:
// UpdateTheme(hwnd);
// return 0;
}

return DefWindowProc(window_handle_, message, wparam, lparam);
Expand Down
Loading