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
|
|
@ -303,6 +303,29 @@ class HubService {
|
||||||
return (purged: r.purged.toInt(), channel: r.channel);
|
return (purged: r.purged.toInt(), channel: r.channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Filesystem paths the daemon owns. Used by Doctor to wire
|
||||||
|
/// "Open log file" / "Open config file" buttons.
|
||||||
|
Future<DaemonPathsSnapshot> daemonPaths() async {
|
||||||
|
final r = await _client.daemonPaths();
|
||||||
|
return DaemonPathsSnapshot(
|
||||||
|
logPath: r.logPath,
|
||||||
|
dbPath: r.dbPath,
|
||||||
|
modulesDir: r.modulesDir,
|
||||||
|
flowsDir: r.flowsDir,
|
||||||
|
configPath: r.configPath,
|
||||||
|
pidPath: r.pidPath,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Remove an installed module by name. Returns the version
|
||||||
|
/// that was removed so the caller can confirm.
|
||||||
|
Future<({String name, String version})> uninstallModule(
|
||||||
|
String name,
|
||||||
|
) async {
|
||||||
|
final r = await _client.uninstallModule(name);
|
||||||
|
return (name: r.name, version: r.version);
|
||||||
|
}
|
||||||
|
|
||||||
/// Active channel + per-channel daemon status snapshot.
|
/// Active channel + per-channel daemon status snapshot.
|
||||||
Future<ChannelStatusSnapshot> channelStatus() async {
|
Future<ChannelStatusSnapshot> channelStatus() async {
|
||||||
final r = await _client.channelStatus();
|
final r = await _client.channelStatus();
|
||||||
|
|
@ -521,6 +544,7 @@ class HubService {
|
||||||
_client.checkUpdate().catchError(
|
_client.checkUpdate().catchError(
|
||||||
(_) => CheckUpdateResponse(),
|
(_) => CheckUpdateResponse(),
|
||||||
),
|
),
|
||||||
|
_client.daemonPaths().catchError((_) => DaemonPathsResponse()),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
final caps = results[0] as List<CapabilityEntry>;
|
final caps = results[0] as List<CapabilityEntry>;
|
||||||
|
|
@ -528,6 +552,7 @@ class HubService {
|
||||||
final chain = results[2] as VerifyEventChainResponse;
|
final chain = results[2] as VerifyEventChainResponse;
|
||||||
final services = results[3] as List<DeclaredService>;
|
final services = results[3] as List<DeclaredService>;
|
||||||
final update = results[4] as CheckUpdateResponse;
|
final update = results[4] as CheckUpdateResponse;
|
||||||
|
final paths = results[5] as DaemonPathsResponse;
|
||||||
|
|
||||||
// Module count = distinct module_name across capabilities.
|
// Module count = distinct module_name across capabilities.
|
||||||
final moduleNames = <String>{for (final c in caps) c.moduleName};
|
final moduleNames = <String>{for (final c in caps) c.moduleName};
|
||||||
|
|
@ -559,6 +584,14 @@ class HubService {
|
||||||
update.releaseNotesUrl.isEmpty ? null : update.releaseNotesUrl,
|
update.releaseNotesUrl.isEmpty ? null : update.releaseNotesUrl,
|
||||||
reason: update.reason.isEmpty ? null : update.reason,
|
reason: update.reason.isEmpty ? null : update.reason,
|
||||||
),
|
),
|
||||||
|
paths: DaemonPathsSnapshot(
|
||||||
|
logPath: paths.logPath,
|
||||||
|
dbPath: paths.dbPath,
|
||||||
|
modulesDir: paths.modulesDir,
|
||||||
|
flowsDir: paths.flowsDir,
|
||||||
|
configPath: paths.configPath,
|
||||||
|
pidPath: paths.pidPath,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -592,6 +625,9 @@ class DoctorSnapshot {
|
||||||
final String? eventChainTamperedAt;
|
final String? eventChainTamperedAt;
|
||||||
final List<ServiceEntry> services;
|
final List<ServiceEntry> services;
|
||||||
final UpdateStatus update;
|
final UpdateStatus update;
|
||||||
|
/// Filesystem paths the daemon owns. Empty fields when the
|
||||||
|
/// hub couldn't resolve them (older daemon, no $HOME).
|
||||||
|
final DaemonPathsSnapshot paths;
|
||||||
|
|
||||||
const DoctorSnapshot({
|
const DoctorSnapshot({
|
||||||
required this.moduleCount,
|
required this.moduleCount,
|
||||||
|
|
@ -602,6 +638,7 @@ class DoctorSnapshot {
|
||||||
required this.eventChainTamperedAt,
|
required this.eventChainTamperedAt,
|
||||||
required this.services,
|
required this.services,
|
||||||
required this.update,
|
required this.update,
|
||||||
|
required this.paths,
|
||||||
});
|
});
|
||||||
|
|
||||||
bool get chainHealthy => eventChainTamperedAt == null;
|
bool get chainHealthy => eventChainTamperedAt == null;
|
||||||
|
|
@ -868,6 +905,28 @@ class ChannelStatusSnapshot {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Filesystem paths the daemon owns. Studio's Doctor page
|
||||||
|
/// surfaces these as "Open" buttons so Windows operators who
|
||||||
|
/// never touch a shell can still inspect everything via the OS
|
||||||
|
/// file manager / default editor.
|
||||||
|
class DaemonPathsSnapshot {
|
||||||
|
final String logPath;
|
||||||
|
final String dbPath;
|
||||||
|
final String modulesDir;
|
||||||
|
final String flowsDir;
|
||||||
|
final String configPath;
|
||||||
|
final String pidPath;
|
||||||
|
|
||||||
|
const DaemonPathsSnapshot({
|
||||||
|
required this.logPath,
|
||||||
|
required this.dbPath,
|
||||||
|
required this.modulesDir,
|
||||||
|
required this.flowsDir,
|
||||||
|
required this.configPath,
|
||||||
|
required this.pidPath,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/// Detected host hardware — see
|
/// Detected host hardware — see
|
||||||
/// docs/architecture/system-ai.md → "Hardware tiers".
|
/// docs/architecture/system-ai.md → "Hardware tiers".
|
||||||
class HardwareSnapshot {
|
class HardwareSnapshot {
|
||||||
|
|
|
||||||
122
lib/data/system_actions.dart
Normal file
122
lib/data/system_actions.dart
Normal file
|
|
@ -0,0 +1,122 @@
|
||||||
|
// System-level actions Studio invokes by spawning the `fai`
|
||||||
|
// binary or asking the OS to open a file. Used by Doctor's
|
||||||
|
// daemon-control + open-paths affordances so Windows operators
|
||||||
|
// who never touch a shell can restart the daemon, apply an
|
||||||
|
// update, or open a log file from inside the GUI.
|
||||||
|
//
|
||||||
|
// Cross-platform notes:
|
||||||
|
// - macOS uses `open` for files + URLs.
|
||||||
|
// - Linux uses `xdg-open`.
|
||||||
|
// - Windows uses `explorer` (file manager) and a quoted CLI
|
||||||
|
// call for processes.
|
||||||
|
//
|
||||||
|
// The `fai` binary is resolved from PATH first; falls back to
|
||||||
|
// `~/.fai/bin/fai` (Unix) or `%USERPROFILE%\.fai\bin\fai.exe`
|
||||||
|
// (Windows). The PowerShell installer puts both in PATH but
|
||||||
|
// some operators don't restart their shell after install — the
|
||||||
|
// fallback covers that case.
|
||||||
|
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
class SystemActions {
|
||||||
|
SystemActions._();
|
||||||
|
|
||||||
|
/// Ask the OS to open [path] in the default handler. On macOS
|
||||||
|
/// this opens text files in TextEdit, configs in the registered
|
||||||
|
/// editor, etc. Returns true on a clean spawn (process exited
|
||||||
|
/// non-zero is still surfaced as false).
|
||||||
|
static Future<({bool ok, String stderr})> openInOs(String path) async {
|
||||||
|
if (path.isEmpty) {
|
||||||
|
return (ok: false, stderr: 'empty path');
|
||||||
|
}
|
||||||
|
final cmd = _openCommand();
|
||||||
|
try {
|
||||||
|
final r = await Process.run(cmd.executable, [...cmd.args, path]);
|
||||||
|
if (r.exitCode == 0) return (ok: true, stderr: '');
|
||||||
|
return (ok: false, stderr: r.stderr.toString().trim());
|
||||||
|
} catch (e) {
|
||||||
|
return (ok: false, stderr: e.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Run a `fai daemon ...` subcommand and surface the captured
|
||||||
|
/// output. Used by Doctor's "Restart daemon" button.
|
||||||
|
static Future<({bool ok, String stdout, String stderr})> faiDaemon(
|
||||||
|
List<String> args,
|
||||||
|
) async {
|
||||||
|
return _runFai(['daemon', ...args]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Run `fai update apply --channel <c>`. Long-running on a slow
|
||||||
|
/// network — caller should show a spinner.
|
||||||
|
static Future<({bool ok, String stdout, String stderr})> faiUpdateApply(
|
||||||
|
String channel,
|
||||||
|
) async {
|
||||||
|
return _runFai(['update', 'apply', '--channel', channel]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<({bool ok, String stdout, String stderr})> _runFai(
|
||||||
|
List<String> args,
|
||||||
|
) async {
|
||||||
|
final exe = _faiExecutable();
|
||||||
|
if (exe == null) {
|
||||||
|
return (
|
||||||
|
ok: false,
|
||||||
|
stdout: '',
|
||||||
|
stderr: 'Could not locate the `fai` binary. Install via the '
|
||||||
|
'platform installer or set FAI_BIN to its full path.',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
final r = await Process.run(exe, args);
|
||||||
|
return (
|
||||||
|
ok: r.exitCode == 0,
|
||||||
|
stdout: r.stdout.toString(),
|
||||||
|
stderr: r.stderr.toString(),
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
return (ok: false, stdout: '', stderr: e.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static ({String executable, List<String> args}) _openCommand() {
|
||||||
|
if (Platform.isMacOS) return (executable: 'open', args: const []);
|
||||||
|
if (Platform.isWindows) return (executable: 'explorer', args: const []);
|
||||||
|
return (executable: 'xdg-open', args: const []);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Locate the `fai` binary. Order: $FAI_BIN, PATH, fallback to
|
||||||
|
/// the canonical install location under the user's home dir.
|
||||||
|
static String? _faiExecutable() {
|
||||||
|
final fromEnv = Platform.environment['FAI_BIN'];
|
||||||
|
if (fromEnv != null && fromEnv.isNotEmpty && File(fromEnv).existsSync()) {
|
||||||
|
return fromEnv;
|
||||||
|
}
|
||||||
|
|
||||||
|
final isWindows = Platform.isWindows;
|
||||||
|
final fromPath = _whichFai(isWindows ? 'fai.exe' : 'fai');
|
||||||
|
if (fromPath != null) return fromPath;
|
||||||
|
|
||||||
|
final home = Platform.environment[isWindows ? 'USERPROFILE' : 'HOME'];
|
||||||
|
if (home == null || home.isEmpty) return null;
|
||||||
|
final fallback = isWindows
|
||||||
|
? '$home\\.fai\\bin\\fai.exe'
|
||||||
|
: '$home/.fai/bin/fai';
|
||||||
|
return File(fallback).existsSync() ? fallback : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Tiny PATH walker — we cannot rely on `which`/`where` being
|
||||||
|
/// reachable via Process.run on every platform.
|
||||||
|
static String? _whichFai(String name) {
|
||||||
|
final pathEnv = Platform.environment['PATH'];
|
||||||
|
if (pathEnv == null || pathEnv.isEmpty) return null;
|
||||||
|
final sep = Platform.isWindows ? ';' : ':';
|
||||||
|
final slash = Platform.isWindows ? '\\' : '/';
|
||||||
|
for (final dir in pathEnv.split(sep)) {
|
||||||
|
if (dir.isEmpty) continue;
|
||||||
|
final candidate = '$dir$slash$name';
|
||||||
|
if (File(candidate).existsSync()) return candidate;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -23,7 +23,7 @@ import 'widgets/widgets.dart';
|
||||||
/// Studio's own build version. Bump on every UI commit so the
|
/// Studio's own build version. Bump on every UI commit so the
|
||||||
/// running app self-identifies — visible in the sidebar header
|
/// running app self-identifies — visible in the sidebar header
|
||||||
/// and quick-glance proof that you're seeing the current build.
|
/// and quick-glance proof that you're seeing the current build.
|
||||||
const String kStudioVersion = '0.16.0';
|
const String kStudioVersion = '0.17.0';
|
||||||
|
|
||||||
Future<void> main() async {
|
Future<void> main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../data/hub.dart';
|
import '../data/hub.dart';
|
||||||
|
import '../data/system_actions.dart';
|
||||||
import '../theme/theme.dart';
|
import '../theme/theme.dart';
|
||||||
import '../theme/tokens.dart';
|
import '../theme/tokens.dart';
|
||||||
import '../widgets/widgets.dart';
|
import '../widgets/widgets.dart';
|
||||||
|
|
@ -71,7 +72,10 @@ class _DoctorPageState extends State<DoctorPage> {
|
||||||
const SizedBox(height: FaiSpace.xl),
|
const SizedBox(height: FaiSpace.xl),
|
||||||
_Section(
|
_Section(
|
||||||
title: 'Event log',
|
title: 'Event log',
|
||||||
child: _EventLogPanel(snapshot: s),
|
child: _EventLogPanel(
|
||||||
|
snapshot: s,
|
||||||
|
onRefresh: _refresh,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: FaiSpace.lg),
|
const SizedBox(height: FaiSpace.lg),
|
||||||
_Section(
|
_Section(
|
||||||
|
|
@ -83,6 +87,16 @@ class _DoctorPageState extends State<DoctorPage> {
|
||||||
title: 'Host services',
|
title: 'Host services',
|
||||||
child: _ServicesPanel(snapshot: s),
|
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 {
|
class _EventLogPanel extends StatelessWidget {
|
||||||
final DoctorSnapshot snapshot;
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
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(
|
FaiPill(
|
||||||
label: healthy ? 'WORM-1' : 'TAMPER',
|
label: healthy ? 'WORM-1' : 'TAMPER',
|
||||||
tone: healthy ? FaiPillTone.success : FaiPillTone.danger,
|
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 {
|
class _ModulesPanel extends StatelessWidget {
|
||||||
final DoctorSnapshot snapshot;
|
final DoctorSnapshot snapshot;
|
||||||
|
|
||||||
|
|
@ -437,14 +682,38 @@ class _ServicesPanel extends StatelessWidget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _UpdateBanner extends StatelessWidget {
|
class _UpdateBanner extends StatefulWidget {
|
||||||
final UpdateStatus status;
|
final UpdateStatus status;
|
||||||
|
|
||||||
const _UpdateBanner({required this.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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
|
final status = widget.status;
|
||||||
final available = status.updateAvailable;
|
final available = status.updateAvailable;
|
||||||
final iconData = available
|
final iconData = available
|
||||||
? Icons.system_update_alt_outlined
|
? Icons.system_update_alt_outlined
|
||||||
|
|
@ -457,10 +726,14 @@ class _UpdateBanner extends StatelessWidget {
|
||||||
: 'Release host unreachable';
|
: 'Release host unreachable';
|
||||||
final body = available
|
final body = available
|
||||||
? 'Channel ${status.channel} now offers ${status.latestVersion}. '
|
? '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}.');
|
: (status.reason ?? 'Could not contact the release feed for ${status.channel}.');
|
||||||
return FaiCard(
|
return FaiCard(
|
||||||
child: Row(
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Icon(iconData, size: 20, color: iconColor),
|
Icon(iconData, size: 20, color: iconColor),
|
||||||
|
|
@ -496,12 +769,46 @@ class _UpdateBanner extends StatelessWidget {
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
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(
|
FaiPill(
|
||||||
label: available ? 'new' : 'offline',
|
label: available ? 'new' : 'offline',
|
||||||
tone: available ? FaiPillTone.success : FaiPillTone.neutral,
|
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,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,11 @@ class _ModulesPageState extends State<ModulesPage> {
|
||||||
itemBuilder: (context, i) {
|
itemBuilder: (context, i) {
|
||||||
final m = modules[i];
|
final m = modules[i];
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: () => FaiModuleSheet.show(context, m.name),
|
onTap: () async {
|
||||||
|
final uninstalled =
|
||||||
|
await FaiModuleSheet.show(context, m.name);
|
||||||
|
if (uninstalled) _refresh();
|
||||||
|
},
|
||||||
behavior: HitTestBehavior.opaque,
|
behavior: HitTestBehavior.opaque,
|
||||||
child: MouseRegion(
|
child: MouseRegion(
|
||||||
cursor: SystemMouseCursors.click,
|
cursor: SystemMouseCursors.click,
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,11 @@ class FaiModuleSheet extends StatefulWidget {
|
||||||
|
|
||||||
const FaiModuleSheet({super.key, required this.moduleName});
|
const FaiModuleSheet({super.key, required this.moduleName});
|
||||||
|
|
||||||
/// Convenience launcher used from the Modules list.
|
/// Convenience launcher used from the Modules list. Resolves
|
||||||
static Future<void> show(BuildContext context, String name) {
|
/// to `true` when the operator uninstalled the module — the
|
||||||
return showModalBottomSheet<void>(
|
/// caller (Modules page) refreshes its list on that signal.
|
||||||
|
static Future<bool> show(BuildContext context, String name) async {
|
||||||
|
final r = await showModalBottomSheet<bool>(
|
||||||
context: context,
|
context: context,
|
||||||
backgroundColor: Theme.of(context).colorScheme.surfaceContainer,
|
backgroundColor: Theme.of(context).colorScheme.surfaceContainer,
|
||||||
isScrollControlled: true,
|
isScrollControlled: true,
|
||||||
|
|
@ -28,6 +30,7 @@ class FaiModuleSheet extends StatefulWidget {
|
||||||
),
|
),
|
||||||
builder: (_) => FaiModuleSheet(moduleName: name),
|
builder: (_) => FaiModuleSheet(moduleName: name),
|
||||||
);
|
);
|
||||||
|
return r ?? false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -36,6 +39,7 @@ class FaiModuleSheet extends StatefulWidget {
|
||||||
|
|
||||||
class _FaiModuleSheetState extends State<FaiModuleSheet> {
|
class _FaiModuleSheetState extends State<FaiModuleSheet> {
|
||||||
late final Future<ModuleDetail> _future;
|
late final Future<ModuleDetail> _future;
|
||||||
|
bool _uninstalling = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
|
@ -43,6 +47,50 @@ class _FaiModuleSheetState extends State<FaiModuleSheet> {
|
||||||
_future = HubService.instance.moduleInfo(widget.moduleName);
|
_future = HubService.instance.moduleInfo(widget.moduleName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _confirmAndUninstall(ModuleDetail detail) async {
|
||||||
|
final ok = await showDialog<bool>(
|
||||||
|
context: context,
|
||||||
|
builder: (ctx) => AlertDialog(
|
||||||
|
title: const Text('Uninstall module?'),
|
||||||
|
content: Text(
|
||||||
|
'Removes ${detail.name} v${detail.version} from this hub. '
|
||||||
|
'Flows that reference it will fail at the next run. '
|
||||||
|
'A `module.uninstalled` audit event is recorded.',
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.pop(ctx, false),
|
||||||
|
child: const Text('Cancel'),
|
||||||
|
),
|
||||||
|
FilledButton(
|
||||||
|
onPressed: () => Navigator.pop(ctx, true),
|
||||||
|
style: FilledButton.styleFrom(
|
||||||
|
backgroundColor: Theme.of(ctx).colorScheme.error,
|
||||||
|
foregroundColor: Theme.of(ctx).colorScheme.onError,
|
||||||
|
),
|
||||||
|
child: const Text('Uninstall'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
if (ok != true || !mounted) return;
|
||||||
|
setState(() => _uninstalling = true);
|
||||||
|
try {
|
||||||
|
final r = await HubService.instance.uninstallModule(detail.name);
|
||||||
|
if (!mounted) return;
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text('Uninstalled ${r.name} v${r.version}.')),
|
||||||
|
);
|
||||||
|
Navigator.pop(context, true);
|
||||||
|
} catch (e) {
|
||||||
|
if (!mounted) return;
|
||||||
|
setState(() => _uninstalling = false);
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text('Uninstall failed: $e')),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
|
|
@ -73,7 +121,13 @@ class _FaiModuleSheetState extends State<FaiModuleSheet> {
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
Flexible(child: _Body(detail: snapshot.data!)),
|
Flexible(
|
||||||
|
child: _Body(
|
||||||
|
detail: snapshot.data!,
|
||||||
|
uninstalling: _uninstalling,
|
||||||
|
onUninstall: () => _confirmAndUninstall(snapshot.data!),
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
@ -102,8 +156,14 @@ class _Handle extends StatelessWidget {
|
||||||
|
|
||||||
class _Body extends StatelessWidget {
|
class _Body extends StatelessWidget {
|
||||||
final ModuleDetail detail;
|
final ModuleDetail detail;
|
||||||
|
final bool uninstalling;
|
||||||
|
final VoidCallback onUninstall;
|
||||||
|
|
||||||
const _Body({required this.detail});
|
const _Body({
|
||||||
|
required this.detail,
|
||||||
|
required this.uninstalling,
|
||||||
|
required this.onUninstall,
|
||||||
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
@ -196,6 +256,29 @@ class _Body extends StatelessWidget {
|
||||||
)
|
)
|
||||||
.toList(),
|
.toList(),
|
||||||
),
|
),
|
||||||
|
const SizedBox(height: FaiSpace.xxl),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
const Spacer(),
|
||||||
|
OutlinedButton.icon(
|
||||||
|
onPressed: uninstalling ? null : onUninstall,
|
||||||
|
icon: uninstalling
|
||||||
|
? const SizedBox(
|
||||||
|
width: 14,
|
||||||
|
height: 14,
|
||||||
|
child: CircularProgressIndicator(strokeWidth: 2),
|
||||||
|
)
|
||||||
|
: const Icon(Icons.delete_outline, size: 16),
|
||||||
|
label: Text(uninstalling ? 'Uninstalling…' : 'Uninstall'),
|
||||||
|
style: OutlinedButton.styleFrom(
|
||||||
|
foregroundColor: theme.colorScheme.error,
|
||||||
|
side: BorderSide(
|
||||||
|
color: theme.colorScheme.error.withValues(alpha: 0.5),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ packages:
|
||||||
path: "../fai_dart_sdk"
|
path: "../fai_dart_sdk"
|
||||||
relative: true
|
relative: true
|
||||||
source: path
|
source: path
|
||||||
version: "0.8.0"
|
version: "0.9.0"
|
||||||
fake_async:
|
fake_async:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
name: fai_studio
|
name: fai_studio
|
||||||
description: "F∆I Studio — desktop GUI for the F∆I hub"
|
description: "F∆I Studio — desktop GUI for the F∆I hub"
|
||||||
publish_to: 'none'
|
publish_to: 'none'
|
||||||
version: 0.16.0
|
version: 0.17.0
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.11.0-200.1.beta
|
sdk: ^3.11.0-200.1.beta
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue