From 742e357b87510a2fc24a5322f2e9a0e472ee8d46 Mon Sep 17 00:00:00 2001 From: H2Sxxa Date: Sun, 4 Aug 2024 11:58:01 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20animation=20&&=20add=20doc?= =?UTF-8?q?tor=20features?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/i18n/en_US/doctor/0x800701bc.md | 0 assets/i18n/en_US/doctor/optional_feature.md | 0 assets/i18n/zh_CN/doctor/0x800701bc.md | 3 + assets/i18n/zh_CN/doctor/optional_feature.md | 3 + lib/i18n/i18n.dart | 2 +- lib/main.dart | 8 ++- lib/views/pages/doctor.dart | 69 ++++++++++++++++++- lib/views/pages/install.dart | 39 +---------- .../{optfeat.dart => optional_features.dart} | 2 +- lib/views/widgets/update_kernel.dart | 44 ++++++++++++ pubspec.yaml | 3 + 11 files changed, 133 insertions(+), 40 deletions(-) create mode 100644 assets/i18n/en_US/doctor/0x800701bc.md create mode 100644 assets/i18n/en_US/doctor/optional_feature.md create mode 100644 assets/i18n/zh_CN/doctor/0x800701bc.md create mode 100644 assets/i18n/zh_CN/doctor/optional_feature.md rename lib/views/widgets/{optfeat.dart => optional_features.dart} (98%) create mode 100644 lib/views/widgets/update_kernel.dart diff --git a/assets/i18n/en_US/doctor/0x800701bc.md b/assets/i18n/en_US/doctor/0x800701bc.md new file mode 100644 index 0000000..e69de29 diff --git a/assets/i18n/en_US/doctor/optional_feature.md b/assets/i18n/en_US/doctor/optional_feature.md new file mode 100644 index 0000000..e69de29 diff --git a/assets/i18n/zh_CN/doctor/0x800701bc.md b/assets/i18n/zh_CN/doctor/0x800701bc.md new file mode 100644 index 0000000..934a331 --- /dev/null +++ b/assets/i18n/zh_CN/doctor/0x800701bc.md @@ -0,0 +1,3 @@ +打开WSL后出现 0x800701bc 错误 + +原因: WSL内核还未升级 \ No newline at end of file diff --git a/assets/i18n/zh_CN/doctor/optional_feature.md b/assets/i18n/zh_CN/doctor/optional_feature.md new file mode 100644 index 0000000..e60fe96 --- /dev/null +++ b/assets/i18n/zh_CN/doctor/optional_feature.md @@ -0,0 +1,3 @@ +打开WSL后提示开启 HyperV... + +原因: 可选功能未开启 \ No newline at end of file diff --git a/lib/i18n/i18n.dart b/lib/i18n/i18n.dart index affa608..528c1fb 100644 --- a/lib/i18n/i18n.dart +++ b/lib/i18n/i18n.dart @@ -69,7 +69,7 @@ extension I18nEx on BuildContext { Widget i18nMarkdown(String fileName, [bool shrinkWrap = true]) { return FutureBuilder( - future: ArcheBus.bus.of().loadString(fileName), + future: ArcheBus.bus.of().loadString("$fileName.md"), builder: (context, snapshot) { var data = snapshot.data; if (data == null) { diff --git a/lib/main.dart b/lib/main.dart index 9d722a2..30b3049 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -138,6 +138,7 @@ class HomePageState extends State with RefreshMountedStateMixin { @override Widget build(BuildContext context) { return Scaffold( + backgroundColor: Theme.of(context).colorScheme.surfaceContainer, body: NavigationView( builder: (context, vertical, horizontal, state) => Column( children: [ @@ -162,7 +163,7 @@ class HomePageState extends State with RefreshMountedStateMixin { appWindow.startDragging(); }, ), - state.content + state.content, ], ), ) @@ -171,24 +172,29 @@ class HomePageState extends State with RefreshMountedStateMixin { backgroundColor: Theme.of(context).colorScheme.surfaceContainer, items: [ PageContainer( + key: UniqueKey(), title: context.i18n.getOrKey("home"), child: const Center( child: Text("TODO"), ), ).toItem(icon: const Icon(Icons.home)), PageContainer( + key: UniqueKey(), title: context.i18n.getOrKey("install"), child: const InstallPage(), ).toItem(icon: const Icon(Icons.install_desktop)), PageContainer( + key: UniqueKey(), title: context.i18n.getOrKey("manage"), child: const DistributionManagePage(), ).toItem(icon: const Icon(Icons.apps)), PageContainer( + key: UniqueKey(), title: context.i18n.getOrKey("doctor"), child: const DoctorPage(), ).toItem(icon: const Icon(FontAwesomeIcons.userDoctor)), PageContainer( + key: UniqueKey(), title: context.i18n.getOrKey("settings"), child: const SettingsPage(), ).toItem(icon: const Icon(Icons.settings)), diff --git a/lib/views/pages/doctor.dart b/lib/views/pages/doctor.dart index 09d1d37..91318a5 100644 --- a/lib/views/pages/doctor.dart +++ b/lib/views/pages/doctor.dart @@ -1,4 +1,8 @@ import 'package:flutter/material.dart'; +import 'package:wslconfigurer/i18n/i18n.dart'; +import 'package:wslconfigurer/views/widgets/basic.dart'; +import 'package:wslconfigurer/views/widgets/optional_features.dart'; +import 'package:wslconfigurer/views/widgets/update_kernel.dart'; class DoctorPage extends StatefulWidget { const DoctorPage({super.key}); @@ -10,6 +14,69 @@ class DoctorPage extends StatefulWidget { class _DoctorPageState extends State { @override Widget build(BuildContext context) { - return const Column(); + return Navigator( + onGenerateRoute: (settings) { + Widget Function(BuildContext context) builder; + var route = settings.name ?? "/"; + if (route == "/optional_features") { + builder = (context) => Scaffold( + backgroundColor: Colors.transparent, + appBar: AppBar( + backgroundColor: Colors.transparent, + ), + body: const CheckOptionalFeatureWidget(), + ); + } else { + builder = (context) => + ScrollableContainer(padding: const EdgeInsets.all(8), children: [ + const DoctorFetaure( + descriptionKey: "0x800701bc", + solution: UpdateKernel(), + ), + DoctorFetaure( + descriptionKey: "optional_feature", + solution: ListTile( + title: context.i18nText("optional_features"), + trailing: FilledButton( + onPressed: () => + Navigator.of(context).pushNamed("/optional_features"), + child: context.i18nText("open"), + ), + ), + ), + ]); + } + + return PageRouteBuilder( + pageBuilder: (context, animation, secondaryAnimation) => + FadeTransition(opacity: animation, child: builder(context)), + ); + }, + ); + } +} + +class DoctorFetaure extends StatelessWidget { + final String descriptionKey; + final Widget? solution; + const DoctorFetaure({super.key, required this.descriptionKey, this.solution}); + + @override + Widget build(BuildContext context) { + return Card.filled( + child: WidthInfCenterWidget( + child: Padding( + padding: const EdgeInsets.all(8), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + context.i18nMarkdown("doctor/$descriptionKey"), + const Divider(), + solution ?? const SizedBox.shrink() + ], + ), + ), + ), + ); } } diff --git a/lib/views/pages/install.dart b/lib/views/pages/install.dart index e907e22..e95e0e2 100644 --- a/lib/views/pages/install.dart +++ b/lib/views/pages/install.dart @@ -5,16 +5,14 @@ import 'package:flutter/services.dart'; import 'package:flutter_staggered_animations/flutter_staggered_animations.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:system_info2/system_info2.dart'; -import 'package:url_launcher/url_launcher_string.dart'; import 'package:wslconfigurer/i18n/i18n.dart'; -import 'package:wslconfigurer/models/config.dart'; import 'package:wslconfigurer/models/distribution.dart'; import 'package:wslconfigurer/views/widgets/basic.dart'; import 'package:wslconfigurer/views/widgets/divider.dart'; -import 'package:wslconfigurer/views/widgets/optfeat.dart'; +import 'package:wslconfigurer/views/widgets/optional_features.dart'; import 'package:wslconfigurer/views/widgets/process.dart'; +import 'package:wslconfigurer/views/widgets/update_kernel.dart'; import 'package:wslconfigurer/windows/ms_open.dart'; -import 'package:wslconfigurer/windows/msi.dart'; import 'package:wslconfigurer/windows/utf16.dart'; class InstallPage extends StatefulWidget { @@ -108,38 +106,7 @@ class _InstallPageState extends State { title: context.i18nText("install.upgrade_wsl2_kernel"), trailing: Text(SysInfo.rawKernelArchitecture), ), - Card.filled( - child: Column( - children: [ - ListTile( - title: context.i18nText("install.manual"), - trailing: IconButton( - onPressed: () => launchUrlString( - AppConfigs.wslLinuxKernelUpdateInstallerUrl), - icon: const Icon(Icons.open_in_browser), - ), - ), - ListTile( - title: context.i18nText("install.automate"), - trailing: IconButton( - onPressed: () { - ComplexDialog.instance - .withContext(context: context) - .withChild( - DownloadMSIProgressDialog( - AppConfigs.wslLinuxKernelUpdateInstallerUrl, - logPath: "installer.log", - ), - ) - .copy(barrierDismissible: false) - .prompt(); - }, - icon: const Icon(Icons.install_desktop), - ), - ) - ], - ), - ), + const Card.filled(child: UpdateKernel()), divider8, ListTile( leading: const Icon(FontAwesomeIcons.section), diff --git a/lib/views/widgets/optfeat.dart b/lib/views/widgets/optional_features.dart similarity index 98% rename from lib/views/widgets/optfeat.dart rename to lib/views/widgets/optional_features.dart index e08d70d..a515a8d 100644 --- a/lib/views/widgets/optfeat.dart +++ b/lib/views/widgets/optional_features.dart @@ -56,7 +56,7 @@ class _CheckOptionalFeatureWidgetState spacing: 8, direction: Axis.vertical, children: [ - context.i18nMarkdown("optional_features.md", true), + context.i18nMarkdown("optional_features", true), FilledButton( onPressed: () => openMSSetting("optionalfeatures"), child: context.i18nText("optional_features"), diff --git a/lib/views/widgets/update_kernel.dart b/lib/views/widgets/update_kernel.dart new file mode 100644 index 0000000..e74c39c --- /dev/null +++ b/lib/views/widgets/update_kernel.dart @@ -0,0 +1,44 @@ +import 'package:arche/arche.dart'; +import 'package:flutter/material.dart'; +import 'package:url_launcher/url_launcher_string.dart'; +import 'package:wslconfigurer/i18n/i18n.dart'; +import 'package:wslconfigurer/models/config.dart'; +import 'package:wslconfigurer/windows/msi.dart'; + +class UpdateKernel extends StatelessWidget { + const UpdateKernel({super.key}); + + @override + Widget build(BuildContext context) { + return Column( + children: [ + ListTile( + title: context.i18nText("install.manual"), + trailing: IconButton( + onPressed: () => + launchUrlString(AppConfigs.wslLinuxKernelUpdateInstallerUrl), + icon: const Icon(Icons.open_in_browser), + ), + ), + ListTile( + title: context.i18nText("install.automate"), + trailing: IconButton( + onPressed: () { + ComplexDialog.instance + .withContext(context: context) + .withChild( + DownloadMSIProgressDialog( + AppConfigs.wslLinuxKernelUpdateInstallerUrl, + logPath: "installer.log", + ), + ) + .copy(barrierDismissible: false) + .prompt(); + }, + icon: const Icon(Icons.install_desktop), + ), + ) + ], + ); + } +} diff --git a/pubspec.yaml b/pubspec.yaml index d12f5d6..b4db9f6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -79,7 +79,10 @@ flutter: assets: - assets/i18n/ - assets/i18n/en_US/ + - assets/i18n/en_US/doctor/ - assets/i18n/zh_CN/ + - assets/i18n/zh_CN/doctor/ + # An image asset can refer to one or more resolution-specific "variants", see # https://flutter.dev/assets-and-images/#resolution-aware