startServer static method

Future<void> startServer()

Implementation

static Future<void> startServer() async {
  await forceKillServer();
  if (_serverProcess != null) return;

  final tempDir = await getTemporaryDirectory();
  final exeFile = File('${tempDir.path}/server.exe');

  if (!await _isExeRunning()) {
    final bytes = await rootBundle.load(
      'packages/face_detection_windows/assets/server.exe',
    );
    await exeFile.writeAsBytes(bytes.buffer.asUint8List());
    print("Copied new exe to :${exeFile.path}");
  } else {
    print("EXE already running. Not overwriting.");
  }

  _serverProcess = await Process.start(exeFile.path, [], runInShell: false);

  print("Server exe launched!");
  await waitForServer('http://localhost:5001/ping');
}