2023-01-30 13:35:06 +01:00
|
|
|
import 'dart:developer';
|
|
|
|
|
2022-07-30 21:09:59 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2022-08-07 01:37:12 +02:00
|
|
|
import 'package:flutter_i18n/flutter_i18n.dart';
|
|
|
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
2022-08-06 23:35:35 +02:00
|
|
|
import 'package:revanced_manager/app/app.locator.dart';
|
2023-10-15 11:51:31 +02:00
|
|
|
import 'package:revanced_manager/services/download_manager.dart';
|
2022-09-12 02:41:53 +02:00
|
|
|
import 'package:revanced_manager/services/github_api.dart';
|
2022-08-25 01:51:47 +02:00
|
|
|
import 'package:revanced_manager/services/manager_api.dart';
|
2022-09-12 02:41:53 +02:00
|
|
|
import 'package:revanced_manager/services/revanced_api.dart';
|
2023-12-23 04:16:28 +01:00
|
|
|
import 'package:revanced_manager/services/root_api.dart';
|
2022-09-05 04:32:36 +02:00
|
|
|
import 'package:revanced_manager/ui/theme/dynamic_theme_builder.dart';
|
2022-09-05 10:07:38 +02:00
|
|
|
import 'package:revanced_manager/ui/views/navigation/navigation_view.dart';
|
2023-03-03 12:06:24 +01:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
2022-09-20 01:03:37 +02:00
|
|
|
import 'package:timezone/data/latest.dart' as tz;
|
2022-07-30 21:09:59 +02:00
|
|
|
|
2023-03-03 12:06:24 +01:00
|
|
|
late SharedPreferences prefs;
|
2022-08-11 21:05:03 +02:00
|
|
|
Future main() async {
|
2023-02-21 13:21:56 +01:00
|
|
|
await setupLocator();
|
2023-03-03 12:06:24 +01:00
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
await locator<ManagerAPI>().initialize();
|
2023-10-15 11:51:31 +02:00
|
|
|
await locator<DownloadManager>().initialize();
|
2023-03-03 12:06:24 +01:00
|
|
|
final String apiUrl = locator<ManagerAPI>().getApiUrl();
|
|
|
|
await locator<RevancedAPI>().initialize(apiUrl);
|
|
|
|
final String repoUrl = locator<ManagerAPI>().getRepoUrl();
|
2022-12-09 13:10:43 +01:00
|
|
|
locator<GithubAPI>().initialize(repoUrl);
|
2022-09-20 01:03:37 +02:00
|
|
|
tz.initializeTimeZones();
|
2023-12-23 04:16:28 +01:00
|
|
|
|
|
|
|
// TODO(aAbed): remove in the future, keep it for now during migration.
|
|
|
|
final rootAPI = RootAPI();
|
|
|
|
if (await rootAPI.hasRootPermissions()) {
|
|
|
|
await rootAPI.removeOrphanedFiles();
|
|
|
|
}
|
|
|
|
|
2023-03-03 12:06:24 +01:00
|
|
|
prefs = await SharedPreferences.getInstance();
|
2022-10-15 14:59:50 +02:00
|
|
|
|
2023-03-03 12:06:24 +01:00
|
|
|
runApp(const MyApp());
|
2022-07-30 21:09:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class MyApp extends StatelessWidget {
|
2023-11-11 13:07:32 +01:00
|
|
|
const MyApp({super.key});
|
2022-07-30 21:09:59 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-11-29 13:15:42 +01:00
|
|
|
// String rawLocale = prefs.getString('language') ?? 'en_US';
|
|
|
|
// String replaceLocale = rawLocale.replaceAll('_', '-');
|
|
|
|
// List<String> localeList = replaceLocale.split('-');
|
|
|
|
// Locale locale = Locale(localeList[0], localeList[1]);
|
2023-01-30 13:35:06 +01:00
|
|
|
const Locale locale = Locale('en', 'US');
|
2022-11-10 18:33:07 +01:00
|
|
|
|
2022-09-05 04:32:36 +02:00
|
|
|
return DynamicThemeBuilder(
|
|
|
|
title: 'ReVanced Manager',
|
2022-09-06 15:40:49 +02:00
|
|
|
home: const NavigationView(),
|
2022-09-05 04:32:36 +02:00
|
|
|
localizationsDelegates: [
|
|
|
|
FlutterI18nDelegate(
|
|
|
|
translationLoader: FileTranslationLoader(
|
2022-11-29 13:15:42 +01:00
|
|
|
fallbackFile: 'en_US',
|
2022-11-10 18:33:07 +01:00
|
|
|
forcedLocale: locale,
|
2022-09-05 04:32:36 +02:00
|
|
|
basePath: 'assets/i18n',
|
2022-11-10 18:33:07 +01:00
|
|
|
useCountryCode: true,
|
2022-09-05 04:32:36 +02:00
|
|
|
),
|
2022-11-10 18:33:07 +01:00
|
|
|
missingTranslationHandler: (key, locale) {
|
2023-01-30 13:35:06 +01:00
|
|
|
log(
|
|
|
|
'--> Missing translation: key: $key, languageCode: ${locale?.languageCode}',
|
|
|
|
);
|
2022-11-10 18:33:07 +01:00
|
|
|
},
|
2022-09-05 04:32:36 +02:00
|
|
|
),
|
|
|
|
GlobalMaterialLocalizations.delegate,
|
2023-08-06 09:39:46 +02:00
|
|
|
GlobalWidgetsLocalizations.delegate,
|
2022-09-05 04:32:36 +02:00
|
|
|
],
|
2022-07-31 10:00:11 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|