diff --git a/lib/windows/ms_open.dart b/lib/windows/ms_open.dart index b1b58ba..7ddbdfc 100644 --- a/lib/windows/ms_open.dart +++ b/lib/windows/ms_open.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:url_launcher/url_launcher_string.dart'; void openMSStoreProduct(String productID) { @@ -7,3 +9,9 @@ void openMSStoreProduct(String productID) { void openMSSetting(String name) { launchUrlString("ms-settings:$name"); } + +void openInExplorer(String path) async { + await Process.run("explorer.exe", [path]); +} + +void openWSLDirExplorer() async => openInExplorer("C:\\Program Files\\WSL"); \ No newline at end of file diff --git a/lib/windows/sh.dart b/lib/windows/sh.dart index 4c9fbef..35fed5a 100644 --- a/lib/windows/sh.dart +++ b/lib/windows/sh.dart @@ -30,3 +30,4 @@ Future enableFeature(String featurename) async { "/norestart" ]); } + diff --git a/lib/windows/wsl.dart b/lib/windows/wsl.dart new file mode 100644 index 0000000..ebd9f3e --- /dev/null +++ b/lib/windows/wsl.dart @@ -0,0 +1,61 @@ +import 'dart:io'; + +class WindowsSubSystemLinux { + static void shutdown(String target, {String? distro}) async { + await Process.run("wsl", [ + ...distro != null ? ["-d", distro] : [], + "--shutdown" + ]); + } + + static Future sudo({ + String? distro, + String? user, + required String password, + Iterable commands = const [], + }) async { + return await exec( + commands: ["echo", password, "|", "sudo", "-S", ...commands], + distro: distro, + user: user, + ); + } + + static Future exec({ + String? distro, + String? user, + Iterable commands = const [], + }) async { + return await Process.start( + "wsl", + [ + ...distro != null ? ["-d", distro] : [], + ...user != null ? ["-u", user] : [], + "-e", + "sh", + "-c", + commands.join(" ") + ], + ); + } + + static Future> getAvailableDistro() async { + return (await Process.run("wsl", ["-l", "-q"])) + .stdout + .toString() + .split("\n") + .map((line) => line.trim()) + .where((line) => line.isNotEmpty) + .toList(); + } + + static List getAvailableDistroSync() { + return Process.runSync("wsl", ["-l", "-q"]) + .stdout + .toString() + .split("\n") + .map((line) => line.trim()) + .where((line) => line.isNotEmpty) + .toList(); + } +}