diff --git a/lib/services/github_api.dart b/lib/services/github_api.dart index 0c0080b9e6..0d68637ff3 100644 --- a/lib/services/github_api.dart +++ b/lib/services/github_api.dart @@ -23,39 +23,6 @@ class GithubAPI { Future?> getLatestRelease( String repoName, - ) async { - try { - final response = await _dio.get( - '/repos/$repoName/releases', - ); - return response.data[0]; - } on Exception catch (e) { - if (kDebugMode) { - print(e); - } - return null; - } - } - - Future?> getPatchesRelease( - String repoName, - String version, - ) async { - try { - final response = await _dio.get( - '/repos/$repoName/releases/tags/$version', - ); - return response.data; - } on Exception catch (e) { - if (kDebugMode) { - print(e); - } - return null; - } - } - - Future?> getLatestPatchesRelease( - String repoName, ) async { try { final response = await _dio.get( @@ -108,32 +75,7 @@ class GithubAPI { } } - Future getLatestReleaseFile( - String extension, - String repoName, - ) async { - try { - final Map? release = await getLatestRelease(repoName); - if (release != null) { - final Map? asset = - (release['assets'] as List).firstWhereOrNull( - (asset) => (asset['name'] as String).endsWith(extension), - ); - if (asset != null) { - return await _downloadManager.getSingleFile( - asset['browser_download_url'], - ); - } - } - } on Exception catch (e) { - if (kDebugMode) { - print(e); - } - } - return null; - } - - Future getPatchesReleaseFile( + Future getReleaseFile( String extension, String repoName, String version, @@ -145,8 +87,10 @@ class GithubAPI { url, ); } - final Map? release = - await getPatchesRelease(repoName, version); + final response = await _dio.get( + '/repos/$repoName/releases/tags/$version', + ); + final Map? release = response.data; if (release != null) { final Map? asset = (release['assets'] as List).firstWhereOrNull( diff --git a/lib/services/manager_api.dart b/lib/services/manager_api.dart index 8851858724..ce146a6433 100644 --- a/lib/services/manager_api.dart +++ b/lib/services/manager_api.dart @@ -422,7 +422,7 @@ class ManagerAPI { final String repoName = !isUsingAlternativeSources() ? defaultPatchesRepo : getPatchesRepo(); final String currentVersion = await getCurrentPatchesVersion(); final String url = getPatchesDownloadURL(); - return await _githubAPI.getPatchesReleaseFile( + return await _githubAPI.getReleaseFile( '.jar', repoName, currentVersion, @@ -441,7 +441,7 @@ class ManagerAPI { final String repoName = !isUsingAlternativeSources() ? defaultIntegrationsRepo : getIntegrationsRepo(); final String currentVersion = await getCurrentIntegrationsVersion(); final String url = getIntegrationsDownloadURL(); - return await _githubAPI.getPatchesReleaseFile( + return await _githubAPI.getReleaseFile( '.apk', repoName, currentVersion, @@ -470,7 +470,7 @@ class ManagerAPI { ); } else { final release = - await _githubAPI.getLatestPatchesRelease(getPatchesRepo()); + await _githubAPI.getLatestRelease(getPatchesRepo()); if (release != null) { final DateTime timestamp = DateTime.parse(release['created_at'] as String); @@ -519,7 +519,7 @@ class ManagerAPI { ); } else { final release = - await _githubAPI.getLatestPatchesRelease(getPatchesRepo()); + await _githubAPI.getLatestRelease(getPatchesRepo()); if (release != null) { return release['tag_name']; } else { diff --git a/lib/ui/views/home/home_viewmodel.dart b/lib/ui/views/home/home_viewmodel.dart index 3327c42b4b..2d33ed26a1 100644 --- a/lib/ui/views/home/home_viewmodel.dart +++ b/lib/ui/views/home/home_viewmodel.dart @@ -480,7 +480,7 @@ class HomeViewModel extends BaseViewModel { } Future?> getLatestPatchesRelease() { - return _githubAPI.getLatestPatchesRelease(_managerAPI.defaultPatchesRepo); + return _githubAPI.getLatestRelease(_managerAPI.defaultPatchesRepo); } Future getLatestPatchesReleaseTime() {