From 90f75f3e07be806a444e4a2ba68de120a7127fc5 Mon Sep 17 00:00:00 2001 From: H2Sxxa Date: Tue, 30 Jul 2024 17:57:56 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Init=20the=20terminal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/i18n/en_US/fields.yaml | 6 ++-- assets/i18n/zh_CN/fields.yaml | 4 ++- lib/views/pages/manage_distro.dart | 58 +++++++++++++++++++++++++++--- lib/windows/ms_open.dart | 4 +-- lib/windows/wsl.dart | 4 +-- 5 files changed, 64 insertions(+), 12 deletions(-) diff --git a/assets/i18n/en_US/fields.yaml b/assets/i18n/en_US/fields.yaml index 4814623..ed475ef 100644 --- a/assets/i18n/en_US/fields.yaml +++ b/assets/i18n/en_US/fields.yaml @@ -30,5 +30,7 @@ install.automate: Automate Install manage: Manage manage.execute: Execute -manage.terminal: Open Terminal -manage.root: (root) \ No newline at end of file +manage.terminal: Terminal +manage.file: File +manage.open_terminal: Open Terminal +manage.root: (root) diff --git a/assets/i18n/zh_CN/fields.yaml b/assets/i18n/zh_CN/fields.yaml index d80f20d..7ea0c0d 100644 --- a/assets/i18n/zh_CN/fields.yaml +++ b/assets/i18n/zh_CN/fields.yaml @@ -30,5 +30,7 @@ install.automate: 自动安装 manage: 管理 manage.execute: 执行 -manage.terminal: 打开终端 +manage.terminal: 终端 +manage.file: 文件 +manage.open_terminal: 打开终端 manage.root: (root) \ No newline at end of file diff --git a/lib/views/pages/manage_distro.dart b/lib/views/pages/manage_distro.dart index ae32fe2..4f15144 100644 --- a/lib/views/pages/manage_distro.dart +++ b/lib/views/pages/manage_distro.dart @@ -11,6 +11,7 @@ import 'package:wslconfigurer/i18n/i18n.dart'; import 'package:wslconfigurer/views/widgets/basic.dart'; import 'package:wslconfigurer/views/widgets/extension.dart'; import 'package:wslconfigurer/views/widgets/process.dart'; +import 'package:wslconfigurer/windows/ms_open.dart'; import 'package:wslconfigurer/windows/wsl.dart'; class DistroManagePage extends StatefulWidget { @@ -53,8 +54,8 @@ class _DistroManagePageState extends State labelType: NavigationLabelType.selected, items: [ NavigationItem( - icon: Icon(Icons.terminal), - label: "Manage", + icon: const Icon(Icons.home), + label: context.i18n.getOrKey("home"), page: AnimationLimiter( child: ListView( children: [ @@ -77,7 +78,7 @@ class _DistroManagePageState extends State ), child: WidthInfCenterWidget( child: Text( - context.i18n.getOrKey("manage.terminal") + + context.i18n.getOrKey("manage.open_terminal") + context.i18n.getOrKey("manage.root")), ), ) @@ -144,6 +145,12 @@ class _DistroManagePageState extends State ), ), ), + NavigationItem( + icon: const Icon(Icons.terminal), + label: context.i18n.getOrKey("manage.terminal"), + page: WSLTerminalWidget( + distro: widget.distro, + )), NavigationItem( icon: const Icon(Icons.folder), page: ListView(children: [ @@ -152,7 +159,7 @@ class _DistroManagePageState extends State child: WSLExplorerWidget(distro: widget.distro), ), ]), - label: "File", + label: context.i18n.getOrKey("manage.file"), ) ], direction: Axis.horizontal, @@ -160,6 +167,42 @@ class _DistroManagePageState extends State } } +class WSLTerminalWidget extends StatefulWidget { + final String distro; + + const WSLTerminalWidget({super.key, required this.distro}); + + @override + State createState() => _WSLTerminalWidgetState(); +} + +class _WSLTerminalWidgetState extends State { + @override + Widget build(BuildContext context) { + return Column( + children: [ + Expanded( + child: ListView( + shrinkWrap: true, + ), + ), + TextField( + decoration: InputDecoration( + border: const OutlineInputBorder(), + suffixIcon: Padding( + padding: const EdgeInsets.all(8), + child: IconButton( + onPressed: () {}, + icon: const Icon(Icons.send), + ), + ), + ), + ) + ], + ); + } +} + class WSLExplorerWidget extends StatefulWidget { final String distro; const WSLExplorerWidget({super.key, required this.distro}); @@ -223,7 +266,6 @@ class _WSLExplorerWidgetState extends State IconData icon; Function()? onTap; - switch (data.type) { case FileSystemEntityType.file: icon = FontAwesomeIcons.file; @@ -249,6 +291,12 @@ class _WSLExplorerWidgetState extends State title: Text(entityBaseName), subtitle: Text(friendlyName), onTap: onTap, + trailing: IconButton( + icon: const Icon(Icons.open_in_new), + onPressed: () { + openInExplorer(entity.path); + }, + ), shape: const RoundedRectangleBorder( borderRadius: BorderRadius.all(Radius.circular(8))), ); diff --git a/lib/windows/ms_open.dart b/lib/windows/ms_open.dart index 7ddbdfc..eecd756 100644 --- a/lib/windows/ms_open.dart +++ b/lib/windows/ms_open.dart @@ -10,8 +10,8 @@ void openMSSetting(String name) { launchUrlString("ms-settings:$name"); } -void openInExplorer(String path) async { +Future openInExplorer(String path) async { await Process.run("explorer.exe", [path]); } -void openWSLDirExplorer() async => openInExplorer("C:\\Program Files\\WSL"); \ No newline at end of file +void openWSLDirExplorer() async => openInExplorer("C:\\Program Files\\WSL"); diff --git a/lib/windows/wsl.dart b/lib/windows/wsl.dart index bc36dbf..338033b 100644 --- a/lib/windows/wsl.dart +++ b/lib/windows/wsl.dart @@ -90,8 +90,8 @@ class WSLExplorer { late Directory current; WSLExplorer(this.distro) { - root = "//wsl.localhost/$distro"; - current = Directory("$root/home"); + root = "\\\\wsl.localhost\\$distro"; + current = Directory("$root\\home"); } Stream list() {