Skip to content

Commit

Permalink
✨ Start WSL
Browse files Browse the repository at this point in the history
  • Loading branch information
H2Sxxa committed Jul 27, 2024
1 parent 53ee198 commit 46541d3
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
17 changes: 16 additions & 1 deletion lib/views/pages/manage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,22 @@ class _DistributionManagePageState extends State<DistributionManagePage> {
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(
Expand Down
33 changes: 32 additions & 1 deletion lib/views/pages/manage_distro.dart
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,6 +14,35 @@ class DistroManagePage extends StatefulWidget {
class _DistroManagePageState extends State<DistroManagePage> {
@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,
),
),
),
),
),
);
}
}
17 changes: 17 additions & 0 deletions lib/windows/wsl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,21 @@ class WindowsSubSystemLinux {
.where((line) => line.isNotEmpty)
.toList();
}

static Future<Process> start({
Iterable<String> args = const [],
String? distro,
String? user,
}) async {
return Process.start(
"start",
[
"wsl.exe",
...distro != null ? ["-d", distro] : [],
...user != null ? ["-u", user] : [],
...args
],
runInShell: true,
);
}
}

0 comments on commit 46541d3

Please sign in to comment.