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

refactor: update deprecated and minor code refactors #710

Merged
merged 6 commits into from
Feb 27, 2023
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
2 changes: 2 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ include: package:flutter_lints/flutter.yaml
analyzer:
exclude:
- lib/utils/env_class.g.dart
- "**/*.locator.dart"
- "**/*.router.dart"

linter:
rules:
Expand Down
5 changes: 5 additions & 0 deletions lib/app/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart';
import 'package:revanced_manager/ui/views/patches_selector/patches_selector_view.dart';
import 'package:revanced_manager/ui/views/settings/settings_view.dart';
import 'package:revanced_manager/ui/widgets/appInfoView/app_info_view.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:stacked/stacked_annotations.dart';
import 'package:stacked_services/stacked_services.dart';

Expand All @@ -40,6 +41,10 @@ import 'package:stacked_services/stacked_services.dart';
LazySingleton(classType: GithubAPI),
LazySingleton(classType: CrowdinAPI),
LazySingleton(classType: Toast),
Presolve(
classType: SharedPreferences,
presolveUsing: SharedPreferences.getInstance,
)
],
)
class AppSetup {}
32 changes: 13 additions & 19 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:revanced_manager/app/app.locator.dart';
import 'package:revanced_manager/services/crowdin_api.dart';
import 'package:revanced_manager/services/github_api.dart';
import 'package:revanced_manager/services/manager_api.dart';
import 'package:revanced_manager/services/patcher_api.dart';
Expand All @@ -13,27 +12,25 @@ import 'package:revanced_manager/ui/theme/dynamic_theme_builder.dart';
import 'package:revanced_manager/ui/views/navigation/navigation_view.dart';
import 'package:revanced_manager/utils/environment.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:stacked_themes/stacked_themes.dart';
import 'package:timezone/data/latest.dart' as tz;

late SharedPreferences prefs;
Future main() async {
await ThemeManager.initialise();
await setupLocator();
WidgetsFlutterBinding.ensureInitialized();
await locator<ManagerAPI>().initialize();
final String apiUrl = locator<ManagerAPI>().getApiUrl();
await locator<RevancedAPI>().initialize(apiUrl);
await locator<CrowdinAPI>().initialize();
final bool isSentryEnabled = locator<ManagerAPI>().isSentryEnabled();
final String repoUrl = locator<ManagerAPI>().getRepoUrl();
await setupLocator();
final manager = locator<ManagerAPI>();
await manager.initialize();
final String apiUrl = manager.getApiUrl();
final bool isSentryEnabled = manager.isSentryEnabled();
final String repoUrl = manager.getRepoUrl();

await Future.wait([
locator<RevancedAPI>().initialize(apiUrl),
locator<PatcherAPI>().initialize(),
]);
locator<GithubAPI>().initialize(repoUrl);
await locator<PatcherAPI>().initialize();
tz.initializeTimeZones();
prefs = await SharedPreferences.getInstance();

await SentryFlutter.init(
return SentryFlutter.init(
(options) {
options
..dsn = isSentryEnabled ? Environment.sentryDSN : ''
Expand All @@ -51,11 +48,8 @@ Future main() async {
}
} as BeforeSendCallback?;
},
appRunner: () {
runApp(const MyApp());
},
appRunner: () => runApp(const MyApp()),
);
runApp(const MyApp());
}

