Replaces the Store-only DE/EN toggle with an app-wide one parked in the sidebar footer next to the theme button. Pressing it flips every translated string at once: nav labels, page titles, common buttons, the bilingual store-index content. Implementation: - Adds `flutter_localizations` + `intl` to pubspec, plus `flutter.generate: true` so `flutter gen-l10n` runs in the build pipeline. - ARB sources at `lib/l10n/app_en.arb` and `app_de.arb`. The EN file is the template; DE carries the German strings. Initial coverage: navigation, common buttons, page titles, channels / store / audit / modules / approvals headers, hub-unreachable copy, MCP + n8n panel headers + hints. Rest of the UI strings are still English-literal — those fall in incrementally as we touch each surface. - Generated `AppLocalizations` lives at `lib/l10n/app_localizations*.dart` (regenerated via `flutter gen-l10n` on every ARB edit). - `StudioAppState` gains `localeNotifier` alongside `modeNotifier`; persisted via SharedPreferences key `locale.code`. - Sidebar `_LanguageToggle` reads/writes through the notifier. The Store's per-page locale state is gone: `_locale` now reads `Localizations.localeOf(context) .languageCode`, so the bilingual store-index content follows the global setting without a second toggle. - `_NavPage.label` becomes `_NavPage.id` + `labelOf(context)`; Cmd+K palette and Sidebar both read the localized label. Out of scope this iteration: localizing the remaining ~80% of UI strings (Settings dialog labels, Store search hint, error messages). Those land incrementally — the i18n infrastructure now means each is a one-line ARB edit + one call-site swap. Signed-off-by: flemming-it <stefan.a.flemming@googlemail.com>
906 lines
29 KiB
Dart
906 lines
29 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../data/hub.dart';
|
|
import '../data/system_actions.dart';
|
|
import '../l10n/app_localizations.dart';
|
|
import '../theme/theme.dart';
|
|
import '../theme/tokens.dart';
|
|
import '../widgets/widgets.dart';
|
|
|
|
class DoctorPage extends StatefulWidget {
|
|
const DoctorPage({super.key});
|
|
|
|
@override
|
|
State<DoctorPage> createState() => _DoctorPageState();
|
|
}
|
|
|
|
class _DoctorPageState extends State<DoctorPage> {
|
|
late Future<DoctorSnapshot> _future;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_future = HubService.instance.doctor();
|
|
}
|
|
|
|
void _refresh() => setState(() {
|
|
_future = HubService.instance.doctor();
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
|
appBar: AppBar(
|
|
title: Text(AppLocalizations.of(context)!.doctorTitle),
|
|
actions: [
|
|
IconButton(
|
|
icon: const Icon(Icons.refresh, size: 18),
|
|
tooltip: 'Re-check',
|
|
onPressed: _refresh,
|
|
),
|
|
const SizedBox(width: FaiSpace.sm),
|
|
],
|
|
),
|
|
body: FutureBuilder<DoctorSnapshot>(
|
|
future: _future,
|
|
builder: (context, snapshot) {
|
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
|
return const Center(child: CircularProgressIndicator());
|
|
}
|
|
if (snapshot.hasError) {
|
|
return FaiEmptyState(
|
|
icon: Icons.cloud_off_outlined,
|
|
iconColor: Theme.of(context).colorScheme.error,
|
|
title: 'Hub unreachable',
|
|
hint: 'Start the hub with `fai serve`.',
|
|
action: FilledButton.tonal(
|
|
onPressed: _refresh,
|
|
child: const Text('Retry'),
|
|
),
|
|
);
|
|
}
|
|
final s = snapshot.data!;
|
|
final showUpdate = s.update.updateAvailable ||
|
|
(!s.update.manifestReachable &&
|
|
s.update.localVersion.isNotEmpty);
|
|
return ListView(
|
|
padding: const EdgeInsets.all(FaiSpace.xl),
|
|
children: [
|
|
if (showUpdate) _UpdateBanner(status: s.update),
|
|
if (showUpdate) const SizedBox(height: FaiSpace.lg),
|
|
_SummaryStrip(snapshot: s),
|
|
const SizedBox(height: FaiSpace.xl),
|
|
_Section(
|
|
title: 'Event log',
|
|
child: _EventLogPanel(
|
|
snapshot: s,
|
|
onRefresh: _refresh,
|
|
),
|
|
),
|
|
const SizedBox(height: FaiSpace.lg),
|
|
_Section(
|
|
title: 'Modules & approvals',
|
|
child: _ModulesPanel(snapshot: s),
|
|
),
|
|
const SizedBox(height: FaiSpace.lg),
|
|
_Section(
|
|
title: 'Host services',
|
|
child: _ServicesPanel(snapshot: s),
|
|
),
|
|
const SizedBox(height: FaiSpace.lg),
|
|
_Section(
|
|
title: 'Daemon files',
|
|
child: _DaemonPathsPanel(paths: s.paths),
|
|
),
|
|
const SizedBox(height: FaiSpace.lg),
|
|
_Section(
|
|
title: 'Daemon control',
|
|
child: _DaemonActionsCard(),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _Section extends StatelessWidget {
|
|
final String title;
|
|
final Widget child;
|
|
|
|
const _Section({required this.title, required this.child});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: FaiSpace.xs, bottom: FaiSpace.sm),
|
|
child: Text(
|
|
title.toUpperCase(),
|
|
style: theme.textTheme.labelSmall?.copyWith(
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
letterSpacing: 0.6,
|
|
fontSize: 10,
|
|
),
|
|
),
|
|
),
|
|
child,
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class _SummaryStrip extends StatelessWidget {
|
|
final DoctorSnapshot snapshot;
|
|
|
|
const _SummaryStrip({required this.snapshot});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Row(
|
|
children: [
|
|
_StatTile(
|
|
label: 'Modules',
|
|
value: snapshot.moduleCount.toString(),
|
|
subtitle: '${snapshot.capabilityCount} capabilities',
|
|
icon: Icons.extension_outlined,
|
|
),
|
|
const SizedBox(width: FaiSpace.md),
|
|
_StatTile(
|
|
label: 'Approvals',
|
|
value: snapshot.pendingApprovals.toString(),
|
|
subtitle: 'pending',
|
|
icon: Icons.inbox_outlined,
|
|
tone: snapshot.pendingApprovals > 0
|
|
? FaiPillTone.warning
|
|
: FaiPillTone.neutral,
|
|
),
|
|
const SizedBox(width: FaiSpace.md),
|
|
_StatTile(
|
|
label: 'Audit',
|
|
value: snapshot.chainHealthy ? '✓' : '⚠',
|
|
subtitle:
|
|
'${snapshot.eventChainVerified}/${snapshot.eventChainTotal} chain',
|
|
icon: Icons.shield_outlined,
|
|
tone: snapshot.chainHealthy
|
|
? FaiPillTone.success
|
|
: FaiPillTone.danger,
|
|
),
|
|
const SizedBox(width: FaiSpace.md),
|
|
_StatTile(
|
|
label: 'Services',
|
|
value: snapshot.services.length.toString(),
|
|
subtitle: 'declared',
|
|
icon: Icons.dns_outlined,
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class _StatTile extends StatelessWidget {
|
|
final String label;
|
|
final String value;
|
|
final String subtitle;
|
|
final IconData icon;
|
|
final FaiPillTone tone;
|
|
|
|
const _StatTile({
|
|
required this.label,
|
|
required this.value,
|
|
required this.subtitle,
|
|
required this.icon,
|
|
this.tone = FaiPillTone.neutral,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
final accentColor = switch (tone) {
|
|
FaiPillTone.success => FaiColors.success,
|
|
FaiPillTone.warning => FaiColors.warning,
|
|
FaiPillTone.danger => theme.colorScheme.error,
|
|
_ => theme.colorScheme.primary,
|
|
};
|
|
return Expanded(
|
|
child: FaiCard(
|
|
accentLeft: accentColor,
|
|
padding: const EdgeInsets.all(FaiSpace.lg),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Icon(icon, size: 14, color: theme.colorScheme.onSurfaceVariant),
|
|
const SizedBox(width: FaiSpace.xs),
|
|
Flexible(
|
|
child: Text(
|
|
label.toUpperCase(),
|
|
overflow: TextOverflow.ellipsis,
|
|
style: theme.textTheme.labelSmall?.copyWith(
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
letterSpacing: 0.5,
|
|
fontSize: 10,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: FaiSpace.sm),
|
|
Text(
|
|
value,
|
|
style: theme.textTheme.displaySmall?.copyWith(
|
|
color: accentColor,
|
|
fontWeight: FontWeight.w700,
|
|
),
|
|
),
|
|
const SizedBox(height: 2),
|
|
Text(
|
|
subtitle,
|
|
style: theme.textTheme.bodySmall?.copyWith(
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _EventLogPanel extends StatelessWidget {
|
|
final DoctorSnapshot snapshot;
|
|
/// Re-runs the doctor() call which re-verifies the chain.
|
|
/// Wired to a "Verify now" button so operators can re-check
|
|
/// after import / restore without restarting the daemon.
|
|
final VoidCallback onRefresh;
|
|
|
|
const _EventLogPanel({required this.snapshot, required this.onRefresh});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
final healthy = snapshot.chainHealthy;
|
|
return FaiCard(
|
|
child: Row(
|
|
children: [
|
|
Icon(
|
|
healthy ? Icons.verified_outlined : Icons.gpp_bad_outlined,
|
|
size: 24,
|
|
color: healthy ? FaiColors.success : theme.colorScheme.error,
|
|
),
|
|
const SizedBox(width: FaiSpace.lg),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
healthy
|
|
? 'Hash chain intact'
|
|
: 'Tampering detected',
|
|
style: theme.textTheme.titleMedium?.copyWith(
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
const SizedBox(height: 2),
|
|
Text(
|
|
healthy
|
|
? '${snapshot.eventChainTotal} events · prev_event_sha256 verified end-to-end'
|
|
: '${snapshot.eventChainVerified} of ${snapshot.eventChainTotal} verified before mismatch at ${snapshot.eventChainTamperedAt}',
|
|
style: theme.textTheme.bodySmall?.copyWith(
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
OutlinedButton.icon(
|
|
onPressed: onRefresh,
|
|
icon: const Icon(Icons.fact_check_outlined, size: 16),
|
|
label: const Text('Verify now'),
|
|
),
|
|
const SizedBox(width: FaiSpace.sm),
|
|
FaiPill(
|
|
label: healthy ? 'WORM-1' : 'TAMPER',
|
|
tone: healthy ? FaiPillTone.success : FaiPillTone.danger,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Lists the daemon's filesystem paths with one "Open" button
|
|
/// per row. Windows operators who never touch a shell still
|
|
/// need a way to inspect the audit DB or edit the operator
|
|
/// config; this panel is that escape hatch.
|
|
class _DaemonPathsPanel extends StatelessWidget {
|
|
final DaemonPathsSnapshot paths;
|
|
|
|
const _DaemonPathsPanel({required this.paths});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final entries = <(String, String, IconData)>[
|
|
('Log', paths.logPath, Icons.description_outlined),
|
|
('Config', paths.configPath, Icons.settings_outlined),
|
|
('Audit DB', paths.dbPath, Icons.storage_outlined),
|
|
('Modules dir', paths.modulesDir, Icons.extension_outlined),
|
|
('Flows dir', paths.flowsDir, Icons.account_tree_outlined),
|
|
('PID file', paths.pidPath, Icons.fingerprint),
|
|
].where((e) => e.$2.isNotEmpty).toList();
|
|
|
|
if (entries.isEmpty) {
|
|
return FaiCard(
|
|
child: Text(
|
|
'Daemon did not report file paths. '
|
|
'Update the running hub via `fai daemon restart`.',
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
),
|
|
);
|
|
}
|
|
|
|
return FaiCard(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
for (final e in entries) _PathRow(label: e.$1, path: e.$2, icon: e.$3),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _PathRow extends StatelessWidget {
|
|
final String label;
|
|
final String path;
|
|
final IconData icon;
|
|
|
|
const _PathRow({required this.label, required this.path, required this.icon});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 4),
|
|
child: Row(
|
|
children: [
|
|
Icon(icon, size: 16, color: theme.colorScheme.onSurfaceVariant),
|
|
const SizedBox(width: FaiSpace.sm),
|
|
SizedBox(
|
|
width: 90,
|
|
child: Text(
|
|
label,
|
|
style: theme.textTheme.labelSmall?.copyWith(
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
),
|
|
Expanded(
|
|
child: SelectableText(
|
|
path,
|
|
style: FaiTheme.mono(
|
|
size: 11,
|
|
color: theme.colorScheme.onSurface,
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: FaiSpace.sm),
|
|
OutlinedButton.icon(
|
|
onPressed: () async {
|
|
final r = await SystemActions.openInOs(path);
|
|
if (!context.mounted) return;
|
|
if (!r.ok) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(content: Text('Could not open: ${r.stderr}')),
|
|
);
|
|
}
|
|
},
|
|
icon: const Icon(Icons.open_in_new, size: 14),
|
|
label: const Text('Open'),
|
|
style: OutlinedButton.styleFrom(
|
|
visualDensity: VisualDensity.compact,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Daemon control affordances: Restart, Apply update, Stop.
|
|
/// Each shells out to the `fai` binary (resolved via PATH or
|
|
/// `~/.fai/bin/fai`). Studio is the GUI shell; the binary owns
|
|
/// the supervisor logic so the daemon and CLI stay in lockstep.
|
|
class _DaemonActionsCard extends StatefulWidget {
|
|
@override
|
|
State<_DaemonActionsCard> createState() => _DaemonActionsCardState();
|
|
}
|
|
|
|
class _DaemonActionsCardState extends State<_DaemonActionsCard> {
|
|
bool _busy = false;
|
|
String? _output;
|
|
ChannelStatusSnapshot? _channels;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_refreshStatus();
|
|
}
|
|
|
|
Future<void> _refreshStatus() async {
|
|
try {
|
|
final snap = await HubService.instance.channelStatus();
|
|
if (!mounted) return;
|
|
setState(() => _channels = snap);
|
|
} catch (_) {
|
|
// Best-effort; the status pill simply renders "unknown".
|
|
}
|
|
}
|
|
|
|
Future<void> _run(
|
|
String label,
|
|
Future<({bool ok, String stdout, String stderr})> Function() action,
|
|
) async {
|
|
setState(() {
|
|
_busy = true;
|
|
_output = null;
|
|
});
|
|
final r = await action();
|
|
if (!mounted) return;
|
|
setState(() {
|
|
_busy = false;
|
|
_output = (r.ok
|
|
? 'OK · $label\n${r.stdout}'
|
|
: 'Failed · $label\n${r.stderr.isEmpty ? r.stdout : r.stderr}')
|
|
.trim();
|
|
});
|
|
// Refresh the status pill — restart / stop / start all
|
|
// change the running flag.
|
|
await _refreshStatus();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
ChannelInfo? active;
|
|
if (_channels != null) {
|
|
for (final c in _channels!.channels) {
|
|
if (c.name == _channels!.active) {
|
|
active = c;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return FaiCard(
|
|
// Row + Expanded forces the card to take the full width
|
|
// its parent offers. Without this, the card hugs the
|
|
// intrinsic width of the longest button row and ends up
|
|
// visibly narrower than its siblings.
|
|
child: SizedBox(
|
|
width: double.infinity,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Icon(
|
|
active?.running == true
|
|
? Icons.check_circle_outline
|
|
: Icons.power_off_outlined,
|
|
size: 18,
|
|
color: active?.running == true
|
|
? FaiColors.success
|
|
: theme.colorScheme.onSurfaceVariant,
|
|
),
|
|
const SizedBox(width: FaiSpace.sm),
|
|
Expanded(
|
|
child: Text(
|
|
active == null
|
|
? 'Daemon status: …'
|
|
: active.running
|
|
? 'Running on ${active.name}: ${active.endpoint}'
|
|
: '${active.name} daemon stopped',
|
|
style: theme.textTheme.bodyMedium?.copyWith(
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
if (active != null) ...[
|
|
const SizedBox(width: FaiSpace.sm),
|
|
Tooltip(
|
|
message: 'PID file at the channel\'s run/<name>.pid',
|
|
child: FaiPill(
|
|
label: active.running ? 'running' : 'stopped',
|
|
tone: active.running
|
|
? FaiPillTone.success
|
|
: FaiPillTone.neutral,
|
|
),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
const SizedBox(height: FaiSpace.sm),
|
|
Text(
|
|
'Studio shells out to the platform binary — mirrors '
|
|
'`fai daemon …` exactly so the CLI and UI stay in lockstep.',
|
|
style: theme.textTheme.bodySmall?.copyWith(
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
const SizedBox(height: FaiSpace.md),
|
|
Wrap(
|
|
spacing: FaiSpace.sm,
|
|
runSpacing: FaiSpace.sm,
|
|
children: [
|
|
FilledButton.tonalIcon(
|
|
onPressed: _busy
|
|
? null
|
|
: () => _run(
|
|
'daemon restart',
|
|
() => SystemActions.faiDaemon(['restart']),
|
|
),
|
|
icon: const Icon(Icons.restart_alt, size: 16),
|
|
label: const Text('Restart'),
|
|
),
|
|
if (active?.running != true)
|
|
FilledButton.icon(
|
|
onPressed: _busy
|
|
? null
|
|
: () => _run(
|
|
'daemon start',
|
|
() => SystemActions.faiDaemon(['start']),
|
|
),
|
|
icon: const Icon(Icons.play_arrow, size: 16),
|
|
label: const Text('Start'),
|
|
),
|
|
OutlinedButton.icon(
|
|
onPressed: _busy
|
|
? null
|
|
: () => _run(
|
|
'daemon stop',
|
|
() => SystemActions.faiDaemon(['stop']),
|
|
),
|
|
icon: const Icon(Icons.stop_circle_outlined, size: 16),
|
|
label: const Text('Stop'),
|
|
),
|
|
OutlinedButton.icon(
|
|
onPressed: _busy
|
|
? null
|
|
: () => _run(
|
|
'daemon status',
|
|
() => SystemActions.faiDaemon(['status']),
|
|
),
|
|
icon: const Icon(Icons.health_and_safety_outlined, size: 16),
|
|
label: const Text('Status'),
|
|
),
|
|
],
|
|
),
|
|
if (_busy) ...[
|
|
const SizedBox(height: FaiSpace.md),
|
|
Row(
|
|
children: [
|
|
const SizedBox(
|
|
width: 14,
|
|
height: 14,
|
|
child: CircularProgressIndicator(strokeWidth: 2),
|
|
),
|
|
const SizedBox(width: FaiSpace.sm),
|
|
Text(
|
|
'Working…',
|
|
style: theme.textTheme.bodySmall?.copyWith(
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
if (_output != null) ...[
|
|
const SizedBox(height: FaiSpace.md),
|
|
Container(
|
|
width: double.infinity,
|
|
padding: const EdgeInsets.all(FaiSpace.sm),
|
|
decoration: BoxDecoration(
|
|
color: theme.colorScheme.surfaceContainerHigh,
|
|
borderRadius: BorderRadius.circular(FaiRadius.sm),
|
|
border: Border.all(color: theme.colorScheme.outlineVariant),
|
|
),
|
|
child: SelectableText(
|
|
_output!,
|
|
style: FaiTheme.mono(
|
|
size: 11,
|
|
color: theme.colorScheme.onSurface,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _ModulesPanel extends StatelessWidget {
|
|
final DoctorSnapshot snapshot;
|
|
|
|
const _ModulesPanel({required this.snapshot});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
return FaiCard(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Icon(
|
|
Icons.extension_outlined,
|
|
size: 18,
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
),
|
|
const SizedBox(width: FaiSpace.sm),
|
|
Text(
|
|
'${snapshot.moduleCount} modules · ${snapshot.capabilityCount} capabilities',
|
|
style: theme.textTheme.bodyMedium,
|
|
),
|
|
const Spacer(),
|
|
FaiPill(
|
|
label: snapshot.moduleCount > 0 ? 'loaded' : 'empty',
|
|
tone: snapshot.moduleCount > 0
|
|
? FaiPillTone.success
|
|
: FaiPillTone.neutral,
|
|
),
|
|
],
|
|
),
|
|
const Divider(height: FaiSpace.xl),
|
|
Row(
|
|
children: [
|
|
Icon(
|
|
Icons.inbox_outlined,
|
|
size: 18,
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
),
|
|
const SizedBox(width: FaiSpace.sm),
|
|
Text(
|
|
snapshot.pendingApprovals == 0
|
|
? 'No pending approvals'
|
|
: '${snapshot.pendingApprovals} approval${snapshot.pendingApprovals == 1 ? '' : 's'} awaiting review',
|
|
style: theme.textTheme.bodyMedium,
|
|
),
|
|
const Spacer(),
|
|
if (snapshot.pendingApprovals > 0)
|
|
FaiPill(
|
|
label: 'attention',
|
|
tone: FaiPillTone.warning,
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _ServicesPanel extends StatelessWidget {
|
|
final DoctorSnapshot snapshot;
|
|
|
|
const _ServicesPanel({required this.snapshot});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
if (snapshot.services.isEmpty) {
|
|
return FaiCard(
|
|
child: Row(
|
|
children: [
|
|
Icon(
|
|
Icons.dns_outlined,
|
|
size: 18,
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
),
|
|
const SizedBox(width: FaiSpace.sm),
|
|
Text(
|
|
'No host services declared',
|
|
style: theme.textTheme.bodyMedium?.copyWith(
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
const Spacer(),
|
|
Text(
|
|
'add to ~/.fai/config.yaml under services:',
|
|
style: FaiTheme.mono(
|
|
size: 11,
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
return FaiCard(
|
|
padding: EdgeInsets.zero,
|
|
child: Column(
|
|
children: [
|
|
for (var i = 0; i < snapshot.services.length; i++) ...[
|
|
if (i > 0)
|
|
Divider(
|
|
height: 1,
|
|
color: theme.colorScheme.outlineVariant,
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.all(FaiSpace.lg),
|
|
child: Row(
|
|
children: [
|
|
Icon(
|
|
Icons.dns_outlined,
|
|
size: 16,
|
|
color: theme.colorScheme.primary,
|
|
),
|
|
const SizedBox(width: FaiSpace.sm),
|
|
Text(
|
|
snapshot.services[i].name,
|
|
style: theme.textTheme.titleSmall?.copyWith(
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
const SizedBox(width: FaiSpace.md),
|
|
Text(
|
|
snapshot.services[i].endpoint,
|
|
style: FaiTheme.mono(
|
|
size: 11,
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
const Spacer(),
|
|
for (final tag in snapshot.services[i].tags) ...[
|
|
FaiPill(label: tag, tone: FaiPillTone.neutral),
|
|
const SizedBox(width: FaiSpace.xs),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _UpdateBanner extends StatefulWidget {
|
|
final UpdateStatus status;
|
|
|
|
const _UpdateBanner({required this.status});
|
|
|
|
@override
|
|
State<_UpdateBanner> createState() => _UpdateBannerState();
|
|
}
|
|
|
|
class _UpdateBannerState extends State<_UpdateBanner> {
|
|
bool _applying = false;
|
|
String? _applyOutput;
|
|
|
|
Future<void> _applyUpdate() async {
|
|
setState(() {
|
|
_applying = true;
|
|
_applyOutput = null;
|
|
});
|
|
final r = await SystemActions.faiUpdateApply(widget.status.channel);
|
|
if (!mounted) return;
|
|
setState(() {
|
|
_applying = false;
|
|
_applyOutput = r.ok
|
|
? 'Update applied. Restart Studio to see the new daemon version.'
|
|
: (r.stderr.isEmpty ? r.stdout : r.stderr).trim();
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
final status = widget.status;
|
|
final available = status.updateAvailable;
|
|
final iconData = available
|
|
? Icons.system_update_alt_outlined
|
|
: Icons.cloud_off_outlined;
|
|
final iconColor = available
|
|
? theme.colorScheme.primary
|
|
: theme.colorScheme.onSurfaceVariant;
|
|
final title = available
|
|
? 'Update available — ${status.latestVersion}'
|
|
: 'Release host unreachable';
|
|
final body = available
|
|
? 'Channel ${status.channel} now offers ${status.latestVersion}. '
|
|
'Apply via the button — Studio shells out to '
|
|
'`fai update apply --channel ${status.channel}`.'
|
|
: (status.reason ?? 'Could not contact the release feed for ${status.channel}.');
|
|
return FaiCard(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Icon(iconData, size: 20, color: iconColor),
|
|
const SizedBox(width: FaiSpace.md),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
title,
|
|
style: theme.textTheme.titleSmall?.copyWith(
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
const SizedBox(height: 2),
|
|
Text(
|
|
body,
|
|
style: FaiTheme.mono(
|
|
size: 11,
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
if (available && status.releaseNotesUrl != null) ...[
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
'notes: ${status.releaseNotesUrl}',
|
|
style: FaiTheme.mono(
|
|
size: 11,
|
|
color: theme.colorScheme.primary,
|
|
),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
if (available)
|
|
FilledButton.icon(
|
|
onPressed: _applying ? null : _applyUpdate,
|
|
icon: _applying
|
|
? const SizedBox(
|
|
width: 14,
|
|
height: 14,
|
|
child: CircularProgressIndicator(strokeWidth: 2),
|
|
)
|
|
: const Icon(Icons.system_update_alt, size: 16),
|
|
label: Text(_applying ? 'Applying…' : 'Apply update'),
|
|
),
|
|
const SizedBox(width: FaiSpace.sm),
|
|
FaiPill(
|
|
label: available ? 'new' : 'offline',
|
|
tone: available ? FaiPillTone.success : FaiPillTone.neutral,
|
|
),
|
|
],
|
|
),
|
|
if (_applyOutput != null) ...[
|
|
const SizedBox(height: FaiSpace.md),
|
|
Container(
|
|
width: double.infinity,
|
|
padding: const EdgeInsets.all(FaiSpace.sm),
|
|
decoration: BoxDecoration(
|
|
color: theme.colorScheme.surfaceContainerHigh,
|
|
borderRadius: BorderRadius.circular(FaiRadius.sm),
|
|
border: Border.all(color: theme.colorScheme.outlineVariant),
|
|
),
|
|
child: SelectableText(
|
|
_applyOutput!,
|
|
style: FaiTheme.mono(
|
|
size: 11,
|
|
color: theme.colorScheme.onSurface,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|