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) {
for (int i = 1; i < updates; i++) { buffer.writeln(release['body']);
if (response.data[i]['prerelease']) { }
break;
}
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,100 +26,99 @@ 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 crossAxisAlignment: CrossAxisAlignment.start,
? model.getLatestManagerRelease() children: [
: model.getLatestPatchesRelease(), if (!changelog)
builder: (_, snapshot) { Padding(
if (!snapshot.hasData) { padding: const EdgeInsets.only(
return const SizedBox( top: 40.0,
height: 300, left: 24.0,
child: Center( right: 24.0,
child: CircularProgressIndicator(), bottom: 20.0,
), ),
); child: Row(
} children: [
Expanded(
return Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
if (!changelog) Text(
Padding( isPatches
padding: const EdgeInsets.only( ? t.homeView.updatePatchesSheetTitle
top: 40.0, : t.homeView.updateSheetTitle,
left: 24.0, style: const TextStyle(
right: 24.0, fontSize: 24,
bottom: 20.0, fontWeight: FontWeight.bold,
), ),
child: Row( ),
children: [ const SizedBox(height: 4.0),
Expanded( Row(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Icon(
Icons.new_releases_outlined,
color:
Theme.of(context).colorScheme.secondary,
),
const SizedBox(width: 8.0),
Text( Text(
isPatches isPatches
? t.homeView.updatePatchesSheetTitle ? model.latestPatchesVersion ?? 'Unknown'
: t.homeView.updateSheetTitle, : model.latestManagerVersion ?? 'Unknown',
style: const TextStyle( style: TextStyle(
fontSize: 24, fontSize: 20,
fontWeight: FontWeight.bold, fontWeight: FontWeight.w500,
color:
Theme.of(context).colorScheme.secondary,
), ),
), ),
const SizedBox(height: 4.0),
Row(
children: [
Icon(
Icons.new_releases_outlined,
color: Theme.of(context)
.colorScheme
.secondary,
),
const SizedBox(width: 8.0),
Text(
snapshot.data!['tag_name'] ?? 'Unknown',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w500,
color: Theme.of(context)
.colorScheme
.secondary,
),
),
],
),
], ],
), ),
), ],
FilledButton( ),
onPressed: () {
Navigator.of(context).pop();
isPatches
? model.updatePatches(context)
: model.updateManager(context);
},
child: Text(t.updateButton),
),
],
), ),
), FilledButton(
Padding( onPressed: () {
padding: const EdgeInsets.only( Navigator.of(context).pop();
top: 12.0, isPatches
left: 24.0, ? model.updatePatches(context)
bottom: 12.0, : model.updateManager(context);
), },
child: Text( child: Text(t.updateButton),
t.homeView.updateChangelogTitle,
style: TextStyle(
fontSize: changelog ? 24 : 20,
fontWeight: FontWeight.w500,
color:
Theme.of(context).colorScheme.onSecondaryContainer,
), ),
), ],
), ),
Container( ),
Padding(
padding: const EdgeInsets.only(
top: 12.0,
left: 24.0,
bottom: 12.0,
),
child: Text(
t.homeView.updateChangelogTitle,
style: TextStyle(
fontSize: changelog ? 24 : 20,
fontWeight: FontWeight.w500,
color: Theme.of(context).colorScheme.onSecondaryContainer,
),
),
),
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,12 +139,12 @@ 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 ?? '',
), ),
), );
], },
); ),
}, ],
), ),
), ),
), ),