Skip to content

Commit c8c475e

Browse files
committed
Error msg
1 parent d241b6f commit c8c475e

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

lib/src/unix_single_instance_base.dart

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,26 @@ Future<String> _applicationConfigDirectory() async {
2323
return dbPath;
2424
}
2525

26+
enum ErrorMode {
27+
// Exits with a -1
28+
exit,
29+
// Throws an error
30+
throwError,
31+
// Returns false
32+
returnFalse,
33+
// Returns true
34+
returnTrue;
35+
}
36+
2637
// Call this at the top of your function, returns a bool. Which is "true" if this is the first instance,
2738
// if this is the second instance (and it has transmitted the arguments across the socket) it returns
2839
// false.
2940
// cmdProcessor is what the first instance does once it receives the command line arguments from the previous
3041
// kDebugMode makes the application noisy.
3142
Future<bool> unixSingleInstance(List<String> arguments,
3243
void Function(List<dynamic> args) cmdProcessor, {
33-
bool kDebugMode = false
44+
bool kDebugMode = false,
45+
ErrorMode errorMode = ErrorMode.exit
3446
}) async {
3547
// TODO make a named arg
3648
// Kept short because of mac os x sandboxing makes the name too long for unix sockets.
@@ -66,7 +78,16 @@ Future<bool> unixSingleInstance(List<String> arguments,
6678
} catch (e) {
6779
print("Socket create error");
6880
print(e);
69-
exit(0);
81+
switch (errorMode) {
82+
case ErrorMode.exit:
83+
exit(-1);
84+
case ErrorMode.throwError:
85+
throw Error.safeToString("socket create error: $e");
86+
case ErrorMode.returnTrue:
87+
return true;
88+
case ErrorMode.returnFalse:
89+
// Pass through
90+
}
7091
return false;
7192
}
7293
return true;

0 commit comments

Comments
 (0)