@@ -39,25 +39,25 @@ enum ErrorMode {
39
39
// false.
40
40
// cmdProcessor is what the first instance does once it receives the command line arguments from the previous
41
41
// kDebugMode makes the application noisy.
42
- Future <bool > unixSingleInstance (List <String > arguments,
43
- void Function (List <dynamic > args) cmdProcessor, {
44
- bool kDebugMode = false ,
45
- ErrorMode errorMode = ErrorMode .exit
46
- }) async {
42
+ Future <bool > unixSingleInstance (
43
+ List <String > arguments, void Function (List <dynamic > args) cmdProcessor,
44
+ {bool kDebugMode = false , ErrorMode errorMode = ErrorMode .exit}) async {
47
45
// TODO make a named arg
48
46
// Kept short because of mac os x sandboxing makes the name too long for unix sockets.
49
47
var socketFilename = 'socket' ;
50
48
// TODO make configurable so it can be per X, per User, or for the whole machine based on optional named args
51
49
var configPath = await _applicationConfigDirectory ();
52
50
await Directory (configPath).create (recursive: true );
53
51
var socketFilepath = p.join (configPath, socketFilename);
54
- final InternetAddress host = InternetAddress (socketFilepath, type: InternetAddressType .unix);
52
+ final InternetAddress host =
53
+ InternetAddress (socketFilepath, type: InternetAddressType .unix);
55
54
var socketFile = File (socketFilepath);
56
55
if (await socketFile.exists ()) {
57
56
if (kDebugMode) {
58
57
print ("Found existing instance!" );
59
58
}
60
- var messageSent = await _sendArgsToUixSocket (arguments, host, kDebugMode: kDebugMode);
59
+ var messageSent =
60
+ await _sendArgsToUixSocket (arguments, host, kDebugMode: kDebugMode);
61
61
if (messageSent) {
62
62
if (kDebugMode) {
63
63
print ("Message sent" );
@@ -74,7 +74,8 @@ Future<bool> unixSingleInstance(List<String> arguments,
74
74
// TODO manage socket subscription, technically not required because OS clean up does the work "for" us but good practices.
75
75
// StreamSubscription<Socket>? socket;
76
76
try {
77
- /*socket = */ await _createUnixSocket (host, cmdProcessor, kDebugMode: kDebugMode);
77
+ /*socket = */ await _createUnixSocket (host, cmdProcessor,
78
+ kDebugMode: kDebugMode);
78
79
} catch (e) {
79
80
print ("Socket create error" );
80
81
print (e);
@@ -86,18 +87,16 @@ Future<bool> unixSingleInstance(List<String> arguments,
86
87
case ErrorMode .returnTrue:
87
88
return true ;
88
89
case ErrorMode .returnFalse:
89
- // Pass through
90
+ // Pass through
90
91
}
91
92
return false ;
92
93
}
93
94
return true ;
94
95
}
95
96
96
97
// JSON serializes the args, and sends across "the wire"
97
- Future <bool > _sendArgsToUixSocket (
98
- List <String > args, InternetAddress host, {
99
- bool kDebugMode = false
100
- }) async {
98
+ Future <bool > _sendArgsToUixSocket (List <String > args, InternetAddress host,
99
+ {bool kDebugMode = false }) async {
101
100
try {
102
101
var s = await Socket .connect (host, 0 );
103
102
s.writeln (jsonEncode (args));
@@ -115,10 +114,9 @@ Future<bool> _sendArgsToUixSocket(
115
114
// Creates the unix socket, or cleans up if it exists but isn't valid and then
116
115
// recursively calls itself -- if the socket is valid, sends the args as json.
117
116
// Return stream subscription.
118
- Future <StreamSubscription <Socket >> _createUnixSocket (InternetAddress host,
119
- void Function (List <dynamic > args) cmdProcessor, {
120
- bool kDebugMode = false
121
- }) async {
117
+ Future <StreamSubscription <Socket >> _createUnixSocket (
118
+ InternetAddress host, void Function (List <dynamic > args) cmdProcessor,
119
+ {bool kDebugMode = false }) async {
122
120
if (kDebugMode) {
123
121
print ("creating socket" );
124
122
}
0 commit comments