Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #4

Merged
merged 15 commits into from
Nov 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/crowdin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Sync Crowdin translations

on:
push:
branches:
- "flutter"
paths:
- "assets/i18n/en_US.json"
- ".github/workflows/crowdin.yml"
schedule:
- cron: "0 0 * * *" # daily
workflow_dispatch:

jobs:
sync-crowdin:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Crowdin
uses: crowdin/[email protected]
with:
config: crowdin.yml
upload_translations: true
download_translations: true
push_translations: true
create_pull_request: false
localization_branch_name: i18n_flutter
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}

# commented due to Manager not being ready for the translated files to be in the main branch
# - name: GitHub is so dumb i just cant
# run: |
# sudo chmod -R ugo+rwX .

# - name: Merge
# run: |
# git checkout flutter
# git add *
# git merge i18n_flutter
# git push
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
.project
.settings/
.fvm/
.vscode/

# Flutter repo-specific
/bin/cache/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class MainActivity : FlutterActivity() {
patcher.addPatches(patches)
patcher.executePatches().forEach { (patch, res) ->
if (res.isSuccess) {
val msg = "[success] $patch"
val msg = "Applied $patch"
handler.post {
installerChannel.invokeMethod(
"update",
Expand All @@ -193,7 +193,7 @@ class MainActivity : FlutterActivity() {
}
return@forEach
}
val msg = "[error] $patch:" + res.exceptionOrNull()!!.printStackTrace()
val msg = "$patch failed.\nError:\n" + res.exceptionOrNull()!!.printStackTrace()
handler.post {
installerChannel.invokeMethod(
"update",
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
buildscript {
ext.cronetVersion = '102.5005.125'
ext.kotlin_version = '1.7.10'
ext.kotlin_version = '1.7.20'
repositories {
google()
mavenCentral()
Expand Down
12 changes: 8 additions & 4 deletions assets/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
"loadedStatusLabel": "Loaded",
"patchesLabel": "Patches Status: ",
"statusLabel": "Status: ",
"loadButton": "Load Patch"
"loadButton": "Load Patch",
"versionLabel": "Version: "
},
"patcherView": {
"widgetTitle": "Patcher",
Expand Down Expand Up @@ -95,7 +96,8 @@
"patchItem": {
"unsupportedWarningButton": "Warning",
"unsupportedDialogTitle": "Warning",
"unsupportedDialogText": "Selecting this patch may result in patching errors.\n\nApp version: {packageVersion}\nCurrent supported versions:\n{supportedVersions}"
"unsupportedDialogText": "Selecting this patch may result in patching errors.\n\nApp version: {packageVersion}\nCurrent supported versions:\n{supportedVersions}",
"unsupportedPatchVersion": "Patch is not supported for this app version. Enable experimental toggle in settings to proceed."
},
"installerView": {
"widgetTitle": "Installer",
Expand All @@ -106,6 +108,7 @@
"notificationTitle": "ReVanced Manager is patching",
"notificationText": "Tap to return to the installer",
"shareApkMenuOption": "Share APK",
"exportApkMenuOption": "Export APK",
"shareLogMenuOption": "Share log",
"installErrorDialogTitle": "Error",
"installErrorDialogText1": "Root install is not possible with the current patches selection.\nRepatch your app or choose non-root install.",
Expand Down Expand Up @@ -142,9 +145,10 @@
"logsHint": "Share device debug logs",
"apiURLLabel": "API URL",
"apiURLHint": "Configure your custom API URL",
"githubTokenLabel": "Github Token",
"githubTokenHint": "Set your github token to load patches without 403 error",
"selectApiURL": "Select URL",
"experimentalPatchesLabel": "Experimental Patch support",
"experimentalPatchesHint": "Enable to use unsupported patches in any app version",
"enabledExperimentalPatches": "Experimental patches enabled",
"aboutLabel": "About",
"snackbarMessage": "Copied to clipboard",
"sentryLabel": "Sentry Logging",
Expand Down
10 changes: 8 additions & 2 deletions crowdin.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
project_id_env: CROWDIN_PROJECT_ID
api_token_env: CROWDIN_PERSONAL_TOKEN

commit_message: 'chore(i18n): sync translations'

preserve_hierarchy: true
files:
- source: /assets/i18n/en.json
translation: /assets/i18n/%locale_with_underscore%.json
- source: assets/i18n/en_US.json
translation: assets/i18n/%locale_with_underscore%.json
1 change: 0 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'package:revanced_manager/services/revanced_api.dart';
import 'package:revanced_manager/ui/theme/dynamic_theme_builder.dart';
import 'package:revanced_manager/ui/views/navigation/navigation_view.dart';
import 'package:stacked_themes/stacked_themes.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:timezone/data/latest.dart' as tz;

Future main() async {
Expand Down
59 changes: 42 additions & 17 deletions lib/services/github_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'package:injectable/injectable.dart';
import 'package:native_dio_client/native_dio_client.dart';
import 'package:revanced_manager/models/patch.dart';
import 'package:revanced_manager/utils/check_for_gms.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:sentry_dio/sentry_dio.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:timeago/timeago.dart';

@lazySingleton
class GithubAPI {
Expand All @@ -33,21 +32,10 @@ class GithubAPI {

void initialize() async {
try {
bool isGMSInstalled = await checkForGMS();
final prefs = await SharedPreferences.getInstance();
final token = prefs.getString('githubToken');
final baseOptions = BaseOptions(baseUrl: 'https://api.github.com');
if(token != null) {
baseOptions.headers.addAll({"Authorization": "Bearer $token"});
}
if (!isGMSInstalled) {
_dio = Dio(baseOptions);
print('GitHub API: Using default engine + $isGMSInstalled');
} else {
_dio = Dio(baseOptions)
..httpClientAdapter = NativeAdapter();
print('ReVanced API: Using CronetEngine + $isGMSInstalled');
}
_dio = Dio(BaseOptions(
baseUrl: 'https://api.github.com',
))..httpClientAdapter = NativeAdapter();

_dio.interceptors.add(_dioCacheManager.interceptor);
_dio.addSentry(
captureFailedRequests: true,
Expand Down Expand Up @@ -144,4 +132,41 @@ class GithubAPI {
}
return patches;
}

Future<String?> getLatestReleaseVersion(
String extension,
String repoName,
) async {
try {
Map<String, dynamic>? release = await _getLatestRelease(
repoName,
);
if (release != null) {
return release['name'];
}
} on Exception catch (e, s) {
await Sentry.captureException(e, stackTrace: s);
return null;
}
return null;
}

Future<String?> getLatestReleaseTime(
String extension,
String repoName,
) async {
try {
Map<String, dynamic>? release = await _getLatestRelease(
repoName,
);
if (release != null) {
DateTime timestamp = DateTime.parse(release['published_at'] as String);
return format(timestamp, locale: 'en_short');
}
} on Exception catch (e, s) {
await Sentry.captureException(e, stackTrace: s);
return null;
}
return null;
}
}
34 changes: 26 additions & 8 deletions lib/services/manager_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ManagerAPI {
final String patcherRepo = 'revanced-patcher';
final String cliRepo = 'revanced-cli';
late SharedPreferences _prefs;
String defaultApiUrl = 'https://releases.rvcd.win/';
String defaultApiUrl = 'https://releases.revanced.app/';
String defaultPatcherRepo = 'revanced/revanced-patcher';
String defaultPatchesRepo = 'revanced/revanced-patches';
String defaultIntegrationsRepo = 'revanced/revanced-integrations';
Expand Down Expand Up @@ -98,6 +98,14 @@ class ManagerAPI {
// await _prefs.setBool('sentryEnabled', value);
// }

bool areExperimentalPatchesEnabled() {
return _prefs.getBool('experimentalPatchesEnabled') ?? false;
}

Future<void> enableExperimentalPatchesStatus(bool value) async {
await _prefs.setBool('experimentalPatchesEnabled', value);
}

Future<void> deleteTempFolder() async {
final Directory dir = Directory('/data/local/tmp/revanced-manager');
if (await dir.exists()) {
Expand Down Expand Up @@ -210,29 +218,39 @@ class ManagerAPI {
}

Future<File?> downloadManager() async {
return await _revancedAPI.getLatestReleaseFile('.apk', defaultManagerRepo);
return await _githubAPI.getLatestReleaseFile('.apk', defaultManagerRepo);
}

Future<String?> getLatestPatcherReleaseTime() async {
return await _revancedAPI.getLatestReleaseTime('.gz', defaultPatcherRepo);
}

Future<String?> getLatestManagerReleaseTime() async {
return await _revancedAPI.getLatestReleaseTime('.apk', defaultManagerRepo);
return await _githubAPI.getLatestReleaseTime('.apk', defaultManagerRepo);
}

Future<String?> getLatestManagerVersion() async {
return await _revancedAPI.getLatestReleaseVersion(
return await _githubAPI.getLatestReleaseVersion(
'.apk',
defaultManagerRepo,
);
}

Future<String?> getLatestPatchesVersion() async {
return await _revancedAPI.getLatestReleaseVersion(
'.json',
defaultPatchesRepo,
);
try {
String repoName = getPatchesRepo();
if (repoName == defaultPatchesRepo) {
return await _revancedAPI.getLatestReleaseVersion(
'.json',
defaultPatchesRepo,
);
} else {
return await _githubAPI.getLatestReleaseVersion('.json', repoName);
}
} on Exception catch (e, s) {
await Sentry.captureException(e, stackTrace: s);
return null;
}
}

Future<String> getCurrentManagerVersion() async {
Expand Down
33 changes: 31 additions & 2 deletions lib/services/patcher_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'package:revanced_manager/services/manager_api.dart';
import 'package:revanced_manager/services/root_api.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:share_extend/share_extend.dart';
import 'package:cr_file_saver/file_saver.dart';
import 'package:stacked_services/stacked_services.dart';

@lazySingleton
Expand Down Expand Up @@ -266,11 +267,32 @@ class PatcherAPI {
return false;
}


void exportPatchedFile(String appName, String version) {
try {
if (_outFile != null) {
String newName = _getFileName(appName, version);

// This is temporary workaround to populate initial file name
// ref: https://github.com/Cleveroad/cr_file_saver/issues/7
int lastSeparator = _outFile!.path.lastIndexOf('/');
String newSourcePath = _outFile!.path.substring(0, lastSeparator + 1) + newName;
_outFile!.copySync(newSourcePath);

CRFileSaver.saveFileWithDialog(SaveFileDialogParams(
sourceFilePath: newSourcePath,
destinationFileName: newName
));
}
} on Exception catch (e, s) {
Sentry.captureException(e, stackTrace: s);
}
}

void sharePatchedFile(String appName, String version) {
try {
if (_outFile != null) {
String prefix = appName.toLowerCase().replaceAll(' ', '-');
String newName = '$prefix-revanced_v$version.apk';
String newName = _getFileName(appName, version);
int lastSeparator = _outFile!.path.lastIndexOf('/');
String newPath =
_outFile!.path.substring(0, lastSeparator + 1) + newName;
Expand All @@ -282,6 +304,13 @@ class PatcherAPI {
}
}

String _getFileName(String appName, String version) {
String prefix = appName.toLowerCase().replaceAll(' ', '-');
String newName = '$prefix-revanced_v$version.apk';
return newName;

}

Future<void> sharePatcherLog(String logs) async {
Directory appCache = await getTemporaryDirectory();
Directory logDir = Directory('${appCache.path}/logs');
Expand Down
3 changes: 3 additions & 0 deletions lib/ui/views/home/home_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ class HomeViewModel extends BaseViewModel {
List<PatchedApplication> patchedInstalledApps = [];
List<PatchedApplication> patchedUpdatableApps = [];

String? _patchesVersion;
get noPatchesLoaded => _patcherAPI.noPatchesLoaded;
String? get patchesVersion => _patchesVersion;

Future<void> initialize(BuildContext context) async {
await flutterLocalNotificationsPlugin.initialize(
Expand All @@ -56,6 +58,7 @@ class HomeViewModel extends BaseViewModel {
if (_patcherAPI.noPatchesLoaded) {
// _toast.show();
}
_patchesVersion = await _managerAPI.getLatestPatchesVersion();
}

void navigateToAppInfo(PatchedApplication app) {
Expand Down
11 changes: 10 additions & 1 deletion lib/ui/views/installer/installer_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,16 @@ class InstallerView extends StatelessWidget {
),
),
),
1: I18nText(
1: I18nText(
'installerView.exportApkMenuOption',
child: const Text(
'',
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
),
2: I18nText(
'installerView.shareLogMenuOption',
child: const Text(
'',
Expand Down
Loading