Skip to content

Commit

Permalink
Added adjustable start path and user #6
Browse files Browse the repository at this point in the history
  • Loading branch information
bostrot committed Dec 17, 2021
1 parent d5136bf commit 45e5265
Show file tree
Hide file tree
Showing 14 changed files with 131 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"C_Cpp.errorSquiggles": "Disabled"
"C_Cpp.errorSquiggles": "Disabled",
"cmake.configureOnOpen": false
}
Binary file modified build/windows/runner/Release/data/app.so
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"family":"MaterialIcons","fonts":[{"asset":"fonts/MaterialIcons-Regular.otf"}]},{"family":"packages/fluent_ui/FluentIcons","fonts":[{"asset":"packages/fluent_ui/fonts/FluentIcons.ttf"}]},{"family":"packages/cupertino_icons/CupertinoIcons","fonts":[{"asset":"packages/cupertino_icons/assets/CupertinoIcons.ttf"}]}]
[{"family":"MaterialIcons","fonts":[{"asset":"fonts/MaterialIcons-Regular.otf"}]},{"family":"packages/cupertino_icons/CupertinoIcons","fonts":[{"asset":"packages/cupertino_icons/assets/CupertinoIcons.ttf"}]},{"family":"packages/fluent_ui/FluentIcons","fonts":[{"asset":"packages/fluent_ui/fonts/FluentIcons.ttf"}]}]
Binary file modified build/windows/runner/Release/data/flutter_assets/NOTICES.Z
Binary file not shown.
Binary file modified build/windows/runner/Release/desktop_window_plugin.dll
Binary file not shown.
Binary file modified build/windows/runner/Release/flutter_windows.dll
Binary file not shown.
Binary file modified build/windows/runner/Release/system_theme_plugin.dll
Binary file not shown.
Binary file modified build/windows/runner/Release/url_launcher_windows_plugin.dll
Binary file not shown.
Binary file modified build/windows/runner/Release/wsl2distromanager.exe
Binary file not shown.
13 changes: 11 additions & 2 deletions lib/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,17 @@ class WSLApi {

/// Start a WSL distro by name
/// @param distribution: String
void start(String distribution) async {
Process.start('start', ['wsl', '-d', distribution],
/// @param startPath: String (optional) Defaults to root ('/')
void start(String distribution,
{String startPath = '', String startUser = ''}) async {
List<String> args = ['wsl', '-d', distribution];
if (startPath != '') {
args.addAll(['--cd', startPath]);
}
if (startUser != '') {
args.addAll(['--user', startUser]);
}
Process.start('start', args,
mode: ProcessStartMode.detached, runInShell: true);
}

Expand Down
115 changes: 114 additions & 1 deletion lib/list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import 'analytics.dart';
import 'api.dart';
import 'dialog.dart';
import 'package:fluent_ui/fluent_ui.dart';
import 'package:file_picker/file_picker.dart';
import 'package:shared_preferences/shared_preferences.dart';

late SharedPreferences prefs;

class DistroList extends StatefulWidget {
const DistroList({Key? key, required this.api, required this.statusMsg})
Expand All @@ -22,6 +26,17 @@ class _DistroListState extends State<DistroList> {
});
}

// Initialize shared preferences
void initPrefs() async {
prefs = await SharedPreferences.getInstance();
}

@override
void initState() {
initPrefs();
super.initState();
}

@override
Widget build(BuildContext context) {
return distroList(widget.api, widget.statusMsg, update, hover);
Expand All @@ -40,6 +55,7 @@ FutureBuilder<Instances> distroList(
return false;
}

// List as FutureBuilder with WSLApi
return FutureBuilder<Instances>(
future: api.list(),
builder: (context, snapshot) {
Expand Down Expand Up @@ -86,7 +102,12 @@ FutureBuilder<Instances> distroList(
icon: const Icon(FluentIcons.play),
onPressed: () {
plausible.event(name: "wsl_started");
api.start(item);
String? startPath =
prefs.getString('StartPath_' + item) ?? '';
String? startName =
prefs.getString('StartUser_' + item) ?? '';
api.start(item,
startPath: startPath, startUser: startName);
Future.delayed(const Duration(milliseconds: 500),
statusMsg('$item started.'));
},
Expand Down Expand Up @@ -154,6 +175,14 @@ FutureBuilder<Instances> distroList(
deleteDialog(context, item, api, statusMsg);
}),
),
Tooltip(
message: 'Settings',
child: IconButton(
icon: const Icon(FluentIcons.settings),
onPressed: () {
settingsDialog(context, item, api, statusMsg);
}),
),
],
),
),
Expand All @@ -175,6 +204,11 @@ FutureBuilder<Instances> distroList(
);
}

/// Delete Dialog
/// @param context: context
/// @param item: distro name
/// @param api: WSLApi
/// @param statusMsg: status message
deleteDialog(context, item, api, Function(String, {bool loading}) statusMsg) {
dialog(
context: context,
Expand All @@ -196,6 +230,79 @@ deleteDialog(context, item, api, Function(String, {bool loading}) statusMsg) {
});
}

/// Rename Dialog
/// @param context: context
/// @param item: distro name
/// @param api: WSLApi
/// @param statusMsg: Function(String, {bool loading})
settingsDialog(context, item, api, Function(String, {bool loading}) statusMsg) {
var title = 'Settings';
final pathController = TextEditingController();
pathController.text = prefs.getString('StartPath_' + item) ?? '';
final userController = TextEditingController();
userController.text = prefs.getString('StartUser_' + item) ?? '';
plausible.event(page: title.split(' ')[0].toLowerCase());
showDialog(
context: context,
builder: (context) {
return ContentDialog(
title: Text(title),
content: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Padding(
padding: EdgeInsets.only(bottom: 8.0),
child: Text('Start directory path'),
),
Tooltip(
message: '(Optional) WSL directory to start in.',
child: TextBox(
controller: pathController,
placeholder: '/home/user/project',
),
),
const Padding(
padding: EdgeInsets.only(bottom: 8.0, top: 8.0),
child: Text('Start user'),
),
Tooltip(
message: '(Optional) WSL default user to use.',
child: TextBox(
controller: userController,
placeholder: 'root',
),
),
const Padding(
padding: EdgeInsets.only(bottom: 8.0, top: 8.0),
child: Text(
'(empty the fields for default or if your WSL version does not support it)'),
),
],
),
actions: [
Button(
child: const Text('Cancel'),
onPressed: () async {
Navigator.pop(context);
}),
Button(
child: const Text('Save'),
onPressed: () {
prefs.setString('StartPath_' + item, pathController.text);
prefs.setString('StartUser_' + item, userController.text);
Navigator.pop(context);
}),
],
);
},
);
}

/// Rename Dialog
/// @param context: context
/// @param item: distro name
/// @param api: WSLApi
/// @param statusMsg: Function(String, {bool loading})
renameDialog(context, item, api, Function(String, {bool loading}) statusMsg) {
dialog(
context: context,
Expand All @@ -215,6 +322,11 @@ renameDialog(context, item, api, Function(String, {bool loading}) statusMsg) {
});
}

/// Copy Dialog
/// @param context: context
/// @param item: distro name
/// @param api: WSLApi
/// @param statusMsg: Function(String, {bool loading})
copyDialog(context, item, api, Function(String, {bool loading}) statusMsg) {
dialog(
context: context,
Expand All @@ -232,6 +344,7 @@ copyDialog(context, item, api, Function(String, {bool loading}) statusMsg) {
});
}

/// Install Dialog
class InstallDialog extends StatelessWidget {
const InstallDialog({Key? key}) : super(key: key);

Expand Down
4 changes: 1 addition & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'create.dart';
import 'analytics.dart';

// TODO: Update on release
const String currentVersion = "v0.5.3+1";
const String currentVersion = "v0.6.0";
const String windowsStoreUrl = "https://www.microsoft.com/store/"
"productId/9NWS9K95NMJB";

Expand All @@ -32,8 +32,6 @@ void main() async {
win.title = "WSL Distro Manager";
win.show();
});
//DesktopWindow.setWindowSize(const Size(650, 500));
//DesktopWindow.setMinWindowSize(const Size(650, 500));

prefs = await SharedPreferences.getInstance();
bool? privacyMode = prefs.getBool('privacyMode');
Expand Down
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ packages:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.1.0"
charcode:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 0.5.3+1 # Current version
version: 0.6.0 # Current version

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down

0 comments on commit 45e5265

Please sign in to comment.