Skip to content

Commit

Permalink
✨ complete the install prepare
Browse files Browse the repository at this point in the history
  • Loading branch information
H2Sxxa committed Jul 22, 2024
1 parent 87c5ba9 commit 07f91d2
Show file tree
Hide file tree
Showing 10 changed files with 242 additions and 163 deletions.
4 changes: 4 additions & 0 deletions assets/i18n/en_US/fields.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ optional_features: Optional Features
language: Language
font: Font
need_admin_permission: Need Admin Permission (Exit and right click exe and "Run as administrator")
success: Susscess
error: Error
output: Output
doctor: Doctor
4 changes: 2 additions & 2 deletions assets/i18n/languages.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
English: en_US
简体中文: zh_CN
en_US: English
zh_CN: 简体中文
6 changes: 5 additions & 1 deletion assets/i18n/zh_CN/fields.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ optional_features: 可选功能
settings: 设置
language: 语言
font: 字体
need_admin_permission: 需要管理员权限 (退出并右键程序 "以管理员身份运行")
need_admin_permission: 需要管理员权限 (退出并右键程序 "以管理员身份运行")
success: 成功
error: 错误
output: 输出
doctor: 诊断
4 changes: 4 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:arche/arche.dart';
import 'package:bitsdojo_window/bitsdojo_window.dart';
import 'package:dynamic_color/dynamic_color.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:superuser/superuser.dart';
import 'package:system_fonts/system_fonts.dart';
import 'package:wslconfigurer/i18n/i18n.dart';
Expand Down Expand Up @@ -158,6 +159,9 @@ class HomePageState extends State<HomePage> with RefreshMountedStateMixin {
title: context.i18n.getOrKey("install"),
child: const InstallPage(),
).toItem(icon: const Icon(Icons.install_desktop)),
PageContainer(
title: context.i18n.getOrKey("doctor"),
).toItem(icon: const Icon(FontAwesomeIcons.userDoctor)),
PageContainer(
title: context.i18n.getOrKey("settings"),
child: const SettingsPage(),
Expand Down
279 changes: 145 additions & 134 deletions lib/views/pages/install.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import 'package:arche/arche.dart';
import 'package:arche/extensions/dialogs.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:superuser/superuser.dart';
import 'package:rinf/rinf.dart';
import 'package:wslconfigurer/views/widgets/process.dart';
import 'package:wslconfigurer/windows/ms_open.dart';
import 'package:wslconfigurer/i18n/i18n.dart';
import 'package:wslconfigurer/messages/windows.pb.dart';
import 'package:wslconfigurer/views/widgets/basic.dart';
import 'package:wslconfigurer/views/widgets/divider.dart';
import 'package:wslconfigurer/windows/sh.dart';

class InstallPage extends StatefulWidget {
const InstallPage({super.key});
Expand All @@ -24,149 +26,158 @@ class _InstallPageState extends State<InstallPage> {
QueryOptionalFeature().sendSignalToRust();
}

@override
Widget build(BuildContext context) {
return StreamBuilder(
stream: OptionFeatures.rustSignalStream,
builder: (context, snapshot) {
var message = snapshot.data;
if (message == null) {
return const Center(
child: CircularProgressIndicator(),
);
}
Widget buildWidget(BuildContext context,
AsyncSnapshot<RustSignal<OptionFeatures>> snapshot) {
var message = snapshot.data;
if (message == null) {
return const Center(
child: CircularProgressIndicator(),
);
}

var features = message.message.features;
var features = message.message.features;

if (features.fold(0, (state, feat) => state + feat.installState) == 2) {
var children = <Widget>[
ListTile(
leading: IconButton(
onPressed: () {
ComplexDialog.instance.text(
context: context,
content: Wrap(
spacing: 8,
direction: Axis.vertical,
children: [
context.i18nMarkdown("optional_features.md", true),
FilledButton(
onPressed: () {
openMSSetting("optionalfeatures");
},
child: context.i18nText("optional_features"),
)
],
),
);
},
icon: const Icon(Icons.help),
),
title: Row(
children: [
Text(
"${context.i18n.getOrKey("configure")} ${context.i18n.getOrKey("optional_features")}"),
],
),
trailing: IconButton(
onPressed: () => setState(() {
QueryOptionalFeature().sendSignalToRust();
}),
icon: const Icon(Icons.refresh),
),
)
];
for (var feat in features) {
children.add(
ListTile(
title: Text(feat.caption),
subtitle: Text(feat.name),
trailing: feat.installState == 1
? const Icon(
Icons.check,
color: Colors.green,
if (features.fold(0, (state, feat) => state + feat.installState) != 2) {
return ScrollableContainer(
key: const ValueKey("prepare"),
children: [
ListTile(
leading: IconButton(
onPressed: () {
ComplexDialog.instance.text(
context: context,
content: Wrap(
spacing: 8,
direction: Axis.vertical,
children: [
context.i18nMarkdown("optional_features.md", true),
FilledButton(
onPressed: () {
openMSSetting("optionalfeatures");
},
child: context.i18nText("optional_features"),
)
: const Icon(
Icons.warning,
color: Colors.amber,
),
),
);
}

children.add(
Padding(
padding: const EdgeInsets.all(8),
child: Align(
alignment: Alignment.centerRight,
child: FilledButton(
onPressed: () {
ComplexDialog.instance.text(
context: context,
content: Text(Superuser.isSuperuser.toString()));
},
child: context.i18nText("install.auto_install")),
),
],
),
);
},
icon: const Icon(Icons.help),
),
);

return ScrollableContainer(
children: children,
);
}

return ScrollableContainer(
children: [
ListTile(
leading: const Icon(FontAwesomeIcons.section),
title: context.i18nText("Install Linux Distribution"),
title: Row(
children: [
Text(
"${context.i18n.getOrKey("configure")} ${context.i18n.getOrKey("optional_features")}"),
],
),
Padding(
padding: const EdgeInsets.all(8),
child: Card.filled(
child: Column(
children: [
ListTile(
title: const Text("Ubuntu"),
trailing: IconButton(
onPressed: () {},
icon: const Icon(Icons.open_in_new)),
),
ListTile(
title: const Text("ArchLinux"),
trailing: IconButton(
onPressed: () {},
icon: const Icon(Icons.open_in_new)),
trailing: IconButton(
onPressed: () => setState(() {
QueryOptionalFeature().sendSignalToRust();
}),
icon: const Icon(Icons.refresh),
),
),
...features.map(
(feat) => ListTile(
title: Text(feat.caption),
subtitle: Text(feat.name),
trailing: feat.installState == 1
? const Icon(
Icons.check,
color: Colors.green,
)
],
),
),
: IconButton(
icon: const Icon(Icons.download),
onPressed: () {
su(
context,
() => enableFeature(feat.name).then(
(process) => ComplexDialog.instance
.text(
context: context,
title: context.i18nText("output"),
content: SingleChildScrollView(
child: ProcessText(
process: process,
),
),
)
.then(
(_) => setState(() {
QueryOptionalFeature().sendSignalToRust();
}),
),
),
);
},
),
),
divider8,
ListTile(
leading: const Icon(FontAwesomeIcons.section),
title: context.i18nText("Install Essential Packages(Optional)"),
)
],
);
}

return ScrollableContainer(
key: const ValueKey("install"),
children: [
ListTile(
leading: const Icon(FontAwesomeIcons.section),
title: context.i18nText("Install Linux Distribution"),
),
Padding(
padding: const EdgeInsets.all(8),
child: Card.filled(
child: Column(
children: [
ListTile(
title: const Text("Ubuntu"),
trailing: IconButton(
onPressed: () {}, icon: const Icon(Icons.open_in_new)),
),
ListTile(
title: const Text("ArchLinux"),
trailing: IconButton(
onPressed: () {}, icon: const Icon(Icons.open_in_new)),
)
],
),
Padding(
padding: const EdgeInsets.all(8),
child: Card.filled(
child: Column(
children: [
ListTile(
title: const Text("C (GCC)"),
trailing: IconButton(
onPressed: () {}, icon: const Icon(Icons.copy)),
),
ListTile(
title: const Text("C (Clang)"),
trailing: IconButton(
onPressed: () {}, icon: const Icon(Icons.copy)),
),
],
),
),
divider8,
ListTile(
leading: const Icon(FontAwesomeIcons.section),
title: context.i18nText("Install Essential Packages(Optional)"),
),
Padding(
padding: const EdgeInsets.all(8),
child: Card.filled(
child: Column(
children: [
ListTile(
title: const Text("C (GCC)"),
trailing: IconButton(
onPressed: () {}, icon: const Icon(Icons.copy)),
),
),
ListTile(
title: const Text("C (Clang)"),
trailing: IconButton(
onPressed: () {}, icon: const Icon(Icons.copy)),
),
],
),
],
),
),
],
);
}

@override
Widget build(BuildContext context) {
return StreamBuilder(
stream: OptionFeatures.rustSignalStream,
builder: (context, snapshot) {
return AnimatedSwitcher(
duration: Durations.medium4,
child: buildWidget(context, snapshot),
);
},
);
Expand Down
Loading

0 comments on commit 07f91d2

Please sign in to comment.