02d9f39845
Closes the operator-facing half of #397. Soft banner mounts at the top of the shell when the server has a newer APK bundled at /api/client/version; tap Install → APK downloads to cache → Android PackageInstaller intent fires → user taps Install in the system dialog → app restarts on the new version. ### Dart side - lib/update/update_info.dart — wire shape for /api/client/version - lib/update/client_update_provider.dart — Riverpod AsyncNotifier polling on app start + every 24h. Compares semver via pub_semver with non-semver string-equality fallback. Server 404 = "no update channel" = silent. Companion shouldShowUpdateBannerProvider gates on a per-version dismissed-set (in-memory; resets on restart). - lib/update/installer.dart — UpdateInstaller wraps dio.download + the MethodChannel call to MainActivity.kt. - lib/update/update_banner.dart — Material banner with idle / downloading (with progress) / error stages. Mounted in _ShellWithPlayerBar above the route content; SizedBox.shrink() when no update available so non-shell routes (login, server-url) see no banner anyway. - isVersionNewer() extracted as a pure function and tested across semver, prerelease ordering, leading-v normalization, and non-semver fallback (date-tag style). ### Android side - AndroidManifest.xml — REQUEST_INSTALL_PACKAGES permission; FileProvider with authorities ${applicationId}.fileprovider. - res/xml/file_paths.xml — exposes the cache directory so the downloaded APK can be served via content:// URI (file:// is blocked since Android 7). - MainActivity.kt — MethodChannel handler builds the FileProvider URI and fires Intent.ACTION_VIEW with FLAG_GRANT_READ_URI_PERMISSION so the system installer can read across the process boundary. Phase 3 (CI sequencing — bake APK + version file into /app/client/ during release.yml's tag flow) is the remaining piece. Without it the server returns 404 from /api/client/version and the banner silently does nothing — graceful degradation, but no actual updates. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
49 lines
1.7 KiB
Dart
49 lines
1.7 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:minstrel/update/client_update_provider.dart';
|
|
|
|
void main() {
|
|
group('isVersionNewer (semver path)', () {
|
|
test('strictly newer', () {
|
|
expect(isVersionNewer('0.1.1', '0.1.0'), isTrue);
|
|
expect(isVersionNewer('0.2.0', '0.1.99'), isTrue);
|
|
expect(isVersionNewer('1.0.0', '0.99.99'), isTrue);
|
|
});
|
|
|
|
test('equal returns false', () {
|
|
expect(isVersionNewer('0.1.0', '0.1.0'), isFalse);
|
|
});
|
|
|
|
test('older returns false', () {
|
|
expect(isVersionNewer('0.1.0', '0.1.1'), isFalse);
|
|
expect(isVersionNewer('0.1.0', '0.2.0'), isFalse);
|
|
});
|
|
|
|
test('strips leading v on either side', () {
|
|
expect(isVersionNewer('v0.1.1', '0.1.0'), isTrue);
|
|
expect(isVersionNewer('0.1.1', 'v0.1.0'), isTrue);
|
|
expect(isVersionNewer('v0.1.0', 'v0.1.0'), isFalse);
|
|
});
|
|
|
|
test('honors prerelease ordering', () {
|
|
// 0.1.0 > 0.1.0-rc.1 per semver
|
|
expect(isVersionNewer('0.1.0', '0.1.0-rc.1'), isTrue);
|
|
expect(isVersionNewer('0.1.0-rc.1', '0.1.0'), isFalse);
|
|
});
|
|
});
|
|
|
|
group('isVersionNewer (non-semver fallback)', () {
|
|
test('different strings → newer', () {
|
|
// Date-tag-style versions don't parse as semver; falls back to
|
|
// string inequality. Operator can dismiss if the comparison is
|
|
// wrong (the alternative — silent skip — would mean operators
|
|
// never see updates).
|
|
expect(isVersionNewer('2026.05.10', '2026.05.09'), isTrue);
|
|
expect(isVersionNewer('2026.05.09', '2026.05.10'), isTrue);
|
|
});
|
|
|
|
test('equal strings → not newer', () {
|
|
expect(isVersionNewer('2026.05.10', '2026.05.10'), isFalse);
|
|
});
|
|
});
|
|
}
|