Skip to content

Commit

Permalink
support all desktop window button switch
Browse files Browse the repository at this point in the history
  • Loading branch information
ErBWs committed Jan 30, 2025
1 parent 632764e commit 09f31d0
Show file tree
Hide file tree
Showing 6 changed files with 209 additions and 169 deletions.
12 changes: 9 additions & 3 deletions lib/bean/appbar/sys_app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:kazumi/utils/utils.dart';
import 'package:flutter/material.dart';
import 'package:window_manager/window_manager.dart';
import 'package:flutter/services.dart';
import 'package:kazumi/utils/storage.dart';

class SysAppBar extends StatelessWidget implements PreferredSizeWidget {
final double? toolbarHeight;
Expand Down Expand Up @@ -58,6 +59,11 @@ class SysAppBar extends StatelessWidget implements PreferredSizeWidget {
});
}

bool showWindowButton() {
return GStorage.setting
.get(SettingBoxKey.showWindowButton, defaultValue: false);
}

@override
Widget build(BuildContext context) {
List<Widget> acs = [];
Expand All @@ -66,13 +72,13 @@ class SysAppBar extends StatelessWidget implements PreferredSizeWidget {
}
if (Utils.isDesktop()) {
// acs.add(IconButton(onPressed: () => windowManager.minimize(), icon: const Icon(Icons.minimize)));
if (!Platform.isMacOS) {
if (!showWindowButton()) {
acs.add(CloseButton(onPressed: () => _handleCloseEvent()));
}
acs.add(const SizedBox(width: 8));
}
return SafeArea(
minimum: (Platform.isMacOS && needTopOffset)
minimum: (Platform.isMacOS && needTopOffset && showWindowButton())
? const EdgeInsets.only(top: 22)
: EdgeInsets.zero,
child: GestureDetector(
Expand Down Expand Up @@ -107,7 +113,7 @@ class SysAppBar extends StatelessWidget implements PreferredSizeWidget {

@override
Size get preferredSize {
if (Platform.isMacOS && needTopOffset) {
if (Platform.isMacOS && needTopOffset && showWindowButton()) {
if (toolbarHeight != null) {
return Size.fromHeight(toolbarHeight! + 22);
} else {
Expand Down
37 changes: 21 additions & 16 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,6 @@ import 'package:provider/provider.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
MediaKit.ensureInitialized();
if (Utils.isDesktop()) {
await windowManager.ensureInitialized();
bool isLowResolution = await Utils.isLowResolution();
WindowOptions windowOptions = WindowOptions(
size: isLowResolution ? const Size(800, 600) : const Size(1280, 860),
center: true,
// backgroundColor: Colors.white,
skipTaskbar: false,
titleBarStyle: TitleBarStyle.hidden,
windowButtonVisibility: Platform.isMacOS ? true : false,
);
windowManager.waitUntilReadyToShow(windowOptions, () async {
await windowManager.show();
await windowManager.focus();
});
}
if (Platform.isAndroid || Platform.isIOS) {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
Expand All @@ -54,6 +38,27 @@ void main() async {
}));
return;
}
bool showWindowButton = await GStorage.setting
.get(SettingBoxKey.showWindowButton, defaultValue: false);
if (Utils.isDesktop()) {
await windowManager.ensureInitialized();
bool isLowResolution = await Utils.isLowResolution();
WindowOptions windowOptions = WindowOptions(
size: isLowResolution ? const Size(800, 600) : const Size(1280, 860),
center: true,
// backgroundColor: Colors.white,
skipTaskbar: false,
titleBarStyle: (Platform.isMacOS || !showWindowButton)
? TitleBarStyle.hidden
: TitleBarStyle.normal,
windowButtonVisibility: showWindowButton,
title: 'Kazumi',
);
windowManager.waitUntilReadyToShow(windowOptions, () async {
await windowManager.show();
await windowManager.focus();
});
}
Request();
await Request.setCookie();
runApp(
Expand Down
6 changes: 4 additions & 2 deletions lib/pages/menu/side_menu.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_modular/flutter_modular.dart';
import 'package:kazumi/pages/router.dart';
import 'package:provider/provider.dart';
import 'package:kazumi/utils/storage.dart';

class SideMenu extends StatefulWidget {
//const SideMenu({Key? key}) : super(key: key);
Expand Down Expand Up @@ -38,6 +38,8 @@ class SideNavigationBarState extends ChangeNotifier {
}

class _SideMenu extends State<SideMenu> {
bool showWindowButton = GStorage.setting
.get(SettingBoxKey.showWindowButton, defaultValue: false);
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
Expand All @@ -55,7 +57,7 @@ class _SideMenu extends State<SideMenu> {
leading: SizedBox(
width: 50,
child: Padding(
padding: Platform.isMacOS
padding: (Platform.isMacOS && showWindowButton)
? const EdgeInsets.only(top: 30)
: const EdgeInsets.only(top: 8),
child: ClipOval(
Expand Down
Loading

0 comments on commit 09f31d0

Please sign in to comment.