-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create release repository to manage new release version
- Loading branch information
Showing
11 changed files
with
108 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export 'new_release.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
|
||
part 'new_release.freezed.dart'; | ||
|
||
@freezed | ||
class NewRelease with _$NewRelease { | ||
const factory NewRelease({ | ||
required String version, | ||
required String downloadUrl, | ||
}) = _NewRelease; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import 'package:appcenter_companion/repositories/github_repository.dart'; | ||
import 'package:package_info_plus/package_info_plus.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
import 'package:version/version.dart'; | ||
|
||
import 'models/new_release.dart'; | ||
|
||
class ReleaseRepository { | ||
ReleaseRepository({ | ||
required GitHubRepository githubRepository, | ||
}) : _githubRepository = githubRepository; | ||
|
||
final GitHubRepository _githubRepository; | ||
|
||
Future<SharedPreferences> get _sharedPreferences => | ||
SharedPreferences.getInstance(); | ||
|
||
Future<List<String>> get _ignoredVersions => _sharedPreferences | ||
.then((prefs) => prefs.getStringList(_keyIgnoredVersions) ?? []); | ||
|
||
Future<bool> _setIgnoredVersions(List<String> ignoredVersions) => | ||
_sharedPreferences.then( | ||
(prefs) => prefs.setStringList(_keyIgnoredVersions, ignoredVersions), | ||
); | ||
|
||
final _keyIgnoredVersions = 'ignoredVersions'; | ||
|
||
Future<NewRelease?> newVersionAvailable() async { | ||
final latestRelease = await _githubRepository.getLatestRelease(); | ||
final latestVersion = Version.parse(latestRelease.tagName); | ||
final ignoredVersions = await _ignoredVersions; | ||
|
||
if (ignoredVersions.contains(latestVersion.toString())) { | ||
return null; | ||
} | ||
|
||
final packageInfo = await PackageInfo.fromPlatform(); | ||
final currentVersion = | ||
Version.parse('${packageInfo.version}+${packageInfo.buildNumber}'); | ||
if (currentVersion.compareTo(latestVersion) < 0) { | ||
return NewRelease( | ||
version: latestVersion.toString(), | ||
downloadUrl: latestRelease.htmlUrl, | ||
); | ||
} | ||
return null; | ||
} | ||
|
||
Future<void> ignoreRelease({ | ||
bool ignored = true, | ||
required String version, | ||
}) async { | ||
final ignoredVersions = await _ignoredVersions; | ||
if (ignored && !ignoredVersions.contains(version)) { | ||
ignoredVersions.add(version); | ||
} | ||
if (!ignored && ignoredVersions.contains(version)) { | ||
ignoredVersions.remove(version); | ||
} | ||
await _setIgnoredVersions(ignoredVersions); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters