Files
PeachDeployments/lib/Peach/see/server/setup/ViewServerSetup.dart
alvocool 38881d1fe1 Add app source and tests
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-11 10:15:30 +03:00

77 lines
2.5 KiB
Dart

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<LogLine> get logs => getDataManager().logs;
Stream<List<DeployStep>> 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<EnvTool> 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 = <String, String>{};
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<EnvTool> tools, String packageManager) {
final packages = tools.map((t) => t.packagesFor(packageManager)).join(' ');
return installCommandFor(packageManager, packages);
}
}