Skip to content

Commit

Permalink
Add option to start the app in full screen mode
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Sep 2, 2022
1 parent f89f131 commit 013fa47
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 66 deletions.
8 changes: 8 additions & 0 deletions app/lib/cubits/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class ButterflySettings with _$ButterflySettings {
@Default([]) List<RemoteStorage> remotes,
@Default('') String defaultRemote,
@Default(false) bool nativeWindowTitleBar,
@Default(false) bool startInFullScreen,
@Default(SyncMode.noMobile) SyncMode syncMode}) = _ButterflySettings;

factory ButterflySettings.fromPrefs(SharedPreferences prefs) {
Expand Down Expand Up @@ -172,6 +173,7 @@ class ButterflySettings with _$ButterflySettings {
remotes: remotes,
defaultRemote: prefs.getString('default_remote') ?? '',
nativeWindowTitleBar: prefs.getBool('native_window_title_bar') ?? false,
startInFullScreen: prefs.getBool('start_in_full_screen') ?? false,
syncMode:
SyncMode.values.byName(prefs.getString('sync_mode') ?? 'noMobile'),
);
Expand Down Expand Up @@ -213,6 +215,7 @@ class ButterflySettings with _$ButterflySettings {
'remotes', remotes.map((e) => json.encode(e.toJson())).toList());
await prefs.setString('default_remote', defaultRemote);
await prefs.setBool('native_window_title_bar', nativeWindowTitleBar);
await prefs.setBool('start_in_full_screen', startInFullScreen);
}

RemoteStorage? getRemote(String identifier) {
Expand Down Expand Up @@ -384,6 +387,11 @@ class SettingsCubit extends Cubit<ButterflySettings> {

Future<void> resetColorEnabled() => changeColorEnabled(true);

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

bool isFirstStart() {
return state.lastVersion == null;
}
Expand Down
25 changes: 24 additions & 1 deletion app/lib/cubits/settings.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ mixin _$ButterflySettings {
List<RemoteStorage> get remotes => throw _privateConstructorUsedError;
String get defaultRemote => throw _privateConstructorUsedError;
bool get nativeWindowTitleBar => throw _privateConstructorUsedError;
bool get startInFullScreen => throw _privateConstructorUsedError;
SyncMode get syncMode => throw _privateConstructorUsedError;

@JsonKey(ignore: true)
Expand Down Expand Up @@ -511,6 +512,7 @@ abstract class $ButterflySettingsCopyWith<$Res> {
List<RemoteStorage> remotes,
String defaultRemote,
bool nativeWindowTitleBar,
bool startInFullScreen,
SyncMode syncMode});
}

Expand Down Expand Up @@ -543,6 +545,7 @@ class _$ButterflySettingsCopyWithImpl<$Res>
Object? remotes = freezed,
Object? defaultRemote = freezed,
Object? nativeWindowTitleBar = freezed,
Object? startInFullScreen = freezed,
Object? syncMode = freezed,
}) {
return _then(_value.copyWith(
Expand Down Expand Up @@ -618,6 +621,10 @@ class _$ButterflySettingsCopyWithImpl<$Res>
? _value.nativeWindowTitleBar
: nativeWindowTitleBar // ignore: cast_nullable_to_non_nullable
as bool,
startInFullScreen: startInFullScreen == freezed
? _value.startInFullScreen
: startInFullScreen // ignore: cast_nullable_to_non_nullable
as bool,
syncMode: syncMode == freezed
? _value.syncMode
: syncMode // ignore: cast_nullable_to_non_nullable
Expand Down Expand Up @@ -652,6 +659,7 @@ abstract class _$$_ButterflySettingsCopyWith<$Res>
List<RemoteStorage> remotes,
String defaultRemote,
bool nativeWindowTitleBar,
bool startInFullScreen,
SyncMode syncMode});
}

