Compare commits

..

18 Commits

Author SHA1 Message Date
9f85450c6c build: Bump version to v0.0.6 2022-09-15 09:14:43 +01:00
cba4e175a3 build: Bump version to v0.0.5 2022-09-15 02:27:36 +01:00
cf3fa935ce fix: Fix select from storage for Android 13 devices 2022-09-15 02:18:07 +01:00
6de7e2e098 build: Bump version to v0.0.4 2022-09-15 01:34:53 +01:00
30d9b5f6fe fix: These foreground icons are more appropriate for each dpi size 2022-09-15 01:30:14 +01:00
ec31667591 feat: Add a warning for split APK patching for now 2022-09-15 01:15:13 +01:00
a82b0cd74d fix: Request IGNORE_BATTERY_OPTIMIZATIONS on boot 2022-09-15 00:57:54 +01:00
34e67d396f fix: Remove unneeded WRITE_EXTERNAL_STORAGE and limit READ_EXTERNAL_STORAGE to SDK versions lower than 33 2022-09-15 00:54:51 +01:00
cdb492910c fix: Update package name if MicroG was applied 2022-09-14 23:40:08 +01:00
9f3a30d9f2 feat: Request root and install permissions as soon as possible 2022-09-14 23:30:02 +01:00
598f7571de feat: Auto dark mode based on system theme 2022-09-14 23:23:03 +01:00
85cd176347 chore: exclude aapt prebuilt (from apktool) 2022-09-14 23:22:18 +02:00
2f78af7f08 refactor: more cleanup 2022-09-14 23:16:48 +02:00
a4b5fc4796 chore: update dependencies 2022-09-14 23:16:33 +02:00
a0a0d0a939 Merge remote-tracking branch 'origin/flutter' into flutter 2022-09-14 23:09:31 +02:00
eef9c2bf31 refactor: cleanup code & fix warnings 2022-09-14 23:09:18 +02:00
84813d34c6 refactor: move classes to flutter pkg 2022-09-14 23:05:47 +02:00
aad7e06f2e chore: update gradle 2022-09-14 23:03:15 +02:00
28 changed files with 433 additions and 364 deletions

View File

@ -57,6 +57,10 @@ android {
signingConfig signingConfigs.debug
}
}
packagingOptions {
exclude '/prebuilt/**'
}
}
flutter {
@ -67,9 +71,9 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
// ReVanced
implementation "app.revanced:revanced-patcher:4.2.3"
implementation "app.revanced:revanced-patcher:4.4.0"
// Signing & aligning
implementation("org.bouncycastle:bcpkix-jdk15on:1.70")
implementation("com.android.tools.build:apksig:7.2.1")
implementation("com.android.tools.build:apksig:7.2.2")
}

View File

@ -1,8 +1,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="app.revanced.manager.flutter">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

View File

