Skip to content

Commit

Permalink
Fix maximize and fullscreen, closes #449
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Jul 20, 2023
1 parent 40dbe91 commit 36b20cc
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 35 deletions.
28 changes: 25 additions & 3 deletions app/lib/cubits/settings.dart
@@ -1,17 +1,19 @@
import 'dart:convert';
import 'dart:typed_data';

import 'package:butterfly/api/full_screen.dart' as full_screen_api;
import 'package:butterfly/api/file_system/file_system.dart';
import 'package:butterfly/widgets/window.dart';
import 'package:butterfly_api/butterfly_api.dart';
import 'package:collection/collection.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:window_manager/window_manager.dart';

import '../views/navigator.dart';

Expand Down Expand Up @@ -371,7 +373,20 @@ class SettingsCubit extends Cubit<ButterflySettings> {
SettingsCubit(SharedPreferences prefs, bool fullScreen)
: super(ButterflySettings.fromPrefs(prefs, fullScreen));

Future<void> changeTheme(ThemeMode theme) async {
void setTheme(MediaQueryData mediaQuery, [ThemeMode? theme]) {
if (kIsWeb || !isWindow) return;
final brightness = switch (theme ?? state.theme) {
ThemeMode.light => Brightness.light,
ThemeMode.dark => Brightness.dark,
ThemeMode.system => mediaQuery.platformBrightness,
};
windowManager.setBrightness(brightness);
}

Future<void> changeTheme(ThemeMode theme, [MediaQueryData? modify]) async {
if (modify != null) {
setTheme(modify, theme);
}
emit(state.copyWith(theme: theme));
return save();
}
Expand Down Expand Up @@ -616,7 +631,14 @@ class SettingsCubit extends Cubit<ButterflySettings> {
return save();
}

Future<void> changeNativeTitleBar(bool value) {
void setNativeTitleBar([bool? value]) {
windowManager.setTitleBarStyle((value ?? state.nativeTitleBar)
? TitleBarStyle.normal
: TitleBarStyle.hidden);
}

Future<void> changeNativeTitleBar(bool value, [bool modify = true]) {
if (modify) setNativeTitleBar(value);
emit(state.copyWith(nativeTitleBar: value));
return save();
}
Expand Down
35 changes: 8 additions & 27 deletions app/lib/main.dart
Expand Up @@ -291,35 +291,16 @@ class ButterflyApp extends StatelessWidget {
create: (_) {
final cubit = SettingsCubit(prefs, isFullScreen);
cubit.setFullScreen(cubit.state.startInFullScreen);
cubit.setTheme(MediaQuery.of(context));
cubit.setNativeTitleBar();
return cubit;
},
child: BlocBuilder<SettingsCubit, ButterflySettings>(
buildWhen: (previous, current) =>
previous.nativeTitleBar != current.nativeTitleBar ||
previous.theme != current.theme,
builder: (context, settings) {
final mediaQuery = MediaQuery.of(context);
if (!kIsWeb && isWindow) {
windowManager.waitUntilReadyToShow().then((_) async {
await windowManager.setTitleBarStyle(settings.nativeTitleBar
? TitleBarStyle.normal
: TitleBarStyle.hidden);
final brightness = switch (settings.theme) {
ThemeMode.light => Brightness.light,
ThemeMode.dark => Brightness.dark,
ThemeMode.system => mediaQuery.platformBrightness,
};
await windowManager.setBrightness(brightness);
await windowManager.show();
});
}
return RepositoryProvider(
create: (context) =>
SyncService(context, context.read<SettingsCubit>()),
lazy: false,
child: _buildApp(lightDynamic, darkDynamic),
);
},
lazy: false,
child: RepositoryProvider(
create: (context) =>
SyncService(context, context.read<SettingsCubit>()),
lazy: false,
child: _buildApp(lightDynamic, darkDynamic),
),
),
);
Expand Down
2 changes: 1 addition & 1 deletion app/lib/settings/personalization.dart
Expand Up @@ -217,7 +217,7 @@ class PersonalizationSettingsPage extends StatelessWidget {
title: AppLocalizations.of(context).theme,
childrenBuilder: (context) {
void changeTheme(ThemeMode themeMode) {
cubit.changeTheme(themeMode);
cubit.changeTheme(themeMode, MediaQuery.of(context));
Navigator.of(context).pop();
}

Expand Down
4 changes: 2 additions & 2 deletions app/pubspec.lock
Expand Up @@ -563,10 +563,10 @@ packages:
dependency: "direct main"
description:
name: go_router
sha256: b33a88c67816312597e5e0f5906c5139a0b9bd9bb137346e872c788da7af8ea0
sha256: "5927202c23bec18ba93f662b5e1f81f2caa2e0cfa472d857d6229f63d59f1730"
url: "https://pub.dev"
source: hosted
version: "9.0.3"
version: "9.1.0"
graphs:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion app/pubspec.yaml
Expand Up @@ -41,7 +41,7 @@ dependencies:
share_plus: ^7.0.2
package_info_plus: ^4.0.2
idb_shim: ^2.3.1
go_router: ^9.0.3
go_router: ^9.1.0
xml: ^6.3.0
collection: ^1.17.2
bloc_concurrency: ^0.2.2
Expand Down
3 changes: 2 additions & 1 deletion fastlane/metadata/android/en-US/changelogs/69.txt
Expand Up @@ -13,4 +13,5 @@
* Fix waypoints not updating in navigator
* Fix background won't be loaded
* Fix position when scaling elements
* Fix window when native title bar is enabled
* Fix window when native title bar is enabled
* Fix full screen and maximize window ([#449](https://github.com/LinwoodDev/Butterfly/issues/449))

0 comments on commit 36b20cc

Please sign in to comment.