mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-07-16 06:36:44 +02:00
Corrections
This commit is contained in:
@ -37,12 +37,12 @@ android {
|
|||||||
ndkVersion flutter.ndkVersion
|
ndkVersion flutter.ndkVersion
|
||||||
|
|
||||||
compileOptions {
|
compileOptions {
|
||||||
sourceCompatibility JavaVersion.VERSION_17
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
targetCompatibility JavaVersion.VERSION_17
|
targetCompatibility JavaVersion.VERSION_1_8
|
||||||
}
|
}
|
||||||
|
|
||||||
kotlinOptions {
|
kotlinOptions {
|
||||||
jvmTarget = '17'
|
jvmTarget = '1.8'
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
|
@ -6,19 +6,20 @@ import java.io.File
|
|||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
|
|
||||||
class DefaultSystemFont {
|
class DefaultSystemFont {
|
||||||
fun get(): String? {
|
fun get(): String {
|
||||||
return try {
|
return try {
|
||||||
val file = File("/system/etc/fonts.xml")
|
val file = File("/system/etc/fonts.xml")
|
||||||
val fileStream = FileInputStream(file)
|
val fileStream = FileInputStream(file)
|
||||||
parseFontsFileStream(fileStream)
|
parseFontsFileStream(fileStream)
|
||||||
} catch (_: Exception) {
|
} catch (e: Exception) {
|
||||||
null
|
e.message ?: "Unknown fonts.xml parsing exception"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun parseFontsFileStream(fileStream: FileInputStream): String {
|
private fun parseFontsFileStream(fileStream: FileInputStream): String {
|
||||||
fileStream.use { stream ->
|
fileStream.use { stream ->
|
||||||
val parser = Xml.newPullParser()
|
val parser = Xml.newPullParser()
|
||||||
|
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false)
|
||||||
parser.setInput(stream, null)
|
parser.setInput(stream, null)
|
||||||
parser.nextTag()
|
parser.nextTag()
|
||||||
return parseFonts(parser)
|
return parseFonts(parser)
|
||||||
@ -26,8 +27,18 @@ class DefaultSystemFont {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun parseFonts(parser: XmlPullParser): String {
|
private fun parseFonts(parser: XmlPullParser): String {
|
||||||
while (parser.name != "font") { parser.next() }
|
while (!((parser.next() == XmlPullParser.END_TAG) && (parser.name == "family"))) {
|
||||||
|
if ((parser.eventType == XmlPullParser.START_TAG) && (parser.name == "font")
|
||||||
|
&& (parser.getAttributeValue(null, "style") == "normal")
|
||||||
|
&& (parser.getAttributeValue(null, "weight") == "400")) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
parser.next()
|
parser.next()
|
||||||
return "/system/fonts/" + parser.text.trim()
|
val fontFile = parser.text.trim()
|
||||||
|
if (fontFile == "") {
|
||||||
|
throw NoSuchFieldException("The font filename couldn't be found in fonts.xml")
|
||||||
|
}
|
||||||
|
return "/system/fonts/$fontFile"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -77,8 +77,8 @@ class MainActivity: FlutterActivity() {
|
|||||||
val params =
|
val params =
|
||||||
PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL)
|
PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL)
|
||||||
var installFlags: Int = PackageInstallerUtils.getInstallFlags(params)
|
var installFlags: Int = PackageInstallerUtils.getInstallFlags(params)
|
||||||
installFlags = installFlags or (0x00000002/*PackageManager.INSTALL_REPLACE_EXISTING*/ or
|
installFlags = installFlags or (0x00000002/*PackageManager.INSTALL_REPLACE_EXISTING*/
|
||||||
0x00000004 /*PackageManager.INSTALL_ALLOW_TEST*/)
|
or 0x00000004 /*PackageManager.INSTALL_ALLOW_TEST*/)
|
||||||
PackageInstallerUtils.setInstallFlags(params, installFlags)
|
PackageInstallerUtils.setInstallFlags(params, installFlags)
|
||||||
val sessionId = packageInstaller.createSession(params)
|
val sessionId = packageInstaller.createSession(params)
|
||||||
val iSession = IPackageInstallerSession.Stub.asInterface(
|
val iSession = IPackageInstallerSession.Stub.asInterface(
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
buildscript {
|
buildscript {
|
||||||
ext.kotlin_version = '1.7.10'
|
ext.kotlin_version = '1.8.10'
|
||||||
ext {
|
ext {
|
||||||
compileSdkVersion = 34 // or latest
|
compileSdkVersion = 34 // or latest
|
||||||
targetSdkVersion = 34 // or latest
|
targetSdkVersion = 34 // or latest
|
||||||
|
@ -287,7 +287,8 @@
|
|||||||
"shizuku": "Shizuku",
|
"shizuku": "Shizuku",
|
||||||
"root": "Root",
|
"root": "Root",
|
||||||
"shizukuBinderNotFound": "Сompatible Shizuku service wasn't found",
|
"shizukuBinderNotFound": "Сompatible Shizuku service wasn't found",
|
||||||
"tryUseSystemFont": "Try to use a system font",
|
"useSystemFont": "Use the system font",
|
||||||
|
"systemFontError": "Error loading the system font: {}",
|
||||||
"removeAppQuestion": {
|
"removeAppQuestion": {
|
||||||
"one": "Remove App?",
|
"one": "Remove App?",
|
||||||
"other": "Remove Apps?"
|
"other": "Remove Apps?"
|
||||||
|
@ -287,7 +287,8 @@
|
|||||||
"shizuku": "Shizuku",
|
"shizuku": "Shizuku",
|
||||||
"root": "Суперпользователь",
|
"root": "Суперпользователь",
|
||||||
"shizukuBinderNotFound": "Совместимый сервис Shizuku не найден",
|
"shizukuBinderNotFound": "Совместимый сервис Shizuku не найден",
|
||||||
"tryUseSystemFont": "Попытаться использовать системный шрифт",
|
"useSystemFont": "Использовать системный шрифт",
|
||||||
|
"systemFontError": "Ошибка загрузки системного шрифта: {}",
|
||||||
"removeAppQuestion": {
|
"removeAppQuestion": {
|
||||||
"one": "Удалить приложение?",
|
"one": "Удалить приложение?",
|
||||||
"other": "Удалить приложения?"
|
"other": "Удалить приложения?"
|
||||||
|
@ -5,7 +5,6 @@ import 'package:flutter/services.dart';
|
|||||||
import 'package:obtainium/pages/home.dart';
|
import 'package:obtainium/pages/home.dart';
|
||||||
import 'package:obtainium/providers/apps_provider.dart';
|
import 'package:obtainium/providers/apps_provider.dart';
|
||||||
import 'package:obtainium/providers/logs_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/notifications_provider.dart';
|
||||||
import 'package:obtainium/providers/settings_provider.dart';
|
import 'package:obtainium/providers/settings_provider.dart';
|
||||||
import 'package:obtainium/providers/source_provider.dart';
|
import 'package:obtainium/providers/source_provider.dart';
|
||||||
@ -201,16 +200,6 @@ class _ObtainiumState extends State<Obtainium> {
|
|||||||
context.locale.languageCode)) {
|
context.locale.languageCode)) {
|
||||||
settingsProvider.resetLocaleSafe(context);
|
settingsProvider.resetLocaleSafe(context);
|
||||||
}
|
}
|
||||||
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(
|
return DynamicColorBuilder(
|
||||||
@ -247,13 +236,17 @@ class _ObtainiumState extends State<Obtainium> {
|
|||||||
colorScheme: settingsProvider.theme == ThemeSettings.dark
|
colorScheme: settingsProvider.theme == ThemeSettings.dark
|
||||||
? darkColorScheme
|
? darkColorScheme
|
||||||
: lightColorScheme,
|
: lightColorScheme,
|
||||||
fontFamily: settingsProvider.appFont),
|
fontFamily: settingsProvider.useSystemFont
|
||||||
|
? 'SystemFont'
|
||||||
|
: 'Metropolis'),
|
||||||
darkTheme: ThemeData(
|
darkTheme: ThemeData(
|
||||||
useMaterial3: true,
|
useMaterial3: true,
|
||||||
colorScheme: settingsProvider.theme == ThemeSettings.light
|
colorScheme: settingsProvider.theme == ThemeSettings.light
|
||||||
? lightColorScheme
|
? lightColorScheme
|
||||||
: darkColorScheme,
|
: darkColorScheme,
|
||||||
fontFamily: settingsProvider.appFont),
|
fontFamily: settingsProvider.useSystemFont
|
||||||
|
? 'SystemFont'
|
||||||
|
: 'Metropolis'),
|
||||||
home: Shortcuts(shortcuts: <LogicalKeySet, Intent>{
|
home: Shortcuts(shortcuts: <LogicalKeySet, Intent>{
|
||||||
LogicalKeySet(LogicalKeyboardKey.select): const ActivateIntent(),
|
LogicalKeySet(LogicalKeyboardKey.select): const ActivateIntent(),
|
||||||
}, child: const HomePage()));
|
}, child: const HomePage()));
|
||||||
|
@ -7,6 +7,7 @@ import 'package:obtainium/custom_errors.dart';
|
|||||||
import 'package:obtainium/main.dart';
|
import 'package:obtainium/main.dart';
|
||||||
import 'package:obtainium/providers/apps_provider.dart';
|
import 'package:obtainium/providers/apps_provider.dart';
|
||||||
import 'package:obtainium/providers/logs_provider.dart';
|
import 'package:obtainium/providers/logs_provider.dart';
|
||||||
|
import 'package:obtainium/providers/native_provider.dart';
|
||||||
import 'package:obtainium/providers/settings_provider.dart';
|
import 'package:obtainium/providers/settings_provider.dart';
|
||||||
import 'package:obtainium/providers/source_provider.dart';
|
import 'package:obtainium/providers/source_provider.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
@ -410,11 +411,23 @@ class _SettingsPageState extends State<SettingsPage> {
|
|||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
Flexible(child: Text(tr('tryUseSystemFont'))),
|
Flexible(child: Text(tr('useSystemFont'))),
|
||||||
Switch(
|
Switch(
|
||||||
value: settingsProvider.tryUseSystemFont,
|
value: settingsProvider.useSystemFont,
|
||||||
onChanged: (value) {
|
onChanged: (useSystemFont) {
|
||||||
settingsProvider.tryUseSystemFont = value;
|
if (useSystemFont) {
|
||||||
|
NativeFeatures.loadSystemFont().then((fontLoadRes) {
|
||||||
|
if (fontLoadRes == 'ok') {
|
||||||
|
settingsProvider.useSystemFont = true;
|
||||||
|
} else {
|
||||||
|
showError(ObtainiumError(
|
||||||
|
tr('systemFontError', args: [fontLoadRes])
|
||||||
|
), context);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
settingsProvider.useSystemFont = false;
|
||||||
|
}
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -4,8 +4,8 @@ import 'package:flutter/services.dart';
|
|||||||
|
|
||||||
class NativeFeatures {
|
class NativeFeatures {
|
||||||
static const MethodChannel _channel = MethodChannel('native');
|
static const MethodChannel _channel = MethodChannel('native');
|
||||||
static bool _callbacksApplied = false;
|
|
||||||
static bool _systemFontLoaded = false;
|
static bool _systemFontLoaded = false;
|
||||||
|
static bool _callbacksApplied = false;
|
||||||
static int _resPermShizuku = -2; // not set
|
static int _resPermShizuku = -2; // not set
|
||||||
|
|
||||||
static Future<ByteData> _readFileBytes(String path) async {
|
static Future<ByteData> _readFileBytes(String path) async {
|
||||||
@ -34,15 +34,15 @@ class NativeFeatures {
|
|||||||
return completer.future;
|
return completer.future;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<bool> tryLoadSystemFont() async {
|
static Future<String> loadSystemFont() async {
|
||||||
if (_systemFontLoaded) { return true; }
|
if (_systemFontLoaded) { return "ok"; }
|
||||||
var font = await _channel.invokeMethod('getSystemFont');
|
var getFontRes = await _channel.invokeMethod('getSystemFont');
|
||||||
if (font == null) { return false; }
|
if (getFontRes[0] != '/') { return getFontRes; } // Error
|
||||||
var fontLoader = FontLoader('SystemFont');
|
var fontLoader = FontLoader('SystemFont');
|
||||||
fontLoader.addFont(_readFileBytes(font));
|
fontLoader.addFont(_readFileBytes(getFontRes));
|
||||||
await fontLoader.load();
|
await fontLoader.load();
|
||||||
_systemFontLoaded = true;
|
_systemFontLoaded = true;
|
||||||
return true;
|
return "ok";
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<int> checkPermissionShizuku() async {
|
static Future<int> checkPermissionShizuku() async {
|
||||||
|
@ -51,21 +51,12 @@ class SettingsProvider with ChangeNotifier {
|
|||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
String get appFont {
|
bool get useSystemFont {
|
||||||
return prefs?.getString('appFont') ?? 'Metropolis';
|
return prefs?.getBool('useSystemFont') ?? false;
|
||||||
}
|
}
|
||||||
|
|
||||||
set appFont(String appFont) {
|
set useSystemFont(bool useSystemFont) {
|
||||||
prefs?.setString('appFont', appFont);
|
prefs?.setBool('useSystemFont', useSystemFont);
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool get tryUseSystemFont {
|
|
||||||
return prefs?.getBool('tryUseSystemFont') ?? false;
|
|
||||||
}
|
|
||||||
|
|
||||||
set tryUseSystemFont(bool tryUseSystemFont) {
|
|
||||||
prefs?.setBool('tryUseSystemFont', tryUseSystemFont);
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user