forked from alesimula/wsa_pacman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.dart
580 lines (528 loc) · 24.5 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
// ignore_for_file: constant_identifier_names, curly_braces_in_flow_control_structures, non_constant_identifier_names
import 'dart:ui';
import 'package:flutter/material.dart' as material;
import 'package:mdi/mdi.dart';
import 'package:flutter_localizations/flutter_localizations.dart' as locale;
import 'package:wsa_pacman/android/android_utils.dart';
import 'package:wsa_pacman/apk_installer.dart';
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter/foundation.dart';
//import 'package:flutter/material.dart' hide showDialog;
import 'package:shared_value/shared_value.dart';
import 'package:wsa_pacman/io/isolate_runner.dart';
import 'package:wsa_pacman/utils/misc_utils.dart';
import 'package:wsa_pacman/utils/wsa_utils.dart';
import 'package:wsa_pacman/utils/locale_utils.dart';
import 'package:wsa_pacman/widget/themed_pane_item.dart';
import 'package:wsa_pacman/windows/win_info.dart';
import 'package:wsa_pacman/windows/win_reg.dart';
import 'package:wsa_pacman/windows/wsa_status.dart';
import 'global_state.dart';
import 'package:provider/provider.dart';
import 'package:system_theme/system_theme.dart';
import 'package:bitsdojo_window/bitsdojo_window.dart';
import 'package:flutter_acrylic/flutter_acrylic.dart' as flutter_acrylic;
import 'package:url_strategy/url_strategy.dart';
import 'screens/wsa.dart';
import 'screens/settings.dart';
import 'utils/string_utils.dart';
import 'dart:io';
import 'dart:developer';
import 'dart:async';
import 'theme.dart';
const String appTitle = 'WSA Package Manager';
const String appVersion = '1.4.0';
late bool darkMode;
class WSAStatusAlert {
WSAStatusAlert(this.type, this.severity, this.title, this.desc);
final ConnectionStatus type;
final InfoBarSeverity severity;
final String Function(AppLocalizations lang) title;
final String Function(AppLocalizations lang) desc;
bool get isConnected => type == ConnectionStatus.CONNECTED;
bool get isDisconnected => type != ConnectionStatus.CONNECTED;
bool get isPoweredOn => isConnected || type == ConnectionStatus.DISCONNECTED
|| type == ConnectionStatus.OFFLINE || type == ConnectionStatus.UNAUTHORIZED;
}
enum ConnectionStatus {
UNSUPPORTED, MISSING, UNKNOWN, ARRESTED, STARTING, OFFLINE, DISCONNECTED, CONNECTED, UNAUTHORIZED
}
extension on ConnectionStatus {
static final Map<ConnectionStatus, WSAStatusAlert> _statusAlers = {
ConnectionStatus.UNSUPPORTED: WSAStatusAlert(ConnectionStatus.UNSUPPORTED, InfoBarSeverity.error, (l)=>l.status_unsupported,
(l)=>l.status_unsupported_desc(WinVer.isWindows10OrGreater ? l.status_subtext_winver_10 : l.status_subtext_winver_older)),
ConnectionStatus.MISSING: WSAStatusAlert(ConnectionStatus.MISSING, InfoBarSeverity.error, (l)=>l.status_missing, (l)=>l.status_missing_desc),
ConnectionStatus.UNKNOWN: WSAStatusAlert(ConnectionStatus.UNKNOWN, InfoBarSeverity.info, (l)=>l.status_unknown, (l)=>l.status_unknown_desc),
ConnectionStatus.STARTING: WSAStatusAlert(ConnectionStatus.STARTING, InfoBarSeverity.info, (l)=>l.status_starting, (l)=>l.status_starting_desc),
ConnectionStatus.ARRESTED: WSAStatusAlert(ConnectionStatus.ARRESTED, InfoBarSeverity.warning, (l)=>l.status_arrested, (l)=>l.status_arrested_desc),
ConnectionStatus.OFFLINE: WSAStatusAlert(ConnectionStatus.OFFLINE, InfoBarSeverity.warning, (l)=>l.status_offline, (l)=>l.status_offline_desc),
ConnectionStatus.DISCONNECTED: WSAStatusAlert(ConnectionStatus.DISCONNECTED, InfoBarSeverity.error, (l)=>l.status_disconnected, (l)=>l.status_disconnected_desc),
ConnectionStatus.CONNECTED: WSAStatusAlert(ConnectionStatus.CONNECTED, InfoBarSeverity.success, (l)=>l.status_connected, (l)=>l.status_connected_desc),
ConnectionStatus.UNAUTHORIZED: WSAStatusAlert(ConnectionStatus.UNAUTHORIZED, InfoBarSeverity.warning, (l)=>l.status_unauthorized, (l)=>'${l.status_unauthorized_desc}\n'),
};
WSAStatusAlert get statusAlert => _statusAlers[this] ?? WSAStatusAlert(this, InfoBarSeverity.error, (l)=>"Unmapped status",
(l)=>"Encountered WSA connection status $this, the status is missing an alert message");
}
extension __EnumExtension on Enum {
String name() {
return toString().split('.').last.toLowerCase();
}
}
class Env {
static final String SYSTEM_ROOT = Platform.environment["SystemRoot"] ?? "";
static final String USER_PROFILE = Platform.environment["UserProfile"] ?? "";
static final String EXEC_DIR = Platform.resolvedExecutable.replaceFirst(RegExp(r'[/\\][^/\\]*$'), r'\');
static final String TOOLS_DIR = "${EXEC_DIR}embedded-tools\\";
static late final String POWERSHELL = WinReg.getString(RegHKey.HKEY_LOCAL_MACHINE, r'SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell', 'Path')?.value ?? '$SYSTEM_ROOT\\System32\\WindowsPowerShell\v1.0\\powershell.exe';
static late final String WSA_SYSTEM_PATH = RegExp(r'^(.*)[\\/]+[^\\/]*[\\/]+[^\\/]*$').firstMatch(
WinReg.getString(RegHKey.HKEY_LOCAL_MACHINE, r'SYSTEM\CurrentControlSet\Services\WsaService', 'ImagePath')?.value.unquoted ??
WinReg.getString(RegHKey.HKEY_CURRENT_USER, r'Software\Microsoft\Windows\CurrentVersion\App Paths\WsaClient.exe', null)?.value ?? ''
)?.group(1) ?? '';
static late final String WSA_EXECUTABLE = '$WSA_SYSTEM_PATH\\WsaClient\\WsaClient.exe';
static late final bool WSA_INSTALLED = File('$WSA_SYSTEM_PATH\\AppxManifest.xml').existsSync();
static late final WSA_INFO = WSAPkgInfo.fromSystemPath(WSA_SYSTEM_PATH);
}
class WSAPeriodicConnector {
static const PERIODIC_CHECK_BOOT_DURATION = Duration(milliseconds: 500);
static const PERIODIC_CHECK_CONNECT_DURATION = Duration(seconds: 5);
static int lastStart = 0;
static bool get shouldWaitStart => DateTime.now().millisecondsSinceEpoch - lastStart < 15000;
static final DynamicTimer timer = DynamicTimer((Timer t) => WSAPeriodicConnector._checkConnectionStatus());
static ConnectionStatus status = ConnectionStatus.UNKNOWN;
static WSAStatusAlert alertStatus = ConnectionStatus.UNKNOWN.statusAlert;
static bool _statusInitialized = false;
static void _checkConnectionStatus() async {
if (_statusInitialized) {
Process.run('${Env.SYSTEM_ROOT}\\System32\\tasklist.exe', []).then((result){
if (!result.stdout.toString().contains(RegExp(r'(^|\n)adb.exe\s+'))) {
status = ConnectionStatus.UNKNOWN;
GState.connectionStatus.update((p0) => status.statusAlert);
}
});
}
if (!WSAStatus.isBooted) {
timer.setDuration(PERIODIC_CHECK_BOOT_DURATION);
ConnectionStatus newStatus = Env.WSA_INSTALLED ? ConnectionStatus.ARRESTED : WinVer.isWindows11OrGreater ? ConnectionStatus.MISSING : ConnectionStatus.UNSUPPORTED;
if (status != newStatus) GState.connectionStatus.$ = (status = newStatus).statusAlert;
return;
}
else {
timer.setDuration(PERIODIC_CHECK_CONNECT_DURATION);
if (status == ConnectionStatus.ARRESTED || status == ConnectionStatus.MISSING || status == ConnectionStatus.UNSUPPORTED)
lastStart = DateTime.now().millisecondsSinceEpoch;
}
final prevStatus = status;
final process = await ADBUtils.devices();
final output = process.stdout.toString();
if (output.contains(RegExp('(^|\\n)(localhost|127.0.0.1):${GState.androidPort.$}\\s+'))) {
if (output.contains(RegExp('(^|\\n)(localhost|127.0.0.1):${GState.androidPort.$}\\s+offline(\$|\\n|\\s)')))
status = (status == ConnectionStatus.ARRESTED || status == ConnectionStatus.STARTING) && shouldWaitStart ?
ConnectionStatus.STARTING : ConnectionStatus.OFFLINE;
else if (output.contains(RegExp('(^|\\n)(localhost|127.0.0.1):${GState.androidPort.$}\\s+host(\$|\\n|\\s)'))) {
reconnect();
}
else if (output.contains(RegExp('(^|\\n)(localhost|127.0.0.1):${GState.androidPort.$}\\s+unauthorized(\$|\\n|\\s)'))) {
status = ConnectionStatus.UNAUTHORIZED;
if (prevStatus == ConnectionStatus.UNKNOWN) reconnect();
}
else {
status = ConnectionStatus.CONNECTED;
if (output.contains(RegExp('(^|\\n)127.0.0.1:${GState.androidPort.$}\\s+'))) {
if (GState.ipAddress.$ != "127.0.0.1") GState.ipAddress.update((old) => "127.0.0.1");
}
else if (GState.ipAddress.$ != "localhost") GState.ipAddress.update((old) => "localhost");
}
}
//else status = ConnectionStatus.DISCONNECTED;
/*if (status != prevStatus) {
(alert.title as Text).data = ""
}*/
else await _tryConnect();
if (status != prevStatus) GState.connectionStatus.update((p0) => status.statusAlert);
_statusInitialized = false;
log("Connection status: ${status.name()}");
}
static Future<void> reconnect() async {
await ADBUtils.disconnectWSA();
await _tryConnect();
}
static Future<void> _tryConnect() async {
ProcessResult? process = await ADBUtils.connectWSA().processTimeout(const Duration(milliseconds: 200));
if (process.stdout?.toString().contains(RegExp(r'(^|\n)(cannot|failed to) connect\s.*')) ?? true)
status = Env.WSA_INSTALLED ? (status == ConnectionStatus.ARRESTED || status == ConnectionStatus.STARTING) && shouldWaitStart ?
ConnectionStatus.STARTING : ConnectionStatus.OFFLINE : ConnectionStatus.DISCONNECTED;
else if (process.stdout?.toString().contains(RegExp(r'(^|\n)(cannot|failed to) authenticate\s.*')) ?? true)
status = ConnectionStatus.UNAUTHORIZED;
else status = ConnectionStatus.CONNECTED;
}
}
/// Checks if the current environment is a desktop environment.
bool get isDesktop {
if (kIsWeb) return false;
return [
TargetPlatform.windows,
TargetPlatform.linux,
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
}
class Constants {
//static late final List<String> args;
static late final String packageFile;
static late final AppPackage packageType;
static late final bool installMode;
static late final IsolateRef<dynamic, APK_READER_FLAGS>? isolate;
}
void main(List<String> arguments) async {
//int prevTime = DateTime.now().millisecondsSinceEpoch;
//arguments = [r'C:\Users\Alex\Downloads\caab_585.apk'];
//arguments = [r'C:\Users\Alex\Downloads\Chrome.xapk'];
WidgetsFlutterBinding.ensureInitialized();
final darkModeFuture = SystemTheme.darkMode;
const app = MyApp();
final wrappedApp = SharedValue.wrapApp(app);
darkMode = await darkModeFuture;
runApp(wrappedApp);
AppOptions.init();
Constants.installMode = arguments.isNotEmpty;
Constants.packageFile = Constants.installMode ? arguments.first : '';
Constants.packageType = AppPackageType.fromArguments(arguments);
Constants.isolate = Constants.installMode ? Constants.packageType.read(arguments.first) : null;
//await SystemTheme.accentInstance.load();
await flutter_acrylic.Window.initialize();
WSAPeriodicConnector._checkConnectionStatus();
flutter_acrylic.Window.hideWindowControls();
//flutter_acrylic.Window.setEffect(effect: flutter_acrylic.WindowEffect.mica);
if (isDesktop) {
doWhenWindowReady(() {
//log("UI started after ${DateTime.now().millisecondsSinceEpoch - prevTime}");
final win = appWindow;
if (!Constants.installMode) {
win.minSize = const Size(640, 500);
win.size = const Size(740, 540);
win.title = appTitle;
}
else {
win.minSize = win.maxSize = win.size = const Size(500, 335);
}
win.alignment = Alignment.center;
win.show();
late final _SET_VISIBLE = Constants.isolate?.sendFlag(APK_READER_FLAGS.UI_LOADED, true);
late final Timer uiTimer; uiTimer = Timer.periodic(const Duration(milliseconds: 100), (t) {if (win.isVisible) {
_SET_VISIBLE;
uiTimer.cancel();
}});
});
}
}
class _FluentLocalizationsEnglish extends LocalizationsDelegate<FluentLocalizations> {
const _FluentLocalizationsEnglish();
@override bool isSupported(Locale locale) => true;
@override bool shouldReload(_FluentLocalizationsEnglish old) => false;
@override Future<FluentLocalizations> load(Locale locale) => DefaultFluentLocalizations.load(locale);
@override String toString() => 'DefaultFluentLocalizations.delegate(en_US)';
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
void setMicaEffect(bool micaEnabled, [bool dark = true]) {
if (WinVer.isWindows11OrGreater)
flutter_acrylic.Window.setEffect(effect: micaEnabled ? flutter_acrylic.WindowEffect.mica : flutter_acrylic.WindowEffect.disabled, dark: dark);
}
@override
Widget build(BuildContext context) {
final theme = GState.theme.of(context).mode;
final mica = GState.mica.of(context);
final bool isDark = theme == ThemeMode.system ? darkMode : theme == ThemeMode.dark;
setMicaEffect(mica.enabled, isDark);
final bool isMicaInstall = Constants.installMode && mica.enabled;
final bool IsFullMicaOrInstall = mica.full || isMicaInstall;
return ChangeNotifierProvider(
create: (_) => AppTheme(),
builder: (context, _) {
final appTheme = context.watch<AppTheme>();
return FluentApp(
title: appTitle,
themeMode: theme,
debugShowCheckedModeBanner: false,
initialRoute: '/',
locale: GState.locale.of(context),
localizationsDelegates: const [
AppLocalizations.delegate,
locale.GlobalMaterialLocalizations.delegate,
locale.GlobalWidgetsLocalizations.delegate,
//locale.GlobalCupertinoLocalizations.delegate,
_FluentLocalizationsEnglish(),
],
supportedLocales: LocaleUtils.supportedLocales,
localeResolutionCallback: LocaleUtils.localeResolutionCallback,
routes: {'/': (_) => Constants.installMode ? const ApkInstaller() : const MyHomePage()},
theme: ThemeData(
buttonTheme: ButtonThemeData(
defaultButtonStyle: ButtonStyle(
shadowColor: ButtonState.all(Colors.transparent),
border: ButtonState.resolveWith((states) {
if (isDark) {
if (states.isDisabled) return const BorderSide(width: 0.5, color: ColorConst.withOpacity(0xf0f0f0, 0.05));
if (states.isNone || (states.isHovering && !states.isPressing)) return const BorderSide(width: 0.5, color: ColorConst.withOpacity(0xf0f0f0, 0.035));
else return const BorderSide(width: 0.5, color: ColorConst.withOpacity(0xf0f0f0, 0.07));
}
else {
if (states.isDisabled) return const BorderSide(width: 0.5, color: ColorConst.withOpacity(0x212121, 0.12));
if (states.isNone || (states.isHovering && !states.isDisabled && !states.isPressing)) return const BorderSide(width: 0.5, color: ColorConst.withOpacity(0x212121, 0.22));
else return const BorderSide(width: 0.5, color: ColorConst.withOpacity(0x212121, 0.07));
}
}),
backgroundColor: ButtonState.resolveWith((states) {
if (isDark) {
if (states.isDisabled) return const ColorConst.withOpacity(0xFFFFFF, 0.045);
if (states.isPressing) return const ColorConst.withOpacity(0xFFFFFF, 0.03);
if (states.isHovering) return const ColorConst.withOpacity(0xFFFFFF, 0.08);
return const ColorConst.withOpacity(0xFFFFFF, 0.055);
}
else {
if (states.isDisabled) return const ColorConst.withOpacity(0xf9f9f9, 0.045);
if (states.isPressing) return const ColorConst.withOpacity(0xf0f0f0, 0.4);
if (states.isHovering) return const ColorConst.withOpacity(0xf9f9f9, 0.65);
return const ColorConst.withOpacity(0xFFFFFF, 0.8);
}
})
) ,
),
scaffoldBackgroundColor: IsFullMicaOrInstall ? Colors.transparent : isDark ? const Color(0xFF272727) : const Color(0xFFf9f9f9),
micaBackgroundColor: mica.enabled ? Colors.transparent : isDark ? const Color(0xFF202020) : const Color(0xFFf3f3f3),
accentColor: appTheme.getColor(isDark),
brightness: isDark ? Brightness.dark : Brightness.light,
visualDensity: VisualDensity.standard,
focusTheme: FocusThemeData(
glowFactor: is10footScreen() ? 2.0 : 0.0,
),
),
);
},
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool value = false;
int index = 0;
final colorsController = ScrollController();
final settingsController = ScrollController();
@override
void dispose() {
colorsController.dispose();
settingsController.dispose();
super.dispose();
}
@override
void initState() {
// TODO: implement initState
/*flutter_acrylic.Acrylic.setEffect(
effect: flutter_acrylic.AcrylicEffect.acrylic,
gradientColor: Colors.black.withOpacity(0.2)
);*/
}
@override
Widget build(BuildContext context) {
final lang = AppLocalizations.of(context)!;
final appTheme = context.watch<AppTheme>();
final mica = GState.mica.of(context);
final theme = FluentTheme.of(context);
return NavigationView(
contentShape: RoundedRectangleBorder(
side: BorderSide(width: 0.3, color: theme.micaBackgroundColor.lerpWith(Colors.black, 0.25)),
borderRadius: const BorderRadius.only(),
),
appBar: NavigationAppBar(
// height: !kIsWeb ? appWindow.titleBarHeight : 31.0,
/*title: () {
if (kIsWeb) return const Text(appTitle);
return MoveWindow(
child: const Align(
alignment: Alignment.centerLeft,
child: Text(appTitle),
),
);
}(),*/
actions: kIsWeb
? null
: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(flex: 1,child: MoveWindow(child: Padding(
padding: const EdgeInsets.only(top: 9, left: 13, right: 13),
child: Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
Text(lang.screen_wsa, style: theme.typography.caption),
const SizedBox(width: 10),
Text('v$appVersion', style: theme.typography.caption?.copyWith(color: theme.inactiveColor.withAlpha(theme.brightness.isLight ? 0x3F : 0x1B))),
])
))),
const WindowButtons()
],
)
/*MoveWindow(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [Spacer(), WindowButtons()],
),
),*/
),
pane: NavigationPane(
selected: index,
onChanged: (i) => setState(() => index = i),
header: Container(
height: kOneLineTileHeight,
padding: const EdgeInsets.symmetric(horizontal: 10.0),
child: material.Row(children: [AnimatedContainer(
width: 28,
height: 28,
duration: const Duration(milliseconds: 750),
curve: Curves.fastOutSlowIn,
decoration: const BoxDecoration (
image: DecorationImage(image: AssetImage("assets/images/logo.png"))
),
), const SizedBox(width: 10), Text("WSA PacMan", style: theme.typography.bodyLarge)]),
),
displayMode: appTheme.displayMode,
indicatorBuilder: ({
required BuildContext context,
required NavigationPane pane,
Axis? axis,
required Widget child,
}) {
if (pane.selected == null) return child;
axis ??= Axis.horizontal;
assert(debugCheckHasFluentTheme(context));
final theme = NavigationPaneTheme.of(context);
switch (appTheme.indicator) {
case NavigationIndicators.end:
return EndNavigationIndicator(
index: pane.selected!,
offsets: () =>
pane.effectiveItems.getPaneItemsOffsets(pane.paneKey),
sizes: pane.effectiveItems.getPaneItemsSizes,
child: child,
color: theme.highlightColor,
curve: theme.animationCurve ?? Curves.linear,
axis: axis,
);
case NavigationIndicators.sticky:
return NavigationPane.defaultNavigationIndicator(
context: context,
axis: axis,
pane: pane,
child: child,
);
default:
return NavigationIndicator(
index: pane.selected!,
offsets: () =>
pane.effectiveItems.getPaneItemsOffsets(pane.paneKey),
sizes: pane.effectiveItems.getPaneItemsSizes,
child: child,
color: theme.highlightColor,
curve: theme.animationCurve ?? Curves.linear,
axis: axis,
);
}
},
items: [
// It doesn't look good when resizing from compact to open
// PaneItemHeader(header: Text('User Interaction')),
ThemablePaneItem(
icon: const Icon(Mdi.androidDebugBridge),
title: const Text('WSA'),
translucent: mica.enabled,
forceDisplayMode: appTheme.displayMode
)
/*PaneItem(
icon: Icon(
appTheme.displayMode == PaneDisplayMode.top
? FluentIcons.more
: FluentIcons.more_vertical,
),
title: const Text('Others'),
),*/
],
footerItems: [
PaneItemSeparator(),
ThemablePaneItem(
icon: const Icon(FluentIcons.settings),
title: Text(lang.screen_settings),
translucent: mica.enabled,
forceDisplayMode: appTheme.displayMode
),
],
),
content: NavigationBody(index: index, children: [
const ScreenWSA(),
//const Others(),
ScreenSettings(controller: settingsController),
]),
);
}
}
class WindowButtons extends StatelessWidget {
const WindowButtons({Key? key}) : super(key: key);
static Color windowButtonAlphaColor(ThemeData style, Set<ButtonStates> states) {
if (style.brightness == Brightness.light) {
if (states.isPressing) return Colors.black.withOpacity(0.075);
if (states.isHovering) return Colors.black.withOpacity(0.11);
return Colors.transparent;
} else {
if (states.isPressing) return Colors.white.withOpacity(0.03);
if (states.isHovering) return Colors.white.withOpacity(0.06);
return Colors.transparent;
}
}
@override
Widget build(BuildContext context) {
assert(debugCheckHasFluentTheme(context));
assert(debugCheckHasFluentLocalizations(context));
final ThemeData theme = FluentTheme.of(context);
final mica = GState.mica.of(context);
final buttonColors = WindowButtonColors(
iconNormal: theme.inactiveColor,
iconMouseDown: theme.inactiveColor,
iconMouseOver: theme.inactiveColor,
//Fixed button colors
mouseOver: mica.enabled ? windowButtonAlphaColor(theme, {ButtonStates.hovering}) : ButtonThemeData.buttonColor(
theme.brightness, {ButtonStates.hovering}).lerpWith(Colors.black, 0.12),
mouseDown: mica.enabled ? windowButtonAlphaColor(theme, {ButtonStates.pressing}) : ButtonThemeData.buttonColor(
theme.brightness, {ButtonStates.pressing}).lerpWith(theme.shadowColor, 0.12).withAlpha(150),
);
final closeButtonColors = WindowButtonColors(
mouseOver: Colors.red,
mouseDown: Colors.red.dark,
iconNormal: theme.inactiveColor,
iconMouseOver: Colors.red.basedOnLuminance(),
iconMouseDown: Colors.red.dark.basedOnLuminance(),
);
return Row(children: [
Tooltip(
message: FluentLocalizations.of(context).minimizeWindowTooltip,
child: MinimizeWindowButton(colors: buttonColors),
),
Tooltip(
message: FluentLocalizations.of(context).restoreWindowTooltip,
child: WindowButton(
colors: buttonColors,
iconBuilder: (context) {
if (appWindow.isMaximized) {
return RestoreIcon(color: context.iconColor);
}
return MaximizeIcon(color: context.iconColor);
},
onPressed: appWindow.maximizeOrRestore,
),
),
Tooltip(
message: FluentLocalizations.of(context).closeWindowTooltip,
child: CloseWindowButton(colors: closeButtonColors),
),
]);
}
}