mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-08-19 13:09:30 +02:00
System font and newer dependencies
This commit is contained in:
@@ -5,6 +5,7 @@ import 'package:flutter/services.dart';
|
||||
import 'package:obtainium/pages/home.dart';
|
||||
import 'package:obtainium/providers/apps_provider.dart';
|
||||
import 'package:obtainium/providers/logs_provider.dart';
|
||||
import 'package:obtainium/providers/native_provider.dart';
|
||||
import 'package:obtainium/providers/notifications_provider.dart';
|
||||
import 'package:obtainium/providers/settings_provider.dart';
|
||||
import 'package:obtainium/providers/source_provider.dart';
|
||||
@@ -185,6 +186,16 @@ class _ObtainiumState extends State<Obtainium> {
|
||||
}
|
||||
existingUpdateInterval = actualUpdateInterval;
|
||||
}
|
||||
settingsProvider.addListener(() async {
|
||||
if (settingsProvider.tryUseSystemFont &&
|
||||
settingsProvider.appFont == "Metropolis") {
|
||||
bool fontLoaded = await NativeFeatures.tryLoadSystemFont();
|
||||
if (fontLoaded) { settingsProvider.appFont = "SystemFont"; }
|
||||
} else if (!settingsProvider.tryUseSystemFont &&
|
||||
settingsProvider.appFont != "Metropolis") {
|
||||
settingsProvider.appFont = "Metropolis";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return DynamicColorBuilder(
|
||||
@@ -221,13 +232,13 @@ class _ObtainiumState extends State<Obtainium> {
|
||||
colorScheme: settingsProvider.theme == ThemeSettings.dark
|
||||
? darkColorScheme
|
||||
: lightColorScheme,
|
||||
fontFamily: 'Metropolis'),
|
||||
fontFamily: settingsProvider.appFont),
|
||||
darkTheme: ThemeData(
|
||||
useMaterial3: true,
|
||||
colorScheme: settingsProvider.theme == ThemeSettings.light
|
||||
? lightColorScheme
|
||||
: darkColorScheme,
|
||||
fontFamily: 'Metropolis'),
|
||||
fontFamily: settingsProvider.appFont),
|
||||
home: Shortcuts(shortcuts: <LogicalKeySet, Intent>{
|
||||
LogicalKeySet(LogicalKeyboardKey.select): const ActivateIntent(),
|
||||
}, child: const HomePage()));
|
||||
|
@@ -351,8 +351,6 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
],
|
||||
),
|
||||
height16,
|
||||
installMethodDropdown,
|
||||
height16,
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
@@ -365,6 +363,7 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
})
|
||||
],
|
||||
),
|
||||
installMethodDropdown,
|
||||
height32,
|
||||
Text(
|
||||
tr('sourceSpecific'),
|
||||
@@ -409,6 +408,18 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
height16,
|
||||
localeDropdown,
|
||||
height16,
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Flexible(child: Text(tr('tryUseSystemFont'))),
|
||||
Switch(
|
||||
value: settingsProvider.tryUseSystemFont,
|
||||
onChanged: (value) {
|
||||
settingsProvider.tryUseSystemFont = value;
|
||||
})
|
||||
],
|
||||
),
|
||||
height16,
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
|
@@ -33,7 +33,7 @@ import 'package:http/http.dart';
|
||||
import 'package:android_intent_plus/android_intent.dart';
|
||||
import 'package:flutter_archive/flutter_archive.dart';
|
||||
import 'package:shared_storage/shared_storage.dart' as saf;
|
||||
import 'installers_provider.dart';
|
||||
import 'native_provider.dart';
|
||||
|
||||
final pm = AndroidPackageManager();
|
||||
|
||||
@@ -523,12 +523,12 @@ class AppsProvider with ChangeNotifier {
|
||||
code = await AndroidPackageInstaller.installApk(
|
||||
apkFilePath: file.file.path);
|
||||
case InstallMethodSettings.shizuku:
|
||||
code = (await Installers.installWithShizuku(
|
||||
code = (await NativeFeatures.installWithShizuku(
|
||||
apkFileUri: file.file.uri.toString()))
|
||||
? 0
|
||||
: 1;
|
||||
case InstallMethodSettings.root:
|
||||
code = (await Installers.installWithRoot(apkFilePath: file.file.path))
|
||||
code = (await NativeFeatures.installWithRoot(apkFilePath: file.file.path))
|
||||
? 0
|
||||
: 1;
|
||||
}
|
||||
@@ -694,14 +694,14 @@ class AppsProvider with ChangeNotifier {
|
||||
throw ObtainiumError(tr('cancelled'));
|
||||
}
|
||||
case InstallMethodSettings.shizuku:
|
||||
int code = await Installers.checkPermissionShizuku();
|
||||
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 Installers.checkPermissionRoot())) {
|
||||
if (!(await NativeFeatures.checkPermissionRoot())) {
|
||||
throw ObtainiumError(tr('cancelled'));
|
||||
}
|
||||
}
|
||||
|
@@ -1,12 +1,25 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class Installers {
|
||||
static const MethodChannel _channel = MethodChannel('installers');
|
||||
class NativeFeatures {
|
||||
static const MethodChannel _channel = MethodChannel('native');
|
||||
static bool _callbacksApplied = false;
|
||||
static int _resPermShizuku = -2; // not set
|
||||
|
||||
static Future waitWhile(bool Function() test,
|
||||
static Future<ByteData> _readFileBytes(String path) async {
|
||||
var file = File(path);
|
||||
var bytes = await file.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() {
|
||||
@@ -20,20 +33,23 @@ class Installers {
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
static Future handleCalls(MethodCall call) async {
|
||||
if (call.method == 'resPermShizuku') {
|
||||
_resPermShizuku = call.arguments['res'];
|
||||
}
|
||||
static Future<bool> tryLoadSystemFont() async {
|
||||
var font = await _channel.invokeMethod('getSystemFont');
|
||||
if (font == null) { return false; }
|
||||
var fontLoader = FontLoader('SystemFont');
|
||||
fontLoader.addFont(_readFileBytes(font));
|
||||
await fontLoader.load();
|
||||
return true;
|
||||
}
|
||||
|
||||
static Future<int> checkPermissionShizuku() async {
|
||||
if (!_callbacksApplied) {
|
||||
_channel.setMethodCallHandler(handleCalls);
|
||||
_channel.setMethodCallHandler(_handleCalls);
|
||||
_callbacksApplied = true;
|
||||
}
|
||||
int res = await _channel.invokeMethod('checkPermissionShizuku');
|
||||
if(res == -2) {
|
||||
await waitWhile(() => _resPermShizuku == -2);
|
||||
if (res == -2) {
|
||||
await _waitWhile(() => _resPermShizuku == -2);
|
||||
res = _resPermShizuku;
|
||||
_resPermShizuku = -2;
|
||||
}
|
@@ -51,6 +51,24 @@ class SettingsProvider with ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
String get appFont {
|
||||
return prefs?.getString('appFont') ?? 'Metropolis';
|
||||
}
|
||||
|
||||
set appFont(String appFont) {
|
||||
prefs?.setString('appFont', appFont);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
bool get tryUseSystemFont {
|
||||
return prefs?.getBool('tryUseSystemFont') ?? false;
|
||||
}
|
||||
|
||||
set tryUseSystemFont(bool tryUseSystemFont) {
|
||||
prefs?.setBool('tryUseSystemFont', tryUseSystemFont);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
InstallMethodSettings get installMethod {
|
||||
return InstallMethodSettings
|
||||
.values[prefs?.getInt('installMethod') ?? InstallMethodSettings.normal.index];
|
||||
|
Reference in New Issue
Block a user