Expand Down Expand Up @@ -686,6 +694,7 @@ class __$$_ButterflySettingsCopyWithImpl<$Res>
Object? remotes = freezed,
Object? defaultRemote = freezed,
Object? nativeWindowTitleBar = freezed,
Object? startInFullScreen = freezed,
Object? syncMode = freezed,
}) {
return _then(_$_ButterflySettings(
Expand Down Expand Up @@ -761,6 +770,10 @@ class __$$_ButterflySettingsCopyWithImpl<$Res>
? _value.nativeWindowTitleBar
: nativeWindowTitleBar // ignore: cast_nullable_to_non_nullable
as bool,
startInFullScreen: startInFullScreen == freezed
? _value.startInFullScreen
: startInFullScreen // ignore: cast_nullable_to_non_nullable
as bool,
syncMode: syncMode == freezed
? _value.syncMode
: syncMode // ignore: cast_nullable_to_non_nullable
Expand Down Expand Up @@ -791,6 +804,7 @@ class _$_ButterflySettings extends _ButterflySettings {
final List<RemoteStorage> remotes = const [],
this.defaultRemote = '',
this.nativeWindowTitleBar = false,
this.startInFullScreen = false,
this.syncMode = SyncMode.noMobile})
: _history = history,
_remotes = remotes,
Expand Down Expand Up @@ -861,11 +875,14 @@ class _$_ButterflySettings extends _ButterflySettings {
final bool nativeWindowTitleBar;
@override
@JsonKey()
final bool startInFullScreen;
@override
@JsonKey()
final SyncMode syncMode;

@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, nativeWindowTitleBar: $nativeWindowTitleBar, syncMode: $syncMode)';
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, startInFullScreen: $startInFullScreen, syncMode: $syncMode)';
}

@override
Expand Down Expand Up @@ -904,6 +921,8 @@ class _$_ButterflySettings extends _ButterflySettings {
.equals(other.defaultRemote, defaultRemote) &&
const DeepCollectionEquality()
.equals(other.nativeWindowTitleBar, nativeWindowTitleBar) &&
const DeepCollectionEquality()
.equals(other.startInFullScreen, startInFullScreen) &&
const DeepCollectionEquality().equals(other.syncMode, syncMode));
}

Expand All @@ -928,6 +947,7 @@ class _$_ButterflySettings extends _ButterflySettings {
const DeepCollectionEquality().hash(_remotes),
const DeepCollectionEquality().hash(defaultRemote),
const DeepCollectionEquality().hash(nativeWindowTitleBar),
const DeepCollectionEquality().hash(startInFullScreen),
const DeepCollectionEquality().hash(syncMode)
]);

Expand Down Expand Up @@ -958,6 +978,7 @@ abstract class _ButterflySettings extends ButterflySettings {
final List<RemoteStorage> remotes,
final String defaultRemote,
final bool nativeWindowTitleBar,
final bool startInFullScreen,
final SyncMode syncMode}) = _$_ButterflySettings;
const _ButterflySettings._() : super._();

Expand Down Expand Up @@ -998,6 +1019,8 @@ abstract class _ButterflySettings extends ButterflySettings {
@override
bool get nativeWindowTitleBar;
@override
bool get startInFullScreen;
@override
SyncMode get syncMode;
@override
@JsonKey(ignore: true)
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 @@ -385,5 +385,6 @@
"example": "1"
}
}
}
},
"startInFullScreen": "Start in full screen"
}
2 changes: 2 additions & 0 deletions app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:shared_preferences/shared_preferences.dart';
import 'package:window_manager/window_manager.dart';