@ -1,333 +0,0 @@
package app.revanced.manager.flutter
import android.os.Handler
import android.os.Looper
import androidx.annotation.NonNull
import app.revanced.manager.flutter.utils.Aapt
import app.revanced.manager.flutter.utils.aligning.ZipAligner
import app.revanced.manager.flutter.utils.signing.Signer
import app.revanced.manager.flutter.utils.zip.ZipFile
import app.revanced.manager.flutter.utils.zip.structures.ZipEntry
import app.revanced.patcher.Patcher
import app.revanced.patcher.PatcherOptions
import app.revanced.patcher.extensions.PatchExtensions.patchName
import app.revanced.patcher.util.patch.impl.DexPatchBundle
import dalvik.system.DexClassLoader
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.Result
import java.io.File
class MainActivity : FlutterActivity() {
private val PATCHER_CHANNEL = "app.revanced.manager.flutter/patcher"
private val INSTALLER_CHANNEL = "app.revanced.manager.flutter/installer"
private val handler = Handler(Looper.getMainLooper())
private lateinit var installerChannel: MethodChannel
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
val mainChannel = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, PATCHER_CHANNEL)
installerChannel = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, INSTALLER_CHANNEL)
mainChannel.setMethodCallHandler { call, result ->
when (call.method) {
"runPatcher" -> {
val patchBundleFilePath = call.argument<String>("patchBundleFilePath")
val originalFilePath = call.argument<String>("originalFilePath")
val inputFilePath = call.argument<String>("inputFilePath")
val patchedFilePath = call.argument<String>("patchedFilePath")
val outFilePath = call.argument<String>("outFilePath")
val integrationsPath = call.argument<String>("integrationsPath")
val selectedPatches = call.argument<List<String>>("selectedPatches")
val cacheDirPath = call.argument<String>("cacheDirPath")
val mergeIntegrations = call.argument<Boolean>("mergeIntegrations")
val resourcePatching = call.argument<Boolean>("resourcePatching")
val keyStoreFilePath = call.argument<String>("keyStoreFilePath")
if (patchBundleFilePath != null &&
originalFilePath != null &&
inputFilePath != null &&
patchedFilePath != null &&
outFilePath != null &&
integrationsPath != null &&
selectedPatches != null &&
cacheDirPath != null &&
mergeIntegrations != null &&
resourcePatching != null &&
keyStoreFilePath != null
) {
runPatcher(
result,
patchBundleFilePath,
originalFilePath,
inputFilePath,
patchedFilePath,
outFilePath,
integrationsPath,
selectedPatches,
cacheDirPath,
mergeIntegrations,
resourcePatching,
keyStoreFilePath
)
} else {
result.notImplemented()
}
}
else -> result.notImplemented()
}
}
}
fun runPatcher(
result: MethodChannel.Result,
patchBundleFilePath: String,
originalFilePath: String,
inputFilePath: String,
patchedFilePath: String,
outFilePath: String,
integrationsPath: String,
selectedPatches: List<String>,
cacheDirPath: String,
mergeIntegrations: Boolean,
resourcePatching: Boolean,
keyStoreFilePath: String
) {
val originalFile = File(originalFilePath)
val inputFile = File(inputFilePath)
val patchedFile = File(patchedFilePath)
val outFile = File(outFilePath)
val integrations = File(integrationsPath)
val keyStoreFile = File(keyStoreFilePath)
val patches =
DexPatchBundle(
patchBundleFilePath,
DexClassLoader(
patchBundleFilePath,
cacheDirPath,
null,
javaClass.classLoader
)
)
.loadPatches()
.filter { patch -> selectedPatches.any { it == patch.patchName } }
Thread(
Runnable {
handler.post {
installerChannel.invokeMethod(
"update",
mapOf(
"progress" to 0.1,
"header" to "",
"log" to "Copying original apk"
)
)
}
originalFile.copyTo(inputFile, true)
handler.post {
installerChannel.invokeMethod(
"update",
mapOf(
"progress" to 0.2,
"header" to "Unpacking apk...",
"log" to "Unpacking input apk"
)
)
}
val patcher =
Patcher(
PatcherOptions(
inputFile,
cacheDirPath,
resourcePatching,
Aapt.binary(applicationContext).absolutePath,
cacheDirPath,
logger =
object :
app.revanced.patcher.logging.Logger {
override fun error(msg: String) {
handler.post {
installerChannel
.invokeMethod(
"update",
mapOf(
"progress" to
-1.0,
"header" to
"",
"log" to
msg
)
)
}
}
override fun warn(msg: String) {
handler.post {
installerChannel
.invokeMethod(
"update",
mapOf(
"progress" to
-1.0,
"header" to
"",
"log" to
msg
)
)
}
}
override fun info(msg: String) {
handler.post {
installerChannel
.invokeMethod(
"update",
mapOf(
"progress" to
-1.0,
"header" to
"",
"log" to
msg
)
)
}
}
override fun trace(msg: String) {
handler.post {
installerChannel
.invokeMethod(
"update",
mapOf(
"progress" to
-1.0,
"header" to
"",
"log" to
msg
)
)
}
}
}
)
)
handler.post {
installerChannel.invokeMethod(
"update",
mapOf("progress" to 0.3, "header" to "", "log" to "")
)
}
if (mergeIntegrations) {
handler.post {
installerChannel.invokeMethod(
"update",
mapOf(
"progress" to 0.4,
"header" to "Merging integrations...",
"log" to "Merging integrations"
)
)
}
patcher.addFiles(listOf(integrations)) {}
}
handler.post {
installerChannel.invokeMethod(
"update",
mapOf(
"progress" to 0.5,
"header" to "Applying patches...",
"log" to ""
)
)
}
patcher.addPatches(patches)
patcher.applyPatches().forEach { (patch, res) ->
if (res.isSuccess) {
val msg = "[success] $patch"
handler.post {
installerChannel.invokeMethod(
"update",
mapOf(
"progress" to 0.5,
"header" to "",
"log" to msg
)
)
}
return@forEach
}
val msg = "[error] $patch:" + res.exceptionOrNull()!!
handler.post {
installerChannel.invokeMethod(
"update",
mapOf("progress" to 0.5, "header" to "", "log" to msg)
)
}
}
handler.post {
installerChannel.invokeMethod(
"update",
mapOf(
"progress" to 0.7,
"header" to "Repacking apk...",
"log" to "Repacking patched apk"
)
)
}
val res = patcher.save()
ZipFile(patchedFile).use { file ->
res.dexFiles.forEach {
file.addEntryCompressData(
ZipEntry.createWithName(it.name),
it.stream.readBytes()
)
}
res.resourceFile?.let {
file.copyEntriesFromFileAligned(
ZipFile(it),
ZipAligner::getEntryAlignment
)
}
file.copyEntriesFromFileAligned(
ZipFile(inputFile),
ZipAligner::getEntryAlignment
)
}
handler.post {
installerChannel.invokeMethod(
"update",
mapOf(
"progress" to 0.9,
"header" to "Signing apk...",
"log" to ""
)
)
}
Signer("ReVanced", "s3cur3p@ssw0rd").signApk(patchedFile, outFile, keyStoreFile)
handler.post {
installerChannel.invokeMethod(
"update",
mapOf(
"progress" to 1.0,
"header" to "Finished!",
"log" to "Finished!"
)
)
}
handler.post { result.success(null) }
}
)
.start()
}
}

