chain-studio/lib/widgets/chain_binary_recovery.dart
flemming-it 891acd2ba2
Some checks failed
Security / Security check (push) Failing after 2s
refactor: rename internal Fai* design system + fai_ helpers to chain
The Studio design system, widgets and helpers carried a Fai* / fai_
prefix (FaiSpace, FaiColors, FaiTheme, FaiLog, 17 fai_*.dart files, the
faiBinary* l10n keys). Studio is the Ch∆In product, so rename them to
Chain* / chain_ — carefully preserving English fail/failure/failed.
Also fix stale references: the 'fai' binary in l10n strings -> 'chain',
FAI_* env vars (FAI_BIN/DATA_DIR/MODULES_DIR/TODAY/BOOTSTRAP_TOKEN) ->
CHAIN_*, fai_platform -> fai_chain, fai_hub -> chain_hub. Vendor
security-hook tooling (FAI_BANNED_TERMS_FILE) + the .fai bundle ext left.
flutter analyze + test: clean (20 passed).

Signed-off-by: flemming-it <stefan.a.flemming@googlemail.com>
2026-06-16 17:53:17 +02:00

95 lines
3.2 KiB
Dart

// Recovery affordance shown when Studio cannot locate the `fai`
// binary on the machine. Replaces the old CLI-jargon dead-end
// ("set CHAIN_BIN to its full path") with two acts a non-CLI
// operator can actually take:
//
// 1. Locate the binary with a native file picker, persisting
// the choice via SystemActions.setFaiBinaryPath.
// 2. Open the install guide in the OS browser.
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import '../data/system_actions.dart';
import '../l10n/app_localizations.dart';
import '../theme/tokens.dart';
class ChainBinaryRecovery extends StatelessWidget {
/// Fired after the operator successfully picks a `fai` binary,
/// so the host can retry whatever action hit the missing
/// binary (e.g. re-run the daemon start / status probe).
final VoidCallback? onLocated;
const ChainBinaryRecovery({super.key, this.onLocated});
Future<void> _locate(BuildContext context) async {
final l = AppLocalizations.of(context)!;
final messenger = ScaffoldMessenger.of(context);
final picked = await FilePicker.pickFiles(
dialogTitle: l.chainBinaryPickerTitle,
);
final path = picked?.files.single.path;
if (path == null) return;
final ok = await SystemActions.setFaiBinaryPath(path);
messenger.showSnackBar(
SnackBar(
content: Text(ok ? l.chainBinarySetOk(path) : l.chainBinaryNotFound),
),
);
if (ok) onLocated?.call();
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final l = AppLocalizations.of(context)!;
return Container(
width: double.infinity,
padding: const EdgeInsets.all(ChainSpace.md),
decoration: BoxDecoration(
color: theme.colorScheme.errorContainer.withValues(alpha: 0.4),
borderRadius: BorderRadius.circular(ChainRadius.sm),
border: Border.all(
color: theme.colorScheme.error.withValues(alpha: 0.4),
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
l.chainBinaryNotFound,
style: theme.textTheme.bodyMedium?.copyWith(
fontWeight: FontWeight.w600,
color: theme.colorScheme.error,
),
),
const SizedBox(height: ChainSpace.xs),
Text(
l.chainBinaryNotFoundHint,
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
),
const SizedBox(height: ChainSpace.md),
Wrap(
spacing: ChainSpace.sm,
runSpacing: ChainSpace.sm,
children: [
FilledButton.tonalIcon(
onPressed: () => _locate(context),
icon: const Icon(Icons.folder_open, size: 16),
label: Text(l.chainBinaryLocateButton),
),
OutlinedButton.icon(
onPressed: () =>
SystemActions.openInOs(kFaiInstallDocsUrl),
icon: const Icon(Icons.open_in_new, size: 16),
label: Text(l.chainBinaryInstallDocsButton),
),
],
),
],
),
);
}
}