fix: Update dialog shows dev version & loading gets stuck in certain circumstances (#1792)

Signed-off-by: validcube <pun.butrach@gmail.com>
Co-authored-by: validcube <pun.butrach@gmail.com>
This commit is contained in:
kitadai31 2024-06-19 16:44:09 +09:00 committed by GitHub
parent 46f6a49a7a
commit fc52560244
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 114 additions and 121 deletions

View file

@ -49,36 +49,27 @@ class GithubAPI {
} }
} }
Future<Map<String, dynamic>?> getLatestManagerRelease( Future<String?> getManagerChangelogs() async {
String repoName,
) async {
try { try {
final response = await _dioGetSynchronously( final response = await _dioGetSynchronously(
'/repos/$repoName/releases', '/repos/${_managerAPI.defaultManagerRepo}/releases?per_page=50',
); );
final Map<String, dynamic> releases = response.data[0]; final buffer = StringBuffer();
int updates = 0;
final String currentVersion = final String currentVersion =
await _managerAPI.getCurrentManagerVersion(); await _managerAPI.getCurrentManagerVersion();
while (response.data[updates]['tag_name'] != currentVersion) { for (final release in response.data) {
updates++; if (release['tag_name'] == currentVersion) {
if (buffer.isEmpty) {
buffer.writeln(release['body']);
} }
for (int i = 1; i < updates; i++) { break;
if (response.data[i]['prerelease']) { }
if (release['prerelease']) {
continue; continue;
} }
releases.update( buffer.writeln(release['body']);
'body',
(value) =>
value +
'\n' +
'# ' +
response.data[i]['tag_name'] +
'\n' +
response.data[i]['body'],
);
} }
return releases; return buffer.toString();
} on Exception catch (e) { } on Exception catch (e) {
if (kDebugMode) { if (kDebugMode) {
print(e); print(e);

View file

@ -39,7 +39,8 @@ class HomeViewModel extends BaseViewModel {
List<PatchedApplication> patchedInstalledApps = []; List<PatchedApplication> patchedInstalledApps = [];
String _currentManagerVersion = ''; String _currentManagerVersion = '';
String _currentPatchesVersion = ''; String _currentPatchesVersion = '';
String? _latestManagerVersion = ''; String? latestManagerVersion;
String? latestPatchesVersion;
File? downloadedApk; File? downloadedApk;
Future<void> initialize(BuildContext context) async { Future<void> initialize(BuildContext context) async {
@ -50,7 +51,6 @@ class HomeViewModel extends BaseViewModel {
await forceRefresh(context); await forceRefresh(context);
return; return;
} }
_latestManagerVersion = await _managerAPI.getLatestManagerVersion();
_currentPatchesVersion = await _managerAPI.getCurrentPatchesVersion(); _currentPatchesVersion = await _managerAPI.getCurrentPatchesVersion();
if (_managerAPI.showUpdateDialog() && await hasManagerUpdates()) { if (_managerAPI.showUpdateDialog() && await hasManagerUpdates()) {
showUpdateDialog(context, false); showUpdateDialog(context, false);
@ -131,21 +131,21 @@ class HomeViewModel extends BaseViewModel {
if (!_managerAPI.releaseBuild) { if (!_managerAPI.releaseBuild) {
return false; return false;
} }
_latestManagerVersion = latestManagerVersion =
await _managerAPI.getLatestManagerVersion() ?? _currentManagerVersion; await _managerAPI.getLatestManagerVersion() ?? _currentManagerVersion;
if (_latestManagerVersion != _currentManagerVersion) { if (latestManagerVersion != _currentManagerVersion) {
return true; return true;
} }
return false; return false;
} }
Future<bool> hasPatchesUpdates() async { Future<bool> hasPatchesUpdates() async {
final String? latestVersion = await _managerAPI.getLatestPatchesVersion(); latestPatchesVersion = await _managerAPI.getLatestPatchesVersion();
if (latestVersion != null) { if (latestPatchesVersion != null) {
try { try {
final int latestVersionInt = final int latestVersionInt =
int.parse(latestVersion.replaceAll(RegExp('[^0-9]'), '')); int.parse(latestPatchesVersion!.replaceAll(RegExp('[^0-9]'), ''));
final int currentVersionInt = final int currentVersionInt =
int.parse(_currentPatchesVersion.replaceAll(RegExp('[^0-9]'), '')); int.parse(_currentPatchesVersion.replaceAll(RegExp('[^0-9]'), ''));
return latestVersionInt > currentVersionInt; return latestVersionInt > currentVersionInt;
@ -475,12 +475,14 @@ class HomeViewModel extends BaseViewModel {
); );
} }
Future<Map<String, dynamic>?> getLatestManagerRelease() { Future<String?> getManagerChangelogs() {
return _githubAPI.getLatestManagerRelease(_managerAPI.defaultManagerRepo); return _githubAPI.getManagerChangelogs();
} }
Future<Map<String, dynamic>?> getLatestPatchesRelease() { Future<String?> getLatestPatchesChangelog() async {
return _githubAPI.getLatestRelease(_managerAPI.defaultPatchesRepo); final release =
await _githubAPI.getLatestRelease(_managerAPI.defaultPatchesRepo);
return release?['body'];
} }
Future<String?> getLatestPatchesReleaseTime() { Future<String?> getLatestPatchesReleaseTime() {

View file

@ -14,6 +14,7 @@ class UpdateConfirmationSheet extends StatelessWidget {
final bool isPatches; final bool isPatches;
final bool changelog; final bool changelog;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final HomeViewModel model = locator<HomeViewModel>(); final HomeViewModel model = locator<HomeViewModel>();
@ -25,21 +26,7 @@ class UpdateConfirmationSheet extends StatelessWidget {
builder: (_, scrollController) => SingleChildScrollView( builder: (_, scrollController) => SingleChildScrollView(
controller: scrollController, controller: scrollController,
child: SafeArea( child: SafeArea(
child: FutureBuilder<Map<String, dynamic>?>( child: Column(
future: !isPatches
? model.getLatestManagerRelease()
: model.getLatestPatchesRelease(),
builder: (_, snapshot) {
if (!snapshot.hasData) {
return const SizedBox(
height: 300,
child: Center(
child: CircularProgressIndicator(),
),
);
}
return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
if (!changelog) if (!changelog)
@ -70,19 +57,19 @@ class UpdateConfirmationSheet extends StatelessWidget {
children: [ children: [
Icon( Icon(
Icons.new_releases_outlined, Icons.new_releases_outlined,
color: Theme.of(context) color:
.colorScheme Theme.of(context).colorScheme.secondary,
.secondary,
), ),
const SizedBox(width: 8.0), const SizedBox(width: 8.0),
Text( Text(
snapshot.data!['tag_name'] ?? 'Unknown', isPatches
? model.latestPatchesVersion ?? 'Unknown'
: model.latestManagerVersion ?? 'Unknown',
style: TextStyle( style: TextStyle(
fontSize: 20, fontSize: 20,
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
color: Theme.of(context) color:
.colorScheme Theme.of(context).colorScheme.secondary,
.secondary,
), ),
), ),
], ],
@ -113,12 +100,25 @@ class UpdateConfirmationSheet extends StatelessWidget {
style: TextStyle( style: TextStyle(
fontSize: changelog ? 24 : 20, fontSize: changelog ? 24 : 20,
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
color: color: Theme.of(context).colorScheme.onSecondaryContainer,
Theme.of(context).colorScheme.onSecondaryContainer,
), ),
), ),
), ),
Container( FutureBuilder<String?>(
future: !isPatches
? model.getManagerChangelogs()
: model.getLatestPatchesChangelog(),
builder: (_, snapshot) {
if (!snapshot.hasData) {
return Padding(
padding: EdgeInsets.only(top: changelog ? 96 : 24),
child: const Center(
child: CircularProgressIndicator(),
),
);
}
return Container(
margin: const EdgeInsets.symmetric(horizontal: 24.0), margin: const EdgeInsets.symmetric(horizontal: 24.0),
decoration: BoxDecoration( decoration: BoxDecoration(
color: Theme.of(context).colorScheme.secondaryContainer, color: Theme.of(context).colorScheme.secondaryContainer,
@ -139,13 +139,13 @@ class UpdateConfirmationSheet extends StatelessWidget {
shrinkWrap: true, shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(), physics: const NeverScrollableScrollPhysics(),
padding: const EdgeInsets.all(20.0), padding: const EdgeInsets.all(20.0),
data: snapshot.data!['body'] ?? '', data: snapshot.data ?? '',
), ),
),
],
); );
}, },
), ),
],
),
), ),
), ),
); );