Skip to content

Commit

Permalink
chore: merge dev to main (#1120)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ushie authored Aug 10, 2023
2 parents fd741f2 + 580d50e commit c6a5f42
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 5 deletions.
5 changes: 4 additions & 1 deletion assets/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"yesButton": "Yes",
"noButton": "No",
"warning": "Warning",
"notice": "Notice",
"new": "New",
"navigationView": {
"dashboardTab": "Dashboard",
Expand Down Expand Up @@ -71,7 +72,8 @@

"patchDialogText": "You have selected a resource patch and a split APK installation has been detected, so patching errors may occur.\nAre you sure you want to proceed?",
"armv7WarningDialogText": "Patching on ARMv7 devices is not yet supported and might fail. Proceed anyways?",
"splitApkWarningDialogText": "Patching a split APK is not yet supported and might fail. Proceed anyways?"
"splitApkWarningDialogText": "Patching a split APK is not yet supported and might fail. Proceed anyways?",
"removedPatchesWarningDialogText": "The following patches have been removed since the last time you used them.\n\n{patches}\n\nProceed anyways?"
},
"appSelectorCard": {
"widgetTitle": "Select an application",
Expand Down Expand Up @@ -198,6 +200,7 @@
"logsLabel": "Logs",
"logsHint": "Share Manager's logs",

"autoUpdatePatchesLabel": "Auto update patches",
"autoUpdatePatchesHint": "Automatically update ReVanced Patches to the latest version",
"experimentalUniversalPatchesLabel": "Experimental universal patches support",
"experimentalUniversalPatchesHint": "Display all applications to use with universal patches, loading list of apps may be slower",
Expand Down
19 changes: 18 additions & 1 deletion lib/services/manager_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ class ManagerAPI {
}

List<Patch> getSavedPatches(String packageName) {
final List<String> patchesJson = _prefs.getStringList('savedPatches-$packageName') ?? [];
final List<String> patchesJson =
_prefs.getStringList('savedPatches-$packageName') ?? [];
final List<Patch> patches = patchesJson.map((String patchJson) {
return Patch.fromJson(jsonDecode(patchJson));
}).toList();
Expand All @@ -118,6 +119,22 @@ class ManagerAPI {
await _prefs.setStringList('savedPatches-$packageName', patchesJson);
}

List<Patch> getUsedPatches(String packageName) {
final List<String> patchesJson =
_prefs.getStringList('usedPatches-$packageName') ?? [];
final List<Patch> patches = patchesJson.map((String patchJson) {
return Patch.fromJson(jsonDecode(patchJson));
}).toList();
return patches;
}

Future<void> setUsedPatches(List<Patch> patches, String packageName) async {
final List<String> patchesJson = patches.map((Patch patch) {
return jsonEncode(patch.toJson());
}).toList();
await _prefs.setStringList('usedPatches-$packageName', patchesJson);
}

String getIntegrationsRepo() {
return _prefs.getString('integrationsRepo') ?? defaultIntegrationsRepo;
}
Expand Down
6 changes: 6 additions & 0 deletions lib/services/root_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ class RootAPI {
}

Future<void> installServiceDScript(String packageName) async {
await Root.exec(
cmd: 'mkdir -p "$_serviceDDirPath"',
);
final String content = '#!/system/bin/sh\n'
'while [ "\$(getprop sys.boot_completed | tr -d \'"\'"\'\\\\r\'"\'"\')" != "1" ]; do sleep 3; done\n'
'base_path=$_revancedDirPath/$packageName/base.apk\n'
Expand All @@ -166,6 +169,9 @@ class RootAPI {
}

Future<void> installPostFsDataScript(String packageName) async {
await Root.exec(
cmd: 'mkdir -p "$_postFsDataDirPath"',
);
final String content = '#!/system/bin/sh\n'
'stock_path=\$(pm path $packageName | grep base | sed \'"\'"\'s/package://g\'"\'"\')\n'
r'[ ! -z $stock_path ] && umount -l $stock_path';
Expand Down
1 change: 1 addition & 0 deletions lib/ui/views/installer/installer_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class InstallerViewModel extends BaseViewModel {
_patcherAPI.getFilteredPatches(_app.packageName),
_app.packageName,
);
await _managerAPI.setUsedPatches(_patches, _app.packageName);
} else if (value == -100.0) {
isPatching = false;
hasErrors = true;
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/views/patcher/patcher_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class PatcherView extends StatelessWidget {
child: FloatingActionButton.extended(
label: I18nText('patcherView.patchButton'),
icon: const Icon(Icons.build),
onPressed: () => model.showPatchConfirmationDialog(context),
onPressed: () => model.showRemovedPatchesDialog(context),
),
),
body: CustomScrollView(
Expand Down
40 changes: 40 additions & 0 deletions lib/ui/views/patcher/patcher_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class PatcherViewModel extends BaseViewModel {
final PatcherAPI _patcherAPI = locator<PatcherAPI>();
PatchedApplication? selectedApp;
List<Patch> selectedPatches = [];
List<String> removedPatches = [];

void navigateToAppSelector() {
_navigationService.navigateTo(Routes.appSelectorView);
Expand Down Expand Up @@ -86,6 +87,38 @@ class PatcherViewModel extends BaseViewModel {
}
}

Future<void> showRemovedPatchesDialog(BuildContext context) async {
if (removedPatches.isNotEmpty) {
return showDialog(
context: context,
builder: (context) => AlertDialog(
title: I18nText('notice'),
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
content: I18nText(
'patcherView.removedPatchesWarningDialogText',
translationParams: {'patches': removedPatches.join('\n')},
),
actions: <Widget>[
CustomMaterialButton(
isFilled: false,
label: I18nText('noButton'),
onPressed: () => Navigator.of(context).pop(),
),
CustomMaterialButton(
label: I18nText('yesButton'),
onPressed: () {
Navigator.of(context).pop();
navigateToInstaller();
},
),
],
),
);
} else {
showArmv7WarningDialog(context);
}
}

Future<void> showArmv7WarningDialog(BuildContext context) async {
final bool armv7 = await AboutInfo.getInfo().then((info) {
final List<String> archs = info['supportedArch'];
Expand Down Expand Up @@ -150,6 +183,7 @@ class PatcherViewModel extends BaseViewModel {

Future<void> loadLastSelectedPatches() async {
this.selectedPatches.clear();
removedPatches.clear();
final List<String> selectedPatches =
await _managerAPI.getSelectedPatches(selectedApp!.originalPackageName);
final List<Patch> patches =
Expand All @@ -165,6 +199,12 @@ class PatcherViewModel extends BaseViewModel {
.selectedPatches
.removeWhere((patch) => patch.compatiblePackages.isEmpty);
}
final usedPatches = _managerAPI.getUsedPatches(selectedApp!.originalPackageName);
for (final patch in usedPatches){
if (!patches.any((p) => p.name == patch.name)){
removedPatches.add('\u2022 ${patch.name}');
}
}
notifyListeners();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class PatchesSelectorViewModel extends BaseViewModel {
return false;
} else {
return !savedPatches
.any((p) => p.name == patch.name.toLowerCase().replaceAll(' ', '-'));
.any((p) => p.getSimpleName() == patch.getSimpleName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class _SAutoUpdatePatchesState extends State<SAutoUpdatePatches> {
return SwitchListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 20.0),
title: I18nText(
'homeView.patchesConsentDialogText3',
'settingsView.autoUpdatePatchesLabel',
child: const Text(
'',
style: TextStyle(
Expand Down

0 comments on commit c6a5f42

Please sign in to comment.