import 'api/file_system.dart';
import 'api/full_screen.dart';
import 'cubits/settings.dart';
import 'embed/embedding.dart';
import 'models/converter.dart';
Expand Down Expand Up @@ -224,6 +225,7 @@ class ButterflyApp extends StatelessWidget {
? TitleBarStyle.normal
: TitleBarStyle.hidden);
}
setFullScreen(settings.startInFullScreen);
return RepositoryProvider(
create: (context) =>
SyncService(context, context.read<SettingsCubit>()),
Expand Down
7 changes: 7 additions & 0 deletions app/lib/settings/personalization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ class PersonalizationSettingsPage extends StatelessWidget {
.read<SettingsCubit>()
.changeColorEnabled(value ?? true),
),
CheckboxListTile(
value: state.startInFullScreen,
onChanged: (value) {},
title: Text(
AppLocalizations.of(context)!.startInFullScreen),
secondary: const Icon(PhosphorIcons.arrowsOutLight),
),
]),
),
),
Expand Down
125 changes: 64 additions & 61 deletions app/lib/views/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -480,67 +480,70 @@ class _WindowButtonsState extends State<WindowButtons> with WindowListener {
if (!kIsWeb && isWindow() && !settings.nativeWindowTitleBar) {
return LayoutBuilder(
builder: (context, constraints) => Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (widget.divider) const VerticalDivider(),
if (!fullScreen)
IconButton(
icon: Icon(alwaysOnTop
? PhosphorIcons.pushPinFill
: PhosphorIcons.pushPinLight),
tooltip: alwaysOnTop
? AppLocalizations.of(context)!.exitAlwaysOnTop
: AppLocalizations.of(context)!.alwaysOnTop,
onPressed: () async {
await windowManager.setAlwaysOnTop(!alwaysOnTop);
setState(() => alwaysOnTop = !alwaysOnTop);
},
),
IconButton(
icon: Icon(fullScreen
? PhosphorIcons.arrowsInLight
: PhosphorIcons.arrowsOutLight),
tooltip: fullScreen
? AppLocalizations.of(context)!.exitFullScreen
: AppLocalizations.of(context)!.enterFullScreen,
onPressed: () async {
setState(() => fullScreen = !fullScreen);
await windowManager.setFullScreen(fullScreen);
},
),
if (!fullScreen) ...[
const VerticalDivider(),
IconButton(
icon: const Icon(PhosphorIcons.minusLight),
tooltip: AppLocalizations.of(context)!.minimize,
iconSize: 16,
splashRadius: 20,
onPressed: () => windowManager.minimize(),
),
IconButton(
icon: Icon(PhosphorIcons.squareLight,
size: maximized ? 14 : 20),
tooltip: maximized
? AppLocalizations.of(context)!.restore
: AppLocalizations.of(context)!.maximize,
iconSize: 16,
splashRadius: 20,
onPressed: () async => await windowManager.isMaximized()
? windowManager.unmaximize()
: windowManager.maximize(),
),
IconButton(
icon: const Icon(PhosphorIcons.xLight),
tooltip: AppLocalizations.of(context)!.close,
hoverColor: Colors.red,
iconSize: 16,
splashRadius: 20,
onPressed: () => windowManager.close(),
)
]
],
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: ConstrainedBox(
constraints: const BoxConstraints(maxHeight: 42),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
if (widget.divider) const VerticalDivider(),
...[
if (!fullScreen)
IconButton(
icon: Icon(alwaysOnTop
? PhosphorIcons.pushPinFill
: PhosphorIcons.pushPinLight),
tooltip: alwaysOnTop
? AppLocalizations.of(context)!.exitAlwaysOnTop
: AppLocalizations.of(context)!.alwaysOnTop,
onPressed: () async {
await windowManager.setAlwaysOnTop(!alwaysOnTop);
setState(() => alwaysOnTop = !alwaysOnTop);
},
),
IconButton(
icon: Icon(fullScreen
? PhosphorIcons.arrowsInLight
: PhosphorIcons.arrowsOutLight),
tooltip: fullScreen
? AppLocalizations.of(context)!.exitFullScreen
: AppLocalizations.of(context)!.enterFullScreen,
onPressed: () async {
setState(() => fullScreen = !fullScreen);
await windowManager.setFullScreen(fullScreen);
},
),
if (!fullScreen) ...[
const VerticalDivider(),
IconButton(
icon: const Icon(PhosphorIcons.minusLight),
tooltip: AppLocalizations.of(context)!.minimize,
splashRadius: 20,
onPressed: () => windowManager.minimize(),
),
IconButton(
icon: Icon(PhosphorIcons.squareLight,
size: maximized ? 14 : 20),
tooltip: maximized
? AppLocalizations.of(context)!.restore
: AppLocalizations.of(context)!.maximize,
splashRadius: 20,
onPressed: () async =>
await windowManager.isMaximized()
? windowManager.unmaximize()
: windowManager.maximize(),
),
IconButton(
icon: const Icon(PhosphorIcons.xLight),
tooltip: AppLocalizations.of(context)!.close,
hoverColor: Colors.red,
splashRadius: 20,
onPressed: () => windowManager.close(),
)
]
].map((e) => AspectRatio(aspectRatio: 1, child: e))
],
),
),
),
);
Expand Down
4 changes: 2 additions & 2 deletions app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
name: _fe_analyzer_shared
url: "https://pub.dartlang.org"
source: hosted
version: "46.0.0"
version: "47.0.0"
adwaita:
dependency: "direct main"
description:
Expand All @@ -21,7 +21,7 @@ packages:
name: analyzer
url: "https://pub.dartlang.org"
source: hosted
version: "4.6.0"
version: "4.7.0"
animations:
dependency: "direct main"
description:
Expand Down
2 changes: 1 addition & 1 deletion app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ dev_dependencies:
sdk: flutter
flutter_driver:
sdk: flutter
analyzer: ^4.6.0
analyzer: ^4.7.0
freezed: ^2.1.0+1
build_runner: ^2.2.0
json_serializable: ^6.3.1
Expand Down
1 change: 1 addition & 0 deletions fastlane/metadata/android/en-US/changelogs/42.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Reset pointer on app hide
* Add default behavior to not ask for area name
* Add option to load images, pdfs and svgs from open dialog
* Add option to start the app in full screen mode
* Fix gesture issues on area and shape painter
* Fix area change problem
* Fix divider on top right in native title bar mode

0 comments on commit 013fa47

Please sign in to comment.