2022-09-13 17:46:22 +01:00
|
|
|
import 'dart:io';
|
2022-11-09 08:36:04 +01:00
|
|
|
import 'package:cr_file_saver/file_saver.dart';
|
2022-09-08 12:09:12 +01:00
|
|
|
import 'package:device_info_plus/device_info_plus.dart';
|
2022-11-09 08:36:04 +01:00
|
|
|
import 'package:file_picker/file_picker.dart';
|
2022-09-13 17:46:22 +01:00
|
|
|
import 'package:logcat/logcat.dart';
|
|
|
|
import 'package:path_provider/path_provider.dart';
|
2022-08-12 23:37:16 +05:30
|
|
|
import 'package:revanced_manager/app/app.locator.dart';
|
|
|
|
import 'package:revanced_manager/app/app.router.dart';
|
2022-09-05 03:32:36 +01:00
|
|
|
import 'package:revanced_manager/services/manager_api.dart';
|
2022-10-15 01:52:10 +05:30
|
|
|
import 'package:revanced_manager/services/toast.dart';
|
2022-11-09 08:36:04 +01:00
|
|
|
import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart';
|
2022-11-12 21:25:33 +05:30
|
|
|
import 'package:revanced_manager/ui/views/settings/settingsFragement/settings_update_language.dart';
|
|
|
|
import 'package:revanced_manager/ui/views/settings/settingsFragement/settings_update_theme.dart';
|
2022-11-09 08:36:04 +01:00
|
|
|
import 'package:sentry_flutter/sentry_flutter.dart';
|
2022-09-13 17:46:22 +01:00
|
|
|
import 'package:share_extend/share_extend.dart';
|
2022-08-10 18:00:28 +05:30
|
|
|
import 'package:stacked/stacked.dart';
|
2022-08-12 23:37:16 +05:30
|
|
|
import 'package:stacked_services/stacked_services.dart';
|
2022-09-08 12:09:12 +01:00
|
|
|
|
2022-08-10 18:00:28 +05:30
|
|
|
class SettingsViewModel extends BaseViewModel {
|
2022-08-18 15:33:33 +01:00
|
|
|
final NavigationService _navigationService = locator<NavigationService>();
|
2022-09-05 03:32:36 +01:00
|
|
|
final ManagerAPI _managerAPI = locator<ManagerAPI>();
|
2022-10-15 01:52:10 +05:30
|
|
|
final Toast _toast = locator<Toast>();
|
2022-08-12 23:37:16 +05:30
|
|
|
|
2022-11-12 21:25:33 +05:30
|
|
|
final SUpdateLanguage sUpdateLanguage = SUpdateLanguage();
|
|
|
|
final SUpdateTheme sUpdateTheme = SUpdateTheme();
|
2022-08-12 23:37:16 +05:30
|
|
|
|
2022-09-05 15:30:26 +01:00
|
|
|
void navigateToContributors() {
|
|
|
|
_navigationService.navigateTo(Routes.contributorsView);
|
|
|
|
}
|
|
|
|
|
2022-11-12 21:25:33 +05:30
|
|
|
bool isSentryEnabled() {
|
|
|
|
return _managerAPI.isSentryEnabled();
|
2022-09-05 03:32:36 +01:00
|
|
|
}
|
|
|
|
|
2022-11-12 21:25:33 +05:30
|
|
|
void useSentry(bool value) {
|
|
|
|
_managerAPI.setSentryStatus(value);
|
|
|
|
_toast.showBottom('settingsView.restartAppForChanges');
|
2022-09-05 03:32:36 +01:00
|
|
|
notifyListeners();
|
|
|
|
}
|
2022-09-07 02:37:25 +01:00
|
|
|
|
2022-11-01 15:26:15 +05:30
|
|
|
bool areExperimentalPatchesEnabled() {
|
|
|
|
return _managerAPI.areExperimentalPatchesEnabled();
|
|
|
|
}
|
|
|
|
|
|
|
|
void useExperimentalPatches(bool value) {
|
|
|
|
_managerAPI.enableExperimentalPatchesStatus(value);
|
|
|
|
notifyListeners();
|
|
|
|
}
|
|
|
|
|
2022-10-17 00:22:07 +05:30
|
|
|
void deleteKeystore() {
|
|
|
|
_managerAPI.deleteKeystore();
|
|
|
|
_toast.showBottom('settingsView.deletedKeystore');
|
|
|
|
notifyListeners();
|
|
|
|
}
|
|
|
|
|
2022-10-17 00:41:20 +05:30
|
|
|
void deleteTempDir() {
|
|
|
|
_managerAPI.deleteTempFolder();
|
|
|
|
_toast.showBottom('settingsView.deletedTempDir');
|
|
|
|
notifyListeners();
|
|
|
|
}
|
|
|
|
|
2022-11-09 08:36:04 +01:00
|
|
|
Future<void> exportPatches() async {
|
|
|
|
try {
|
|
|
|
File outFile = File(_managerAPI.storedPatchesFile);
|
|
|
|
if (outFile.existsSync()) {
|
2022-11-10 23:03:07 +05:30
|
|
|
String dateTime =
|
|
|
|
DateTime.now().toString().replaceAll(' ', '_').split('.').first;
|
|
|
|
String tempFilePath =
|
|
|
|
'${outFile.path.substring(0, outFile.path.lastIndexOf('/') + 1)}selected_patches_$dateTime.json';
|
2022-11-09 08:36:04 +01:00
|
|
|
outFile.copySync(tempFilePath);
|
|
|
|
await CRFileSaver.saveFileWithDialog(SaveFileDialogParams(
|
2022-11-10 23:03:07 +05:30
|
|
|
sourceFilePath: tempFilePath, destinationFileName: ''));
|
2022-11-09 08:36:04 +01:00
|
|
|
File(tempFilePath).delete();
|
|
|
|
locator<Toast>().showBottom('settingsView.exportedPatches');
|
|
|
|
} else {
|
|
|
|
locator<Toast>().showBottom('settingsView.noExportFileFound');
|
|
|
|
}
|
|
|
|
} on Exception catch (e, s) {
|
|
|
|
Sentry.captureException(e, stackTrace: s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> importPatches() async {
|
|
|
|
try {
|
|
|
|
FilePickerResult? result = await FilePicker.platform.pickFiles(
|
|
|
|
type: FileType.custom,
|
|
|
|
allowedExtensions: ['json'],
|
|
|
|
);
|
|
|
|
if (result != null && result.files.single.path != null) {
|
|
|
|
File inFile = File(result.files.single.path!);
|
|
|
|
final File storedPatchesFile = File(_managerAPI.storedPatchesFile);
|
|
|
|
if (!storedPatchesFile.existsSync()) {
|
|
|
|
storedPatchesFile.createSync(recursive: true);
|
|
|
|
}
|
|
|
|
inFile.copySync(storedPatchesFile.path);
|
|
|
|
inFile.delete();
|
|
|
|
if (locator<PatcherViewModel>().selectedApp != null) {
|
|
|
|
locator<PatcherViewModel>().loadLastSelectedPatches();
|
|
|
|
}
|
|
|
|
locator<Toast>().showBottom('settingsView.importedPatches');
|
|
|
|
}
|
|
|
|
} on Exception catch (e, s) {
|
|
|
|
await Sentry.captureException(e, stackTrace: s);
|
|
|
|
locator<Toast>().showBottom('settingsView.jsonSelectorErrorMessage');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void resetSelectedPatches() {
|
|
|
|
_managerAPI.resetLastSelectedPatches();
|
|
|
|
_toast.showBottom('settingsView.resetStoredPatches');
|
|
|
|
}
|
|
|
|
|
2022-09-08 12:09:12 +01:00
|
|
|
Future<int> getSdkVersion() async {
|
|
|
|
AndroidDeviceInfo info = await DeviceInfoPlugin().androidInfo;
|
|
|
|
return info.version.sdkInt ?? -1;
|
|
|
|
}
|
2022-09-13 17:46:22 +01:00
|
|
|
|
2022-10-17 01:58:50 +05:30
|
|
|
Future<void> deleteLogs() async {
|
|
|
|
Directory appCacheDir = await getTemporaryDirectory();
|
|
|
|
Directory logsDir = Directory('${appCacheDir.path}/logs');
|
|
|
|
if (logsDir.existsSync()) {
|
|
|
|
logsDir.deleteSync(recursive: true);
|
|
|
|
}
|
|
|
|
_toast.showBottom('settingsView.deletedLogs');
|
|
|
|
}
|
|
|
|
|
2022-09-13 17:46:22 +01:00
|
|
|
Future<void> exportLogcatLogs() async {
|
|
|
|
Directory appCache = await getTemporaryDirectory();
|
|
|
|
Directory logDir = Directory('${appCache.path}/logs');
|
|
|
|
logDir.createSync();
|
|
|
|
String dateTime = DateTime.now()
|
|
|
|
.toIso8601String()
|
|
|
|
.replaceAll('-', '')
|
|
|
|
.replaceAll(':', '')
|
|
|
|
.replaceAll('T', '')
|
|
|
|
.replaceAll('.', '');
|
2022-09-14 10:40:45 +01:00
|
|
|
File logcat = File('${logDir.path}/revanced-manager_logcat_$dateTime.log');
|
2022-09-13 17:46:22 +01:00
|
|
|
String logs = await Logcat.execute();
|
|
|
|
logcat.writeAsStringSync(logs);
|
|
|
|
ShareExtend.share(logcat.path, 'file');
|
|
|
|
}
|
2022-08-10 18:00:28 +05:30
|
|
|
}
|