mirror of
https://github.com/revanced/revanced-manager
synced 2024-05-14 13:56:57 +02:00
remove user interaction
This commit is contained in:
parent
96736afb94
commit
02822f4b38
@ -44,19 +44,7 @@
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ExportSettingsActivity"
|
||||
android:exported="true"
|
||||
android:launchMode="singleTop"
|
||||
android:theme="@style/ExportSettingsTheme"
|
||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
||||
android:hardwareAccelerated="true"
|
||||
android:windowSoftInputMode="adjustResize">
|
||||
<meta-data
|
||||
android:name="io.flutter.embedding.android.NormalTheme"
|
||||
android:resource="@style/ExportSettingsTheme"/>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
</intent-filter>
|
||||
android:exported="true">
|
||||
</activity>
|
||||
<meta-data
|
||||
android:name="flutterEmbedding"
|
||||
|
@ -1,45 +1,56 @@
|
||||
package app.revanced.manager.flutter
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
import io.flutter.embedding.android.TransparencyMode
|
||||
import io.flutter.embedding.engine.FlutterEngine
|
||||
import io.flutter.plugin.common.MethodChannel
|
||||
import java.io.Serializable
|
||||
import android.os.Bundle
|
||||
import android.util.Base64
|
||||
import org.json.JSONObject
|
||||
import java.io.File
|
||||
|
||||
class ExportSettingsActivity : FlutterActivity() {
|
||||
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
|
||||
super.configureFlutterEngine(flutterEngine)
|
||||
import android.util.Log
|
||||
|
||||
val settingsChannel = "app.revanced.manager.flutter/settings"
|
||||
class ExportSettingsActivity : Activity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
val mainChannel =
|
||||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, settingsChannel)
|
||||
val json = JSONObject()
|
||||
|
||||
mainChannel.setMethodCallHandler { call, result ->
|
||||
when (call.method) {
|
||||
"accept" -> {
|
||||
val data = call.argument<String>("data")
|
||||
val resultIntent = Intent()
|
||||
resultIntent.putExtra("data", data as Serializable)
|
||||
setResult(Activity.RESULT_OK, resultIntent)
|
||||
finish()
|
||||
}
|
||||
"deny" -> {
|
||||
setResult(Activity.RESULT_CANCELED)
|
||||
finish()
|
||||
}
|
||||
else -> result.notImplemented()
|
||||
}
|
||||
// Default Data
|
||||
json.put("keystorePassword", "s3cur3p@ssw0rd")
|
||||
|
||||
// Load Shared Preferences
|
||||
val sharedPreferences = getSharedPreferences("FlutterSharedPreferences", Context.MODE_PRIVATE)
|
||||
val allEntries: Map<String, *> = sharedPreferences.getAll()
|
||||
for ((key, value) in allEntries.entries) {
|
||||
json.put(
|
||||
key.replace("flutter.", ""),
|
||||
if (value is Boolean) if (value) 1 else 0 else value
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getDartEntrypointFunctionName(): String {
|
||||
return "mainExportSettings"
|
||||
}
|
||||
// Load keystore
|
||||
val keystoreFile = File(getExternalFilesDir(null), "/revanced-manager.keystore")
|
||||
if (keystoreFile.exists()) {
|
||||
val keystoreBytes = keystoreFile.readBytes()
|
||||
val keystoreBase64 =
|
||||
Base64.encodeToString(keystoreBytes, Base64.DEFAULT).replace("\n", "")
|
||||
json.put("keystore", keystoreBase64)
|
||||
}
|
||||
|
||||
override fun getTransparencyMode(): TransparencyMode {
|
||||
return TransparencyMode.transparent
|
||||
// Load saved patches
|
||||
val storedPatchesFile = File(filesDir.parentFile.absolutePath, "/app_flutter/selected-patches.json")
|
||||
if (storedPatchesFile.exists()) {
|
||||
val patchesBytes = storedPatchesFile.readBytes()
|
||||
val patches = String(patchesBytes, Charsets.UTF_8)
|
||||
json.put("patches", patches)
|
||||
}
|
||||
|
||||
// Send data back
|
||||
Log.e("ExportSettingsActivity", json.toString())
|
||||
val resultIntent = Intent()
|
||||
resultIntent.putExtra("data", json.toString())
|
||||
setResult(Activity.RESULT_OK, resultIntent)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
@ -15,10 +15,4 @@
|
||||
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
|
||||
<item name="android:windowBackground">?android:colorBackground</item>
|
||||
</style>
|
||||
|
||||
<style name="ExportSettingsTheme" parent="android:Theme.Light.NoTitleBar">
|
||||
<item name="android:windowIsTranslucent">true</item>
|
||||
<item name="android:windowBackground">#52000000</item>
|
||||
<item name="android:windowContentOverlay">@null</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
@ -304,11 +304,5 @@
|
||||
"integrationsContributors": "Integrations contributors",
|
||||
"cliContributors": "CLI contributors",
|
||||
"managerContributors": "Manager contributors"
|
||||
},
|
||||
"exportSettingsView": {
|
||||
"widgetTitle": "Import settings",
|
||||
"description": "Would you like to import your settings to the previous version of ReVanced Manager?",
|
||||
"exportButton": "Import",
|
||||
"dismissButton": "No thanks"
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import 'package:revanced_manager/services/github_api.dart';
|
||||
import 'package:revanced_manager/services/manager_api.dart';
|
||||
import 'package:revanced_manager/services/revanced_api.dart';
|
||||
import 'package:revanced_manager/ui/theme/dynamic_theme_builder.dart';
|
||||
import 'package:revanced_manager/ui/views/export_settings/export_settings_view.dart';
|
||||
import 'package:revanced_manager/ui/views/navigation/navigation_view.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:stacked_themes/stacked_themes.dart';
|
||||
@ -16,14 +15,6 @@ import 'package:timezone/data/latest.dart' as tz;
|
||||
|
||||
late SharedPreferences prefs;
|
||||
Future main() async {
|
||||
initialize(const NavigationView());
|
||||
}
|
||||
|
||||
Future mainExportSettings() async {
|
||||
initialize(const ExportSettingsView());
|
||||
}
|
||||
|
||||
Future initialize(Widget homeView) async {
|
||||
await ThemeManager.initialise();
|
||||
await setupLocator();
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
@ -35,12 +26,11 @@ Future initialize(Widget homeView) async {
|
||||
tz.initializeTimeZones();
|
||||
prefs = await SharedPreferences.getInstance();
|
||||
|
||||
runApp(MyApp(homeView: homeView));
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({Key? key, required this.homeView}) : super(key: key);
|
||||
final Widget homeView;
|
||||
const MyApp({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -52,7 +42,7 @@ class MyApp extends StatelessWidget {
|
||||
|
||||
return DynamicThemeBuilder(
|
||||
title: 'ReVanced Manager',
|
||||
home: homeView,
|
||||
home: const NavigationView(),
|
||||
localizationsDelegates: [
|
||||
FlutterI18nDelegate(
|
||||
translationLoader: FileTranslationLoader(
|
||||
|
@ -1,41 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_i18n/flutter_i18n.dart';
|
||||
import 'package:revanced_manager/ui/views/export_settings/export_settings_viewmodel.dart';
|
||||
import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart';
|
||||
|
||||
final _exportSettingsViewModel = ExportSettingsViewModel();
|
||||
|
||||
class ExportSettingsView extends StatelessWidget {
|
||||
const ExportSettingsView({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
SystemChrome.setSystemUIOverlayStyle(
|
||||
SystemUiOverlayStyle(
|
||||
systemNavigationBarColor: Colors.black.withOpacity(0.002),
|
||||
statusBarColor: Colors.black.withOpacity(0.002),
|
||||
),
|
||||
);
|
||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||
|
||||
return AlertDialog(
|
||||
title: I18nText('exportSettingsView.widgetTitle'),
|
||||
content: I18nText('exportSettingsView.description'),
|
||||
icon: const Icon(Icons.update),
|
||||
actions: <Widget> [
|
||||
CustomMaterialButton(
|
||||
isFilled: false,
|
||||
label: I18nText('exportSettingsView.dismissButton'),
|
||||
onPressed: _exportSettingsViewModel.deny,
|
||||
),
|
||||
CustomMaterialButton(
|
||||
label: I18nText('exportSettingsView.exportButton'),
|
||||
onPressed: () async {
|
||||
await _exportSettingsViewModel.accept();
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dynamic_themes/dynamic_themes.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:revanced_manager/app/app.locator.dart';
|
||||
import 'package:revanced_manager/services/manager_api.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
|
||||
@lazySingleton
|
||||
class ExportSettingsViewModel extends BaseViewModel {
|
||||
final _channel = const MethodChannel('app.revanced.manager.flutter/settings');
|
||||
final ManagerAPI _managerAPI = locator<ManagerAPI>();
|
||||
|
||||
Future<void> accept() async {
|
||||
final externalDir = await getExternalStorageDirectory();
|
||||
|
||||
final Map<String, dynamic> data = {};
|
||||
|
||||
data['themeMode'] = _managerAPI.getThemeMode();
|
||||
data['useDynamicTheme'] = _managerAPI.getUseDynamicTheme() ? 1 : 0;
|
||||
|
||||
data['apiUrl'] = _managerAPI.getApiUrl();
|
||||
data['patchesRepo'] = _managerAPI.getPatchesRepo();
|
||||
data['integrationsRepo'] = _managerAPI.getIntegrationsRepo();
|
||||
|
||||
data['patchesAutoUpdate'] = _managerAPI.isPatchesAutoUpdate() ? 1 : 0;
|
||||
data['patchesChangeEnabled'] = _managerAPI.isPatchesChangeEnabled() ? 1 : 0;
|
||||
data['universalPatchesEnabled'] = _managerAPI.areUniversalPatchesEnabled() ? 1 : 0;
|
||||
data['experimentalPatchesEnabled'] = _managerAPI.areExperimentalPatchesEnabled() ? 1 : 0;
|
||||
|
||||
data['keystorePassword'] = _managerAPI.getKeystorePassword();
|
||||
|
||||
// Load keystore
|
||||
if (externalDir != null) {
|
||||
final keystoreFile = File('${externalDir.path}/revanced-manager.keystore');
|
||||
if (keystoreFile.existsSync()) {
|
||||
final keystoreBytes = keystoreFile.readAsBytesSync();
|
||||
data['keystore'] = base64Encode(keystoreBytes);
|
||||
}
|
||||
}
|
||||
|
||||
// Load patches
|
||||
final patchFile = File(_managerAPI.storedPatchesFile);
|
||||
if (patchFile.existsSync()) {
|
||||
data['patches'] = patchFile.readAsStringSync();
|
||||
}
|
||||
|
||||
_channel.invokeMethod('accept', {'data': jsonEncode(data)});
|
||||
}
|
||||
|
||||
void deny() {
|
||||
_channel.invokeMethod('deny');
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user