Less restrictive install permission requests (#488)

This commit is contained in:
Imran Remtulla
2023-04-30 00:02:23 -04:00
parent 392554123b
commit 81f66683d2
4 changed files with 10 additions and 12 deletions

View File

@@ -124,9 +124,6 @@ class _AddAppPageState extends State<AddAppPage> {
pickedSource!, userInput, additionalSettings, pickedSource!, userInput, additionalSettings,
trackOnlyOverride: trackOnly, trackOnlyOverride: trackOnly,
overrideSource: pickedSourceOverride); overrideSource: pickedSourceOverride);
if (!trackOnly) {
await settingsProvider.getInstallPermission();
}
// Only download the APK here if you need to for the package ID // Only download the APK here if you need to for the package ID
if (sourceProvider.isTempId(app) && if (sourceProvider.isTempId(app) &&
app.additionalSettings['trackOnly'] != true) { app.additionalSettings['trackOnly'] != true) {

View File

@@ -327,9 +327,6 @@ class _AppPageState extends State<AppPage> {
? () async { ? () async {
try { try {
HapticFeedback.heavyImpact(); HapticFeedback.heavyImpact();
if (app?.app.additionalSettings['trackOnly'] != true) {
await settingsProvider.getInstallPermission();
}
var res = await appsProvider.downloadAndInstallLatestApps( var res = await appsProvider.downloadAndInstallLatestApps(
[app!.app.id], globalNavigatorKey.currentContext); [app!.app.id], globalNavigatorKey.currentContext);
if (res.isNotEmpty && mounted) { if (res.isNotEmpty && mounted) {

View File

@@ -624,11 +624,6 @@ class AppsPageState extends State<AppsPage> {
bool shouldInstallNew = values['installs'] == true; bool shouldInstallNew = values['installs'] == true;
bool shouldMarkTrackOnlies = values['trackonlies'] == true; bool shouldMarkTrackOnlies = values['trackonlies'] == true;
(() async { (() async {
if (shouldInstallNew || shouldInstallUpdates) {
await settingsProvider.getInstallPermission();
}
})()
.then((_) {
List<String> toInstall = []; List<String> toInstall = [];
if (shouldInstallUpdates) { if (shouldInstallUpdates) {
toInstall.addAll(existingUpdateIdsAllOrSelected); toInstall.addAll(existingUpdateIdsAllOrSelected);
@@ -639,6 +634,12 @@ class AppsPageState extends State<AppsPage> {
if (shouldMarkTrackOnlies) { if (shouldMarkTrackOnlies) {
toInstall.addAll(trackOnlyUpdateIdsAllOrSelected); toInstall.addAll(trackOnlyUpdateIdsAllOrSelected);
} }
if (toInstall.length > 1) {
// Permission is requested automatically, but if there are more than 1 installs,
// We want to explicitly request it and wait for the result to avoid multiple requests
await settingsProvider.getInstallPermission(
enforce: false);
}
appsProvider appsProvider
.downloadAndInstallLatestApps( .downloadAndInstallLatestApps(
toInstall, globalNavigatorKey.currentContext) toInstall, globalNavigatorKey.currentContext)

View File

@@ -120,7 +120,7 @@ class SettingsProvider with ChangeNotifier {
return result; return result;
} }
Future<void> getInstallPermission() async { Future<void> getInstallPermission({bool enforce = false}) async {
while (!(await Permission.requestInstallPackages.isGranted)) { while (!(await Permission.requestInstallPackages.isGranted)) {
// Explicit request as InstallPlugin request sometimes bugged // Explicit request as InstallPlugin request sometimes bugged
Fluttertoast.showToast( Fluttertoast.showToast(
@@ -129,6 +129,9 @@ class SettingsProvider with ChangeNotifier {
PermissionStatus.granted) { PermissionStatus.granted) {
break; break;
} }
if (!enforce) {
break;
}
} }
} }