Skip to content

Commit

Permalink
🎉 Clean dependency and WSL Distribution Fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
H2Sxxa committed Jul 23, 2024
1 parent c20344b commit 81c8557
Show file tree
Hide file tree
Showing 11 changed files with 393 additions and 236 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 @@ -12,4 +12,8 @@ need_admin_permission: Need Admin Permission (Exit and right click exe and "Run
success: Susscess
error: Error
output: Output
doctor: Doctor
doctor: Doctor
install.install_linux_distro: Install Linux Distribution
microsoft_store: MicroSoft Store
recommand: Recommand
distro_info_url: Linux Distribution Info Url
4 changes: 4 additions & 0 deletions assets/i18n/zh_CN/fields.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ success: 成功
error: 错误
output: 输出
doctor: 诊断
install.install_linux_distro: 安装 Linux 发行版
microsoft_store: 微软商店
recommand: 推荐
distro_info_url: Linux 发行版信息地址
91 changes: 48 additions & 43 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ void main() async {
// Init Config
var config = ArcheBus.bus
.provideof(instance: AppConfigs(ArcheConfig.path("app.config.json")));

config.distroInfoUrl.getOrWrite(AppConfigs.defaultDistroInfoUrl);

if (config.font.has()) {
var font = await SystemFonts().loadFont(config.font.get());
if (font == null) {
Expand Down Expand Up @@ -120,53 +123,55 @@ class HomePageState extends State<HomePage> with RefreshMountedStateMixin {

@override
Widget build(BuildContext context) {
return NavigationView(
builder: (context, vertical, horizontal, state) => Column(
children: [
Container(
color: Theme.of(context).colorScheme.surfaceContainer,
child: WindowTitleBarBox(
return Scaffold(
body: NavigationView(
builder: (context, vertical, horizontal, state) => Column(
children: [
Container(
color: Theme.of(context).colorScheme.surfaceContainer,
child: WindowTitleBarBox(
child: Row(
children: [
Expanded(child: MoveWindow()),
const WindowButtons()
],
),
),
),
Expanded(
child: Row(
children: [
Expanded(child: MoveWindow()),
const WindowButtons()
GestureDetector(
behavior: HitTestBehavior.translucent,
child: horizontal(),
onPanStart: (details) {
appWindow.startDragging();
},
),
state.content
],
),
),
),
Expanded(
child: Row(
children: [
GestureDetector(
behavior: HitTestBehavior.translucent,
child: horizontal(),
onPanStart: (details) {
appWindow.startDragging();
},
),
state.content
],
),
)
],
),
backgroundColor: Theme.of(context).colorScheme.surfaceContainer,
items: [
PageContainer(
title: context.i18n.getOrKey("home"),
).toItem(icon: const Icon(Icons.home)),
PageContainer(
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(),
).toItem(icon: const Icon(Icons.settings)),
]);
)
],
),
backgroundColor: Theme.of(context).colorScheme.surfaceContainer,
items: [
PageContainer(
title: context.i18n.getOrKey("home"),
).toItem(icon: const Icon(Icons.home)),
PageContainer(
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(),
).toItem(icon: const Icon(Icons.settings)),
]),
);
}
}

Expand Down
5 changes: 4 additions & 1 deletion lib/models/config.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import 'package:arche/arche.dart';

class AppConfigs {
final ConfigEntry<T> Function<T>(String configKey) _generator;
final ConfigEntry<T> Function<T>(String key) _generator;
AppConfigs(ArcheConfig config)
: _generator = ConfigEntry.withConfig(config, generateMap: true);

ConfigEntry<String> get locale => _generator("locale");
ConfigEntry<String> get font => _generator("font");
ConfigEntry<String> get distroInfoUrl => _generator("distro_info_url");
static const defaultDistroInfoUrl =
"https://raw.githubusercontent.com/microsoft/WSL/master/distributions/DistributionInfo.json";
}
45 changes: 45 additions & 0 deletions lib/models/distribution.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import 'dart:convert';
import 'dart:io';

import 'package:arche/arche.dart';
import 'package:wslconfigurer/models/config.dart';

class LinuxDistribution {
late final String name;
late final String friendlyName;
late final String storeAppId;
late final bool amd64;
late final bool arm64;
late final String? amd64PackageUrl;
late final String? arm64PackageUrl;
late final String packageFamilyName;
static Future<List<LinuxDistribution>> fetch() async {
var url = ArcheBus()
.of<AppConfigs>()
.distroInfoUrl
.getOr(AppConfigs.defaultDistroInfoUrl);
var request = await HttpClient().getUrl(Uri.parse(url));
var response = await request.close();
Iterable json = jsonDecode(
await response.transform(utf8.decoder).join())["Distributions"];

return json
.map(
(distro) => LinuxDistribution()
..name = distro["Name"]
..friendlyName = distro["FriendlyName"]
..storeAppId = distro["StoreAppId"]
..amd64 = distro["Amd64"]
..arm64 = distro["Arm64"]
..amd64PackageUrl = distro["Amd64PackageUrl"]
..arm64PackageUrl = distro["Arm64PackageUrl"]
..packageFamilyName = distro["PackageFamilyName"],
)
.toList();
}

@override
String toString() {
return "LinuxDistribution: $name";
}
}
Empty file added lib/views/pages/doctor.dart
Empty file.
Loading

0 comments on commit 81c8557

Please sign in to comment.