View File

@ -0,0 +1,299 @@
package app.revanced.manager.flutter
import android.os.Handler
import android.os.Looper
import androidx.annotation.NonNull
import app.revanced.manager.flutter.utils.Aapt
import app.revanced.manager.flutter.utils.aligning.ZipAligner
import app.revanced.manager.flutter.utils.signing.Signer
import app.revanced.manager.flutter.utils.zip.ZipFile
import app.revanced.manager.flutter.utils.zip.structures.ZipEntry
import app.revanced.patcher.Patcher
import app.revanced.patcher.PatcherOptions
import app.revanced.patcher.extensions.PatchExtensions.patchName
import app.revanced.patcher.logging.Logger
import app.revanced.patcher.util.patch.impl.DexPatchBundle
import dalvik.system.DexClassLoader
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
import java.io.File
private const val PATCHER_CHANNEL = "app.revanced.manager.flutter/patcher"
private const val INSTALLER_CHANNEL = "app.revanced.manager.flutter/installer"
class MainActivity : FlutterActivity() {
private val handler = Handler(Looper.getMainLooper())
private lateinit var installerChannel: MethodChannel
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
val mainChannel = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, PATCHER_CHANNEL)
installerChannel = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, INSTALLER_CHANNEL)
mainChannel.setMethodCallHandler { call, result ->
when (call.method) {
"runPatcher" -> {
val patchBundleFilePath = call.argument<String>("patchBundleFilePath")
val originalFilePath = call.argument<String>("originalFilePath")
val inputFilePath = call.argument<String>("inputFilePath")
val patchedFilePath = call.argument<String>("patchedFilePath")
val outFilePath = call.argument<String>("outFilePath")
val integrationsPath = call.argument<String>("integrationsPath")
val selectedPatches = call.argument<List<String>>("selectedPatches")
val cacheDirPath = call.argument<String>("cacheDirPath")
val mergeIntegrations = call.argument<Boolean>("mergeIntegrations")
val resourcePatching = call.argument<Boolean>("resourcePatching")
val keyStoreFilePath = call.argument<String>("keyStoreFilePath")
if (patchBundleFilePath != null &&
originalFilePath != null &&
inputFilePath != null &&
patchedFilePath != null &&
outFilePath != null &&
integrationsPath != null &&
selectedPatches != null &&
cacheDirPath != null &&
mergeIntegrations != null &&
resourcePatching != null &&
keyStoreFilePath != null
) {
runPatcher(
result,
patchBundleFilePath,
originalFilePath,
inputFilePath,
patchedFilePath,
outFilePath,
integrationsPath,
selectedPatches,
cacheDirPath,
mergeIntegrations,
resourcePatching,
keyStoreFilePath
)
} else {
result.notImplemented()
}
}
else -> result.notImplemented()
}
}
}
private fun runPatcher(
result: MethodChannel.Result,
patchBundleFilePath: String,
originalFilePath: String,
inputFilePath: String,
patchedFilePath: String,
outFilePath: String,
integrationsPath: String,
selectedPatches: List<String>,
cacheDirPath: String,
mergeIntegrations: Boolean,
resourcePatching: Boolean,
keyStoreFilePath: String
) {
val originalFile = File(originalFilePath)
val inputFile = File(inputFilePath)
val patchedFile = File(patchedFilePath)
val outFile = File(outFilePath)
val integrations = File(integrationsPath)
val keyStoreFile = File(keyStoreFilePath)
val patches = DexPatchBundle(
patchBundleFilePath,
DexClassLoader(
patchBundleFilePath,
cacheDirPath,
null,
javaClass.classLoader
)
).loadPatches().filter { patch -> selectedPatches.any { it == patch.patchName } }
Thread {
handler.post {
installerChannel.invokeMethod(
"update",
mapOf(
"progress" to 0.1,
"header" to "",
"log" to "Copying original apk"
)
)
}
originalFile.copyTo(inputFile, true)
handler.post {
installerChannel.invokeMethod(
"update",
mapOf(
"progress" to 0.2,
"header" to "Unpacking apk...",
"log" to "Unpacking input apk"
)
)
}
val patcher =
Patcher(
PatcherOptions(
inputFile,
cacheDirPath,
resourcePatching,
Aapt.binary(applicationContext).absolutePath,
cacheDirPath,
logger = ManagerLogger()
)
)
handler.post {
installerChannel.invokeMethod(
"update",
mapOf("progress" to 0.3, "header" to "", "log" to "")
)
}
if (mergeIntegrations) {
handler.post {
installerChannel.invokeMethod(
"update",
mapOf(
"progress" to 0.4,
"header" to "Merging integrations...",
"log" to "Merging integrations"
)
)
}
patcher.addFiles(listOf(integrations)) {}
}
handler.post {
installerChannel.invokeMethod(
"update",
mapOf(
"progress" to 0.5,
"header" to "Applying patches...",
"log" to ""
)
)
}
patcher.addPatches(patches)
patcher.applyPatches().forEach { (patch, res) ->
if (res.isSuccess) {
val msg = "[success] $patch"
handler.post {
installerChannel.invokeMethod(
"update",
mapOf(
"progress" to 0.5,
"header" to "",
"log" to msg
)
)
}
return@forEach
}
val msg = "[error] $patch:" + res.exceptionOrNull()!!
handler.post {
installerChannel.invokeMethod(
"update",
mapOf("progress" to 0.5, "header" to "", "log" to msg)
)
}
}
handler.post {
installerChannel.invokeMethod(
"update",
mapOf(
"progress" to 0.7,
"header" to "Repacking apk...",
"log" to "Repacking patched apk"
)
)
}
val res = patcher.save()
ZipFile(patchedFile).use { file ->
res.dexFiles.forEach {
file.addEntryCompressData(
ZipEntry.createWithName(it.name),
it.stream.readBytes()
)
}
res.resourceFile?.let {
file.copyEntriesFromFileAligned(
ZipFile(it),
ZipAligner::getEntryAlignment
)
}
file.copyEntriesFromFileAligned(
ZipFile(inputFile),
ZipAligner::getEntryAlignment
)
}
handler.post {
installerChannel.invokeMethod(
"update",
mapOf(
"progress" to 0.9,
"header" to "Signing apk...",
"log" to ""
)
)
}
Signer("ReVanced", "s3cur3p@ssw0rd").signApk(patchedFile, outFile, keyStoreFile)
handler.post {
installerChannel.invokeMethod(
"update",
mapOf(
"progress" to 1.0,
"header" to "Finished!",
"log" to "Finished!"
)
)
}
handler.post { result.success(null) }
}
.start()
}
inner class ManagerLogger : Logger {
override fun error(msg: String) {
handler.post {
installerChannel
.invokeMethod(
"update",
mapOf("progress" to -1.0, "header" to "", "log" to msg)
)
}
}
override fun warn(msg: String) {
handler.post {
installerChannel.invokeMethod(
"update",
mapOf("progress" to -1.0, "header" to "", "log" to msg)
)
}
}
override fun info(msg: String) {
handler.post {
installerChannel.invokeMethod(
"update",
mapOf("progress" to -1.0, "header" to "", "log" to msg)
)
}
}
override fun trace(msg: String) {
handler.post {
installerChannel.invokeMethod(
"update",
mapOf("progress" to -1.0, "header" to "", "log" to msg)
)
}
}
}
}

