mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-08-01 05:10:15 +02:00
Move to plugins🐱🎉
This commit is contained in:
@@ -12,6 +12,7 @@ import 'package:obtainium/providers/settings_provider.dart';
|
||||
import 'package:obtainium/providers/source_provider.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
import 'package:shizuku_apk_installer/shizuku_apk_installer.dart';
|
||||
import 'package:url_launcher/url_launcher_string.dart';
|
||||
|
||||
class SettingsPage extends StatefulWidget {
|
||||
@@ -402,12 +403,17 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
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);
|
||||
ShizukuApkInstaller.checkPermission().then((resCode) {
|
||||
settingsProvider.useShizuku = resCode!.startsWith('granted');
|
||||
switch(resCode){
|
||||
case 'binder_not_found':
|
||||
showError(ObtainiumError(tr('shizukuBinderNotFound')), context);
|
||||
case 'old_shizuku':
|
||||
showError(ObtainiumError(tr('shizukuOld')), context);
|
||||
case 'old_android_with_adb':
|
||||
showError(ObtainiumError(tr('shizukuOldAndroidWithADB')), context);
|
||||
case 'denied':
|
||||
showError(ObtainiumError(tr('cancelled')), context);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@@ -416,6 +422,24 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
})
|
||||
],
|
||||
),
|
||||
if (settingsProvider.useShizuku)
|
||||
Column(
|
||||
children: [
|
||||
height16,
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Flexible(
|
||||
child: Text(tr('shizukuPretendToBeGooglePlay'))),
|
||||
Switch(
|
||||
value: settingsProvider.pretendToBeGooglePlay,
|
||||
onChanged: (value) {
|
||||
settingsProvider.pretendToBeGooglePlay = value;
|
||||
})
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
height32,
|
||||
Text(
|
||||
tr('sourceSpecific'),
|
||||
@@ -459,25 +483,35 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
),
|
||||
height16,
|
||||
localeDropdown,
|
||||
height16,
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Flexible(child: Text(tr('useSystemFont'))),
|
||||
Switch(
|
||||
value: settingsProvider.useSystemFont,
|
||||
onChanged: (useSystemFont) {
|
||||
if (useSystemFont) {
|
||||
NativeFeatures.loadSystemFont()
|
||||
.then((val) {
|
||||
settingsProvider.useSystemFont = true;
|
||||
});
|
||||
} else {
|
||||
settingsProvider.useSystemFont = false;
|
||||
}
|
||||
})
|
||||
],
|
||||
),
|
||||
FutureBuilder(
|
||||
builder: (ctx, val) {
|
||||
return (val.data?.version.sdkInt ?? 0) >= 34
|
||||
? Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
height16,
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Flexible(child: Text(tr('useSystemFont'))),
|
||||
Switch(
|
||||
value: settingsProvider.useSystemFont,
|
||||
onChanged: (useSystemFont) {
|
||||
if (useSystemFont) {
|
||||
NativeFeatures.loadSystemFont().then((val) {
|
||||
settingsProvider.useSystemFont = true;
|
||||
});
|
||||
} else {
|
||||
settingsProvider.useSystemFont = false;
|
||||
}
|
||||
})
|
||||
]
|
||||
)
|
||||
]
|
||||
)
|
||||
: const SizedBox.shrink();
|
||||
},
|
||||
future: DeviceInfoPlugin().androidInfo),
|
||||
height16,
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
|
@@ -34,7 +34,7 @@ import 'package:android_intent_plus/android_intent.dart';
|
||||
import 'package:flutter_archive/flutter_archive.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
import 'package:shared_storage/shared_storage.dart' as saf;
|
||||
import 'native_provider.dart';
|
||||
import 'package:shizuku_apk_installer/shizuku_apk_installer.dart';
|
||||
|
||||
final pm = AndroidPackageManager();
|
||||
|
||||
@@ -634,7 +634,7 @@ class AppsProvider with ChangeNotifier {
|
||||
!(await canDowngradeApps())) {
|
||||
throw DowngradeError();
|
||||
}
|
||||
if (needsBGWorkaround) {
|
||||
if (needsBGWorkaround && !settingsProvider.useShizuku) {
|
||||
// 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
|
||||
@@ -647,13 +647,10 @@ class AppsProvider with ChangeNotifier {
|
||||
}
|
||||
int? code;
|
||||
if (!settingsProvider.useShizuku) {
|
||||
code = await AndroidPackageInstaller.installApk(
|
||||
apkFilePath: file.file.path);
|
||||
code = await AndroidPackageInstaller.installApk(apkFilePath: file.file.path);
|
||||
} else {
|
||||
code = (await NativeFeatures.installWithShizuku(
|
||||
apkFileUri: file.file.uri.toString()))
|
||||
? 0
|
||||
: 1;
|
||||
code = await ShizukuApkInstaller.installAPK(file.file.uri.toString(),
|
||||
settingsProvider.pretendToBeGooglePlay ? "com.android.vending" : "");
|
||||
}
|
||||
bool installed = false;
|
||||
if (code != null && code != 0 && code != 3) {
|
||||
@@ -828,11 +825,16 @@ class AppsProvider with ChangeNotifier {
|
||||
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'));
|
||||
String? code = await ShizukuApkInstaller.checkPermission();
|
||||
switch(code!){
|
||||
case 'binder_not_found':
|
||||
throw ObtainiumError(tr('shizukuBinderNotFound'));
|
||||
case 'old_shizuku':
|
||||
throw ObtainiumError(tr('shizukuOld'));
|
||||
case 'old_android_with_adb':
|
||||
throw ObtainiumError(tr('shizukuOldAndroidWithADB'));
|
||||
case 'denied':
|
||||
throw ObtainiumError(tr('cancelled'));
|
||||
}
|
||||
}
|
||||
if (!willBeSilent && context != null && !settingsProvider.useShizuku) {
|
||||
|
@@ -4,36 +4,13 @@ import 'package:android_system_font/android_system_font.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class NativeFeatures {
|
||||
static const MethodChannel _channel = MethodChannel('native');
|
||||
static bool _systemFontLoaded = false;
|
||||
static bool _callbacksApplied = false;
|
||||
static int _resPermShizuku = -2; // not set
|
||||
|
||||
static Future<ByteData> _readFileBytes(String path) async {
|
||||
var bytes = await File(path).readAsBytes();
|
||||
return ByteData.view(bytes.buffer);
|
||||
}
|
||||
|
||||
static Future _handleCalls(MethodCall call) async {
|
||||
if (call.method == 'resPermShizuku') {
|
||||
_resPermShizuku = call.arguments['res'];
|
||||
}
|
||||
}
|
||||
|
||||
static Future _waitWhile(bool Function() test,
|
||||
[Duration pollInterval = const Duration(milliseconds: 250)]) {
|
||||
var completer = Completer();
|
||||
check() {
|
||||
if (test()) {
|
||||
Timer(pollInterval, check);
|
||||
} else {
|
||||
completer.complete();
|
||||
}
|
||||
}
|
||||
check();
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
static Future loadSystemFont() async {
|
||||
if (_systemFontLoaded) return;
|
||||
var fontLoader = FontLoader('SystemFont');
|
||||
@@ -42,23 +19,4 @@ class NativeFeatures {
|
||||
fontLoader.load();
|
||||
_systemFontLoaded = true;
|
||||
}
|
||||
|
||||
static Future<int> checkPermissionShizuku() async {
|
||||
if (!_callbacksApplied) {
|
||||
_channel.setMethodCallHandler(_handleCalls);
|
||||
_callbacksApplied = true;
|
||||
}
|
||||
int res = await _channel.invokeMethod('checkPermissionShizuku');
|
||||
if (res == -2) {
|
||||
await _waitWhile(() => _resPermShizuku == -2);
|
||||
res = _resPermShizuku;
|
||||
_resPermShizuku = -2;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static Future<bool> installWithShizuku({required String apkFileUri}) async {
|
||||
return await _channel.invokeMethod(
|
||||
'installWithShizuku', {'apkFileUri': apkFileUri});
|
||||
}
|
||||
}
|
||||
|
@@ -82,6 +82,15 @@ class SettingsProvider with ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
bool get pretendToBeGooglePlay{
|
||||
return prefs?.getBool('pretendToBeGooglePlay') ?? false;
|
||||
}
|
||||
|
||||
set pretendToBeGooglePlay(bool pretendToBeGooglePlay) {
|
||||
prefs?.setBool('pretendToBeGooglePlay', pretendToBeGooglePlay);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
ThemeSettings get theme {
|
||||
return ThemeSettings
|
||||
.values[prefs?.getInt('theme') ?? ThemeSettings.system.index];
|
||||
|
Reference in New Issue
Block a user