Skip to content

Commit

Permalink
✨ CI Build and Optional Feature Page
Browse files Browse the repository at this point in the history
  • Loading branch information
H2Sxxa committed Jul 20, 2024
1 parent 6b1017d commit 87c5ba9
Show file tree
Hide file tree
Showing 18 changed files with 274 additions and 51 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Build

on:
workflow_dispatch:
push:
branches: [ main ]
paths:
- lib/**
- .github/workflows/**
- native/**
pull_request:

jobs:
build-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
channel: "stable"
- name: Install Rust & Prepare Complie
run: |
rustup update stable
cargo install rinf
rinf message
dart fix --apply
- name: Build
run: flutter build windows --release
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: windows-x64
path: build/windows/x64/runner/Release/*



4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ app.*.map.json
/android/app/profile
/android/app/release

app.config.json

# Rust related
.cargo/
target/

# Generated messages
*/**/messages/

app.config.json
9 changes: 8 additions & 1 deletion assets/i18n/en_US/fields.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
home: Home
install: Install
settings: Settings
install.prepare: Prepare
install.auto_install: Auto Install
install.auto_install: Auto Install (Admin)
open: Open
configure: Configure
optional_features: Optional Features
language: Language
font: Font
need_admin_permission: Need Admin Permission (Exit and right click exe and "Run as administrator")
9 changes: 9 additions & 0 deletions assets/i18n/en_US/optional_features.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Mannual Install

Find and check the features you're missing in "Turn Windows features on or off".

If you can't find them, you can click the "Optional Features" Button.

Then scroll to bottom and click "More Windows features".

After checking, restart to complete the installation.
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.yaml
简体中文: zh_CN.yaml
English: en_US
简体中文: zh_CN
9 changes: 8 additions & 1 deletion assets/i18n/zh_CN/fields.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
home: 主页
install: 安装
install.prepare: 准备
install.auto_install: 自动安装
install.auto_install: 自动安装 (管理员)
open: 打开
configure: 配置
optional_features: 可选功能
settings: 设置
language: 语言
font: 字体
need_admin_permission: 需要管理员权限 (退出并右键程序 "以管理员身份运行")
9 changes: 9 additions & 0 deletions assets/i18n/zh_CN/optional_features.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# 手动安装

在"启用或关闭 Windows 功能"中找到并勾选你缺少的功能。

如果你找不到他们,你可以点击"可选功能"按钮。

然后滑到底部点击"更多Windows功能"。

勾选后重新启动即可完成安装。
4 changes: 3 additions & 1 deletion lib/i18n/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ const i18nFolder = "assets/i18n";
const i18nLanguages = "$i18nFolder/languages.yaml";

String i18nLanguage(String locale) => "$i18nFolder/$locale";
String i18nLanguageFields(String locale) => "${i18nLanguage(locale)}/fields.yaml";

String i18nLanguageFile(String locale, String fileName) =>
"${i18nLanguage(locale)}/$fileName";
29 changes: 27 additions & 2 deletions lib/i18n/i18n.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'dart:async';
import 'package:arche/arche.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:url_launcher/url_launcher_string.dart';
import 'package:wslconfigurer/i18n/constants.dart';
import 'package:yaml/yaml.dart';

Expand All @@ -19,8 +21,13 @@ class I18n {
this.locale = locale;
}

_fields =
_load(await rootBundle.loadString(i18nLanguageFields(this.locale)));
_fields = _load(await rootBundle.loadString(fileName("fields.yaml")));
}

String fileName(String fileName) => i18nLanguageFile(locale, fileName);

Future<String> loadString(String fileName) async {
return await rootBundle.loadString(this.fileName(fileName));
}

