|
|
|
|
@ -37,7 +37,8 @@ class _RelayManagementScreenState extends State<RelayManagementScreen> {
|
|
|
|
|
MultiMediaService? _multiMediaService;
|
|
|
|
|
List<MediaServerConfig> _mediaServers = [];
|
|
|
|
|
MediaServerConfig? _defaultMediaServer;
|
|
|
|
|
bool _mediaServersExpanded = false; // Track expansion state
|
|
|
|
|
bool _mediaServersExpanded = false;
|
|
|
|
|
bool _settingsExpanded = true; // Settings expanded by default
|
|
|
|
|
|
|
|
|
|
// Store original values to detect changes
|
|
|
|
|
List<MediaServerConfig> _originalMediaServers = [];
|
|
|
|
|
@ -504,180 +505,165 @@ class _RelayManagementScreenState extends State<RelayManagementScreen> {
|
|
|
|
|
return SingleChildScrollView(
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
// Settings section
|
|
|
|
|
Container(
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
padding: const EdgeInsets.all(16),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: Theme.of(context).cardColor,
|
|
|
|
|
border: Border(
|
|
|
|
|
bottom: BorderSide(
|
|
|
|
|
color: Theme.of(context).dividerColor,
|
|
|
|
|
width: 1,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
'Settings',
|
|
|
|
|
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
ElevatedButton.icon(
|
|
|
|
|
onPressed: _hasUnsavedChanges ? _saveAllSettings : null,
|
|
|
|
|
icon: const Icon(Icons.save, size: 18),
|
|
|
|
|
label: const Text('Save'),
|
|
|
|
|
style: ElevatedButton.styleFrom(
|
|
|
|
|
backgroundColor: Colors.green,
|
|
|
|
|
foregroundColor: Colors.white,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
if (_hasUnsavedChanges)
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(top: 8.0),
|
|
|
|
|
child: Text(
|
|
|
|
|
'You have unsaved changes',
|
|
|
|
|
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
|
|
|
|
color: Colors.orange,
|
|
|
|
|
fontStyle: FontStyle.italic,
|
|
|
|
|
),
|
|
|
|
|
// Settings section - Now using ExpansionTile for uniformity
|
|
|
|
|
ExpansionTile(
|
|
|
|
|
title: const Text('Settings'),
|
|
|
|
|
subtitle: _hasUnsavedChanges
|
|
|
|
|
? const Text('You have unsaved changes', style: TextStyle(color: Colors.orange))
|
|
|
|
|
: Text('${_useNip05RelaysAutomatically ? "NIP-05" : "Manual"} relays • ${_isDarkMode ? "Dark" : "Light"} mode'),
|
|
|
|
|
initiallyExpanded: _settingsExpanded,
|
|
|
|
|
trailing: _hasUnsavedChanges
|
|
|
|
|
? ElevatedButton.icon(
|
|
|
|
|
onPressed: _saveAllSettings,
|
|
|
|
|
icon: const Icon(Icons.save, size: 18),
|
|
|
|
|
label: const Text('Save'),
|
|
|
|
|
style: ElevatedButton.styleFrom(
|
|
|
|
|
backgroundColor: Colors.green,
|
|
|
|
|
foregroundColor: Colors.white,
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 12),
|
|
|
|
|
if (_isLoadingSetting)
|
|
|
|
|
const Row(
|
|
|
|
|
children: [
|
|
|
|
|
SizedBox(
|
|
|
|
|
width: 16,
|
|
|
|
|
height: 16,
|
|
|
|
|
child: CircularProgressIndicator(strokeWidth: 2),
|
|
|
|
|
),
|
|
|
|
|
SizedBox(width: 12),
|
|
|
|
|
Text('Loading settings...'),
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
else
|
|
|
|
|
SwitchListTile(
|
|
|
|
|
title: const Text('Use NIP-05 relays automatically'),
|
|
|
|
|
subtitle: const Text(
|
|
|
|
|
'Automatically replace relays with NIP-05 preferred relays upon login',
|
|
|
|
|
style: TextStyle(fontSize: 12),
|
|
|
|
|
),
|
|
|
|
|
value: _useNip05RelaysAutomatically,
|
|
|
|
|
onChanged: (value) {
|
|
|
|
|
_saveSetting('use_nip05_relays_automatically', value);
|
|
|
|
|
},
|
|
|
|
|
contentPadding: EdgeInsets.zero,
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
|
SwitchListTile(
|
|
|
|
|
title: const Text('Dark Mode'),
|
|
|
|
|
subtitle: const Text(
|
|
|
|
|
'Enable dark theme for the app',
|
|
|
|
|
style: TextStyle(fontSize: 12),
|
|
|
|
|
),
|
|
|
|
|
value: _isDarkMode,
|
|
|
|
|
onChanged: (value) {
|
|
|
|
|
_saveSetting('dark_mode', value);
|
|
|
|
|
},
|
|
|
|
|
contentPadding: EdgeInsets.zero,
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
|
// Media Server Settings - Multiple Servers
|
|
|
|
|
Builder(
|
|
|
|
|
builder: (context) {
|
|
|
|
|
final immichEnabled = dotenv.env['IMMICH_ENABLE']?.toLowerCase() != 'false';
|
|
|
|
|
final defaultBlossomServer = dotenv.env['BLOSSOM_SERVER'] ?? 'https://media.based21.com';
|
|
|
|
|
|
|
|
|
|
return ExpansionTile(
|
|
|
|
|
key: ValueKey('media-servers-${_mediaServers.length}-${_mediaServersExpanded}'),
|
|
|
|
|
title: const Text('Media Servers'),
|
|
|
|
|
subtitle: Text(_mediaServers.isEmpty
|
|
|
|
|
? 'No servers configured'
|
|
|
|
|
: '${_mediaServers.length} server(s)${_defaultMediaServer != null ? " • Default: ${_defaultMediaServer!.name ?? _defaultMediaServer!.type}" : ""}'),
|
|
|
|
|
initiallyExpanded: _mediaServersExpanded,
|
|
|
|
|
onExpansionChanged: (expanded) {
|
|
|
|
|
setState(() {
|
|
|
|
|
_mediaServersExpanded = expanded;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
: null,
|
|
|
|
|
onExpansionChanged: (expanded) {
|
|
|
|
|
setState(() {
|
|
|
|
|
_settingsExpanded = expanded;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
children: [
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.all(16),
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
if (_isLoadingSetting)
|
|
|
|
|
const Row(
|
|
|
|
|
children: [
|
|
|
|
|
// Server list
|
|
|
|
|
if (_mediaServers.isEmpty)
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
|
child: Text(
|
|
|
|
|
'No media servers configured. Add one to get started.',
|
|
|
|
|
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
|
|
|
|
color: Colors.grey,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
else
|
|
|
|
|
...List.generate(_mediaServers.length, (index) {
|
|
|
|
|
final server = _mediaServers[index];
|
|
|
|
|
return ListTile(
|
|
|
|
|
key: ValueKey(server.id),
|
|
|
|
|
leading: Icon(
|
|
|
|
|
server.isDefault ? Icons.star : Icons.star_border,
|
|
|
|
|
color: server.isDefault ? Colors.amber : Colors.grey,
|
|
|
|
|
),
|
|
|
|
|
title: Text(server.name ?? '${server.type.toUpperCase()} Server'),
|
|
|
|
|
subtitle: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Text(server.baseUrl),
|
|
|
|
|
if (server.isDefault)
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(top: 4.0),
|
|
|
|
|
child: Chip(
|
|
|
|
|
label: const Text('Default'),
|
|
|
|
|
labelStyle: const TextStyle(fontSize: 10),
|
|
|
|
|
padding: EdgeInsets.zero,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
trailing: Row(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
IconButton(
|
|
|
|
|
icon: const Icon(Icons.edit),
|
|
|
|
|
onPressed: () => _editMediaServer(server),
|
|
|
|
|
SizedBox(
|
|
|
|
|
width: 16,
|
|
|
|
|
height: 16,
|
|
|
|
|
child: CircularProgressIndicator(strokeWidth: 2),
|
|
|
|
|
),
|
|
|
|
|
SizedBox(width: 12),
|
|
|
|
|
Text('Loading settings...'),
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
else ...[
|
|
|
|
|
SwitchListTile(
|
|
|
|
|
title: const Text('Use NIP-05 relays automatically'),
|
|
|
|
|
subtitle: const Text(
|
|
|
|
|
'Automatically replace relays with NIP-05 preferred relays upon login',
|
|
|
|
|
style: TextStyle(fontSize: 12),
|
|
|
|
|
),
|
|
|
|
|
value: _useNip05RelaysAutomatically,
|
|
|
|
|
onChanged: (value) {
|
|
|
|
|
_saveSetting('use_nip05_relays_automatically', value);
|
|
|
|
|
},
|
|
|
|
|
contentPadding: EdgeInsets.zero,
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
|
SwitchListTile(
|
|
|
|
|
title: const Text('Dark Mode'),
|
|
|
|
|
subtitle: const Text(
|
|
|
|
|
'Enable dark theme for the app',
|
|
|
|
|
style: TextStyle(fontSize: 12),
|
|
|
|
|
),
|
|
|
|
|
value: _isDarkMode,
|
|
|
|
|
onChanged: (value) {
|
|
|
|
|
_saveSetting('dark_mode', value);
|
|
|
|
|
},
|
|
|
|
|
contentPadding: EdgeInsets.zero,
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
|
// Media Server Settings - Multiple Servers
|
|
|
|
|
Builder(
|
|
|
|
|
builder: (context) {
|
|
|
|
|
final immichEnabled = dotenv.env['IMMICH_ENABLE']?.toLowerCase() != 'false';
|
|
|
|
|
final defaultBlossomServer = dotenv.env['BLOSSOM_SERVER'] ?? 'https://media.based21.com';
|
|
|
|
|
|
|
|
|
|
return ExpansionTile(
|
|
|
|
|
key: ValueKey('media-servers-${_mediaServers.length}-${_mediaServersExpanded}'),
|
|
|
|
|
title: const Text('Media Servers'),
|
|
|
|
|
subtitle: Text(_mediaServers.isEmpty
|
|
|
|
|
? 'No servers configured'
|
|
|
|
|
: '${_mediaServers.length} server(s)${_defaultMediaServer != null ? " • Default: ${_defaultMediaServer!.name ?? _defaultMediaServer!.type}" : ""}'),
|
|
|
|
|
initiallyExpanded: _mediaServersExpanded,
|
|
|
|
|
onExpansionChanged: (expanded) {
|
|
|
|
|
setState(() {
|
|
|
|
|
_mediaServersExpanded = expanded;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
children: [
|
|
|
|
|
// Server list
|
|
|
|
|
if (_mediaServers.isEmpty)
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
|
child: Text(
|
|
|
|
|
'No media servers configured. Add one to get started.',
|
|
|
|
|
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
|
|
|
|
color: Colors.grey,
|
|
|
|
|
),
|
|
|
|
|
IconButton(
|
|
|
|
|
icon: const Icon(Icons.delete),
|
|
|
|
|
onPressed: () => _removeMediaServer(server),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
else
|
|
|
|
|
...List.generate(_mediaServers.length, (index) {
|
|
|
|
|
final server = _mediaServers[index];
|
|
|
|
|
return ListTile(
|
|
|
|
|
key: ValueKey(server.id),
|
|
|
|
|
leading: Icon(
|
|
|
|
|
server.isDefault ? Icons.star : Icons.star_border,
|
|
|
|
|
color: server.isDefault ? Colors.amber : Colors.grey,
|
|
|
|
|
),
|
|
|
|
|
title: Text(server.name ?? '${server.type.toUpperCase()} Server'),
|
|
|
|
|
subtitle: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Text(server.baseUrl),
|
|
|
|
|
if (server.isDefault)
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(top: 4.0),
|
|
|
|
|
child: Chip(
|
|
|
|
|
label: const Text('Default'),
|
|
|
|
|
labelStyle: const TextStyle(fontSize: 10),
|
|
|
|
|
padding: EdgeInsets.zero,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
trailing: Row(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
IconButton(
|
|
|
|
|
icon: const Icon(Icons.edit),
|
|
|
|
|
onPressed: () => _editMediaServer(server),
|
|
|
|
|
),
|
|
|
|
|
IconButton(
|
|
|
|
|
icon: const Icon(Icons.delete),
|
|
|
|
|
onPressed: () => _removeMediaServer(server),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
onTap: () => _setDefaultServer(server),
|
|
|
|
|
);
|
|
|
|
|
}),
|
|
|
|
|
const Divider(),
|
|
|
|
|
// Add server button
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
|
child: ElevatedButton.icon(
|
|
|
|
|
onPressed: () => _addMediaServer(immichEnabled, defaultBlossomServer),
|
|
|
|
|
icon: const Icon(Icons.add),
|
|
|
|
|
label: const Text('Add Media Server'),
|
|
|
|
|
),
|
|
|
|
|
onTap: () => _setDefaultServer(server),
|
|
|
|
|
);
|
|
|
|
|
}),
|
|
|
|
|
const Divider(),
|
|
|
|
|
// Add server button
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
|
child: ElevatedButton.icon(
|
|
|
|
|
onPressed: () => _addMediaServer(immichEnabled, defaultBlossomServer),
|
|
|
|
|
icon: const Icon(Icons.add),
|
|
|
|
|
label: const Text('Add Media Server'),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
// Error message
|
|
|
|
|
if (widget.controller.error != null)
|
|
|
|
|
|