-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
singe instance when opening file with exe
- Loading branch information
1 parent
9c6a4aa
commit 2ad9274
Showing
4 changed files
with
130 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
|
||
import 'dart:async'; | ||
import 'dart:convert'; | ||
import 'dart:io'; | ||
|
||
import 'package:window_manager/window_manager.dart'; | ||
|
||
import '../stateManagement/events/statusInfo.dart'; | ||
import '../stateManagement/hierarchy/FileHierarchy.dart'; | ||
import '../stateManagement/openFiles/openFilesManager.dart'; | ||
import '../stateManagement/openFiles/types/xml/sync/syncServer.dart'; | ||
import 'utils.dart'; | ||
|
||
void onFileOpenCommand(List<String> paths) async { | ||
await Future.wait(paths.map((path) async { | ||
await openHierarchyManager.openFile(path); | ||
if (await canOpenAsFile(path)) | ||
areasManager.openFile(path); | ||
})); | ||
await windowManager.focus(); | ||
messageLog.add(""); | ||
} | ||
|
||
Future<bool> trySendFileArgs(List<String> args) async { | ||
if (args.isEmpty) | ||
return false; | ||
var completer = Completer<bool>(); | ||
WebSocket? webSocket; | ||
var timeout = Timer(const Duration(milliseconds: 500), () { | ||
completer.complete(false); | ||
webSocket?.close(); | ||
}); | ||
unawaited(WebSocket.connect("ws://localhost:$wsPort") | ||
.then((ws) { | ||
if (completer.isCompleted) { | ||
ws.close(); | ||
return; | ||
} | ||
webSocket = ws; | ||
ws.add(jsonEncode(CustomWsMessage("openFiles", {"files": args}))); | ||
ws.listen((data) { | ||
var msg = SyncMessage.fromJson(jsonDecode(data)); | ||
if (msg.method == "connected") { | ||
completer.complete(true); | ||
ws.close(); | ||
timeout.cancel(); | ||
} | ||
}); | ||
}) | ||
.catchError((e) { | ||
completer.complete(false); | ||
}) | ||
); | ||
|
||
return completer.future; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters