Skip to content
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

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

Merged
merged 6 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 13 additions & 22 deletions lib/services/github_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,36 +49,27 @@ class GithubAPI {
}
}

Future<Map<String, dynamic>?> getLatestManagerRelease(
String repoName,
) async {
Future<String?> getManagerChangelogs() async {
try {
final response = await _dioGetSynchronously(
'/repos/$repoName/releases',
'/repos/${_managerAPI.defaultManagerRepo}/releases?per_page=50',
);
final Map<String, dynamic> releases = response.data[0];
int updates = 0;
final buffer = StringBuffer();
final String currentVersion =
await _managerAPI.getCurrentManagerVersion();
while (response.data[updates]['tag_name'] != currentVersion) {
updates++;
}
for (int i = 1; i < updates; i++) {
if (response.data[i]['prerelease']) {
for (final release in response.data) {
if (release['tag_name'] == currentVersion) {
if (buffer.isEmpty) {
buffer.writeln(release['body']);
}
break;
}
if (release['prerelease']) {
continue;
}
releases.update(
'body',
(value) =>
value +
'\n' +
'# ' +
response.data[i]['tag_name'] +
'\n' +
response.data[i]['body'],
);
buffer.writeln(release['body']);
TheAabedKhan marked this conversation as resolved.
Show resolved Hide resolved
}
return releases;
return buffer.toString();
} on Exception catch (e) {
if (kDebugMode) {
print(e);
Expand Down
24 changes: 13 additions & 11 deletions lib/ui/views/home/home_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class HomeViewModel extends BaseViewModel {
List<PatchedApplication> patchedInstalledApps = [];
String _currentManagerVersion = '';
String _currentPatchesVersion = '';
String? _latestManagerVersion = '';
String? latestManagerVersion;
String? latestPatchesVersion;
File? downloadedApk;

Future<void> initialize(BuildContext context) async {
Expand All @@ -50,7 +51,6 @@ class HomeViewModel extends BaseViewModel {
await forceRefresh(context);
return;
}
_latestManagerVersion = await _managerAPI.getLatestManagerVersion();
_currentPatchesVersion = await _managerAPI.getCurrentPatchesVersion();
if (_managerAPI.showUpdateDialog() && await hasManagerUpdates()) {
showUpdateDialog(context, false);
Expand Down Expand Up @@ -131,21 +131,21 @@ class HomeViewModel extends BaseViewModel {
if (!_managerAPI.releaseBuild) {
return false;
}
_latestManagerVersion =
latestManagerVersion =
await _managerAPI.getLatestManagerVersion() ?? _currentManagerVersion;

if (_latestManagerVersion != _currentManagerVersion) {
if (latestManagerVersion != _currentManagerVersion) {
return true;
}
return false;
}

Future<bool> hasPatchesUpdates() async {
final String? latestVersion = await _managerAPI.getLatestPatchesVersion();
if (latestVersion != null) {
latestPatchesVersion = await _managerAPI.getLatestPatchesVersion();
if (latestPatchesVersion != null) {
try {
final int latestVersionInt =
int.parse(latestVersion.replaceAll(RegExp('[^0-9]'), ''));
int.parse(latestPatchesVersion!.replaceAll(RegExp('[^0-9]'), ''));
final int currentVersionInt =
int.parse(_currentPatchesVersion.replaceAll(RegExp('[^0-9]'), ''));
return latestVersionInt > currentVersionInt;
Expand Down Expand Up @@ -475,12 +475,14 @@ class HomeViewModel extends BaseViewModel {
);
}

Future<Map<String, dynamic>?> getLatestManagerRelease() {
return _githubAPI.getLatestManagerRelease(_managerAPI.defaultManagerRepo);
Future<String?> getManagerChangelogs() {
return _githubAPI.getManagerChangelogs();
}

Future<Map<String, dynamic>?> getLatestPatchesRelease() {
return _githubAPI.getLatestRelease(_managerAPI.defaultPatchesRepo);
Future<String?> getLatestPatchesChangelog() async {
final release =
await _githubAPI.getLatestRelease(_managerAPI.defaultPatchesRepo);
return release?['body'];
}

Future<String?> getLatestPatchesReleaseTime() {
Expand Down
176 changes: 88 additions & 88 deletions lib/ui/widgets/homeView/update_confirmation_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class UpdateConfirmationSheet extends StatelessWidget {

final bool isPatches;
final bool changelog;

@override
Widget build(BuildContext context) {
final HomeViewModel model = locator<HomeViewModel>();
Expand All @@ -25,100 +26,99 @@ class UpdateConfirmationSheet extends StatelessWidget {
builder: (_, scrollController) => SingleChildScrollView(
controller: scrollController,
child: SafeArea(
child: FutureBuilder<Map<String, dynamic>?>(
future: !isPatches
? model.getLatestManagerRelease()
: model.getLatestPatchesRelease(),
builder: (_, snapshot) {
if (!snapshot.hasData) {
return const SizedBox(
height: 300,
child: Center(
child: CircularProgressIndicator(),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (!changelog)
Padding(
padding: const EdgeInsets.only(
top: 40.0,
left: 24.0,
right: 24.0,
bottom: 20.0,
),
);
}

return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (!changelog)
Padding(
padding: const EdgeInsets.only(
top: 40.0,
left: 24.0,
right: 24.0,
bottom: 20.0,
),
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
isPatches
? t.homeView.updatePatchesSheetTitle
: t.homeView.updateSheetTitle,
style: const TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 4.0),
Row(
children: [
Icon(
Icons.new_releases_outlined,
color:
Theme.of(context).colorScheme.secondary,
),
const SizedBox(width: 8.0),
Text(
isPatches
? t.homeView.updatePatchesSheetTitle
: t.homeView.updateSheetTitle,
style: const TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
? model.latestPatchesVersion ?? 'Unknown'
: model.latestManagerVersion ?? 'Unknown',
style: TextStyle(
fontSize: 20,
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),
),
],
],
),
),
),
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,
FilledButton(
onPressed: () {
Navigator.of(context).pop();
isPatches
? model.updatePatches(context)
: model.updateManager(context);
},
child: Text(t.updateButton),
),
),
],
),
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),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.secondaryContainer,
Expand All @@ -139,12 +139,12 @@ class UpdateConfirmationSheet extends StatelessWidget {
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
padding: const EdgeInsets.all(20.0),
data: snapshot.data!['body'] ?? '',
data: snapshot.data ?? '',
),
),
],
);
},
);
},
),
],
),
),
),
Expand Down