Probably fixed

This commit is contained in:
Gregory
2024-02-05 18:26:17 +03:00
parent 9d76359543
commit 9717db0ca4
8 changed files with 57 additions and 109 deletions

View File

@@ -30,29 +30,6 @@ class _SettingsPageState extends State<SettingsPage> {
settingsProvider.initializeSettings();
}
var installMethodDropdown = DropdownButtonFormField(
decoration: InputDecoration(labelText: tr('installMethod')),
value: settingsProvider.installMethod,
items: [
DropdownMenuItem(
value: InstallMethodSettings.normal,
child: Text(tr('normal')),
),
const DropdownMenuItem(
value: InstallMethodSettings.shizuku,
child: Text('Shizuku'),
),
DropdownMenuItem(
value: InstallMethodSettings.root,
child: Text(tr('root')),
)
],
onChanged: (value) {
if (value != null) {
settingsProvider.installMethod = value;
}
});
var themeDropdown = DropdownButtonFormField(
decoration: InputDecoration(labelText: tr('theme')),
value: settingsProvider.theme,
@@ -363,7 +340,29 @@ class _SettingsPageState extends State<SettingsPage> {
})
],
),
installMethodDropdown,
height16,
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(child: Text(tr('useShizuku'))),
Switch(
value: settingsProvider.useShizuku,
onChanged: (useShizuku) {
if (useShizuku) {
NativeFeatures.checkPermissionShizuku().then((resCode) {
settingsProvider.useShizuku = resCode == 1;
if (resCode == 0) {
showError(ObtainiumError(tr('cancelled')), context);
} else if (resCode == -1) {
showError(ObtainiumError(tr('shizukuBinderNotFound')), context);
}
});
} else {
settingsProvider.useShizuku = false;
}
})
],
),
height32,
Text(
tr('sourceSpecific'),

View File

@@ -547,8 +547,7 @@ class AppsProvider with ChangeNotifier {
!(await canDowngradeApps())) {
throw DowngradeError();
}
if (needsBGWorkaround &&
settingsProvider.installMethod == InstallMethodSettings.normal) {
if (needsBGWorkaround) {
// The below 'await' will never return if we are in a background process
// To work around this, we should assume the install will be successful
// So we update the app's installed version first as we will never get to the later code
@@ -560,20 +559,14 @@ class AppsProvider with ChangeNotifier {
attemptToCorrectInstallStatus: false);
}
int? code;
switch (settingsProvider.installMethod) {
case InstallMethodSettings.normal:
code = await AndroidPackageInstaller.installApk(
apkFilePath: file.file.path);
case InstallMethodSettings.shizuku:
code = (await NativeFeatures.installWithShizuku(
apkFileUri: file.file.uri.toString()))
? 0
: 1;
case InstallMethodSettings.root:
code =
(await NativeFeatures.installWithRoot(apkFilePath: file.file.path))
? 0
: 1;
if (!settingsProvider.useShizuku) {
code = await AndroidPackageInstaller.installApk(
apkFilePath: file.file.path);
} else {
code = (await NativeFeatures.installWithShizuku(
apkFileUri: file.file.uri.toString()))
? 0
: 1;
}
bool installed = false;
if (code != null && code != 0 && code != 3) {
@@ -732,25 +725,19 @@ class AppsProvider with ChangeNotifier {
}
var appId = downloadedFile?.appId ?? downloadedDir!.appId;
bool willBeSilent = await canInstallSilently(apps[appId]!.app);
switch (settingsProvider.installMethod) {
case InstallMethodSettings.normal:
if (!(await settingsProvider.getInstallPermission(
enforce: false))) {
throw ObtainiumError(tr('cancelled'));
}
case InstallMethodSettings.shizuku:
int code = await NativeFeatures.checkPermissionShizuku();
if (code == -1) {
throw ObtainiumError(tr('shizukuBinderNotFound'));
} else if (code == 0) {
throw ObtainiumError(tr('cancelled'));
}
case InstallMethodSettings.root:
if (!(await NativeFeatures.checkPermissionRoot())) {
throw ObtainiumError(tr('cancelled'));
}
if (!settingsProvider.useShizuku) {
if (!(await settingsProvider.getInstallPermission(enforce: false))) {
throw ObtainiumError(tr('cancelled'));
}
} else {
int code = await NativeFeatures.checkPermissionShizuku();
if (code == 0) {
throw ObtainiumError(tr('cancelled'));
} else if (code == -1) {
throw ObtainiumError(tr('shizukuBinderNotFound'));
}
}
if (!willBeSilent && context != null) {
if (!willBeSilent && context != null && !settingsProvider.useShizuku) {
// ignore: use_build_context_synchronously
await waitForUserToReturnToForeground(context);
}

View File

@@ -59,17 +59,8 @@ class NativeFeatures {
return res;
}
static Future<bool> checkPermissionRoot() async {
return await _channel.invokeMethod('checkPermissionRoot');
}
static Future<bool> installWithShizuku({required String apkFileUri}) async {
return await _channel.invokeMethod(
'installWithShizuku', {'apkFileUri': apkFileUri});
}
static Future<bool> installWithRoot({required String apkFilePath}) async {
return await _channel.invokeMethod(
'installWithRoot', {'apkFilePath': apkFilePath});
}
}

View File

@@ -18,8 +18,6 @@ String obtainiumTempId = 'imranr98_obtainium_${GitHub().hosts[0]}';
String obtainiumId = 'dev.imranr.obtainium';
String obtainiumUrl = 'https://github.com/ImranR98/Obtainium';
enum InstallMethodSettings { normal, shizuku, root }
enum ThemeSettings { system, light, dark }
enum ColourSettings { basic, materialYou }
@@ -61,13 +59,12 @@ class SettingsProvider with ChangeNotifier {
notifyListeners();
}
InstallMethodSettings get installMethod {
return InstallMethodSettings.values[
prefs?.getInt('installMethod') ?? InstallMethodSettings.normal.index];
bool get useShizuku{
return prefs?.getBool('useShizuku') ?? false;
}
set installMethod(InstallMethodSettings t) {
prefs?.setInt('installMethod', t.index);
set useShizuku(bool useShizuku) {
prefs?.setBool('useShizuku', useShizuku);
notifyListeners();
}