Skip to content

Commit

Permalink
Merge pull request #223 from LinwoodCloud/feature/native-window-title…
Browse files Browse the repository at this point in the history
…-bar

Add option to set native window title bar
  • Loading branch information
CodeDoctorDE authored Jul 24, 2022
2 parents ae24f57 + 565f810 commit 1a36d5f
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 92 deletions.
12 changes: 11 additions & 1 deletion app/lib/cubits/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ class ButterflySettings with _$ButterflySettings {
@Default(true) bool colorEnabled,
String? lastVersion,
@Default([]) List<RemoteStorage> 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) {
Expand Down Expand Up @@ -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,
);
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -467,4 +470,11 @@ class SettingsCubit extends Cubit<ButterflySettings> {
}).toList()));
return save();
}

Future<void> changeNativeWindowTitleBar(bool value) {
emit(state.copyWith(nativeWindowTitleBar: value));
return save();
}

Future<void> resetNativeWindowTitleBar() => changeNativeWindowTitleBar(false);
}
37 changes: 30 additions & 7 deletions app/lib/cubits/settings.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ mixin _$ButterflySettings {
String? get lastVersion => throw _privateConstructorUsedError;
List<RemoteStorage> get remotes => throw _privateConstructorUsedError;
String get defaultRemote => throw _privateConstructorUsedError;
bool get nativeWindowTitleBar => throw _privateConstructorUsedError;

@JsonKey(ignore: true)
$ButterflySettingsCopyWith<ButterflySettings> get copyWith =>
Expand Down Expand Up @@ -507,7 +508,8 @@ abstract class $ButterflySettingsCopyWith<$Res> {
bool colorEnabled,
String? lastVersion,
List<RemoteStorage> remotes,
String defaultRemote});
String defaultRemote,
bool nativeWindowTitleBar});
}

/// @nodoc
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
));
}
}
Expand Down Expand Up @@ -636,7 +643,8 @@ abstract class _$$_ButterflySettingsCopyWith<$Res>
bool colorEnabled,
String? lastVersion,
List<RemoteStorage> remotes,
String defaultRemote});
String defaultRemote,
bool nativeWindowTitleBar});
}

/// @nodoc
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
));
}
}
Expand All @@ -763,7 +776,8 @@ class _$_ButterflySettings extends _ButterflySettings {
this.colorEnabled = true,
this.lastVersion,
final List<RemoteStorage> remotes = const [],
this.defaultRemote = ''})
this.defaultRemote = '',
this.nativeWindowTitleBar = false})
: _history = history,
_remotes = remotes,
super._();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -916,7 +936,8 @@ abstract class _ButterflySettings extends ButterflySettings {
final bool colorEnabled,
final String? lastVersion,
final List<RemoteStorage> remotes,
final String defaultRemote}) = _$_ButterflySettings;
final String defaultRemote,
final bool nativeWindowTitleBar}) = _$_ButterflySettings;
const _ButterflySettings._() : super._();

@override
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
30 changes: 17 additions & 13 deletions app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,20 +188,27 @@ class ButterflyApp extends StatelessWidget {
Widget build(BuildContext context) {
return BlocProvider(
create: (_) => SettingsCubit.fromPrefs(prefs),
child: RepositoryProvider(
create: (context) =>
SyncService(context, context.read<SettingsCubit>()),
lazy: false,
child: _buildApp(),
child: BlocBuilder<SettingsCubit, ButterflySettings>(
buildWhen: (previous, current) =>
previous.nativeWindowTitleBar != current.nativeWindowTitleBar,
builder: (context, settings) {
if (!kIsWeb && isWindow()) {
windowManager.setTitleBarStyle(settings.nativeWindowTitleBar
? TitleBarStyle.normal
: TitleBarStyle.hidden);
}
return RepositoryProvider(
create: (context) =>
SyncService(context, context.read<SettingsCubit>()),
lazy: false,
child: _buildApp(),
);
},
),
);
}

Widget _buildApp() {
final virtualWindowFrameBuilder =
kIsWeb || (!Platform.isWindows && !Platform.isLinux)
? null
: VirtualWindowFrameInit();
return BlocBuilder<SettingsCubit, ButterflySettings>(
buildWhen: (previous, current) =>
previous.theme != current.theme ||
Expand All @@ -221,10 +228,7 @@ class ButterflyApp extends StatelessWidget {
if (child == null) {
return const Center(child: CircularProgressIndicator());
}
if (kIsWeb || virtualWindowFrameBuilder == null) {
return child;
}
return virtualWindowFrameBuilder(context, child);
return child;
},
darkTheme: ThemeManager.getThemeByName(state.design, dark: true),
));
Expand Down
12 changes: 12 additions & 0 deletions app/lib/settings/personalization.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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<SettingsCubit>()
.changeNativeWindowTitleBar(value ?? false),
),
CheckboxListTile(
secondary: const Icon(PhosphorIcons.squaresFourLight),
title: Text(AppLocalizations.of(context)!.start),
Expand Down
13 changes: 9 additions & 4 deletions app/lib/views/app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ class PadAppBar extends StatelessWidget with PreferredSizeWidget {
Widget build(BuildContext context) {
var bloc = context.read<DocumentBloc>();
return GestureDetector(onSecondaryTap: () {
if (isWindow()) {
if (!kIsWeb && isWindow()) {
windowManager.popUpWindowMenu();
}
}, onLongPress: () {
if (isWindow()) {
if (!kIsWeb && isWindow()) {
windowManager.popUpWindowMenu();
}
}, child: LayoutBuilder(
Expand Down Expand Up @@ -185,7 +185,12 @@ class PadAppBar extends StatelessWidget with PreferredSizeWidget {
isMobile: false,
)),
]);
if (!kIsWeb && isWindow()) {
if (!kIsWeb &&
isWindow() &&
!context
.read<SettingsCubit>()
.state
.nativeWindowTitleBar) {
return DragToMoveArea(child: title);
}
return title;
Expand Down Expand Up @@ -217,7 +222,7 @@ class PadAppBar extends StatelessWidget with PreferredSizeWidget {
},
),
],
if (isWindow()) ...[
if (!kIsWeb && isWindow()) ...[
const VerticalDivider(),
const WindowButtons()
]
Expand Down
Loading

0 comments on commit 1a36d5f

Please sign in to comment.