From 59c769fb96490cea450832de123eee861b9f2a8d Mon Sep 17 00:00:00 2001 From: CodeDoctorDE Date: Fri, 22 Jul 2022 17:36:53 +0200 Subject: [PATCH] Add option to set native window title bar, closes #219 --- app/lib/cubits/settings.dart | 12 ++++++++- app/lib/cubits/settings.freezed.dart | 37 ++++++++++++++++++++++----- app/lib/l10n/app_en.arb | 3 ++- app/lib/main.dart | 19 ++++++++++---- app/lib/settings/personalization.dart | 12 +++++++++ 5 files changed, 69 insertions(+), 14 deletions(-) diff --git a/app/lib/cubits/settings.dart b/app/lib/cubits/settings.dart index 3829a4379de3..ce25816d6c5c 100644 --- a/app/lib/cubits/settings.dart +++ b/app/lib/cubits/settings.dart @@ -128,7 +128,8 @@ class ButterflySettings with _$ButterflySettings { @Default(true) bool colorEnabled, String? lastVersion, @Default([]) List remotes, - @Default('') String defaultRemote}) = _ButterflySettings; + @Default('') String defaultRemote, + @Default(false) bool nativeWindowTitleBar}) = _ButterflySettings; factory ButterflySettings.fromPrefs(SharedPreferences prefs) { final remotes = prefs.getStringList('remotes')?.map((e) { @@ -167,6 +168,7 @@ class ButterflySettings with _$ButterflySettings { colorEnabled: prefs.getBool('color_enabled') ?? true, remotes: remotes, defaultRemote: prefs.getString('default_remote') ?? '', + nativeWindowTitleBar: prefs.getBool('native_window_title_bar') ?? false, ); } @@ -205,6 +207,7 @@ class ButterflySettings with _$ButterflySettings { await prefs.setStringList( 'remotes', remotes.map((e) => json.encode(e.toJson())).toList()); await prefs.setString('default_remote', defaultRemote); + await prefs.setBool('native_window_title_bar', nativeWindowTitleBar); } RemoteStorage? getRemote(String identifier) { @@ -467,4 +470,11 @@ class SettingsCubit extends Cubit { }).toList())); return save(); } + + Future changeNativeWindowTitleBar(bool value) { + emit(state.copyWith(nativeWindowTitleBar: value)); + return save(); + } + + Future resetNativeWindowTitleBar() => changeNativeWindowTitleBar(false); } diff --git a/app/lib/cubits/settings.freezed.dart b/app/lib/cubits/settings.freezed.dart index 40c3f1cadf5a..e38270a9e0dc 100644 --- a/app/lib/cubits/settings.freezed.dart +++ b/app/lib/cubits/settings.freezed.dart @@ -479,6 +479,7 @@ mixin _$ButterflySettings { String? get lastVersion => throw _privateConstructorUsedError; List get remotes => throw _privateConstructorUsedError; String get defaultRemote => throw _privateConstructorUsedError; + bool get nativeWindowTitleBar => throw _privateConstructorUsedError; @JsonKey(ignore: true) $ButterflySettingsCopyWith get copyWith => @@ -507,7 +508,8 @@ abstract class $ButterflySettingsCopyWith<$Res> { bool colorEnabled, String? lastVersion, List remotes, - String defaultRemote}); + String defaultRemote, + bool nativeWindowTitleBar}); } /// @nodoc @@ -538,6 +540,7 @@ class _$ButterflySettingsCopyWithImpl<$Res> Object? lastVersion = freezed, Object? remotes = freezed, Object? defaultRemote = freezed, + Object? nativeWindowTitleBar = freezed, }) { return _then(_value.copyWith( theme: theme == freezed @@ -608,6 +611,10 @@ class _$ButterflySettingsCopyWithImpl<$Res> ? _value.defaultRemote : defaultRemote // ignore: cast_nullable_to_non_nullable as String, + nativeWindowTitleBar: nativeWindowTitleBar == freezed + ? _value.nativeWindowTitleBar + : nativeWindowTitleBar // ignore: cast_nullable_to_non_nullable + as bool, )); } } @@ -636,7 +643,8 @@ abstract class _$$_ButterflySettingsCopyWith<$Res> bool colorEnabled, String? lastVersion, List remotes, - String defaultRemote}); + String defaultRemote, + bool nativeWindowTitleBar}); } /// @nodoc @@ -669,6 +677,7 @@ class __$$_ButterflySettingsCopyWithImpl<$Res> Object? lastVersion = freezed, Object? remotes = freezed, Object? defaultRemote = freezed, + Object? nativeWindowTitleBar = freezed, }) { return _then(_$_ButterflySettings( theme: theme == freezed @@ -739,6 +748,10 @@ class __$$_ButterflySettingsCopyWithImpl<$Res> ? _value.defaultRemote : defaultRemote // ignore: cast_nullable_to_non_nullable as String, + nativeWindowTitleBar: nativeWindowTitleBar == freezed + ? _value.nativeWindowTitleBar + : nativeWindowTitleBar // ignore: cast_nullable_to_non_nullable + as bool, )); } } @@ -763,7 +776,8 @@ class _$_ButterflySettings extends _ButterflySettings { this.colorEnabled = true, this.lastVersion, final List remotes = const [], - this.defaultRemote = ''}) + this.defaultRemote = '', + this.nativeWindowTitleBar = false}) : _history = history, _remotes = remotes, super._(); @@ -828,10 +842,13 @@ class _$_ButterflySettings extends _ButterflySettings { @override @JsonKey() final String defaultRemote; + @override + @JsonKey() + final bool nativeWindowTitleBar; @override String toString() { - return 'ButterflySettings(theme: $theme, localeTag: $localeTag, documentPath: $documentPath, dateFormat: $dateFormat, touchSensitivity: $touchSensitivity, mouseSensitivity: $mouseSensitivity, penSensitivity: $penSensitivity, selectSensitivity: $selectSensitivity, penOnlyInput: $penOnlyInput, inputGestures: $inputGestures, design: $design, history: $history, startEnabled: $startEnabled, colorEnabled: $colorEnabled, lastVersion: $lastVersion, remotes: $remotes, defaultRemote: $defaultRemote)'; + return 'ButterflySettings(theme: $theme, localeTag: $localeTag, documentPath: $documentPath, dateFormat: $dateFormat, touchSensitivity: $touchSensitivity, mouseSensitivity: $mouseSensitivity, penSensitivity: $penSensitivity, selectSensitivity: $selectSensitivity, penOnlyInput: $penOnlyInput, inputGestures: $inputGestures, design: $design, history: $history, startEnabled: $startEnabled, colorEnabled: $colorEnabled, lastVersion: $lastVersion, remotes: $remotes, defaultRemote: $defaultRemote, nativeWindowTitleBar: $nativeWindowTitleBar)'; } @override @@ -867,7 +884,9 @@ class _$_ButterflySettings extends _ButterflySettings { .equals(other.lastVersion, lastVersion) && const DeepCollectionEquality().equals(other._remotes, _remotes) && const DeepCollectionEquality() - .equals(other.defaultRemote, defaultRemote)); + .equals(other.defaultRemote, defaultRemote) && + const DeepCollectionEquality() + .equals(other.nativeWindowTitleBar, nativeWindowTitleBar)); } @override @@ -889,7 +908,8 @@ class _$_ButterflySettings extends _ButterflySettings { const DeepCollectionEquality().hash(colorEnabled), const DeepCollectionEquality().hash(lastVersion), const DeepCollectionEquality().hash(_remotes), - const DeepCollectionEquality().hash(defaultRemote)); + const DeepCollectionEquality().hash(defaultRemote), + const DeepCollectionEquality().hash(nativeWindowTitleBar)); @JsonKey(ignore: true) @override @@ -916,7 +936,8 @@ abstract class _ButterflySettings extends ButterflySettings { final bool colorEnabled, final String? lastVersion, final List remotes, - final String defaultRemote}) = _$_ButterflySettings; + final String defaultRemote, + final bool nativeWindowTitleBar}) = _$_ButterflySettings; const _ButterflySettings._() : super._(); @override @@ -954,6 +975,8 @@ abstract class _ButterflySettings extends ButterflySettings { @override String get defaultRemote; @override + bool get nativeWindowTitleBar; + @override @JsonKey(ignore: true) _$$_ButterflySettingsCopyWith<_$_ButterflySettings> get copyWith => throw _privateConstructorUsedError; diff --git a/app/lib/l10n/app_en.arb b/app/lib/l10n/app_en.arb index ae237c96e84d..60af2430c4ad 100644 --- a/app/lib/l10n/app_en.arb +++ b/app/lib/l10n/app_en.arb @@ -358,5 +358,6 @@ "folderSynced": "Folder synced", "syncRootDirectory": "Sync root directory", "penOnlyInput": "Pen only input", - "inputGestures": "Input gestures" + "inputGestures": "Input gestures", + "nativeWindowTitleBar": "Native window title bar" } \ No newline at end of file diff --git a/app/lib/main.dart b/app/lib/main.dart index 85f0db9061c7..686005a5af13 100644 --- a/app/lib/main.dart +++ b/app/lib/main.dart @@ -188,11 +188,20 @@ class ButterflyApp extends StatelessWidget { Widget build(BuildContext context) { return BlocProvider( create: (_) => SettingsCubit.fromPrefs(prefs), - child: RepositoryProvider( - create: (context) => - SyncService(context, context.read()), - lazy: false, - child: _buildApp(), + child: BlocBuilder( + buildWhen: (previous, current) => + previous.nativeWindowTitleBar != current.nativeWindowTitleBar, + builder: (context, settings) { + windowManager.setTitleBarStyle(settings.nativeWindowTitleBar + ? TitleBarStyle.normal + : TitleBarStyle.hidden); + return RepositoryProvider( + create: (context) => + SyncService(context, context.read()), + lazy: false, + child: _buildApp(), + ); + }, ), ); } diff --git a/app/lib/settings/personalization.dart b/app/lib/settings/personalization.dart index 2b2b05044f90..3e43884f7aea 100644 --- a/app/lib/settings/personalization.dart +++ b/app/lib/settings/personalization.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:butterfly/cubits/settings.dart'; import 'package:butterfly/views/main.dart'; import 'package:butterfly/visualizer/string.dart'; @@ -103,6 +105,16 @@ class PersonalizationSettingsPage extends StatelessWidget { child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ + if (!kIsWeb && (Platform.isWindows || Platform.isLinux)) + CheckboxListTile( + value: state.nativeWindowTitleBar, + title: Text(AppLocalizations.of(context)! + .nativeWindowTitleBar), + secondary: const Icon(PhosphorIcons.appWindowLight), + onChanged: (value) => context + .read() + .changeNativeWindowTitleBar(value ?? false), + ), CheckboxListTile( secondary: const Icon(PhosphorIcons.squaresFourLight), title: Text(AppLocalizations.of(context)!.start),