Skip to content

Commit

Permalink
Added support for different versionCodes for different ABIs for the s…
Browse files Browse the repository at this point in the history
…ame versionName
  • Loading branch information
redsolver committed May 4, 2021
1 parent 7a1e1be commit d4cef7d
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 15 deletions.
13 changes: 9 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ Future<void> main() async {
// if (Platform.isAndroid) {
final deviceInfo = DeviceInfoPlugin();

unawaited(deviceInfo.androidInfo.then((value) => androidInfo = value));
/* unawaited( */

androidInfo = await deviceInfo.androidInfo;

// }

runApp(
Expand Down Expand Up @@ -636,7 +639,8 @@ class _MyHomePageState extends State<MyHomePage> {
}

if (localVersionCodes.containsKey(a.packageName)) {
if (a.currentVersionCode > localVersionCodes.get(a.packageName)) {
if (a.currentVersionCodeForDeviceArchitecture >
localVersionCodes.get(a.packageName)) {
updateKeys.add(key);
continue;
} else {
Expand Down Expand Up @@ -1203,7 +1207,7 @@ class _MyHomePageState extends State<MyHomePage> {

if (snap.data
.versionCode <
app.currentVersionCode) {
app.currentVersionCodeForDeviceArchitecture) {
return Container(
color: Colors
.orange,
Expand Down Expand Up @@ -1585,6 +1589,7 @@ class _MyHomePageState extends State<MyHomePage> {
},
),
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
currentIndex: currentPage,
selectedItemColor: Theme.of(context).accentColor,
onTap: (index) {
Expand Down Expand Up @@ -1648,7 +1653,7 @@ class _MyHomePageState extends State<MyHomePage> {
await task.init();

if ((task?.installedApplication?.versionCode ?? 0) >=
app.currentVersionCode) {
app.currentVersionCodeForDeviceArchitecture) {
print('skip $name');
task.dispose();
continue;
Expand Down
32 changes: 32 additions & 0 deletions lib/model/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,19 @@ class App {
@HiveField(13)
int currentVersionCode;

Build getCurrentBuild() {
return builds.firstWhere(
(element) => /* element.versionName == currentVersionName || */
element.versionCode == currentVersionCode,
orElse: () => null,
);
}

int get currentVersionCodeForDeviceArchitecture {
final currentBuild = getCurrentBuild();
return currentBuild.versionCodeForDeviceArchitecture ?? currentVersionCode;
}

@HiveField(14)
int added;
@HiveField(15)
Expand Down Expand Up @@ -188,6 +201,20 @@ class Build {
@HiveField(11)
Map<String, ABISpecificBuild> abis;

int get versionCodeForDeviceArchitecture {
if (abis != null) {
for (final abi in androidInfo.supportedAbis) {
if (abis.containsKey(abi)) {
final vCode = abis[abi].versionCode;
if (vCode != null) {
return vCode;
}
}
}
}
return versionCode;
}

// TODO Show some more of this info on the app page

@HiveField(5)
Expand Down Expand Up @@ -224,6 +251,11 @@ class ABISpecificBuild {
@HiveField(2)
String sha256;

@HiveField(3)
String versionName;
@HiveField(4)
int versionCode;

ABISpecificBuild();

factory ABISpecificBuild.fromJson(Map<dynamic, dynamic> json) =>
Expand Down
18 changes: 14 additions & 4 deletions lib/model/app.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/page/widget/install.dart
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class _InstallWidgetState extends State<InstallWidget>
width: 8,
),
task.installedApplication.versionCode >=
app.currentVersionCode
app.currentVersionCodeForDeviceArchitecture
? Expanded(
child: RaisedButton(
color: Theme.of(context).accentColor,
Expand Down
8 changes: 2 additions & 6 deletions lib/util/install_task.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ class InstallTask {
}

Future<void> init() async {
currentBuild = app.builds.firstWhere(
(element) => element.versionCode == app.currentVersionCode,
orElse: () => null,
);
currentBuild = app.getCurrentBuild();

final deviceInfo = DeviceInfoPlugin();
final androidInfo = await deviceInfo.androidInfo;
Expand Down Expand Up @@ -305,7 +302,7 @@ class InstallTask {
Future<void> install(/* File apk, int versionCode */) async {
if (downloadedApk == null) throw 'APK not downloaded';

final versionCode = currentBuild.versionCode;
final versionCode = currentBuild.versionCodeForDeviceArchitecture;

if (isShizukuEnabled) {
void showShizukuErrorDialog(Widget content, String text) {
Expand Down Expand Up @@ -359,7 +356,6 @@ class InstallTask {
/* setState(() {
progress = 1;
state = InstallState.none;
expectedVersionCode = versionCode;
}); */

final result = await platform.invokeMethod(
Expand Down

0 comments on commit d4cef7d

Please sign in to comment.