Skip to content

Commit

Permalink
🌐 i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
H2Sxxa committed Jul 28, 2024
1 parent d333442 commit 9449f1c
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 38 deletions.
6 changes: 5 additions & 1 deletion assets/i18n/en_US/fields.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ theme: Theme
thememode.dark: Dark
thememode.system: System
thememode.light: Light
manage: Manage

install: Install
install.prepare: Prepare
Expand All @@ -28,3 +27,8 @@ install.file: Import from File
install.upgrade_wsl2_kernel: Upgrade WSL2 Linux Kernel
install.manual: Manual Install
install.automate: Automate Install

manage: Manage
manage.execute: Execute
manage.terminal: Terminal
manage.root: (root)
8 changes: 6 additions & 2 deletions assets/i18n/zh_CN/fields.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ theme: 主题
thememode.dark: 深色
thememode.system: 跟随系统
thememode.light: 浅色
manage: 管理

install: 安装
install.prepare: 准备
Expand All @@ -27,4 +26,9 @@ install.online: 在线安装
install.file: 从文件导入
install.upgrade_wsl2_kernel: 更新 WSL2 Linux 内核
install.manual: 手动安装
install.automate: 自动安装
install.automate: 自动安装

manage: 管理
manage.execute: 执行
manage.terminal: 终端
manage.root: (root)
95 changes: 60 additions & 35 deletions lib/views/pages/manage_distro.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import 'package:arche/arche.dart';
import 'package:arche/extensions/iter.dart';
import 'package:flutter/material.dart';
import 'package:flutter_staggered_animations/flutter_staggered_animations.dart';
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/wsl.dart';

Expand Down Expand Up @@ -34,23 +37,43 @@ class _DistroManagePageState extends State<DistroManagePage>
exec.dispose();
}

@override
void refreshMountedFn(Function() fn) {
process?.kill();

super.refreshMountedFn(fn);
}

@override
Widget build(BuildContext context) {
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",
Card.filled(
child: Padding(
padding: const EdgeInsets.all(8),
child: Column(
children: [
FilledButton(
onPressed: () =>
WindowsSubSystemLinux.start(distro: widget.distro),
child: WidthInfCenterWidget(
child: context.i18nText("manage.terminal"),
),
),
FilledButton(
onPressed: () => WindowsSubSystemLinux.start(
distro: widget.distro,
user: "root",
),
child: WidthInfCenterWidget(
child: Text(context.i18n.getOrKey("manage.terminal") +
context.i18n.getOrKey("manage.root")),
),
)
].eachPadding(),
),
),
child: const Text("Login As `root`"),
),
Card.filled(
child: Padding(
Expand All @@ -62,35 +85,37 @@ class _DistroManagePageState extends State<DistroManagePage>
decoration:
const InputDecoration(border: OutlineInputBorder()),
),
Padding(
padding: const EdgeInsets.only(top: 8, bottom: 8),
child: FilledButton(
onPressed: () => WindowsSubSystemLinux.exec(
distro: widget.distro,
commands: exec.text.split(" "),
).then(
(value) => refreshMountedFn(() => process = value),
),
child: const SizedBox(
width: double.infinity,
child: Center(
child: Text("Exec"),
),
),
FilledButton(
onPressed: () => WindowsSubSystemLinux.exec(
distro: widget.distro,
commands: exec.text.split(" "),
).then(
(value) => refreshMountedFn(() => process = value),
),
child: WidthInfCenterWidget(
child: context.i18nText("manage.execute"),
),
),
FilledButton(
onPressed: () => WindowsSubSystemLinux.exec(
distro: widget.distro,
commands: exec.text.split(" "),
).then(
(value) => refreshMountedFn(() => process = value),
),
child: WidthInfCenterWidget(
child: Text(context.i18n.getOrKey("manage.execute") +
context.i18n.getOrKey("manage.root")),
),
),
process != null
? Row(
children: [
ProcessText(
key: ValueKey(process),
process: process!,
codec: utf8,
)
],
? ProcessText(
key: ValueKey(process),
process: process!,
codec: utf8,
)
: const SizedBox.shrink(),
],
].eachPadding(),
),
),
),
Expand Down
10 changes: 10 additions & 0 deletions lib/views/widgets/basic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,13 @@ class RRectCountainer extends StatelessWidget {
);
}
}

class WidthInfCenterWidget extends StatelessWidget {
final Widget child;
const WidthInfCenterWidget({super.key, required this.child});

@override
Widget build(BuildContext context) {
return SizedBox(width: double.infinity, child: Center(child: child));
}
}
12 changes: 12 additions & 0 deletions lib/views/widgets/extension.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:flutter/material.dart';

extension EachPadding<T extends Widget> on List<T> {
List<Widget> eachPadding({EdgeInsetsGeometry? padding}) {
return map(
(child) => Padding(
padding: padding ?? const EdgeInsets.all(4),
child: child,
),
).toList();
}
}
2 changes: 2 additions & 0 deletions lib/windows/wsl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class WindowsSubSystemLinux {
"wsl.exe",
...distro != null ? ["-d", distro] : [],
...user != null ? ["-u", user] : [],
"--cd",
"~",
...args
],
runInShell: true,
Expand Down

0 comments on commit 9449f1c

Please sign in to comment.