import '../../../about/external/data/EnvCheck.dart'; import '../../../about/internal/application/ServerProfile.dart'; import '../../../about/internal/application/StepTracker.dart'; import '../../../comms/Comms.dart' show LogLine; import '../../parent/ParentViewModel.dart'; import 'ConnectServerSetup.dart'; class ViewServerSetup extends ParentViewModel { ConnectServerSetup connection; ViewServerSetup(super.context, this.connection); Stream get logs => getDataManager().logs; Stream> get steps => getDataManager().stepStream; /// Step 1: prove the credentials work and read what's already there. The /// failure is reported inline rather than as an overlay — on this screen a /// failed connection is a step of the wizard, not an interruption. void probeServer(ServerProfile server) async { try { final packageManager = await getDataManager().detectPackageManager( server, ); final versions = await getDataManager().probeEnvironment( server, kEnvTools.map((t) => '${t.key} ${t.detect}').toList(), ); connection.onServerProbed(packageManager, versions); } catch (error) { connection.onProbeFailed(error.toString()); } } /// Step 3: install everything the user ticked in one package-manager call, /// enable the units that need it, then re-probe those tools. void installEnvironment( ServerProfile server, List tools, String command, ) async { try { final result = await getDataManager().installEnvironment( server: server, command: command, units: tools.where((t) => t.unit != null).map((t) => t.unit!).toList(), ); var versions = {}; try { versions = await getDataManager().probeEnvironment( server, tools.map((t) => '${t.key} ${t.detect}').toList(), ); } catch (_) { // The install result is what matters; a failed re-probe just leaves // the tiles showing their previous state. } connection.onInstallFinished(result, versions); } catch (error) { handleError( error, () => installEnvironment(server, tools, command), () {}, "Retry", ); } } /// The single command that installs every selected tool. String buildInstallCommand(List tools, String packageManager) { final packages = tools.map((t) => t.packagesFor(packageManager)).join(' '); return installCommandFor(packageManager, packages); } }