feat: add remote pull and push

This commit is contained in:
2026-09-23 00:19:58 +02:00
parent 9aaba69e3c
commit ccf5165417
29 changed files with 3042 additions and 24 deletions
+113 -1
View File
@@ -5,6 +5,7 @@ import 'package:provider/provider.dart';
import '../l10n/app_localizations.dart';
import '../utils/navigation.dart';
import '../viewmodels/admin_pin_view_model.dart';
import '../viewmodels/remote_sync_view_model.dart';
class AdminScreenView extends StatelessWidget {
const AdminScreenView({super.key});
@@ -15,9 +16,39 @@ class AdminScreenView extends StatelessWidget {
adminPinViewModel.lock();
}
Future<void> _confirmUnlink(BuildContext context) async {
final l10n = AppLocalizations.of(context);
final confirmed = await showDialog<bool>(
context: context,
builder: (ctx) => AlertDialog(
title: const Text('Disconnect from server'),
content: const Text(
'This will unlink the device from the remote server. '
'Open tabs will no longer be synced. Continue?',
),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx, false),
child: Text(l10n.cancel),
),
FilledButton(
onPressed: () => Navigator.pop(ctx, true),
style: FilledButton.styleFrom(backgroundColor: Colors.red),
child: const Text('Disconnect'),
),
],
),
);
if (confirmed == true && context.mounted) {
context.read<RemoteSyncViewModel>().unlink();
}
}
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context);
final remoteSync = context.watch<RemoteSyncViewModel>();
return PopScope(
onPopInvokedWithResult: (didPop, result) {
@@ -68,6 +99,81 @@ class AdminScreenView extends StatelessWidget {
),
],
),
const SizedBox(height: 8),
_AdminSection(
title: 'Remote Server',
children: [
if (remoteSync.isConfigured) ...[
_AdminTile(
icon: Icons.cloud_done_outlined,
title: 'Connected',
subtitle: 'Device linked to remote server',
trailing: TextButton(
onPressed: () => _confirmUnlink(context),
style: TextButton.styleFrom(foregroundColor: Colors.red),
child: const Text('Disconnect'),
),
onTap: null,
),
] else
_AdminTile(
icon: Icons.cloud_outlined,
title: 'Not connected',
subtitle: 'Link to remote dashboard',
onTap: () => context.push('/register'),
),
],
),
if (remoteSync.isConfigured) ...[
const SizedBox(height: 8),
_AdminSection(
title: l10n.remoteActivity,
children: [
_AdminTile(
icon: Icons.sync,
title: l10n.syncNow,
subtitle: remoteSync.isSyncing
? l10n.syncing
: remoteSync.lastSyncAt != null
? l10n.lastSync(remoteSync.lastSyncAt!.toLocal().toString().substring(0, 19))
: l10n.notSyncedYet,
trailing: remoteSync.isSyncing
? const SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(strokeWidth: 2),
)
: null,
onTap: () => remoteSync.syncNow(),
),
],
),
if (remoteSync.activity.isNotEmpty)
_AdminSection(
title: l10n.remoteActivityHistory,
children: remoteSync.activity.map((entry) {
return ListTile(
dense: true,
leading: Icon(
entry.result == 'completed'
? Icons.check_circle_outline
: entry.result == 'conflict'
? Icons.warning_amber_outlined
: Icons.error_outline,
size: 20,
),
title: Text(
'${entry.commandType} (${entry.commandId.substring(0, 8)}...)',
style: const TextStyle(fontSize: 13),
),
subtitle: Text(
'${entry.processedAt.toLocal()} - ${entry.result}',
style: const TextStyle(fontSize: 11),
),
);
}).toList(),
),
],
],
),
),
@@ -121,12 +227,14 @@ class _AdminTile extends StatelessWidget {
final IconData icon;
final String title;
final String? subtitle;
final Widget? trailing;
final VoidCallback? onTap;
const _AdminTile({
required this.icon,
required this.title,
this.subtitle,
this.trailing,
required this.onTap,
});
@@ -169,6 +277,10 @@ class _AdminTile extends StatelessWidget {
],
),
),
if (trailing != null) ...[
const SizedBox(width: 8),
trailing!,
],
if (onTap != null)
Icon(
Icons.chevron_right_rounded,
@@ -180,4 +292,4 @@ class _AdminTile extends StatelessWidget {
),
);
}
}
}