Add app source and tests
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
79
lib/Peach/see/configuration/ViewConfiguration.dart
Normal file
79
lib/Peach/see/configuration/ViewConfiguration.dart
Normal file
@@ -0,0 +1,79 @@
|
||||
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 'ConnectConfiguration.dart';
|
||||
|
||||
class ViewConfiguration extends ParentViewModel {
|
||||
ConnectConfiguration connection;
|
||||
|
||||
ViewConfiguration(super.context, this.connection);
|
||||
|
||||
Stream<LogLine> get logs => getDataManager().logs;
|
||||
|
||||
Stream<List<DeployStep>> get steps => getDataManager().stepStream;
|
||||
|
||||
/// Detects the package manager, then probes for every tool at once.
|
||||
void probeEnvironment(ServerProfile server) async {
|
||||
if (!await canReach(server, () => probeEnvironment(server))) return;
|
||||
try {
|
||||
final packageManager = await getDataManager().detectPackageManager(
|
||||
server,
|
||||
);
|
||||
final versions = await getDataManager().probeEnvironment(
|
||||
server,
|
||||
kEnvTools.map((t) => '${t.key} ${t.detect}').toList(),
|
||||
);
|
||||
connection.onEnvironmentProbed(packageManager, versions);
|
||||
} catch (error) {
|
||||
connection.onProbeFailed(error.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/// Builds the install command for [tool] under [packageManager] and hands it
|
||||
/// back for confirmation — nothing runs on the server until the user agrees.
|
||||
void prepareInstall(EnvTool tool, String packageManager) {
|
||||
if (packageManager == 'unknown') {
|
||||
connection.onProbeFailed(
|
||||
'Unknown package manager — cannot auto-install.',
|
||||
);
|
||||
return;
|
||||
}
|
||||
connection.onInstallCommandReady(
|
||||
tool,
|
||||
installCommandFor(packageManager, tool.packagesFor(packageManager)),
|
||||
);
|
||||
}
|
||||
|
||||
/// Installs [tool], enables its unit where it has one, then re-probes just
|
||||
/// that tool so the card updates without a full re-scan.
|
||||
void installTool(ServerProfile server, EnvTool tool, String command) async {
|
||||
try {
|
||||
await getDataManager().installPackages(
|
||||
server: server,
|
||||
command: command,
|
||||
enableUnit: tool.unit,
|
||||
);
|
||||
var version = '';
|
||||
try {
|
||||
final probed = await getDataManager().probeEnvironment(server, [
|
||||
'${tool.key} ${tool.detect}',
|
||||
]);
|
||||
version = probed[tool.key] ?? '';
|
||||
} catch (_) {
|
||||
// The install itself succeeded; a failed re-probe just leaves the
|
||||
// version blank until the next full scan.
|
||||
}
|
||||
connection.onToolInstalled(tool, version);
|
||||
} catch (error) {
|
||||
connection.onToolInstalled(tool, '');
|
||||
handleError(
|
||||
error,
|
||||
() => installTool(server, tool, command),
|
||||
() {},
|
||||
"Retry",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user