@@ -39,25 +39,25 @@ enum ErrorMode {
3939// false.
4040// cmdProcessor is what the first instance does once it receives the command line arguments from the previous
4141// 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 {
4745 // TODO make a named arg
4846 // Kept short because of mac os x sandboxing makes the name too long for unix sockets.
4947 var socketFilename = 'socket' ;
5048 // TODO make configurable so it can be per X, per User, or for the whole machine based on optional named args
5149 var configPath = await _applicationConfigDirectory ();
5250 await Directory (configPath).create (recursive: true );
5351 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);
5554 var socketFile = File (socketFilepath);
5655 if (await socketFile.exists ()) {
5756 if (kDebugMode) {
5857 print ("Found existing instance!" );
5958 }
60- var messageSent = await _sendArgsToUixSocket (arguments, host, kDebugMode: kDebugMode);
59+ var messageSent =
60+ await _sendArgsToUixSocket (arguments, host, kDebugMode: kDebugMode);
6161 if (messageSent) {
6262 if (kDebugMode) {
6363 print ("Message sent" );
@@ -74,7 +74,8 @@ Future<bool> unixSingleInstance(List<String> arguments,
7474 // TODO manage socket subscription, technically not required because OS clean up does the work "for" us but good practices.
7575 // StreamSubscription<Socket>? socket;
7676 try {
77- /*socket = */ await _createUnixSocket (host, cmdProcessor, kDebugMode: kDebugMode);
77+ /*socket = */ await _createUnixSocket (host, cmdProcessor,
78+ kDebugMode: kDebugMode);
7879 } catch (e) {
7980 print ("Socket create error" );
8081 print (e);
@@ -86,18 +87,16 @@ Future<bool> unixSingleInstance(List<String> arguments,
8687 case ErrorMode .returnTrue:
8788 return true ;
8889 case ErrorMode .returnFalse:
89- // Pass through
90+ // Pass through
9091 }
9192 return false ;
9293 }
9394 return true ;
9495}
9596
9697// 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 {
101100 try {
102101 var s = await Socket .connect (host, 0 );
103102 s.writeln (jsonEncode (args));
@@ -115,10 +114,9 @@ Future<bool> _sendArgsToUixSocket(
115114// Creates the unix socket, or cleans up if it exists but isn't valid and then
116115// recursively calls itself -- if the socket is valid, sends the args as json.
117116// 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 {
122120 if (kDebugMode) {
123121 print ("creating socket" );
124122 }
0 commit comments