mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 23:34:24 +01:00
new: no titlebar on desktop
This commit is contained in:
@@ -25,8 +25,7 @@ enum SSHErrType {
|
||||
}
|
||||
|
||||
class SSHErr extends Err<SSHErrType> {
|
||||
SSHErr({required super.type, super.message})
|
||||
: super(from: ErrFrom.ssh);
|
||||
SSHErr({required super.type, super.message}) : super(from: ErrFrom.ssh);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
@@ -47,8 +46,7 @@ enum DockerErrType {
|
||||
}
|
||||
|
||||
class DockerErr extends Err<DockerErrType> {
|
||||
DockerErr({required super.type, super.message})
|
||||
: super(from: ErrFrom.docker);
|
||||
DockerErr({required super.type, super.message}) : super(from: ErrFrom.docker);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
@@ -63,8 +61,7 @@ enum ICloudErrType {
|
||||
}
|
||||
|
||||
class ICloudErr extends Err<ICloudErrType> {
|
||||
ICloudErr({required super.type, super.message})
|
||||
: super(from: ErrFrom.icloud);
|
||||
ICloudErr({required super.type, super.message}) : super(from: ErrFrom.icloud);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
@@ -79,8 +76,7 @@ enum WebdavErrType {
|
||||
}
|
||||
|
||||
class WebdavErr extends Err<WebdavErrType> {
|
||||
WebdavErr({required super.type, super.message})
|
||||
: super(from: ErrFrom.webdav);
|
||||
WebdavErr({required super.type, super.message}) : super(from: ErrFrom.webdav);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
class BuildData {
|
||||
static const String name = "ServerBox";
|
||||
static const int build = 665;
|
||||
static const int build = 667;
|
||||
static const String engine = "3.16.2";
|
||||
static const String buildAt = "2023-12-05 18:58:17";
|
||||
static const int modifications = 1;
|
||||
static const String buildAt = "2023-12-09 14:56:57";
|
||||
static const int modifications = 11;
|
||||
static const int script = 31;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:macos_window_utils/window_manipulator.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:toolbox/core/channel/bg_run.dart';
|
||||
@@ -15,6 +14,7 @@ import 'package:toolbox/core/utils/sync/webdav.dart';
|
||||
import 'package:toolbox/data/res/logger.dart';
|
||||
import 'package:toolbox/data/res/provider.dart';
|
||||
import 'package:toolbox/data/res/store.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
import 'app.dart';
|
||||
import 'core/analysis.dart';
|
||||
@@ -66,14 +66,15 @@ void _runInZone(void Function() body) {
|
||||
body,
|
||||
(obj, trace) {
|
||||
Analysis.recordException(trace);
|
||||
Loggers.root.warning(obj);
|
||||
Loggers.root.warning(obj, null, trace);
|
||||
},
|
||||
zoneSpecification: zoneSpec,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> initApp() async {
|
||||
await _initMacOSWindow();
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await _initDesktopWindow();
|
||||
|
||||
// Base of all data.
|
||||
await _initDb();
|
||||
@@ -125,12 +126,19 @@ void _setupLogger() {
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _initMacOSWindow() async {
|
||||
if (!isMacOS) return;
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await WindowManipulator.initialize();
|
||||
WindowManipulator.makeTitlebarTransparent();
|
||||
WindowManipulator.enableFullSizeContentView();
|
||||
WindowManipulator.hideTitle();
|
||||
await CustomAppBar.updateTitlebarHeight();
|
||||
Future<void> _initDesktopWindow() async {
|
||||
if (!isDesktop) return;
|
||||
await windowManager.ensureInitialized();
|
||||
const windowOptions = WindowOptions(
|
||||
size: Size(400, 777),
|
||||
center: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
skipTaskbar: false,
|
||||
titleBarStyle: TitleBarStyle.hidden,
|
||||
);
|
||||
if (isMacOS) await CustomAppBar.updateTitlebarHeight();
|
||||
windowManager.waitUntilReadyToShow(windowOptions, () async {
|
||||
await windowManager.show();
|
||||
await windowManager.focus();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -33,8 +33,8 @@ class _AndroidSettingsPageState extends State<AndroidSettingsPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: CustomAppBar(
|
||||
title: const Text('Android'),
|
||||
appBar: const CustomAppBar(
|
||||
title: Text('Android'),
|
||||
),
|
||||
body: ListView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 17),
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_highlight/theme_map.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:toolbox/core/build_mode.dart';
|
||||
import 'package:toolbox/core/extension/colorx.dart';
|
||||
import 'package:toolbox/core/extension/context/common.dart';
|
||||
import 'package:toolbox/core/extension/context/locale.dart';
|
||||
@@ -123,25 +124,28 @@ class _SettingPageState extends State<SettingPage> {
|
||||
),
|
||||
|
||||
/// Only for debug, this will cause the app to crash
|
||||
// onDoubleTap: () => context.showRoundDialog(
|
||||
// title: Text(l10n.attention),
|
||||
// child: Text(l10n.sureDelete(l10n.all)),
|
||||
// actions: [
|
||||
// TextButton(
|
||||
// onPressed: () {
|
||||
// Stores.docker.box.deleteFromDisk();
|
||||
// Stores.server.box.deleteFromDisk();
|
||||
// Stores.setting.box.deleteFromDisk();
|
||||
// Stores.history.box.deleteFromDisk();
|
||||
// Stores.snippet.box.deleteFromDisk();
|
||||
// Stores.key.box.deleteFromDisk();
|
||||
// exit(0);
|
||||
// },
|
||||
// child: Text(l10n.ok,
|
||||
// style: const TextStyle(color: Colors.red)),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
onDoubleTap: () => context.showRoundDialog(
|
||||
title: Text(l10n.attention),
|
||||
child: Text(l10n.askContinue(
|
||||
'Delete all data from disk, and exit the app?',
|
||||
)),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
if (!BuildMode.isDebug) return;
|
||||
Stores.docker.box.deleteFromDisk();
|
||||
Stores.server.box.deleteFromDisk();
|
||||
Stores.setting.box.deleteFromDisk();
|
||||
Stores.history.box.deleteFromDisk();
|
||||
Stores.snippet.box.deleteFromDisk();
|
||||
Stores.key.box.deleteFromDisk();
|
||||
exit(0);
|
||||
},
|
||||
child: Text(l10n.ok,
|
||||
style: const TextStyle(color: Colors.red)),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: const Icon(Icons.delete),
|
||||
),
|
||||
),
|
||||
@@ -160,8 +164,8 @@ class _SettingPageState extends State<SettingPage> {
|
||||
_buildSFTP(),
|
||||
_buildTitle(l10n.editor),
|
||||
_buildEditor(),
|
||||
_buildTitle(l10n.fullScreen),
|
||||
_buildFullScreen(),
|
||||
if (isDesktop) _buildTitle(l10n.fullScreen),
|
||||
if (isDesktop) _buildFullScreen(),
|
||||
const SizedBox(height: 37),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -34,8 +34,8 @@ class _IOSSettingsPageState extends State<IOSSettingsPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: CustomAppBar(
|
||||
title: const Text('iOS'),
|
||||
appBar: const CustomAppBar(
|
||||
title: Text('iOS'),
|
||||
),
|
||||
body: ListView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 17),
|
||||
|
||||
@@ -1,22 +1,95 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:macos_window_utils/window_manipulator.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
double? _titlebarHeight;
|
||||
int? _titlebarHeight;
|
||||
bool _drawTitlebar = false;
|
||||
|
||||
class CustomAppBar extends AppBar implements PreferredSizeWidget {
|
||||
CustomAppBar({
|
||||
class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
|
||||
const CustomAppBar({
|
||||
super.key,
|
||||
super.title,
|
||||
super.actions,
|
||||
super.centerTitle,
|
||||
super.leading,
|
||||
super.backgroundColor,
|
||||
}) : super(toolbarHeight: (_titlebarHeight ?? 0) + kToolbarHeight);
|
||||
this.title,
|
||||
this.actions,
|
||||
this.centerTitle,
|
||||
this.leading,
|
||||
this.backgroundColor,
|
||||
});
|
||||
|
||||
final Widget? title;
|
||||
final List<Widget>? actions;
|
||||
final bool? centerTitle;
|
||||
final Widget? leading;
|
||||
final Color? backgroundColor;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final bar = AppBar(
|
||||
key: key,
|
||||
title: title,
|
||||
actions: actions,
|
||||
centerTitle: centerTitle,
|
||||
leading: leading,
|
||||
backgroundColor: backgroundColor,
|
||||
toolbarHeight: (_titlebarHeight ?? 0) + kToolbarHeight,
|
||||
);
|
||||
if (!_drawTitlebar) return bar;
|
||||
return Stack(
|
||||
children: [
|
||||
bar,
|
||||
Positioned(
|
||||
right: 0,
|
||||
top: 0,
|
||||
child: Row(
|
||||
children: [
|
||||
const SizedBox(width: 8),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.minimize),
|
||||
onPressed: () => windowManager.minimize(),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.crop_square),
|
||||
onPressed: () async {
|
||||
if (await windowManager.isMaximized()) {
|
||||
windowManager.unmaximize();
|
||||
} else {
|
||||
windowManager.maximize();
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: () => windowManager.close(),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
static Future<void> updateTitlebarHeight() async {
|
||||
final newTitlebarHeight = await WindowManipulator.getTitlebarHeight();
|
||||
if (_titlebarHeight != newTitlebarHeight) {
|
||||
_titlebarHeight = newTitlebarHeight;
|
||||
switch (Platform.operatingSystem) {
|
||||
case 'macos':
|
||||
final newTitlebarHeight = await windowManager.getTitleBarHeight();
|
||||
if (_titlebarHeight != newTitlebarHeight) {
|
||||
_titlebarHeight = newTitlebarHeight;
|
||||
}
|
||||
break;
|
||||
// Draw a titlebar on Linux
|
||||
case 'linux' || 'windows':
|
||||
_titlebarHeight = 27;
|
||||
_drawTitlebar = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Size get preferredSize =>
|
||||
Size.fromHeight((_titlebarHeight ?? 0) + kToolbarHeight);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user