Skip to content

Commit

Permalink
✨ Init the terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
H2Sxxa committed Jul 30, 2024
1 parent 57f6916 commit 90f75f3
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 12 deletions.
6 changes: 4 additions & 2 deletions assets/i18n/en_US/fields.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ install.automate: Automate Install

manage: Manage
manage.execute: Execute
manage.terminal: Open Terminal
manage.root: (root)
manage.terminal: Terminal
manage.file: File
manage.open_terminal: Open Terminal
manage.root: (root)
4 changes: 3 additions & 1 deletion assets/i18n/zh_CN/fields.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ install.automate: 自动安装

manage: 管理
manage.execute: 执行
manage.terminal: 打开终端
manage.terminal: 终端
manage.file: 文件
manage.open_terminal: 打开终端
manage.root: (root)
58 changes: 53 additions & 5 deletions lib/views/pages/manage_distro.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -53,8 +54,8 @@ class _DistroManagePageState extends State<DistroManagePage>
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: [
Expand All @@ -77,7 +78,7 @@ class _DistroManagePageState extends State<DistroManagePage>
),
child: WidthInfCenterWidget(
child: Text(
context.i18n.getOrKey("manage.terminal") +
context.i18n.getOrKey("manage.open_terminal") +
context.i18n.getOrKey("manage.root")),
),
)
Expand Down Expand Up @@ -144,6 +145,12 @@ class _DistroManagePageState extends State<DistroManagePage>
),
),
),
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: [
Expand All @@ -152,14 +159,50 @@ class _DistroManagePageState extends State<DistroManagePage>
child: WSLExplorerWidget(distro: widget.distro),
),
]),
label: "File",
label: context.i18n.getOrKey("manage.file"),
)
],
direction: Axis.horizontal,
);
}
}

class WSLTerminalWidget extends StatefulWidget {
final String distro;

const WSLTerminalWidget({super.key, required this.distro});

@override
State<StatefulWidget> createState() => _WSLTerminalWidgetState();
}

class _WSLTerminalWidgetState extends State<WSLTerminalWidget> {
@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});
Expand Down Expand Up @@ -223,7 +266,6 @@ class _WSLExplorerWidgetState extends State<WSLExplorerWidget>

IconData icon;
Function()? onTap;

switch (data.type) {
case FileSystemEntityType.file:
icon = FontAwesomeIcons.file;
Expand All @@ -249,6 +291,12 @@ class _WSLExplorerWidgetState extends State<WSLExplorerWidget>
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))),
);
Expand Down
4 changes: 2 additions & 2 deletions lib/windows/ms_open.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ void openMSSetting(String name) {
launchUrlString("ms-settings:$name");
}

void openInExplorer(String path) async {
Future<void> openInExplorer(String path) async {
await Process.run("explorer.exe", [path]);
}

void openWSLDirExplorer() async => openInExplorer("C:\\Program Files\\WSL");
void openWSLDirExplorer() async => openInExplorer("C:\\Program Files\\WSL");
4 changes: 2 additions & 2 deletions lib/windows/wsl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<FileSystemEntity> list() {
Expand Down

0 comments on commit 90f75f3

Please sign in to comment.