class MyApp extends StatelessWidget {
Expand Down
17 changes: 10 additions & 7 deletions lib/services/crowdin_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ import 'package:sentry_flutter/sentry_flutter.dart';

@lazySingleton
class CrowdinAPI {
late Dio _dio = Dio();
final DioCacheManager _dioCacheManager = DioCacheManager(CacheConfig());
final apiKey = Environment.crowdinKEY;
CrowdinAPI() {
initialize();
}
Dio _dio = Dio();
DioCacheManager get _dioCacheManager => DioCacheManager(CacheConfig());
String get apiKey => Environment.crowdinKEY;

Future<void> initialize() async {
void initialize() {
try {
_dio = Dio(
BaseOptions(
Expand All @@ -24,15 +27,15 @@ class CrowdinAPI {
captureFailedRequests: true,
);
} on Exception catch (e, s) {
await Sentry.captureException(e, stackTrace: s);
Sentry.captureException(e, stackTrace: s).ignore();
}
}

Future<void> clearAllCache() async {
try {
await _dioCacheManager.clearAll();
} on Exception catch (e, s) {
await Sentry.captureException(e, stackTrace: s);
Sentry.captureException(e, stackTrace: s).ignore();
}
}

Expand All @@ -56,7 +59,7 @@ class CrowdinAPI {

return targetLanguages;
} on Exception catch (e, s) {
await Sentry.captureException(e, stackTrace: s);
Sentry.captureException(e, stackTrace: s).ignore();
return [];
}
}
Expand Down
14 changes: 7 additions & 7 deletions lib/services/github_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ class GithubAPI {
captureFailedRequests: true,
);
} on Exception catch (e, s) {
await Sentry.captureException(e, stackTrace: s);
Sentry.captureException(e, stackTrace: s).ignore();
}
}

Future<void> clearAllCache() async {
try {
await _dioCacheManager.clearAll();
} on Exception catch (e, s) {
await Sentry.captureException(e, stackTrace: s);
Sentry.captureException(e, stackTrace: s).ignore();
}
}

Expand All @@ -62,7 +62,7 @@ class GithubAPI {
);
return response.data[0];
} on Exception catch (e, s) {
await Sentry.captureException(e, stackTrace: s);
Sentry.captureException(e, stackTrace: s).ignore();
return null;
}
}
Expand Down Expand Up @@ -93,7 +93,7 @@ class GithubAPI {
)
.toList();
} on Exception catch (e, s) {
await Sentry.captureException(e, stackTrace: s);
Sentry.captureException(e, stackTrace: s).ignore();
return List.empty();
}
}
Expand All @@ -113,7 +113,7 @@ class GithubAPI {
}
}
} on Exception catch (e, s) {
await Sentry.captureException(e, stackTrace: s);
Sentry.captureException(e, stackTrace: s).ignore();
return null;
}
return null;
Expand All @@ -128,7 +128,7 @@ class GithubAPI {
patches = list.map((patch) => Patch.fromJson(patch)).toList();
}
} on Exception catch (e, s) {
await Sentry.captureException(e, stackTrace: s);
Sentry.captureException(e, stackTrace: s).ignore();
return List.empty();
}
return patches;
Expand All @@ -143,7 +143,7 @@ class GithubAPI {
return 'Unknown';
}
} on Exception catch (e, s) {
await Sentry.captureException(e, stackTrace: s);
Sentry.captureException(e, stackTrace: s).ignore();
return '';
}
}
Expand Down
12 changes: 6 additions & 6 deletions lib/services/manager_api.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:convert';
import 'dart:io';

