Skip to content

Commit

Permalink
feat: allow selecting installed if app is full apk
Browse files Browse the repository at this point in the history
  • Loading branch information
Ushie committed May 13, 2023
1 parent 359f052 commit 8fc86db
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion assets/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"errorMessage": "Unable to use selected application",
"downloadToast": "Download function is not available yet",
"featureNotAvailable": "Feature not implemented",
"featureNotAvailableText": "This feature has not been added yet for non-root. You'll need to select APK files from storage for now."
"featureNotAvailableText": "This application is a split APK and cannot be selected. Unfortunately, this feature is only available for rooted users at the moment. However, you can still install the application by selecting its APK files from your device's storage instead"
},
"patchesSelectorView": {
"viewTitle": "Select patches",
Expand Down
11 changes: 1 addition & 10 deletions lib/ui/views/app_selector/app_selector_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,7 @@ class _AppSelectorViewState extends State<AppSelectorView> {
model.getSuggestedVersion(
app.packageName,
),
onTap: () {
model.isRooted
? model.selectApp(app).then(
(_) => Navigator.of(context)
.pop(),
)
: model.showSelectFromStorageDialog(
context,
);
},
onTap: () => model.canSelectInstalled(context, app.packageName),
),
)
.toList(),
Expand Down
24 changes: 24 additions & 0 deletions lib/ui/views/app_selector/app_selector_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ class AppSelectorViewModel extends BaseViewModel {
return _patcherAPI.getSuggestedVersion(packageName);
}

Future<bool> checkSplitApk(String packageName) async {
final app = await DeviceApps.getApp(packageName);
if (app != null) {
return app.isSplit;
}
return true;
}

Future<void> selectApp(ApplicationWithIcon application) async {
locator<PatcherViewModel>().selectedApp = PatchedApplication(
name: application.appName,
Expand All @@ -78,6 +86,22 @@ class AppSelectorViewModel extends BaseViewModel {
locator<PatcherViewModel>().loadLastSelectedPatches();
}

Future<void> canSelectInstalled(
BuildContext context,
String packageName,
) async {
final app =
await DeviceApps.getApp(packageName, true) as ApplicationWithIcon?;
if (app != null) {
if (await checkSplitApk(packageName) && !isRooted) {
return showSelectFromStorageDialog(context);
} else if (!await checkSplitApk(packageName) || isRooted) {
selectApp(app);
Navigator.pop(context);
}
}
}

Future showSelectFromStorageDialog(BuildContext context) async {
return showDialog(
context: context,
Expand Down

0 comments on commit 8fc86db

Please sign in to comment.