String getOrKey(String translateKey) {
Expand All @@ -47,4 +54,22 @@ extension I18nEx on BuildContext {
T i18nBuilder<T>(String translateKey, T Function(String text) builder) {
return builder(ArcheBus.bus.of<I18n>().getOrKey(translateKey));
}

Widget i18nMarkdown(String fileName, [bool shrinkWrap = true]) {
return FutureBuilder(
future: ArcheBus.bus.of<I18n>().loadString(fileName),
builder: (context, snapshot) {
var data = snapshot.data;
if (data == null) {
return const CircularProgressIndicator();
}

return MarkdownBody(
data: data,
shrinkWrap: shrinkWrap,
onTapLink: (text, href, title) => launchUrlString(href.toString()),
);
},
);
}
}
41 changes: 34 additions & 7 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,84 @@ 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:superuser/superuser.dart';
import 'package:system_fonts/system_fonts.dart';
import 'package:wslconfigurer/i18n/i18n.dart';
import 'package:wslconfigurer/models/config.dart';
import 'package:wslconfigurer/models/key.dart';
import 'package:wslconfigurer/views/pages/settings.dart';
import 'package:wslconfigurer/views/widgets/basic.dart';
import 'package:wslconfigurer/views/pages/install.dart';
import 'package:rinf/rinf.dart';
import './messages/generated.dart';

void main() async {
await initializeRust(assignRustSignal);
WidgetsFlutterBinding.ensureInitialized();
await initializeRust(assignRustSignal);
// Init Config
var config = ArcheBus.bus
.provideof(instance: AppConfigs(ArcheConfig.path("app.config.json")));
if (config.font.has()) {
var font = await SystemFonts().loadFont(config.font.get());
if (font == null) {
config.font.delete();
}
}

// Init I18n
var i18n = I18n();
await i18n.init(config.locale.tryGet());
ArcheBus.bus.provide(i18n);
// Start Launch App
appWindow.size = const Size(750, 550);
runApp(const MyApp());
runApp(MyApp(key: appKey));
appWindow.show();
doWhenWindowReady(() {
final win = appWindow;
const initialSize = Size(750, 550);
win.minSize = initialSize;
win.size = initialSize;
win.alignment = Alignment.center;
win.title = "WSL Configurer";
if (Superuser.isSuperuser) {
win.title = "WSL Configurer (Admin)";
} else {
win.title = "WSL Configurer (User)";
}

win.show();
});
}

class MyApp extends StatelessWidget {
class MyApp extends StatefulWidget {
const MyApp({super.key});

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

class MyAppState extends State<MyApp> with RefreshMountedStateMixin {
@override
Widget build(BuildContext context) {
var configs = ArcheBus.bus.of<AppConfigs>();
return DynamicColorBuilder(
builder: (lightDynamic, darkDynamic) => MaterialApp(
theme: ThemeData(
useMaterial3: true,
colorScheme: lightDynamic,
typography: Typography.material2021(),
fontFamily: configs.font.tryGet(),
),
darkTheme: ThemeData(
brightness: Brightness.dark,
useMaterial3: true,
colorScheme: darkDynamic,
typography: Typography.material2021(),
fontFamily: configs.font.tryGet(),
),
home: WindowTitleBarBox(
child: const HomePage(),
child: HomePage(
key: rootKey,
),
),
debugShowCheckedModeBanner: false,
themeMode: ThemeMode.system,
Expand All @@ -68,10 +94,10 @@ class HomePage extends StatefulWidget {
const HomePage({super.key});

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

class _HomePageState extends State<HomePage> {
class HomePageState extends State<HomePage> with RefreshMountedStateMixin {
late AppLifecycleListener _lifecycleListener;

@override
Expand Down Expand Up @@ -134,6 +160,7 @@ class _HomePageState extends State<HomePage> {
).toItem(icon: const Icon(Icons.install_desktop)),
PageContainer(
title: context.i18n.getOrKey("settings"),
child: const SettingsPage(),
).toItem(icon: const Icon(Icons.settings)),
]);
}
Expand Down
1 change: 1 addition & 0 deletions lib/models/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ class AppConfigs {
: _generator = ConfigEntry.withConfig(config, generateMap: true);

ConfigEntry<String> get locale => _generator("locale");
ConfigEntry<String> get font => _generator("font");
}
5 changes: 5 additions & 0 deletions lib/models/key.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import 'package:flutter/material.dart';
import 'package:wslconfigurer/main.dart';

GlobalKey<HomePageState> rootKey = GlobalKey();
GlobalKey<MyAppState> appKey = GlobalKey();
44 changes: 13 additions & 31 deletions lib/views/pages/install.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ 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:wslconfigurer/controllers/ms_open.dart';
import 'package:superuser/superuser.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';
Expand Down Expand Up @@ -45,15 +46,15 @@ class _InstallPageState extends State<InstallPage> {
ComplexDialog.instance.text(
context: context,
content: Wrap(
spacing: 8,
direction: Axis.vertical,
children: [
const Text(
"Optional Features -> WSL/VirtualMachinePlatform"),
context.i18nMarkdown("optional_features.md", true),
FilledButton(
onPressed: () {
openMSSetting("optionalfeatures");
},
child: Text("Open"),
child: context.i18nText("optional_features"),
)
],
),
Expand All @@ -63,11 +64,14 @@ class _InstallPageState extends State<InstallPage> {
),
title: Row(
children: [
context.i18nText("Open Windows Features"),
Text(
"${context.i18n.getOrKey("configure")} ${context.i18n.getOrKey("optional_features")}"),
],
),
trailing: IconButton(
onPressed: () => setState(() {}),
onPressed: () => setState(() {
QueryOptionalFeature().sendSignalToRust();
}),
icon: const Icon(Icons.refresh),
),
)
Expand Down Expand Up @@ -97,7 +101,9 @@ class _InstallPageState extends State<InstallPage> {
alignment: Alignment.centerRight,
child: FilledButton(
onPressed: () {
//TODO
ComplexDialog.instance.text(
context: context,
content: Text(Superuser.isSuperuser.toString()));
},
child: context.i18nText("install.auto_install")),
),
Expand All @@ -111,30 +117,6 @@ class _InstallPageState extends State<InstallPage> {

return ScrollableContainer(
children: [
ListTile(
leading: const Icon(FontAwesomeIcons.section),
title: context.i18nText("install.prepare"),
),
Padding(
padding: const EdgeInsets.all(8),
child: Card.filled(
child: Column(
children: [
ListTile(
title: const Text("HyperV"),
trailing: IconButton(
onPressed: () {},
icon: const Icon(Icons.arrow_right_rounded)),
),
const ListTile(
title: Text("WSL"),
trailing: Icon(Icons.check),
)
],
),
),
),
divider8,
ListTile(
leading: const Icon(FontAwesomeIcons.section),
title: context.i18nText("Install Linux Distribution"),
Expand Down
Loading

0 comments on commit 87c5ba9

Please sign in to comment.