import 'package:device_apps/device_apps.dart';
import 'package:injectable/injectable.dart';
import 'package:package_info_plus/package_info_plus.dart';
Expand All @@ -17,10 +18,10 @@ import 'package:shared_preferences/shared_preferences.dart';
class ManagerAPI {
final RevancedAPI _revancedAPI = locator<RevancedAPI>();
final GithubAPI _githubAPI = locator<GithubAPI>();
final SharedPreferences _prefs = locator<SharedPreferences>();
final RootAPI _rootAPI = RootAPI();
final String patcherRepo = 'revanced-patcher';
final String cliRepo = 'revanced-cli';
late SharedPreferences _prefs;
String storedPatchesFile = '/selected-patches.json';
String defaultApiUrl = 'https://releases.revanced.app/';
String defaultRepoUrl = 'https://api.github.com';
Expand All @@ -31,7 +32,6 @@ class ManagerAPI {
String defaultManagerRepo = 'revanced/revanced-manager';

Future<void> initialize() async {
_prefs = await SharedPreferences.getInstance();
storedPatchesFile =
(await getApplicationDocumentsDirectory()).path + storedPatchesFile;
}
Expand Down Expand Up @@ -180,7 +180,7 @@ class ManagerAPI {
_revancedAPI.clearAllCache();
_githubAPI.clearAllCache();
} on Exception catch (e, s) {
await Sentry.captureException(e, stackTrace: s);
Sentry.captureException(e, stackTrace: s).ignore();
}
}

Expand All @@ -197,7 +197,7 @@ class ManagerAPI {
return await _githubAPI.getPatches(repoName);
}
} on Exception catch (e, s) {
await Sentry.captureException(e, stackTrace: s);
Sentry.captureException(e, stackTrace: s).ignore();
return [];
}
}
Expand All @@ -214,7 +214,7 @@ class ManagerAPI {
return await _githubAPI.getLatestReleaseFile('.jar', repoName);
}
} on Exception catch (e, s) {
await Sentry.captureException(e, stackTrace: s);
Sentry.captureException(e, stackTrace: s).ignore();
return null;
}
}
Expand All @@ -231,7 +231,7 @@ class ManagerAPI {
return await _githubAPI.getLatestReleaseFile('.apk', repoName);
}
} on Exception catch (e, s) {
await Sentry.captureException(e, stackTrace: s);
Sentry.captureException(e, stackTrace: s).ignore();
return null;
}
}
Expand Down
26 changes: 15 additions & 11 deletions lib/services/patcher_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class PatcherAPI {
_patches = await _managerAPI.getPatches();
}
} on Exception catch (e, s) {
await Sentry.captureException(e, stackTrace: s);
Sentry.captureException(e, stackTrace: s).ignore();
_patches = List.empty();
}
}
Expand Down Expand Up @@ -92,7 +92,7 @@ class PatcherAPI {
}
}
} on Exception catch (e, s) {
await Sentry.captureException(e, stackTrace: s);
Sentry.captureException(e, stackTrace: s).ignore();
continue;
}
}
Expand Down Expand Up @@ -171,7 +171,7 @@ class PatcherAPI {
}
return originalFilePath;
} on Exception catch (e, s) {
await Sentry.captureException(e, stackTrace: s);
Sentry.captureException(e, stackTrace: s).ignore();
return originalFilePath;
}
}
Expand All @@ -194,7 +194,7 @@ class PatcherAPI {
selectedPatches.add(settingsPatch);
}
} on Exception catch (e, s) {
await Sentry.captureException(e, stackTrace: s);
Sentry.captureException(e, stackTrace: s).ignore();
// ignore
}
}
Expand Down Expand Up @@ -231,11 +231,11 @@ class PatcherAPI {
'keyStoreFilePath': _keyStoreFile.path,
},
);
} on Exception catch (e, s) {
} on Exception catch (e) {
if (kDebugMode) {
print(e);
}
throw await Sentry.captureException(e, stackTrace: s);
rethrow;
}
}
}
Expand All @@ -257,7 +257,7 @@ class PatcherAPI {
return await DeviceApps.isAppInstalled(patchedApp.packageName);
}
} on Exception catch (e, s) {
await Sentry.captureException(e, stackTrace: s);
Sentry.captureException(e, stackTrace: s).ignore();
return false;
}
}
Expand All @@ -268,11 +268,15 @@ class PatcherAPI {
try {
if (_outFile != null) {
final String newName = _getFileName(appName, version);
CRFileSaver.saveFileWithDialog(SaveFileDialogParams(
sourceFilePath: _outFile!.path, destinationFileName: newName,),);
CRFileSaver.saveFileWithDialog(
SaveFileDialogParams(
sourceFilePath: _outFile!.path,
destinationFileName: newName,
),
);
}
} on Exception catch (e, s) {
Sentry.captureException(e, stackTrace: s);
Sentry.captureException(e, stackTrace: s).ignore();
}
}

Expand All @@ -287,7 +291,7 @@ class PatcherAPI {
ShareExtend.share(shareFile.path, 'file');
}
} on Exception catch (e, s) {
Sentry.captureException(e, stackTrace: s);
Sentry.captureException(e, stackTrace: s).ignore();
}
}

Expand Down
Loading