install method

Future<void> install()

Implementation

Future<void> install() async {
  final cliVersion = app.version ?? CliStrings.version;
  final platform = SupportedPlatform.current;
  final fileName = _getArchiveFileName(platform, cliVersion);

  final releaseUrl =
      'https://github.com/$_owner/$_repo/releases/download/assist-v$cliVersion/$fileName';

  final tempDir = Directory.systemTemp.createTempSync('assist_gui_');
  final archivePath = p.join(tempDir.path, fileName);
  final extractedPath = p.join(tempDir.path, 'extracted');

  print('Temp dir: ${tempDir.path}');

  print('⬇️ Downloading GUI release for $platform...');
  print(releaseUrl);
  final response = await http.get(Uri.parse(releaseUrl));

  if (response.statusCode != 200) {
    throw Exception('❌ Failed to download GUI: ${response.statusCode}');
  }

  await File(archivePath).writeAsBytes(response.bodyBytes);

  print('📦 Extracting...');
  await _extractArchive(archivePath, extractedPath);

  final installPath = getInstallDirectory().path;
  final installDir = Directory(installPath);

  if (!installDir.existsSync()) {
    installDir.createSync(recursive: true);
  }

  // Move full bundle into installDir
  _copyDirectory(Directory(extractedPath), Directory(installPath));

  // Clean up
  // tempDir.deleteSync(recursive: true);

  // Find entry executable
  final guiExecutable = _findExecutable(installPath);
  if (guiExecutable == null) {
    throw Exception('❌ Could not find GUI executable inside bundle.');
  }

  if (Platform.isLinux || Platform.isMacOS) {
    await Process.run('chmod', ['+x', guiExecutable]);
  }

  print('✅ Installed GUI to: $installPath');

  // Update config
  await AssistConfigManager.updateGuiData(
    path: guiExecutable,
    bundle: installPath,
  );

  await AssistConfigManager.setVersion(cliVersion);

  // await task(
  //   'Decompressing Data...',
  //   task: (spinner) async {
  //     await _uncompressData();
  //   },
  //   successMessage: '[Done] ${'Decompression'.gray()}',
  // );
  // line();
  // await task(
  //   'Configuring...',
  //   task: (spinner) async {
  //     await _uncompressData();
  //   },
  //   successMessage: '[Done] ${'Configuration'.gray()} ',
  // );
  // line();
  // await task(
  //   'Installing data...',
  //   task: (spinner) async {
  //     await _install();
  //   },
  //   successMessage: '[Done] ${'Installation'.gray()}',
  // );
}