From 9368391cefddeca5db8ca1cee4b5bfbda20177a5 Mon Sep 17 00:00:00 2001 From: wanghongenpin Date: Sun, 17 Aug 2025 08:49:44 +0800 Subject: [PATCH] mac toolbar button --- lib/main.dart | 17 +++++++++++++++-- lib/ui/content/panel.dart | 1 + lib/ui/desktop/desktop.dart | 7 ++++++- lib/ui/desktop/left_menus/navigation.dart | 15 ++++++++------- lib/ui/desktop/request/list.dart | 2 +- macos/Flutter/GeneratedPluginRegistrant.swift | 2 ++ macos/Podfile | 2 +- macos/Runner.xcodeproj/project.pbxproj | 6 +++--- pubspec.yaml | 1 + 9 files changed, 38 insertions(+), 15 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 6d38b91..cc714f8 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -18,6 +18,7 @@ import 'dart:convert'; import 'dart:io'; import 'package:flutter/material.dart'; +import 'package:macos_window_utils/macos/ns_window_button_type.dart'; import 'package:proxypin/network/bin/configuration.dart'; import 'package:proxypin/ui/component/chinese_font.dart'; import 'package:proxypin/ui/component/multi_window.dart'; @@ -28,6 +29,7 @@ import 'package:proxypin/ui/mobile/mobile.dart'; import 'package:proxypin/utils/navigator.dart'; import 'package:proxypin/utils/platform.dart'; import 'package:window_manager/window_manager.dart'; +import 'package:macos_window_utils/macos_window_utils.dart'; import 'l10n/app_localizations.dart'; @@ -70,7 +72,18 @@ void main(List args) async { windowManager.setBrightness(appConfiguration.themeMode == ThemeMode.dark ? Brightness.dark : Brightness.light); } - windowManager.waitUntilReadyToShow(windowOptions, () async { + if (Platform.isMacOS) { + await WindowManipulator.initialize(); + // 调整关闭按钮的位置 + WindowManipulator.overrideStandardWindowButtonPosition( + buttonType: NSWindowButtonType.closeButton, offset: Offset(10, 16)); + WindowManipulator.overrideStandardWindowButtonPosition( + buttonType: NSWindowButtonType.miniaturizeButton, offset: const Offset(29, 16)); + WindowManipulator.overrideStandardWindowButtonPosition( + buttonType: NSWindowButtonType.zoomButton, offset: const Offset(48, 16)); + } + + await windowManager.waitUntilReadyToShow(windowOptions, () async { if (windowPosition != null) { await windowManager.setPosition(windowPosition); } @@ -116,7 +129,7 @@ class FluentApp extends StatelessWidget { bool isDark = brightness == Brightness.dark; Color? themeColor = isDark ? appConfiguration.themeColor : appConfiguration.themeColor; - Color? cardColor = isDark ? Colors.grey[850]! : Colors.white; + Color? cardColor = isDark ? Color(0XFF3C3C3C) : Colors.white; Color? surfaceContainer = isDark ? Colors.grey[800] : Colors.white; Color? secondary = useMaterial3 ? null : themeColor; diff --git a/lib/ui/content/panel.dart b/lib/ui/content/panel.dart index 45c44d4..3da426d 100644 --- a/lib/ui/content/panel.dart +++ b/lib/ui/content/panel.dart @@ -114,6 +114,7 @@ class NetworkTabState extends State with SingleTickerProvi var tabBar = TabBar( padding: const EdgeInsets.only(bottom: 0), controller: _tabController, + dividerColor: Theme.of(context).dividerColor.withOpacity(0.15), labelPadding: const EdgeInsets.symmetric(horizontal: 10), tabs: tabs.map((title) => Tab(child: Text(title, style: widget.tabStyle, maxLines: 1))).toList(), ); diff --git a/lib/ui/desktop/desktop.dart b/lib/ui/desktop/desktop.dart index 5614c0a..25f7d6d 100644 --- a/lib/ui/desktop/desktop.dart +++ b/lib/ui/desktop/desktop.dart @@ -109,7 +109,12 @@ class _DesktopHomePagePageState extends State implements EventL ]; return Scaffold( - appBar: Tab(child: Toolbar(proxyServer, requestListStateKey, sideNotifier: _selectIndex)), + appBar: Tab( + child: Container( + decoration: BoxDecoration( + border: Border(bottom: BorderSide(color: Theme.of(context).dividerColor.withOpacity(0.25), width: 0.2))), + child: Toolbar(proxyServer, requestListStateKey, sideNotifier: _selectIndex), + )), body: Row( children: [ LeftNavigationBar( diff --git a/lib/ui/desktop/left_menus/navigation.dart b/lib/ui/desktop/left_menus/navigation.dart index e2fd2ca..516aafd 100644 --- a/lib/ui/desktop/left_menus/navigation.dart +++ b/lib/ui/desktop/left_menus/navigation.dart @@ -42,19 +42,19 @@ class _LeftNavigationBarState extends State { List get destinations => [ NavigationRailDestination( - padding: const EdgeInsets.only(bottom: 3), + padding: const EdgeInsets.only(bottom: 5), icon: Icon(Icons.workspaces_outlined), label: Text(localizations.requests, style: Theme.of(context).textTheme.bodySmall)), NavigationRailDestination( - padding: const EdgeInsets.only(bottom: 3), + padding: const EdgeInsets.only(bottom: 5), icon: Icon(Icons.favorite_outline_outlined), label: Text(localizations.favorites, style: Theme.of(context).textTheme.bodySmall)), NavigationRailDestination( - padding: const EdgeInsets.only(bottom: 3), + padding: const EdgeInsets.only(bottom: 5), icon: Icon(Icons.history_outlined), label: Text(localizations.history, style: Theme.of(context).textTheme.bodySmall)), NavigationRailDestination( - padding: const EdgeInsets.only(bottom: 3), + padding: const EdgeInsets.only(bottom: 5), icon: Icon(Icons.hardware_outlined), label: Text(localizations.toolbox, style: Theme.of(context).textTheme.bodySmall)), ]; @@ -69,7 +69,7 @@ class _LeftNavigationBarState extends State { } return Container( - width: localizations.localeName == 'en' ? 68 : 55, + width: localizations.localeName == 'en' ? 70 : 57, decoration: BoxDecoration(border: Border(right: BorderSide(color: Theme.of(context).dividerColor, width: 0.2))), child: Column(children: [ @@ -110,10 +110,11 @@ class _LeftNavigationBarState extends State { //left menu eg: requests, favorites, history, toolbox Widget leftNavigation(int index) { return NavigationRail( - minWidth: 55, + minWidth: 57, backgroundColor: Theme.of(context).scaffoldBackgroundColor, selectedIconTheme: IconTheme.of(context).copyWith(color: Theme.of(context).colorScheme.primary, size: 22), - unselectedIconTheme: IconTheme.of(context).copyWith(color: Colors.black54, size: 22), + unselectedIconTheme: + IconTheme.of(context).copyWith(color: IconTheme.of(context).color?.withOpacity(0.55), size: 22), labelType: NavigationRailLabelType.all, destinations: destinations, selectedIndex: index, diff --git a/lib/ui/desktop/request/list.dart b/lib/ui/desktop/request/list.dart index 05c9ef1..a751711 100644 --- a/lib/ui/desktop/request/list.dart +++ b/lib/ui/desktop/request/list.dart @@ -91,7 +91,7 @@ class DesktopRequestListState extends State with Autom child: Scaffold( appBar: AppBar( toolbarHeight: 40, - title: SizedBox(height: 40, child: TabBar(tabs: tabs)), + title: SizedBox(height: 40, child: TabBar(tabs: tabs, dividerColor: Colors.transparent)), automaticallyImplyLeading: false, actions: [popupMenus()], ), diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 76534dc..0d1ddd6 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -10,6 +10,7 @@ import device_info_plus import file_picker import flutter_desktop_context_menu import flutter_js +import macos_window_utils import path_provider_foundation import proxy_manager import screen_retriever_macos @@ -25,6 +26,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { FilePickerPlugin.register(with: registry.registrar(forPlugin: "FilePickerPlugin")) FlutterDesktopContextMenuPlugin.register(with: registry.registrar(forPlugin: "FlutterDesktopContextMenuPlugin")) FlutterJsPlugin.register(with: registry.registrar(forPlugin: "FlutterJsPlugin")) + MacOSWindowUtilsPlugin.register(with: registry.registrar(forPlugin: "MacOSWindowUtilsPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) ProxyManagerPlugin.register(with: registry.registrar(forPlugin: "ProxyManagerPlugin")) ScreenRetrieverMacosPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverMacosPlugin")) diff --git a/macos/Podfile b/macos/Podfile index c795730..b52666a 100644 --- a/macos/Podfile +++ b/macos/Podfile @@ -1,4 +1,4 @@ -platform :osx, '10.14' +platform :osx, '10.15' # CocoaPods analytics sends network stats synchronously affecting flutter build latency. ENV['COCOAPODS_DISABLE_STATS'] = 'true' diff --git a/macos/Runner.xcodeproj/project.pbxproj b/macos/Runner.xcodeproj/project.pbxproj index ee63bbb..52c3d50 100644 --- a/macos/Runner.xcodeproj/project.pbxproj +++ b/macos/Runner.xcodeproj/project.pbxproj @@ -592,7 +592,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.14; + MACOSX_DEPLOYMENT_TARGET = 10.15; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; SWIFT_COMPILATION_MODE = wholemodule; @@ -685,7 +685,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.14; + MACOSX_DEPLOYMENT_TARGET = 10.15; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; @@ -734,7 +734,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.14; + MACOSX_DEPLOYMENT_TARGET = 10.15; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; SWIFT_COMPILATION_MODE = wholemodule; diff --git a/pubspec.yaml b/pubspec.yaml index 62f6699..a84b441 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -47,6 +47,7 @@ dependencies: brotli: ^0.6.0 + macos_window_utils: ^1.8.4 win32audio: ^1.3.1 vclibs: ^0.1.3