Skip to content

Commit

Permalink
Better update process
Browse files Browse the repository at this point in the history
  • Loading branch information
blopker committed Nov 3, 2024
1 parent f657b1e commit 85b6f03
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/strings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ class Strings {
static const downloadURL =
'https://github.com/blopker/alic/releases/latest/download/Alic.Image.Compressor.dmg';
static const githubAPI =
'https://api.github.com/repos/blopker/alic/tags?per_page=10';
'https://api.github.com/repos/blopker/alic/releases/latest';
static const repoURL = 'https://github.com/blopker/alic/';
}
11 changes: 6 additions & 5 deletions lib/update.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ class Update {
}

Future<Update> getLatestBuildNumber() async {
final uri = Uri.parse(Strings.githubAPI);
var url = Strings.githubAPI;
final uri = Uri.parse(url);
final response =
await http.get(uri, headers: {"Accept": "application/vnd.github+json"});

// log.d('Response: ${response.body}');
if (response.statusCode == 200) {
final List decodedData = jsonDecode(response.body);
final tags = decodedData.map((e) => e['name'].toString()).toList();
final latestBuild = tags.firstWhere((element) => element.contains('+'));
final Map<String, dynamic> decodedData = jsonDecode(response.body);
final latestBuild = decodedData['tag_name'];
final buildNumber = int.parse(latestBuild.split('+').last);
log.d('Latest build: $latestBuild, build number: $buildNumber');
return Update(
version: latestBuild,
buildNumber: buildNumber,
Expand Down

0 comments on commit 85b6f03

Please sign in to comment.