diff --git a/assets/scripts/settings.bash b/assets/scripts/settings.bash new file mode 100644 index 0000000..319e776 --- /dev/null +++ b/assets/scripts/settings.bash @@ -0,0 +1,16 @@ +# This script triggers the KEY setting in /etc/wsl.conf +test="KEY[ ]*=" +currentWSL=$(cat /etc/wsl.conf) +# Check if it has [PARENT] section +if [[ $currentWSL == *"[PARENT]"* ]]; then + if [[ $currentWSL =~ $test ]]; then + # Replace KEY value with the new value + sed -i 's/KEY[ ]*=[ ]*.*/KEY = VALUE/g' /etc/wsl.conf + else + # Add KEY value after PARENT + sed -i 's/\[PARENT\]/\[PARENT\]\nKEY = VALUE/g' /etc/wsl.conf + fi +else + # Add [PARENT] section and KEY value + echo -e "[PARENT]\nKEY = VALUE" >> /etc/wsl.conf +fi \ No newline at end of file diff --git a/build/windows/runner/Release/data/app.so b/build/windows/runner/Release/data/app.so index 2489b36..89167fb 100644 Binary files a/build/windows/runner/Release/data/app.so and b/build/windows/runner/Release/data/app.so differ diff --git a/build/windows/runner/Release/data/flutter_assets/AssetManifest.json b/build/windows/runner/Release/data/flutter_assets/AssetManifest.json index 562e2a5..f64d3d0 100644 --- a/build/windows/runner/Release/data/flutter_assets/AssetManifest.json +++ b/build/windows/runner/Release/data/flutter_assets/AssetManifest.json @@ -1 +1 @@ -{"lib/i18n/de.json":["lib/i18n/de.json"],"lib/i18n/en.json":["lib/i18n/en.json"],"lib/i18n/pt.json":["lib/i18n/pt.json"],"lib/i18n/zh.json":["lib/i18n/zh.json"],"packages/fluent_ui/assets/AcrylicNoise.png":["packages/fluent_ui/assets/AcrylicNoise.png"],"packages/fluent_ui/fonts/FluentIcons.ttf":["packages/fluent_ui/fonts/FluentIcons.ttf"],"packages/localization/test/assets/lang/en_US.json":["packages/localization/test/assets/lang/en_US.json"],"packages/localization/test/assets/lang/pt_BR.json":["packages/localization/test/assets/lang/pt_BR.json"],"packages/localization/test/assets/lang2/en_US.json":["packages/localization/test/assets/lang2/en_US.json"],"packages/localization/test/assets/lang2/pt_BR.json":["packages/localization/test/assets/lang2/pt_BR.json"],"packages/window_manager/images/ic_chrome_close.png":["packages/window_manager/images/ic_chrome_close.png"],"packages/window_manager/images/ic_chrome_maximize.png":["packages/window_manager/images/ic_chrome_maximize.png"],"packages/window_manager/images/ic_chrome_minimize.png":["packages/window_manager/images/ic_chrome_minimize.png"],"packages/window_manager/images/ic_chrome_unmaximize.png":["packages/window_manager/images/ic_chrome_unmaximize.png"]} \ No newline at end of file +{"assets/scripts/settings.bash":["assets/scripts/settings.bash"],"lib/i18n/de.json":["lib/i18n/de.json"],"lib/i18n/en.json":["lib/i18n/en.json"],"lib/i18n/pt.json":["lib/i18n/pt.json"],"lib/i18n/zh.json":["lib/i18n/zh.json"],"packages/fluent_ui/assets/AcrylicNoise.png":["packages/fluent_ui/assets/AcrylicNoise.png"],"packages/fluent_ui/fonts/FluentIcons.ttf":["packages/fluent_ui/fonts/FluentIcons.ttf"],"packages/localization/test/assets/lang/en_US.json":["packages/localization/test/assets/lang/en_US.json"],"packages/localization/test/assets/lang/pt_BR.json":["packages/localization/test/assets/lang/pt_BR.json"],"packages/localization/test/assets/lang2/en_US.json":["packages/localization/test/assets/lang2/en_US.json"],"packages/localization/test/assets/lang2/pt_BR.json":["packages/localization/test/assets/lang2/pt_BR.json"],"packages/window_manager/images/ic_chrome_close.png":["packages/window_manager/images/ic_chrome_close.png"],"packages/window_manager/images/ic_chrome_maximize.png":["packages/window_manager/images/ic_chrome_maximize.png"],"packages/window_manager/images/ic_chrome_minimize.png":["packages/window_manager/images/ic_chrome_minimize.png"],"packages/window_manager/images/ic_chrome_unmaximize.png":["packages/window_manager/images/ic_chrome_unmaximize.png"]} \ No newline at end of file diff --git a/build/windows/runner/Release/data/flutter_assets/lib/i18n/de.json b/build/windows/runner/Release/data/flutter_assets/lib/i18n/de.json index 3f8d3bf..64781b3 100644 --- a/build/windows/runner/Release/data/flutter_assets/lib/i18n/de.json +++ b/build/windows/runner/Release/data/flutter_assets/lib/i18n/de.json @@ -124,5 +124,10 @@ "addcommunityactions-text": "Community Actions hinzufügen", "done-text": "Fertig", "search-text": "Suche", - "shareyourquickaction-text": "Teilen Sie Ihre Schnellaktionen" -} + "shareyourquickaction-text": "Teilen Sie Ihre Schnellaktionen", + "wslsettings-text": "WSL-Einstellungen", + "boot-text": "Boot", + "automount-text": "Automount", + "network-text": "Netzwerk", + "interop-text": "Interop" +} \ No newline at end of file diff --git a/build/windows/runner/Release/data/flutter_assets/lib/i18n/en.json b/build/windows/runner/Release/data/flutter_assets/lib/i18n/en.json index 94d5b35..8c4f7c0 100644 --- a/build/windows/runner/Release/data/flutter_assets/lib/i18n/en.json +++ b/build/windows/runner/Release/data/flutter_assets/lib/i18n/en.json @@ -123,5 +123,10 @@ "documentation-text": "Documentation", "addcommunityactions-text": "Add Community Actions", "search-text": "Search", - "shareyourquickaction-text": "Share your Quick Action" + "shareyourquickaction-text": "Share your Quick Action", + "wslsettings-text": "WSL Settings", + "boot-text": "Boot", + "automount-text": "Automount", + "network-text": "Network", + "interop-text": "Interop" } \ No newline at end of file diff --git a/build/windows/runner/Release/data/flutter_assets/lib/i18n/pt.json b/build/windows/runner/Release/data/flutter_assets/lib/i18n/pt.json index 15f90c9..95fdc8c 100644 --- a/build/windows/runner/Release/data/flutter_assets/lib/i18n/pt.json +++ b/build/windows/runner/Release/data/flutter_assets/lib/i18n/pt.json @@ -124,5 +124,10 @@ "addcommunityactions-text": "Adicionar ações da comunidade", "done-text": "Feito", "search-text": "Procurar", - "shareyourquickaction-text": "Compartilhe sua ação rápida" + "shareyourquickaction-text": "Compartilhe sua ação rápida", + "wslsettings-text": "Configurações do WSL", + "boot-text": "Boot", + "automount-text": "Automount", + "network-text": "Rede", + "interop-text": "Interop" } \ No newline at end of file diff --git a/build/windows/runner/Release/data/flutter_assets/lib/i18n/zh.json b/build/windows/runner/Release/data/flutter_assets/lib/i18n/zh.json index 122c5f4..b680c93 100644 --- a/build/windows/runner/Release/data/flutter_assets/lib/i18n/zh.json +++ b/build/windows/runner/Release/data/flutter_assets/lib/i18n/zh.json @@ -124,5 +124,10 @@ "addcommunityactions-text": "添加社区快速操作", "done-text": "完成", "search-text": "搜索", - "shareyourquickaction-text": "分享你的快速操作" + "shareyourquickaction-text": "分享你的快速操作", + "wslsettings-text": "WSL 设置", + "boot-text": "启动", + "automount-text": "自动挂载", + "network-text": "网络", + "interop-text": "互操作性" } \ No newline at end of file diff --git a/build/windows/runner/Release/desktop_window_plugin.dll b/build/windows/runner/Release/desktop_window_plugin.dll index 651cadd..c0a8866 100644 Binary files a/build/windows/runner/Release/desktop_window_plugin.dll and b/build/windows/runner/Release/desktop_window_plugin.dll differ diff --git a/build/windows/runner/Release/flutter_acrylic_plugin.dll b/build/windows/runner/Release/flutter_acrylic_plugin.dll index 4c7b8c3..2e2def9 100644 Binary files a/build/windows/runner/Release/flutter_acrylic_plugin.dll and b/build/windows/runner/Release/flutter_acrylic_plugin.dll differ diff --git a/build/windows/runner/Release/screen_retriever_plugin.dll b/build/windows/runner/Release/screen_retriever_plugin.dll index c22e663..00bd08d 100644 Binary files a/build/windows/runner/Release/screen_retriever_plugin.dll and b/build/windows/runner/Release/screen_retriever_plugin.dll differ diff --git a/build/windows/runner/Release/system_theme_plugin.dll b/build/windows/runner/Release/system_theme_plugin.dll index 5d84df5..eaf80b4 100644 Binary files a/build/windows/runner/Release/system_theme_plugin.dll and b/build/windows/runner/Release/system_theme_plugin.dll differ diff --git a/build/windows/runner/Release/url_launcher_windows_plugin.dll b/build/windows/runner/Release/url_launcher_windows_plugin.dll index 7439a72..4c3aba0 100644 Binary files a/build/windows/runner/Release/url_launcher_windows_plugin.dll and b/build/windows/runner/Release/url_launcher_windows_plugin.dll differ diff --git a/build/windows/runner/Release/window_manager_plugin.dll b/build/windows/runner/Release/window_manager_plugin.dll index 11606b2..3200e16 100644 Binary files a/build/windows/runner/Release/window_manager_plugin.dll and b/build/windows/runner/Release/window_manager_plugin.dll differ diff --git a/build/windows/runner/Release/wsl2distromanager.exe b/build/windows/runner/Release/wsl2distromanager.exe index 146d180..512817a 100644 Binary files a/build/windows/runner/Release/wsl2distromanager.exe and b/build/windows/runner/Release/wsl2distromanager.exe differ diff --git a/lib/api/wsl.dart b/lib/api/wsl.dart index 010ed19..699c45d 100644 --- a/lib/api/wsl.dart +++ b/lib/api/wsl.dart @@ -1,10 +1,12 @@ import 'dart:async'; +import 'dart:ffi'; import 'dart:io'; import 'dart:convert' show Utf8Decoder, json, jsonDecode, utf8; import 'package:dio/dio.dart'; import 'package:localization/localization.dart'; import '../components/constants.dart'; import '../components/helpers.dart'; +import 'package:flutter/services.dart' show rootBundle; class Instances { List running = []; @@ -375,6 +377,7 @@ class WSLApi { String? user, required Function(String) onMsg, required Function onDone, + bool showOutput = true, }) async { List processes = []; Process result = await Process.start( @@ -416,7 +419,7 @@ class WSLApi { '-f', '/tmp/currentsessionlog' ], - mode: ProcessStartMode.detached, + mode: showOutput ? ProcessStartMode.detached : ProcessStartMode.normal, runInShell: true); // Delay to allow tail to start @@ -656,4 +659,24 @@ class WSLApi { } return utf8.decode(utf8Lines); } + + /// Change setting in wsl.conf with key and value + /// @param key: String + /// @param value: String + /// @return Future + Future setSetting( + String distro, String parent, String key, String value) async { + // Read trigger script from assets + String script = await rootBundle.loadString('assets/scripts/settings.bash'); + script = script.replaceAll(RegExp(r'^#.*\n', multiLine: true), ''); + script = script.replaceAll('PARENT', parent); + script = script.replaceAll('KEY', key); + script = script.replaceAll('VALUE', value); + List scriptLines = script.split('\n'); + + // Execute trigger script + await execCmds(distro, scriptLines, + onMsg: (msg) {}, onDone: () {}, showOutput: false); + return true; + } } diff --git a/lib/dialogs/settings_dialog.dart b/lib/dialogs/settings_dialog.dart index 3c9c084..9a66306 100644 --- a/lib/dialogs/settings_dialog.dart +++ b/lib/dialogs/settings_dialog.dart @@ -132,58 +132,9 @@ Column settingsColumn( const SizedBox( height: 8.0, ), - SizedBox( - width: MediaQuery.of(context).size.width, - child: Builder(builder: (childcontext) { - List actions = []; - List? quickSettingsTitles = - prefs.getStringList("quickSettingsTitles"); - List? quickSettingsContents = - prefs.getStringList("quickSettingsContents"); - if (quickSettingsContents != null && quickSettingsTitles != null) { - for (int i = 0; i < quickSettingsTitles.length; i++) { - actions.add(MenuFlyoutItem( - leading: const MouseRegion( - cursor: SystemMouseCursors.click, - child: Padding( - padding: EdgeInsets.all(8.0), - child: Icon(FluentIcons.play), - ), - ), - onPressed: () async { - plausible.event(page: 'use_action'); - setState(() { - cmds = ''; - }); - await Future.delayed(const Duration(milliseconds: 500)); - // Add new - setState(() { - cmds = quickSettingsContents[i]; - }); - }, - text: MouseRegion( - cursor: SystemMouseCursors.click, - child: Text(quickSettingsTitles[i])), - )); - } - } - return actions.isNotEmpty - ? MouseRegion( - cursor: SystemMouseCursors.click, - child: DropDownButton( - buttonStyle: ButtonStyle( - padding: ButtonState.all(const EdgeInsets.only( - left: 15.0, right: 15.0, top: 10.0, bottom: 10.0))), - leading: const Icon(FluentIcons.code), - title: Text('runquickaction-text'.i18n()), - items: actions, - ), - ) - : const SizedBox(); - }), - ), + wslSettings(item, setState), const SizedBox( - height: 12.0, + height: 8.0, ), cmds.isNotEmpty ? Padding( @@ -292,3 +243,115 @@ Column settingsColumn( ], ); } + +// ToggleSwitch for enabling systemd +Widget wslSettings(item, Function setState) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text('wslsettings-text'.i18n()), + const SizedBox( + height: 8.0, + ), + Expander( + header: Text('boot-text'.i18n()), + content: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + settingSwitch(item, setState, "boot", "systemd"), + settingText(item, setState, "boot", "command"), + ], + ), + ), + const SizedBox(height: 8.0), + Expander( + header: Text('automount-text'.i18n()), + content: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + settingSwitch(item, setState, "automount", "enabled"), + settingSwitch(item, setState, "automount", "mountFsTab"), + settingText(item, setState, "automount", "root"), + settingText(item, setState, "automount", "options"), + ], + ), + ), + const SizedBox(height: 8.0), + Expander( + header: Text('network-text'.i18n()), + content: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + settingSwitch(item, setState, "network", "generateHosts"), + settingSwitch(item, setState, "network", "generateResolvConf"), + settingText(item, setState, "network", "hostname"), + ], + ), + ), + const SizedBox(height: 8.0), + Expander( + header: Text('interop-text'.i18n()), + content: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + settingSwitch(item, setState, "interop", "enabled"), + settingSwitch(item, setState, "interop", "appendWindowsPath"), + ], + ), + ), + ], + ); +} + +Widget settingSwitch(item, Function setState, String parent, String setting) { + final name = setting.uppercaseFirst(); + return Padding( + padding: const EdgeInsets.all(8.0), + child: Row( + children: [ + ToggleSwitch( + checked: prefs.getBool('$item-$setting') ?? false, + onChanged: (value) { + prefs.setBool('$item-$setting', value); + setState(() {}); + // Execute command in WSL + WSLApi().setSetting(item, parent, setting, value.toString()); + }, + ), + const SizedBox( + width: 8.0, + ), + Text(name), + ], + ), + ); +} + +Widget settingText(item, Function setState, String parent, String setting) { + final name = setting.uppercaseFirst(); + final controller = + TextEditingController(text: prefs.getString('$item-$setting') ?? ""); + return Padding( + padding: const EdgeInsets.all(8.0), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text("$name:"), + const SizedBox( + width: 8.0, + ), + SizedBox( + width: 300.0, + child: TextBox( + controller: controller, + onChanged: (value) { + prefs.setString('$item-$setting', value); + // Execute command in WSL + WSLApi().setSetting(item, parent, setting, value); + }, + ), + ), + ], + ), + ); +} diff --git a/lib/i18n/de.json b/lib/i18n/de.json index 3f8d3bf..64781b3 100644 --- a/lib/i18n/de.json +++ b/lib/i18n/de.json @@ -124,5 +124,10 @@ "addcommunityactions-text": "Community Actions hinzufügen", "done-text": "Fertig", "search-text": "Suche", - "shareyourquickaction-text": "Teilen Sie Ihre Schnellaktionen" -} + "shareyourquickaction-text": "Teilen Sie Ihre Schnellaktionen", + "wslsettings-text": "WSL-Einstellungen", + "boot-text": "Boot", + "automount-text": "Automount", + "network-text": "Netzwerk", + "interop-text": "Interop" +} \ No newline at end of file diff --git a/lib/i18n/en.json b/lib/i18n/en.json index 94d5b35..8c4f7c0 100644 --- a/lib/i18n/en.json +++ b/lib/i18n/en.json @@ -123,5 +123,10 @@ "documentation-text": "Documentation", "addcommunityactions-text": "Add Community Actions", "search-text": "Search", - "shareyourquickaction-text": "Share your Quick Action" + "shareyourquickaction-text": "Share your Quick Action", + "wslsettings-text": "WSL Settings", + "boot-text": "Boot", + "automount-text": "Automount", + "network-text": "Network", + "interop-text": "Interop" } \ No newline at end of file diff --git a/lib/i18n/pt.json b/lib/i18n/pt.json index 15f90c9..95fdc8c 100644 --- a/lib/i18n/pt.json +++ b/lib/i18n/pt.json @@ -124,5 +124,10 @@ "addcommunityactions-text": "Adicionar ações da comunidade", "done-text": "Feito", "search-text": "Procurar", - "shareyourquickaction-text": "Compartilhe sua ação rápida" + "shareyourquickaction-text": "Compartilhe sua ação rápida", + "wslsettings-text": "Configurações do WSL", + "boot-text": "Boot", + "automount-text": "Automount", + "network-text": "Rede", + "interop-text": "Interop" } \ No newline at end of file diff --git a/lib/i18n/zh.json b/lib/i18n/zh.json index 122c5f4..b680c93 100644 --- a/lib/i18n/zh.json +++ b/lib/i18n/zh.json @@ -124,5 +124,10 @@ "addcommunityactions-text": "添加社区快速操作", "done-text": "完成", "search-text": "搜索", - "shareyourquickaction-text": "分享你的快速操作" + "shareyourquickaction-text": "分享你的快速操作", + "wslsettings-text": "WSL 设置", + "boot-text": "启动", + "automount-text": "自动挂载", + "network-text": "网络", + "interop-text": "互操作性" } \ No newline at end of file diff --git a/pubspec.lock b/pubspec.lock index c07901c..6fa26ca 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -297,10 +297,10 @@ packages: dependency: transitive description: name: macos_window_utils - sha256: ece6315199f84931d7e32869aa3d8d4d2a82e6f4416ed292f9cf9345b0105feb + sha256: "0ff6c40c67e2dd93f696b2333dfc04f830a8c4b93edabc841bd1d87e3ac48935" url: "https://pub.dev" source: hosted - version: "1.0.2" + version: "1.0.1" matcher: dependency: transitive description: @@ -758,10 +758,10 @@ packages: dependency: transitive description: name: xml - sha256: "979ee37d622dec6365e2efa4d906c37470995871fe9ae080d967e192d88286b5" + sha256: ac0e3f4bf00ba2708c33fbabbbe766300e509f8c82dbd4ab6525039813f7e2fb url: "https://pub.dev" source: hosted - version: "6.2.2" + version: "6.1.0" yaml: dependency: "direct main" description: @@ -772,4 +772,4 @@ packages: version: "3.1.1" sdks: dart: ">=2.18.5 <3.0.0" - flutter: ">=3.7.0" + flutter: ">=3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 71081a6..e621626 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -41,6 +41,7 @@ flutter: uses-material-design: true assets: - lib/i18n/ + - assets/scripts/settings.bash # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec