Skip to content

Commit e4d2652

Browse files
authored
add startup args for windows and macos (#8)
Co-authored-by: Wojciech Warwas <wojciech.warwas@thecodebrothers.pl>
1 parent c3992fb commit e4d2652

4 files changed

Lines changed: 13 additions & 5 deletions

File tree

lib/src/app_auto_launcher.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
class AppAutoLauncher {
22
final String appName;
33
final String appPath;
4+
final List<String> args;
45

56
AppAutoLauncher({
67
required this.appName,
78
required this.appPath,
9+
this.args = const [],
810
});
911

1012
Future<bool> isEnabled() {

lib/src/app_auto_launcher_impl_macos.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ class AppAutoLauncherImplMacOS extends AppAutoLauncher {
66
AppAutoLauncherImplMacOS({
77
required String appName,
88
required String appPath,
9-
}) : super(appName: appName, appPath: appPath);
9+
List<String> args = const [],
10+
}) : super(appName: appName, appPath: appPath, args: args);
1011

1112
File get _plistFile => File(
1213
'${Platform.environment['HOME']}/Library/LaunchAgents/$appName.plist');
@@ -28,6 +29,7 @@ class AppAutoLauncherImplMacOS extends AppAutoLauncher {
2829
<key>ProgramArguments</key>
2930
<array>
3031
<string>$appPath</string>
32+
${args.map((e) => '<string>$e</string>').join("\n")}
3133
</array>
3234
<key>RunAtLoad</key>
3335
<true/>

lib/src/app_auto_launcher_impl_windows.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ class AppAutoLauncherImplWindows extends AppAutoLauncher {
77
AppAutoLauncherImplWindows({
88
required String appName,
99
required String appPath,
10-
}) : super(appName: appName, appPath: appPath);
10+
List<String> args = const [],
11+
}) : super(appName: appName, appPath: appPath, args: args);
1112

1213
RegistryKey get _regKey => Registry.openPath(
1314
RegistryHive.currentUser,
@@ -26,7 +27,7 @@ class AppAutoLauncherImplWindows extends AppAutoLauncher {
2627
_regKey.createValue(RegistryValue(
2728
appName,
2829
RegistryValueType.string,
29-
appPath,
30+
'$appPath ${args.join(' ')}',
3031
));
3132
return true;
3233
}

lib/src/launch_at_startup.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import 'dart:io';
33

44
import 'package:flutter/foundation.dart';
55

6+
import 'app_auto_launcher.dart';
67
import 'app_auto_launcher_impl_linux.dart';
78
import 'app_auto_launcher_impl_macos.dart';
9+
import 'app_auto_launcher_impl_noop.dart';
810
import 'app_auto_launcher_impl_windows.dart'
911
if (dart.library.html) 'app_auto_launcher_impl_windows_noop.dart';
10-
import 'app_auto_launcher_impl_noop.dart';
11-
import 'app_auto_launcher.dart';
1212

1313
class LaunchAtStartup {
1414
LaunchAtStartup._();
@@ -21,6 +21,7 @@ class LaunchAtStartup {
2121
void setup({
2222
required String appName,
2323
required String appPath,
24+
List<String> args = const [],
2425
}) {
2526
if (!kIsWeb && Platform.isLinux) {
2627
_appAutoLauncher = AppAutoLauncherImplLinux(
@@ -31,11 +32,13 @@ class LaunchAtStartup {
3132
_appAutoLauncher = AppAutoLauncherImplMacOS(
3233
appName: appName,
3334
appPath: appPath,
35+
args: args,
3436
);
3537
} else if (!kIsWeb && Platform.isWindows) {
3638
_appAutoLauncher = AppAutoLauncherImplWindows(
3739
appName: appName,
3840
appPath: appPath,
41+
args: args,
3942
);
4043
}
4144
}

0 commit comments

Comments
 (0)