♻️ Gloablize pop intent

This commit is contained in:
2025-10-12 18:26:28 +08:00
parent 41c56a2319
commit 5327f04ec0

View File

@@ -92,108 +92,126 @@ class WindowScaffold extends HookConsumerWidget {
if (!kIsWeb && if (!kIsWeb &&
(Platform.isWindows || Platform.isLinux || Platform.isMacOS)) { (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
return Material( return Shortcuts(
color: Theme.of(context).colorScheme.surfaceContainer, shortcuts: <LogicalKeySet, Intent>{
child: Stack( LogicalKeySet(LogicalKeyboardKey.escape): const PopIntent(),
fit: StackFit.expand, },
children: [ child: Actions(
Column( actions: <Type, Action<Intent>>{PopIntent: PopAction(context)},
child: Material(
color: Theme.of(context).colorScheme.surfaceContainer,
child: Stack(
fit: StackFit.expand,
children: [ children: [
DragToMoveArea( Column(
child: children: [
Platform.isMacOS DragToMoveArea(
? Stack( child:
alignment: Alignment.center, Platform.isMacOS
children: [ ? Stack(
Row( alignment: Alignment.center,
children: [ children: [
if (Platform.isMacOS) Row(
const SizedBox(width: 80), children: [
...pageButtonActions, if (Platform.isMacOS)
const SizedBox(width: 80),
...pageButtonActions,
],
),
Text(
'Solar Network',
textAlign: TextAlign.center,
style: TextStyle(
color:
Theme.of(
context,
).colorScheme.onSurface,
),
),
],
)
: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Expanded(
child: Row(
children: [
Image.asset(
Theme.of(context).brightness ==
Brightness.dark
? 'assets/icons/icon-dark.png'
: 'assets/icons/icon.png',
width: 20,
height: 20,
),
const SizedBox(width: 8),
Text(
'Solar Network',
textAlign: TextAlign.start,
),
],
).padding(horizontal: 12, vertical: 5),
),
IconButton(
icon: Icon(Symbols.minimize),
onPressed: () => windowManager.minimize(),
iconSize: 16,
padding: EdgeInsets.all(8),
constraints: BoxConstraints(),
color: Theme.of(context).iconTheme.color,
),
IconButton(
icon: Icon(
isMaximized.value
? Symbols.fullscreen_exit
: Symbols.fullscreen,
),
onPressed: () async {
if (await windowManager.isMaximized()) {
windowManager.restore();
} else {
windowManager.maximize();
}
},
iconSize: 16,
padding: EdgeInsets.all(8),
constraints: BoxConstraints(),
color: Theme.of(context).iconTheme.color,
),
IconButton(
icon: Icon(Symbols.close),
onPressed: () => windowManager.hide(),
iconSize: 16,
padding: EdgeInsets.all(8),
constraints: BoxConstraints(),
color: Theme.of(context).iconTheme.color,
),
], ],
), ),
Text( ),
'Solar Network', Expanded(child: child),
textAlign: TextAlign.center, ],
style: TextStyle(
color:
Theme.of(context).colorScheme.onSurface,
),
),
],
)
: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Expanded(
child: Row(
children: [
Image.asset(
Theme.of(context).brightness ==
Brightness.dark
? 'assets/icons/icon-dark.png'
: 'assets/icons/icon.png',
width: 20,
height: 20,
),
const SizedBox(width: 8),
Text(
'Solar Network',
textAlign: TextAlign.start,
),
],
).padding(horizontal: 12, vertical: 5),
),
IconButton(
icon: Icon(Symbols.minimize),
onPressed: () => windowManager.minimize(),
iconSize: 16,
padding: EdgeInsets.all(8),
constraints: BoxConstraints(),
color: Theme.of(context).iconTheme.color,
),
IconButton(
icon: Icon(
isMaximized.value
? Symbols.fullscreen_exit
: Symbols.fullscreen,
),
onPressed: () async {
if (await windowManager.isMaximized()) {
windowManager.restore();
} else {
windowManager.maximize();
}
},
iconSize: 16,
padding: EdgeInsets.all(8),
constraints: BoxConstraints(),
color: Theme.of(context).iconTheme.color,
),
IconButton(
icon: Icon(Symbols.close),
onPressed: () => windowManager.hide(),
iconSize: 16,
padding: EdgeInsets.all(8),
constraints: BoxConstraints(),
color: Theme.of(context).iconTheme.color,
),
],
),
), ),
Expanded(child: child), _WebSocketIndicator(),
], ],
), ),
_WebSocketIndicator(), ),
],
), ),
); );
} }
return Stack( return Shortcuts(
fit: StackFit.expand, shortcuts: <LogicalKeySet, Intent>{
children: [Positioned.fill(child: child), _WebSocketIndicator()], LogicalKeySet(LogicalKeyboardKey.escape): const PopIntent(),
},
child: Actions(
actions: <Type, Action<Intent>>{PopIntent: PopAction(context)},
child: Stack(
fit: StackFit.expand,
children: [Positioned.fill(child: child), _WebSocketIndicator()],
),
),
); );
} }
} }
@@ -300,37 +318,29 @@ class AppScaffold extends HookConsumerWidget {
], ],
); );
return Shortcuts( return Focus(
shortcuts: <LogicalKeySet, Intent>{ focusNode: focusNode,
LogicalKeySet(LogicalKeyboardKey.escape): const PopIntent(), child: Scaffold(
}, extendBody: extendBody ?? true,
child: Actions( extendBodyBehindAppBar: true,
actions: <Type, Action<Intent>>{PopIntent: PopAction(context)}, backgroundColor:
child: Focus( noBackground
focusNode: focusNode, ? Colors.transparent
child: Scaffold( : Theme.of(context).scaffoldBackgroundColor,
extendBody: extendBody ?? true, body:
extendBodyBehindAppBar: true, noBackground
backgroundColor: ? content
noBackground : AppBackground(isRoot: true, child: content),
? Colors.transparent appBar: appBar,
: Theme.of(context).scaffoldBackgroundColor, bottomNavigationBar: bottomNavigationBar,
body: bottomSheet: bottomSheet,
noBackground drawer: drawer,
? content endDrawer: endDrawer,
: AppBackground(isRoot: true, child: content), floatingActionButton: floatingActionButton,
appBar: appBar, floatingActionButtonAnimator: floatingActionButtonAnimator,
bottomNavigationBar: bottomNavigationBar, floatingActionButtonLocation: TabbedFabLocation(context),
bottomSheet: bottomSheet, onDrawerChanged: onDrawerChanged,
drawer: drawer, onEndDrawerChanged: onEndDrawerChanged,
endDrawer: endDrawer,
floatingActionButton: floatingActionButton,
floatingActionButtonAnimator: floatingActionButtonAnimator,
floatingActionButtonLocation: TabbedFabLocation(context),
onDrawerChanged: onDrawerChanged,
onEndDrawerChanged: onEndDrawerChanged,
),
),
), ),
); );
} }