diff --git a/lib/views/pages/manage.dart b/lib/views/pages/manage.dart index ccd5464..210c943 100644 --- a/lib/views/pages/manage.dart +++ b/lib/views/pages/manage.dart @@ -15,7 +15,22 @@ class _DistributionManagePageState extends State { String? current; Widget buildWidget() { if (current != null) { - return DistroManagePage(distro: current!); + return Padding( + padding: const EdgeInsets.all(8), + child: Scaffold( + backgroundColor: Colors.transparent, + appBar: AppBar( + backgroundColor: Colors.transparent, + leading: BackButton( + onPressed: () => setState(() { + current = null; + }), + ), + title: Text(current!), + ), + body: DistroManagePage(distro: current!), + ), + ); } return FutureBuilder( diff --git a/lib/views/pages/manage_distro.dart b/lib/views/pages/manage_distro.dart index 3e19cca..5524d01 100644 --- a/lib/views/pages/manage_distro.dart +++ b/lib/views/pages/manage_distro.dart @@ -1,5 +1,7 @@ +import 'package:arche/extensions/iter.dart'; import 'package:flutter/material.dart'; import 'package:flutter_staggered_animations/flutter_staggered_animations.dart'; +import 'package:wslconfigurer/windows/wsl.dart'; class DistroManagePage extends StatefulWidget { final String distro; @@ -12,6 +14,35 @@ class DistroManagePage extends StatefulWidget { class _DistroManagePageState extends State { @override Widget build(BuildContext context) { - return AnimationLimiter(child: Text(widget.distro)); + return AnimationLimiter( + child: ListView( + children: [ + FilledButton( + onPressed: () => + WindowsSubSystemLinux.start(distro: widget.distro), + child: const Text( + "Login As `User`", + )), + FilledButton( + onPressed: () => WindowsSubSystemLinux.start( + distro: widget.distro, + user: "root", + ), + child: const Text("Login As `Root`")), + ].enumerate( + (index, widget) => AnimationConfiguration.staggeredList( + position: index, + duration: const Duration(milliseconds: 375), + child: SlideAnimation( + verticalOffset: 50.0, + child: Padding( + padding: const EdgeInsets.all(4), + child: widget, + ), + ), + ), + ), + ), + ); } } diff --git a/lib/windows/wsl.dart b/lib/windows/wsl.dart index c327274..e8f1e02 100644 --- a/lib/windows/wsl.dart +++ b/lib/windows/wsl.dart @@ -63,4 +63,21 @@ class WindowsSubSystemLinux { .where((line) => line.isNotEmpty) .toList(); } + + static Future start({ + Iterable args = const [], + String? distro, + String? user, + }) async { + return Process.start( + "start", + [ + "wsl.exe", + ...distro != null ? ["-d", distro] : [], + ...user != null ? ["-u", user] : [], + ...args + ], + runInShell: true, + ); + } }