View File

@ -1,3 +1,5 @@
@file:Suppress("unused")
package app.revanced.manager.flutter.utils.zip
import java.io.DataInput
@ -17,8 +19,8 @@ fun UShort.toBigEndian() = (this.toUInt() shl 16).toBigEndian().toUShort()
fun ByteBuffer.getUShort() = this.short.toUShort()
fun ByteBuffer.getUInt() = this.int.toUInt()
fun ByteBuffer.putUShort(ushort: UShort) = this.putShort(ushort.toShort())
fun ByteBuffer.putUInt(uint: UInt) = this.putInt(uint.toInt())
fun ByteBuffer.putUShort(ushort: UShort): ByteBuffer = this.putShort(ushort.toShort())
fun ByteBuffer.putUInt(uint: UInt): ByteBuffer = this.putInt(uint.toInt())
fun DataInput.readUShort() = this.readShort().toUShort()
fun DataInput.readUInt() = this.readInt().toUInt()

View File

@ -10,7 +10,7 @@ import java.nio.channels.FileChannel
import java.util.zip.CRC32
import java.util.zip.Deflater
class ZipFile(val file: File) : Closeable {
class ZipFile(file: File) : Closeable {
var entries: MutableList<ZipEntry> = mutableListOf()
private val filePointer: RandomAccessFile = RandomAccessFile(file, "rw")
@ -134,8 +134,8 @@ class ZipFile(val file: File) : Closeable {
addEntry(entry, compressedBuffer)
}
fun addEntryCopyData(entry: ZipEntry, data: ByteBuffer, alignment: Int? = null) {
alignment?.let { alignment ->
private fun addEntryCopyData(entry: ZipEntry, data: ByteBuffer, alignment: Int? = null) {
alignment?.let {
//calculate where data would end up
val dataOffset = filePointer.filePointer + entry.LFHSize

View File

@ -76,7 +76,7 @@ data class ZipEntry(
val fileNameLength = input.readUShortLE()
var fileName = ""
val extraFieldLength = input.readUShortLE()
var extraField = ByteArray(extraFieldLength.toInt())
val extraField = ByteArray(extraFieldLength.toInt())
val fileCommentLength = input.readUShortLE()
var fileComment = ""
val diskNumber = input.readUShortLE()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 814 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB

View File

@ -1,12 +1,12 @@
buildscript {
ext.kotlin_version = '1.6.10'
ext.kotlin_version = '1.7.10'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath 'com.android.tools.build:gradle:7.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

View File

@ -1,6 +1,6 @@
#Fri Jun 23 08:50:38 CEST 2017
#Mon May 09 12:07:41 MSK 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-rc-1-bin.zip
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
zipStoreBase=GRADLE_USER_HOME

View File

@ -42,7 +42,9 @@
},
"patcherView": {
"widgetTitle": "Patcher",
"patchButton": "Patch"
"patchButton": "Patch",
"patchDialogTitle": "Warning",
"patchDialogText": "You have selected a resource patch and a split APK installation was detected so patching errors can occur.\nAre you sure you want to proceed with patching a split base APK?"
},
"appSelectorCard": {
"widgetTitle": "Select application",

View File

@ -7,7 +7,7 @@ part 'patched_application.g.dart';
@JsonSerializable()
class PatchedApplication {
String name;
final String packageName;
String packageName;
String version;
final String apkFilePath;
@JsonKey(

View File

@ -82,6 +82,24 @@ class PatcherAPI {
.toList();
}
Future<bool> needsIntegrations(List<Patch> selectedPatches) async {
return selectedPatches.any(
(patch) => patch.dependencies.contains('integrations'),
);
}
Future<bool> needsResourcePatching(List<Patch> selectedPatches) async {
return selectedPatches.any(
(patch) => patch.dependencies.any((dep) => dep.contains('resource-')),
);
}
Future<bool> needsSettingsPatch(List<Patch> selectedPatches) async {
return selectedPatches.any(
(patch) => patch.dependencies.contains('settings'),
);
}
Future<String> getOriginalFilePath(
String packageName,
String originalFilePath,
@ -101,15 +119,9 @@ class PatcherAPI {
String originalFilePath,
List<Patch> selectedPatches,
) async {
bool mergeIntegrations = selectedPatches.any(
(patch) => patch.dependencies.contains('integrations'),
);
bool resourcePatching = selectedPatches.any(
(patch) => patch.dependencies.any((dep) => dep.contains('resource-')),
);
bool includeSettings = selectedPatches.any(
(patch) => patch.dependencies.contains('settings'),
);
bool mergeIntegrations = await needsIntegrations(selectedPatches);
bool resourcePatching = await needsResourcePatching(selectedPatches);
bool includeSettings = await needsSettingsPatch(selectedPatches);
if (includeSettings) {
try {
Patch? settingsPatch = _patches.firstWhereOrNull(

View File

@ -76,7 +76,7 @@ class DynamicThemeBuilder extends StatelessWidget {
2: lightDynamicTheme,
3: darkDynamicTheme,
},
fallbackTheme: darkCustomTheme,
fallbackTheme: lightCustomTheme,
),
builder: (context, theme) => MaterialApp(
debugShowCheckedModeBanner: false,

View File

@ -142,6 +142,13 @@ class InstallerViewModel extends BaseViewModel {
update(1.0, 'Installed!', 'Installed!');
_app.patchDate = DateTime.now();
_app.appliedPatches = _patches.map((p) => p.name).toList();
bool hasMicroG = _patches.any((p) => p.name.endsWith('microg-support'));
if (hasMicroG) {
_app.packageName = _app.packageName.replaceFirst(
'com.google.',
'app.revanced.',
);
}
await _managerAPI.savePatchedApp(_app);
}
}

View File

@ -11,6 +11,7 @@ class NavigationView extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ViewModelBuilder<NavigationViewModel>.reactive(
onModelReady: (model) => model.initialize(context),
viewModelBuilder: () => locator<NavigationViewModel>(),
builder: (context, model, child) => Scaffold(
body: PageTransitionSwitcher(

View File

@ -1,12 +1,33 @@
// ignore_for_file: use_build_context_synchronously
import 'package:dynamic_themes/dynamic_themes.dart';
import 'package:flutter/material.dart';
import 'package:injectable/injectable.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:revanced_manager/services/root_api.dart';
import 'package:revanced_manager/ui/views/home/home_view.dart';
import 'package:revanced_manager/ui/views/patcher/patcher_view.dart';
import 'package:revanced_manager/ui/views/settings/settings_view.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:stacked/stacked.dart';
@lazySingleton
class NavigationViewModel extends IndexTrackingViewModel {
void initialize(BuildContext context) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
if (prefs.getBool('useDarkTheme') == null) {
if (MediaQuery.of(context).platformBrightness == Brightness.light) {
await prefs.setBool('useDarkTheme', false);
DynamicTheme.of(context)!.setTheme(0);
} else {
await prefs.setBool('useDarkTheme', true);
DynamicTheme.of(context)!.setTheme(1);
}
}
RootAPI().hasRootPermissions();
Permission.requestInstallPackages.request();
Permission.ignoreBatteryOptimizations.request();
}
Widget getViewForIndex(int index) {
switch (index) {
case 0:

View File

@ -22,7 +22,7 @@ class PatcherView extends StatelessWidget {
child: FloatingActionButton.extended(
label: I18nText('patcherView.patchButton'),
icon: const Icon(Icons.build),
onPressed: () => model.navigateToInstaller(),
onPressed: () => model.showPatchConfirmationDialog(context),
),
),
body: CustomScrollView(

View File

@ -1,14 +1,20 @@
import 'package:device_apps/device_apps.dart';
import 'package:flutter/material.dart';
import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:injectable/injectable.dart';
import 'package:revanced_manager/app/app.locator.dart';
import 'package:revanced_manager/app/app.router.dart';
import 'package:revanced_manager/models/patch.dart';
import 'package:revanced_manager/models/patched_application.dart';
import 'package:revanced_manager/services/patcher_api.dart';
import 'package:revanced_manager/ui/widgets/installerView/custom_material_button.dart';
import 'package:stacked/stacked.dart';
import 'package:stacked_services/stacked_services.dart';
@lazySingleton
class PatcherViewModel extends BaseViewModel {
final NavigationService _navigationService = locator<NavigationService>();
final PatcherAPI _patcherAPI = locator<PatcherAPI>();
PatchedApplication? selectedApp;
List<Patch> selectedPatches = [];
@ -31,4 +37,46 @@ class PatcherViewModel extends BaseViewModel {
bool dimPatchesCard() {
return selectedApp == null;
}
Future<bool> isValidPatchConfig() async {
bool needsResourcePatching =
await _patcherAPI.needsResourcePatching(selectedPatches);
if (needsResourcePatching && selectedApp != null) {
Application? app = await DeviceApps.getApp(selectedApp!.packageName);
if (app != null && app.isSplit) {
return false;
}
}
return true;
}
Future<void> showPatchConfirmationDialog(BuildContext context) async {
bool isValid = await isValidPatchConfig();
if (isValid) {
navigateToInstaller();
} else {
return showDialog(
context: context,
builder: (context) => AlertDialog(
title: I18nText('patcherView.patchDialogTitle'),
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
content: I18nText('patcherView.patchDialogText'),
actions: <Widget>[
CustomMaterialButton(
isFilled: false,
label: I18nText('cancelButton'),
onPressed: () => Navigator.of(context).pop(),
),
CustomMaterialButton(
label: I18nText('okButton'),
onPressed: () {
Navigator.of(context).pop();
navigateToInstaller();
},
)
],
),
);
}
}
}

View File

@ -4,7 +4,7 @@ homepage: https://github.com/revanced/revanced-manager
publish_to: 'none'
version: 0.0.3+3
version: 0.0.6+6
environment:
sdk: ">=2.17.5 <3.0.0"
@ -17,14 +17,17 @@ dependencies:
device_apps:
git:
url: https://github.com/ponces/flutter_plugin_device_apps
ref: appinfo-from-storage
ref: revanced-manager
device_info_plus: ^4.1.2
dio: ^4.0.6
dio_http_cache_lts: ^0.4.1
dynamic_color: ^1.5.4
dynamic_themes: ^1.1.0
expandable: ^5.0.1
file_picker: ^5.0.1
file_picker:
git:
url: https://github.com/alexmercerind/flutter_file_picker
ref: master
flex_color_scheme: ^6.0.0
flutter:
sdk: flutter
@ -49,6 +52,7 @@ dependencies:
ref: feature/nullSafe
package_info_plus: ^1.4.3+1
path_provider: ^2.0.11
permission_handler: ^10.0.0
pull_to_refresh: ^2.0.0
root: ^2.0.2
share_extend: ^2.0.0