Add self-hosted update system via Forgejo releases
The app now checks for new APK releases on a Forgejo instance and can download and install them without leaving the app. Settings: - New "Update repository URL" field (e.g. https://git.example.com/user/fabled_app) - "App version" tile with a manual "Check" button and live status display - Download progress bar and "Install" button appear when update is found Startup: - Shell runs a silent background check on first load when a repo URL is set - A dialog appears automatically if a newer release is found Provider (update_provider.dart): - UpdateNotifier: idle → checking → available → downloading → available - Hits Forgejo /api/v1/repos/{owner}/{repo}/releases/latest - Parses semver tag, finds .apk asset, downloads with progress via Dio - Opens the APK with open_file to trigger the system package installer Android: - REQUEST_INSTALL_PACKAGES permission - FileProvider configured for open_file (shares APK URI with installer) - res/xml/file_paths.xml covers external-files and cache directories Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import 'package:go_router/go_router.dart';
|
||||
import '../../core/constants.dart';
|
||||
import '../../providers/auth_provider.dart';
|
||||
import '../../providers/settings_provider.dart';
|
||||
import '../../providers/update_provider.dart';
|
||||
|
||||
class SettingsScreen extends ConsumerWidget {
|
||||
const SettingsScreen({super.key});
|
||||
@@ -13,6 +14,8 @@ class SettingsScreen extends ConsumerWidget {
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final serverUrl = ref.watch(serverUrlProvider);
|
||||
final themeMode = ref.watch(themeModeProvider);
|
||||
final repoUrl = ref.watch(forgejoRepoUrlProvider);
|
||||
final update = ref.watch(updateProvider);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Settings')),
|
||||
@@ -52,6 +55,59 @@ class SettingsScreen extends ConsumerWidget {
|
||||
),
|
||||
),
|
||||
const Divider(),
|
||||
|
||||
// ── Updates ──────────────────────────────────────────────────────
|
||||
ListTile(
|
||||
leading: const Icon(Icons.update),
|
||||
title: const Text('Update repository'),
|
||||
subtitle: Text(repoUrl?.isNotEmpty == true
|
||||
? repoUrl!
|
||||
: 'Not configured — tap to set'),
|
||||
onTap: () => _editRepoUrl(context, ref, repoUrl),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.info_outline),
|
||||
title: const Text('App version'),
|
||||
subtitle: _versionSubtitle(update),
|
||||
trailing: update.status == UpdateStatus.checking
|
||||
? const SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: TextButton(
|
||||
onPressed: () {
|
||||
final url = ref.read(forgejoRepoUrlProvider);
|
||||
if (url == null || url.isEmpty) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text(
|
||||
'Set a repository URL first.'),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
ref.read(updateProvider.notifier).check(url);
|
||||
},
|
||||
child: const Text('Check'),
|
||||
),
|
||||
),
|
||||
if (update.status == UpdateStatus.available ||
|
||||
update.status == UpdateStatus.downloading)
|
||||
_UpdateTile(update: update),
|
||||
if (update.status == UpdateStatus.error)
|
||||
ListTile(
|
||||
leading:
|
||||
const Icon(Icons.error_outline, color: Colors.red),
|
||||
title: const Text('Update check failed'),
|
||||
subtitle: Text(
|
||||
update.errorMessage ?? 'Unknown error',
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
|
||||
const Divider(),
|
||||
ListTile(
|
||||
title: const Text('Sign Out'),
|
||||
leading: const Icon(Icons.logout),
|
||||
@@ -64,4 +120,96 @@ class SettingsScreen extends ConsumerWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _versionSubtitle(UpdateState update) {
|
||||
final current = update.currentVersion;
|
||||
final latest = update.latestVersion;
|
||||
|
||||
if (current == null && latest == null) {
|
||||
return const Text('Tap "Check" to look for updates');
|
||||
}
|
||||
if (update.status == UpdateStatus.upToDate) {
|
||||
return Text('v$current — up to date');
|
||||
}
|
||||
if (update.status == UpdateStatus.available ||
|
||||
update.status == UpdateStatus.downloading) {
|
||||
return Text('v$current installed');
|
||||
}
|
||||
return Text(current != null ? 'v$current' : '');
|
||||
}
|
||||
|
||||
Future<void> _editRepoUrl(
|
||||
BuildContext context, WidgetRef ref, String? current) async {
|
||||
String draft = current ?? '';
|
||||
await showDialog<void>(
|
||||
context: context,
|
||||
builder: (dialogContext) => AlertDialog(
|
||||
title: const Text('Update repository URL'),
|
||||
content: TextFormField(
|
||||
initialValue: draft,
|
||||
onChanged: (v) => draft = v,
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'https://git.example.com/user/fabled_app',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
autocorrect: false,
|
||||
keyboardType: TextInputType.url,
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialogContext),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
ref
|
||||
.read(forgejoRepoUrlProvider.notifier)
|
||||
.setUrl(draft.trim());
|
||||
Navigator.pop(dialogContext);
|
||||
},
|
||||
child: const Text('Save'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _UpdateTile extends ConsumerWidget {
|
||||
final UpdateState update;
|
||||
const _UpdateTile({required this.update});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final isDownloading = update.status == UpdateStatus.downloading;
|
||||
|
||||
return ListTile(
|
||||
leading: const Icon(Icons.system_update, color: Colors.green),
|
||||
title: Text('v${update.latestVersion} available'),
|
||||
subtitle: isDownloading
|
||||
? Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const SizedBox(height: 4),
|
||||
LinearProgressIndicator(
|
||||
value: update.downloadProgress > 0
|
||||
? update.downloadProgress
|
||||
: null,
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
'${(update.downloadProgress * 100).toStringAsFixed(0)}%'),
|
||||
],
|
||||
)
|
||||
: const Text('Tap to download and install'),
|
||||
trailing: isDownloading
|
||||
? null
|
||||
: FilledButton(
|
||||
onPressed: () =>
|
||||
ref.read(updateProvider.notifier).downloadAndInstall(),
|
||||
child: const Text('Install'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user