- Flutter app with chat and terminal screens - WebSocket integration for real-time chat - xterm integration for screen sessions - Markdown rendering with code blocks - JWT authentication Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
148 lines
3.9 KiB
Dart
148 lines
3.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import '../providers/auth_provider.dart';
|
|
import '../models/session.dart';
|
|
import 'terminal_screen.dart';
|
|
|
|
class SessionsScreen extends StatefulWidget {
|
|
const SessionsScreen({super.key});
|
|
|
|
@override
|
|
State<SessionsScreen> createState() => _SessionsScreenState();
|
|
}
|
|
|
|
class _SessionsScreenState extends State<SessionsScreen> {
|
|
List<ScreenSession>? _sessions;
|
|
bool _isLoading = true;
|
|
String? _error;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_loadSessions();
|
|
}
|
|
|
|
Future<void> _loadSessions() async {
|
|
setState(() {
|
|
_isLoading = true;
|
|
_error = null;
|
|
});
|
|
|
|
try {
|
|
final auth = context.read<AuthProvider>();
|
|
final sessions = await auth.apiService.getSessions();
|
|
setState(() {
|
|
_sessions = sessions;
|
|
_isLoading = false;
|
|
});
|
|
} catch (e) {
|
|
setState(() {
|
|
_error = e.toString();
|
|
_isLoading = false;
|
|
});
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('Screen Sessions'),
|
|
actions: [
|
|
IconButton(
|
|
icon: const Icon(Icons.refresh),
|
|
onPressed: _loadSessions,
|
|
),
|
|
],
|
|
),
|
|
body: _buildBody(),
|
|
);
|
|
}
|
|
|
|
Widget _buildBody() {
|
|
if (_isLoading) {
|
|
return const Center(child: CircularProgressIndicator());
|
|
}
|
|
|
|
if (_error != null) {
|
|
return Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(Icons.error_outline, size: 48, color: Colors.red.shade400),
|
|
const SizedBox(height: 16),
|
|
Text(_error!, style: const TextStyle(color: Colors.red)),
|
|
const SizedBox(height: 16),
|
|
ElevatedButton(
|
|
onPressed: _loadSessions,
|
|
child: const Text('Retry'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
if (_sessions == null || _sessions!.isEmpty) {
|
|
return Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(Icons.terminal, size: 64, color: Colors.grey.shade600),
|
|
const SizedBox(height: 16),
|
|
Text(
|
|
'No active screen sessions',
|
|
style: TextStyle(color: Colors.grey.shade500, fontSize: 16),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
return RefreshIndicator(
|
|
onRefresh: _loadSessions,
|
|
child: ListView.builder(
|
|
padding: const EdgeInsets.all(16),
|
|
itemCount: _sessions!.length,
|
|
itemBuilder: (context, index) {
|
|
final session = _sessions![index];
|
|
return Card(
|
|
margin: const EdgeInsets.only(bottom: 12),
|
|
child: ListTile(
|
|
leading: Container(
|
|
width: 48,
|
|
height: 48,
|
|
decoration: BoxDecoration(
|
|
color: session.attached
|
|
? Colors.green.withOpacity(0.2)
|
|
: Colors.grey.withOpacity(0.2),
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: Icon(
|
|
Icons.terminal,
|
|
color: session.attached ? Colors.green : Colors.grey,
|
|
),
|
|
),
|
|
title: Text(
|
|
session.name,
|
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
|
),
|
|
subtitle: Text(
|
|
'PID: ${session.pid} - ${session.attached ? "Attached" : "Detached"}',
|
|
),
|
|
trailing: const Icon(Icons.chevron_right),
|
|
onTap: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (_) => TerminalScreen(sessionName: session.name),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|