feat(studio): module uninstall + Doctor daemon control (v0.17.0)
UI parity for Windows operators who never touch a shell:
- Module sheet gains an Uninstall button at the bottom.
Two-step confirmation, then calls UninstallModule + closes
the sheet + refreshes the Modules page.
- Doctor page picks up two new sections:
* Daemon files — log / config / audit DB / modules /
flows / pid, each with a one-click "Open" button that
shells out to the OS handler (open / xdg-open /
explorer).
* Daemon control — Restart / Stop / Status buttons that
spawn `fai daemon …`. Captured stdout/stderr renders
inline so the operator sees what happened.
- Update banner gains an "Apply update" button that spawns
`fai update apply --channel <c>`. The previous version
showed the command as text — Windows users had no way to
execute it.
- Event log panel gains a "Verify now" button that re-runs
the chain check (via the existing doctor refresh).
New SystemActions helper resolves the `fai` binary via
$FAI_BIN → PATH → `~/.fai/bin/fai` (or the Windows
equivalent), so the buttons work whether the operator
restarted their shell after installing or not.
Signed-off-by: flemming-it <stefan.a.flemming@googlemail.com>
This commit is contained in:
parent
d9aabfd00a
commit
73e394b39f
8 changed files with 624 additions and 49 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../data/hub.dart';
|
||||
import '../data/system_actions.dart';
|
||||
import '../theme/theme.dart';
|
||||
import '../theme/tokens.dart';
|
||||
import '../widgets/widgets.dart';
|
||||
|
|
@ -71,7 +72,10 @@ class _DoctorPageState extends State<DoctorPage> {
|
|||
const SizedBox(height: FaiSpace.xl),
|
||||
_Section(
|
||||
title: 'Event log',
|
||||
child: _EventLogPanel(snapshot: s),
|
||||
child: _EventLogPanel(
|
||||
snapshot: s,
|
||||
onRefresh: _refresh,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: FaiSpace.lg),
|
||||
_Section(
|
||||
|
|
@ -83,6 +87,16 @@ class _DoctorPageState extends State<DoctorPage> {
|
|||
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(),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
|
|
@ -240,8 +254,12 @@ class _StatTile extends StatelessWidget {
|
|||
|
||||
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});
|
||||
const _EventLogPanel({required this.snapshot, required this.onRefresh});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
|
@ -280,6 +298,12 @@ class _EventLogPanel extends StatelessWidget {
|
|||
],
|
||||
),
|
||||
),
|
||||
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,
|
||||
|
|
@ -290,6 +314,227 @@ class _EventLogPanel extends StatelessWidget {
|
|||
}
|
||||
}
|
||||
|
||||
/// 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;
|
||||
|
||||
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();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
return FaiCard(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Spawn the platform binary to manage the running daemon. '
|
||||
'Mirrors the CLI: `fai daemon …`.',
|
||||
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 daemon'),
|
||||
),
|
||||
OutlinedButton.icon(
|
||||
onPressed: _busy
|
||||
? null
|
||||
: () =>
|
||||
_run('daemon stop', () => SystemActions.faiDaemon(['stop'])),
|
||||
icon: const Icon(Icons.stop_circle_outlined, size: 16),
|
||||
label: const Text('Stop daemon'),
|
||||
),
|
||||
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;
|
||||
|
||||
|
|
@ -437,14 +682,38 @@ class _ServicesPanel extends StatelessWidget {
|
|||
}
|
||||
}
|
||||
|
||||
class _UpdateBanner extends StatelessWidget {
|
||||
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
|
||||
|
|
@ -457,49 +726,87 @@ class _UpdateBanner extends StatelessWidget {
|
|||
: 'Release host unreachable';
|
||||
final body = available
|
||||
? 'Channel ${status.channel} now offers ${status.latestVersion}. '
|
||||
'Apply with: fai update apply --channel ${status.channel}'
|
||||
'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: Row(
|
||||
child: Column(
|
||||
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,
|
||||
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,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
FaiPill(
|
||||
label: available ? 'new' : 'offline',
|
||||
tone: available ? FaiPillTone.success : FaiPillTone.neutral,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue