mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-08-01 21:30:16 +02:00
Corrections
This commit is contained in:
@@ -5,7 +5,6 @@ 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';
|
||||
@@ -201,16 +200,6 @@ class _ObtainiumState extends State<Obtainium> {
|
||||
context.locale.languageCode)) {
|
||||
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(
|
||||
@@ -247,13 +236,17 @@ class _ObtainiumState extends State<Obtainium> {
|
||||
colorScheme: settingsProvider.theme == ThemeSettings.dark
|
||||
? darkColorScheme
|
||||
: lightColorScheme,
|
||||
fontFamily: settingsProvider.appFont),
|
||||
fontFamily: settingsProvider.useSystemFont
|
||||
? 'SystemFont'
|
||||
: 'Metropolis'),
|
||||
darkTheme: ThemeData(
|
||||
useMaterial3: true,
|
||||
colorScheme: settingsProvider.theme == ThemeSettings.light
|
||||
? lightColorScheme
|
||||
: darkColorScheme,
|
||||
fontFamily: settingsProvider.appFont),
|
||||
fontFamily: settingsProvider.useSystemFont
|
||||
? 'SystemFont'
|
||||
: 'Metropolis'),
|
||||
home: Shortcuts(shortcuts: <LogicalKeySet, Intent>{
|
||||
LogicalKeySet(LogicalKeyboardKey.select): const ActivateIntent(),
|
||||
}, child: const HomePage()));
|
||||
|
@@ -7,6 +7,7 @@ import 'package:obtainium/custom_errors.dart';
|
||||
import 'package:obtainium/main.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/settings_provider.dart';
|
||||
import 'package:obtainium/providers/source_provider.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
@@ -410,11 +411,23 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Flexible(child: Text(tr('tryUseSystemFont'))),
|
||||
Flexible(child: Text(tr('useSystemFont'))),
|
||||
Switch(
|
||||
value: settingsProvider.tryUseSystemFont,
|
||||
onChanged: (value) {
|
||||
settingsProvider.tryUseSystemFont = value;
|
||||
value: settingsProvider.useSystemFont,
|
||||
onChanged: (useSystemFont) {
|
||||
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 {
|
||||
static const MethodChannel _channel = MethodChannel('native');
|
||||
static bool _callbacksApplied = false;
|
||||
static bool _systemFontLoaded = false;
|
||||
static bool _callbacksApplied = false;
|
||||
static int _resPermShizuku = -2; // not set
|
||||
|
||||
static Future<ByteData> _readFileBytes(String path) async {
|
||||
@@ -34,15 +34,15 @@ class NativeFeatures {
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
static Future<bool> tryLoadSystemFont() async {
|
||||
if (_systemFontLoaded) { return true; }
|
||||
var font = await _channel.invokeMethod('getSystemFont');
|
||||
if (font == null) { return false; }
|
||||
static Future<String> loadSystemFont() async {
|
||||
if (_systemFontLoaded) { return "ok"; }
|
||||
var getFontRes = await _channel.invokeMethod('getSystemFont');
|
||||
if (getFontRes[0] != '/') { return getFontRes; } // Error
|
||||
var fontLoader = FontLoader('SystemFont');
|
||||
fontLoader.addFont(_readFileBytes(font));
|
||||
fontLoader.addFont(_readFileBytes(getFontRes));
|
||||
await fontLoader.load();
|
||||
_systemFontLoaded = true;
|
||||
return true;
|
||||
return "ok";
|
||||
}
|
||||
|
||||
static Future<int> checkPermissionShizuku() async {
|
||||
|
@@ -51,21 +51,12 @@ class SettingsProvider with ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
String get appFont {
|
||||
return prefs?.getString('appFont') ?? 'Metropolis';
|
||||
bool get useSystemFont {
|
||||
return prefs?.getBool('useSystemFont') ?? false;
|
||||
}
|
||||
|
||||
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);
|
||||
set useSystemFont(bool useSystemFont) {
|
||||
prefs?.setBool('useSystemFont', useSystemFont);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user