-
Notifications
You must be signed in to change notification settings - Fork 19
Update-available icon, What's new in the library strip, version in settings #177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0e8959d
Add strip status icons: update, what's new, about
SunkenInTime c0999f0
const
SunkenInTime 014db65
Drop redundant const
SunkenInTime 6d0b53d
Move What's new before library search, drop About icon; version lives…
SunkenInTime 1bc54f0
What's new: one card per release
SunkenInTime 02084c3
What's new: raised cards, no lines
SunkenInTime bd19a76
What's new: flat cards, drop description
SunkenInTime File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| import 'dart:convert'; | ||
|
|
||
| import 'package:flutter/foundation.dart' show debugPrint, visibleForTesting; | ||
| import 'package:http/http.dart' as http; | ||
| import 'package:icarus/const/settings.dart'; | ||
|
|
||
| /// One line of a release's patch notes. | ||
| class ReleaseNoteChange { | ||
| const ReleaseNoteChange({required this.message, this.type}); | ||
|
|
||
| final String message; | ||
|
|
||
| /// Free-form tag from the release metadata: `feature`, `fix`, `improvement`. | ||
| final String? type; | ||
| } | ||
|
|
||
| /// One shipped version, as published in the updater manifest. | ||
| class ReleaseNotesEntry { | ||
| const ReleaseNotesEntry({ | ||
| required this.version, | ||
| required this.shortVersion, | ||
| required this.changes, | ||
| this.date, | ||
| }); | ||
|
|
||
| /// Full version string, e.g. `4.6.2+102`. | ||
| final String version; | ||
|
|
||
| /// Build number, e.g. `102`. Compares against [Settings.versionNumber]. | ||
| final int shortVersion; | ||
| final String? date; | ||
| final List<ReleaseNoteChange> changes; | ||
|
|
||
| /// `4.6.2` from `4.6.2+102`. | ||
| String get versionName => version.split('+').first; | ||
|
|
||
| bool get isInstalled => shortVersion == Settings.versionNumber; | ||
| bool get isNewerThanInstalled => shortVersion > Settings.versionNumber; | ||
| } | ||
|
|
||
| /// Reads the patch notes of every shipped version from the same manifest the | ||
| /// desktop updater reads. Store and web builds read it too: it is only JSON. | ||
| class ReleaseNotes { | ||
| @visibleForTesting | ||
| static Future<Map<String, dynamic>?> Function()? fetchManifestOverride; | ||
|
|
||
| static Future<List<ReleaseNotesEntry>> fetch() async { | ||
| final manifest = await _fetchManifest(); | ||
| if (manifest == null) { | ||
| throw const ReleaseNotesUnavailable(); | ||
| } | ||
| return parse(manifest); | ||
| } | ||
|
|
||
| static Future<Map<String, dynamic>?> _fetchManifest() async { | ||
| final override = fetchManifestOverride; | ||
| if (override != null) return override(); | ||
|
|
||
| try { | ||
| final response = await http.get(Settings.desktopUpdaterArchiveUrl); | ||
| if (response.statusCode != 200) { | ||
| debugPrint('Failed to load release notes: ${response.statusCode}'); | ||
| return null; | ||
| } | ||
| return json.decode(response.body) as Map<String, dynamic>; | ||
| } catch (e) { | ||
| debugPrint('Error fetching release notes: $e'); | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| /// Newest first. Rebuilds of the same version (`4.6.2+101`, `4.6.2+102`) | ||
| /// collapse into the highest build so a version reads as one release. | ||
| static List<ReleaseNotesEntry> parse(Map<String, dynamic> manifest) { | ||
| final rawItems = manifest['items']; | ||
| if (rawItems is! List) return const []; | ||
|
|
||
| final byVersionName = <String, ReleaseNotesEntry>{}; | ||
| for (final rawItem in rawItems) { | ||
| if (rawItem is! Map) continue; | ||
| final item = Map<String, dynamic>.from(rawItem); | ||
| final entry = _parseEntry(item); | ||
| if (entry == null) continue; | ||
| final existing = byVersionName[entry.versionName]; | ||
| if (existing == null || entry.shortVersion > existing.shortVersion) { | ||
| byVersionName[entry.versionName] = entry; | ||
| } | ||
| } | ||
|
|
||
| final entries = byVersionName.values.toList() | ||
| ..sort((a, b) => b.shortVersion.compareTo(a.shortVersion)); | ||
| return entries; | ||
| } | ||
|
|
||
| static ReleaseNotesEntry? _parseEntry(Map<String, dynamic> item) { | ||
| final version = item['version']?.toString().trim(); | ||
| if (version == null || version.isEmpty) return null; | ||
|
|
||
| final shortVersion = | ||
| _toInt(item['shortVersion']) ?? int.tryParse(version.split('+').last); | ||
| if (shortVersion == null) return null; | ||
|
|
||
| final rawChanges = item['changes']; | ||
| final changes = <ReleaseNoteChange>[]; | ||
| if (rawChanges is List) { | ||
| for (final rawChange in rawChanges) { | ||
| if (rawChange is! Map) continue; | ||
| final message = rawChange['message']?.toString().trim(); | ||
| if (message == null || message.isEmpty) continue; | ||
| changes.add(ReleaseNoteChange( | ||
| message: message, | ||
| type: rawChange['type']?.toString(), | ||
| )); | ||
| } | ||
| } | ||
|
|
||
| final date = item['date']?.toString().trim(); | ||
| return ReleaseNotesEntry( | ||
| version: version, | ||
| shortVersion: shortVersion, | ||
| changes: changes, | ||
| date: date == null || date.isEmpty ? null : date, | ||
| ); | ||
| } | ||
|
|
||
| static int? _toInt(dynamic value) { | ||
| if (value is int) return value; | ||
| if (value is String) return int.tryParse(value); | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| class ReleaseNotesUnavailable implements Exception { | ||
| const ReleaseNotesUnavailable(); | ||
|
|
||
| @override | ||
| String toString() => 'Release notes unavailable.'; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import 'dart:io'; | ||
|
|
||
| import 'package:desktop_updater/desktop_updater.dart'; | ||
| import 'package:flutter/foundation.dart' show debugPrint, kDebugMode, kIsWeb; | ||
| import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
| import 'package:icarus/const/settings.dart'; | ||
| import 'package:icarus/providers/update_status_provider.dart'; | ||
| import 'package:icarus/services/windows_desktop_update_controller.dart'; | ||
|
|
||
| const desktopUpdateLocalization = DesktopUpdateLocalization( | ||
| updateAvailableText: 'Update Available', | ||
| newVersionAvailableText: '{} {} is available', | ||
| newVersionLongText: | ||
| 'A desktop update is ready. Downloading will fetch {} MB of files.', | ||
| downloadText: 'Download Update', | ||
| restartText: 'Restart to update', | ||
| skipThisVersionText: 'Later', | ||
| warningTitleText: 'Restart Required', | ||
| restartWarningText: | ||
| 'Icarus needs to restart to finish installing the update. Unsaved changes will be lost. Restart now?', | ||
| warningCancelText: 'Not now', | ||
| warningConfirmText: 'Restart', | ||
| ); | ||
|
|
||
| /// The in-app updater for direct Windows installs. Null everywhere else: | ||
| /// the Store, macOS, and web update through their own channels, and the | ||
| /// Store check has to fail first before we know this is a direct install. | ||
| final desktopUpdateControllerProvider = | ||
| Provider<WindowsDesktopUpdateController?>((ref) { | ||
| if (kDebugMode && kDebugForceDesktopUpdateDialog) { | ||
| final controller = WindowsDesktopUpdateController.debugPreview( | ||
| localization: desktopUpdateLocalization, | ||
| ); | ||
| ref.onDispose(controller.dispose); | ||
| return controller; | ||
| } | ||
|
|
||
| final status = ref.watch(appUpdateStatusProvider).valueOrNull; | ||
| if (status == null) return null; | ||
|
|
||
| final bool isDirectWindowsInstall = | ||
| !kIsWeb && Platform.isWindows && !status.isSupported; | ||
| if (!isDirectWindowsInstall) return null; | ||
|
|
||
| debugPrint( | ||
| 'Desktop updater channel: $kResolvedUpdateChannel | Manifest: ${Settings.desktopUpdaterArchiveUrl}', | ||
| ); | ||
| final controller = WindowsDesktopUpdateController( | ||
| appArchiveUrl: Settings.desktopUpdaterArchiveUrl, | ||
| localization: desktopUpdateLocalization, | ||
| ); | ||
| ref.onDispose(controller.dispose); | ||
| return controller; | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
| import 'package:icarus/const/release_notes.dart'; | ||
|
|
||
| final releaseNotesProvider = FutureProvider<List<ReleaseNotesEntry>>((ref) { | ||
| return ReleaseNotes.fetch(); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A manifest entry only needs a non-empty
versionstring and an integer build number to be accepted. A value such asnot-a-semver-releasewithshortVersion: 999is shown as an available release, and the release header overflows because arbitrary version text shares a non-wrapping row with the badge and date. Validate the updater version format before constructing an entry, and constrain or ellipsize the version label in the dialog.