|
|
|
|
@ -203,7 +203,7 @@ class _RelayManagementScreenState extends State<RelayManagementScreen> {
|
|
|
|
|
// Database might be closed (e.g., during tests) - handle gracefully
|
|
|
|
|
Logger.error('Failed to load settings: $e', e);
|
|
|
|
|
if (mounted) {
|
|
|
|
|
setState(() {
|
|
|
|
|
setState(() {
|
|
|
|
|
_isLoadingSetting = false;
|
|
|
|
|
// Set defaults if loading failed
|
|
|
|
|
_useNip05RelaysAutomatically = false;
|
|
|
|
|
@ -211,7 +211,7 @@ class _RelayManagementScreenState extends State<RelayManagementScreen> {
|
|
|
|
|
_originalUseNip05RelaysAutomatically = false;
|
|
|
|
|
_originalIsDarkMode = false;
|
|
|
|
|
_hasUnsavedChanges = false;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -338,9 +338,9 @@ class _RelayManagementScreenState extends State<RelayManagementScreen> {
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
Logger.error('Failed to save settings: $e');
|
|
|
|
|
if (mounted) {
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
|
SnackBar(
|
|
|
|
|
if (mounted) {
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
|
SnackBar(
|
|
|
|
|
content: Text('Failed to save settings: $e'),
|
|
|
|
|
backgroundColor: Colors.red,
|
|
|
|
|
duration: const Duration(seconds: 2),
|
|
|
|
|
@ -631,7 +631,7 @@ class _RelayManagementScreenState extends State<RelayManagementScreen> {
|
|
|
|
|
),
|
|
|
|
|
trailing: Row(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
children: [
|
|
|
|
|
IconButton(
|
|
|
|
|
icon: const Icon(Icons.edit),
|
|
|
|
|
onPressed: () => _editMediaServer(server),
|
|
|
|
|
@ -695,34 +695,34 @@ class _RelayManagementScreenState extends State<RelayManagementScreen> {
|
|
|
|
|
subtitle: Text('${widget.controller.relays.length} relay(s) configured'),
|
|
|
|
|
initiallyExpanded: false,
|
|
|
|
|
children: [
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.all(16),
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.all(16),
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
|
children: [
|
|
|
|
|
// Test All and Toggle All buttons
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
// Test All and Toggle All buttons
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: ElevatedButton.icon(
|
|
|
|
|
onPressed: widget.controller.isCheckingHealth
|
|
|
|
|
? null
|
|
|
|
|
: widget.controller.checkRelayHealth,
|
|
|
|
|
icon: widget.controller.isCheckingHealth
|
|
|
|
|
? const SizedBox(
|
|
|
|
|
width: 16,
|
|
|
|
|
height: 16,
|
|
|
|
|
child: CircularProgressIndicator(strokeWidth: 2),
|
|
|
|
|
)
|
|
|
|
|
: const Icon(Icons.network_check),
|
|
|
|
|
label: const Text('Test All'),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 8),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: ElevatedButton.icon(
|
|
|
|
|
onPressed: widget.controller.relays.isEmpty
|
|
|
|
|
? null
|
|
|
|
|
Expanded(
|
|
|
|
|
child: ElevatedButton.icon(
|
|
|
|
|
onPressed: widget.controller.isCheckingHealth
|
|
|
|
|
? null
|
|
|
|
|
: widget.controller.checkRelayHealth,
|
|
|
|
|
icon: widget.controller.isCheckingHealth
|
|
|
|
|
? const SizedBox(
|
|
|
|
|
width: 16,
|
|
|
|
|
height: 16,
|
|
|
|
|
child: CircularProgressIndicator(strokeWidth: 2),
|
|
|
|
|
)
|
|
|
|
|
: const Icon(Icons.network_check),
|
|
|
|
|
label: const Text('Test All'),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 8),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: ElevatedButton.icon(
|
|
|
|
|
onPressed: widget.controller.relays.isEmpty
|
|
|
|
|
? null
|
|
|
|
|
: () async {
|
|
|
|
|
final hasEnabled = widget.controller.relays.any((r) => r.isEnabled);
|
|
|
|
|
if (hasEnabled) {
|
|
|
|
|
@ -731,43 +731,43 @@ class _RelayManagementScreenState extends State<RelayManagementScreen> {
|
|
|
|
|
await widget.controller.turnAllOn();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
icon: const Icon(Icons.power_settings_new),
|
|
|
|
|
label: Text(
|
|
|
|
|
widget.controller.relays.isNotEmpty &&
|
|
|
|
|
icon: const Icon(Icons.power_settings_new),
|
|
|
|
|
label: Text(
|
|
|
|
|
widget.controller.relays.isNotEmpty &&
|
|
|
|
|
widget.controller.relays.any((r) => r.isEnabled)
|
|
|
|
|
? 'Turn All Off'
|
|
|
|
|
: 'Turn All On',
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
? 'Turn All Off'
|
|
|
|
|
: 'Turn All On',
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
|
// Add relay input
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: TextField(
|
|
|
|
|
controller: _urlController,
|
|
|
|
|
decoration: InputDecoration(
|
|
|
|
|
labelText: 'Relay URL',
|
|
|
|
|
hintText: 'wss://relay.example.com',
|
|
|
|
|
border: const OutlineInputBorder(),
|
|
|
|
|
),
|
|
|
|
|
keyboardType: TextInputType.url,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
|
// Add relay input
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: TextField(
|
|
|
|
|
controller: _urlController,
|
|
|
|
|
decoration: InputDecoration(
|
|
|
|
|
labelText: 'Relay URL',
|
|
|
|
|
hintText: 'wss://relay.example.com',
|
|
|
|
|
border: const OutlineInputBorder(),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 8),
|
|
|
|
|
ElevatedButton.icon(
|
|
|
|
|
keyboardType: TextInputType.url,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 8),
|
|
|
|
|
ElevatedButton.icon(
|
|
|
|
|
onPressed: () async {
|
|
|
|
|
final url = _urlController.text.trim();
|
|
|
|
|
if (url.isNotEmpty) {
|
|
|
|
|
final url = _urlController.text.trim();
|
|
|
|
|
if (url.isNotEmpty) {
|
|
|
|
|
final success = await widget.controller.addRelay(url);
|
|
|
|
|
if (mounted) {
|
|
|
|
|
if (success) {
|
|
|
|
|
_urlController.clear();
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
|
const SnackBar(
|
|
|
|
|
_urlController.clear();
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
|
const SnackBar(
|
|
|
|
|
content: Text('Relay added and connected successfully'),
|
|
|
|
|
backgroundColor: Colors.green,
|
|
|
|
|
duration: Duration(seconds: 1),
|
|
|
|
|
@ -781,72 +781,72 @@ class _RelayManagementScreenState extends State<RelayManagementScreen> {
|
|
|
|
|
),
|
|
|
|
|
backgroundColor: Colors.orange,
|
|
|
|
|
duration: const Duration(seconds: 3),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
icon: const Icon(Icons.add),
|
|
|
|
|
label: const Text('Add'),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
icon: const Icon(Icons.add),
|
|
|
|
|
label: const Text('Add'),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
|
// Relay list
|
|
|
|
|
// Relay list
|
|
|
|
|
SizedBox(
|
|
|
|
|
height: 300,
|
|
|
|
|
child: widget.controller.relays.isEmpty
|
|
|
|
|
? Center(
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
children: [
|
|
|
|
|
Icon(
|
|
|
|
|
Icons.cloud_off,
|
|
|
|
|
child: widget.controller.relays.isEmpty
|
|
|
|
|
? Center(
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
children: [
|
|
|
|
|
Icon(
|
|
|
|
|
Icons.cloud_off,
|
|
|
|
|
size: 48,
|
|
|
|
|
color: Colors.grey.shade400,
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
|
Text(
|
|
|
|
|
'No relays configured',
|
|
|
|
|
color: Colors.grey.shade400,
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
|
Text(
|
|
|
|
|
'No relays configured',
|
|
|
|
|
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
|
|
|
|
color: Colors.grey,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
|
Text(
|
|
|
|
|
'Add a relay to get started',
|
|
|
|
|
color: Colors.grey,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
|
Text(
|
|
|
|
|
'Add a relay to get started',
|
|
|
|
|
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
|
|
|
|
color: Colors.grey,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
color: Colors.grey,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
: ListView.builder(
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
: ListView.builder(
|
|
|
|
|
shrinkWrap: true,
|
|
|
|
|
itemCount: widget.controller.relays.length,
|
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
|
final relay = widget.controller.relays[index];
|
|
|
|
|
return _RelayListItem(
|
|
|
|
|
relay: relay,
|
|
|
|
|
itemCount: widget.controller.relays.length,
|
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
|
final relay = widget.controller.relays[index];
|
|
|
|
|
return _RelayListItem(
|
|
|
|
|
relay: relay,
|
|
|
|
|
onToggle: () async {
|
|
|
|
|
await widget.controller.toggleRelay(relay.url);
|
|
|
|
|
},
|
|
|
|
|
onRemove: () {
|
|
|
|
|
widget.controller.removeRelay(relay.url);
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
|
SnackBar(
|
|
|
|
|
content: Text('Relay ${relay.url} removed'),
|
|
|
|
|
duration: const Duration(seconds: 2),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
onRemove: () {
|
|
|
|
|
widget.controller.removeRelay(relay.url);
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
|
SnackBar(
|
|
|
|
|
content: Text('Relay ${relay.url} removed'),
|
|
|
|
|
duration: const Duration(seconds: 2),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
@ -884,21 +884,21 @@ class _RelayListItem extends StatelessWidget {
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
|
|
|
|
child: Row(
|
|
|
|
|
children: [
|
|
|
|
|
// Status indicator
|
|
|
|
|
Container(
|
|
|
|
|
children: [
|
|
|
|
|
// Status indicator
|
|
|
|
|
Container(
|
|
|
|
|
width: 10,
|
|
|
|
|
height: 10,
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
shape: BoxShape.circle,
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
shape: BoxShape.circle,
|
|
|
|
|
color: relay.isConnected && relay.isEnabled
|
|
|
|
|
? Colors.green
|
|
|
|
|
: Colors.grey,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 8),
|
|
|
|
|
? Colors.green
|
|
|
|
|
: Colors.grey,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 8),
|
|
|
|
|
// URL and status text
|
|
|
|
|
Expanded(
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
@ -911,17 +911,17 @@ class _RelayListItem extends StatelessWidget {
|
|
|
|
|
),
|
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
|
maxLines: 1,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 2),
|
|
|
|
|
Text(
|
|
|
|
|
Text(
|
|
|
|
|
relay.isConnected && relay.isEnabled
|
|
|
|
|
? 'Connected'
|
|
|
|
|
: 'Disabled',
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
? 'Connected'
|
|
|
|
|
: 'Disabled',
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 11,
|
|
|
|
|
color: relay.isConnected && relay.isEnabled
|
|
|
|
|
? Colors.green
|
|
|
|
|
: Colors.grey,
|
|
|
|
|
? Colors.green
|
|
|
|
|
: Colors.grey,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
@ -940,30 +940,30 @@ class _RelayListItem extends StatelessWidget {
|
|
|
|
|
color: relay.isEnabled
|
|
|
|
|
? Colors.green
|
|
|
|
|
: Colors.grey[600],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 4),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 4),
|
|
|
|
|
Transform.scale(
|
|
|
|
|
scale: 0.8,
|
|
|
|
|
child: Switch(
|
|
|
|
|
value: relay.isEnabled,
|
|
|
|
|
onChanged: (_) => onToggle(),
|
|
|
|
|
),
|
|
|
|
|
value: relay.isEnabled,
|
|
|
|
|
onChanged: (_) => onToggle(),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 4),
|
|
|
|
|
// Remove button
|
|
|
|
|
IconButton(
|
|
|
|
|
// Remove button
|
|
|
|
|
IconButton(
|
|
|
|
|
icon: const Icon(Icons.delete, size: 18),
|
|
|
|
|
color: Colors.red,
|
|
|
|
|
tooltip: 'Remove',
|
|
|
|
|
onPressed: onRemove,
|
|
|
|
|
color: Colors.red,
|
|
|
|
|
tooltip: 'Remove',
|
|
|
|
|
onPressed: onRemove,
|
|
|
|
|
padding: EdgeInsets.zero,
|
|
|
|
|
constraints: const BoxConstraints(
|
|
|
|
|
minWidth: 32,
|
|
|
|
|
minHeight: 32,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
|