Skip to content

Commit

Permalink
Rename isLatestRelease method
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamKarolDiCioccio committed Jun 21, 2024
1 parent 9ea1698 commit 1ef434b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
4 changes: 2 additions & 2 deletions app/lib/dialogs/update.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class _UpdateDialogState extends State<UpdateDialog> {
}

Future<void> _checkForUpdates() async {
bool isLatestVersion = await UpdateHelper.isLatestVersion();
bool isUpdateAvailable = await UpdateHelper.isUpdateAvailable();
setState(() {
_isUpdateAvailable = !isLatestVersion;
_isUpdateAvailable = isUpdateAvailable;
_isLoading = false;
});
}
Expand Down
25 changes: 19 additions & 6 deletions app/lib/helpers/update.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,20 @@ import 'package:shared_preferences/shared_preferences.dart';
class UpdateHelper {
static late GitHubRelease _latestRelease;

static Future<bool> isLatestVersion() async {
static bool _isVersionSuperior(String version) {
final currentVersion = Env.version.split('.').map(int.parse).toList();
final newVersion = version.split('.').map(int.parse).toList();

for (var i = 0; i < currentVersion.length; i++) {
if (currentVersion[i] < newVersion[i]) {
return true;
}
}

return false;
}

static Future<bool> isUpdateAvailable() async {
if (!Platform.isWindows) {
throw UnimplementedError('Platform not supported');
}
Expand All @@ -27,21 +40,21 @@ class UpdateHelper {

if (prefs.getString('skipUpdate') == _latestRelease.tag_name) {
logger.i('Skipping update: ${_latestRelease.tag_name}');
return true;
} else if (_latestRelease.tag_name == Env.version) {
return false;
} else if (!_isVersionSuperior(_latestRelease.tag_name)) {
logger.i('No new version available');
return true;
return false;
}

logger.i('New version available: ${_latestRelease.tag_name}');

for (final asset in _latestRelease.assets) {
if (Platform.isWindows && asset.name.contains('windows_x64')) {
return false;
return true;
}
}

return true;
return false;
}

static Future downloadAndInstallLatestVersion() async {
Expand Down
6 changes: 3 additions & 3 deletions app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ class _MyAppState extends State<MyApp> {
}

void _checkForUpdates() {
UpdateHelper.isLatestVersion().then(
(isLatestVersion) {
if (!isLatestVersion) {
UpdateHelper.isUpdateAvailable().then(
(updateAvailable) {
if (updateAvailable) {
SnackBarHelpers.showSnackBar(
AppLocalizations.of(scaffoldMessengerKey.currentState!.context)
.snackBarUpdateTitle,
Expand Down

0 comments on commit 1ef434b

Please sign in to comment.