mirror of
https://github.com/revanced/revanced-manager.git
synced 2025-06-12 12:47:37 +02:00
feat: Add ReVanced API and implement cache on it and on Github API
This commit is contained in:
@ -1,34 +1,24 @@
|
||||
import 'package:github/github.dart';
|
||||
import 'package:revanced_manager/app/app.locator.dart';
|
||||
import 'package:revanced_manager/services/github_api.dart';
|
||||
import 'package:revanced_manager/services/manager_api.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
|
||||
class ContributorsViewModel extends BaseViewModel {
|
||||
final ManagerAPI _managerAPI = locator<ManagerAPI>();
|
||||
final GithubAPI _githubAPI = GithubAPI();
|
||||
List<Contributor> patcherContributors = [];
|
||||
List<Contributor> patchesContributors = [];
|
||||
List<Contributor> integrationsContributors = [];
|
||||
List<Contributor> cliContributors = [];
|
||||
List<Contributor> managerContributors = [];
|
||||
List<dynamic> patcherContributors = [];
|
||||
List<dynamic> patchesContributors = [];
|
||||
List<dynamic> integrationsContributors = [];
|
||||
List<dynamic> cliContributors = [];
|
||||
List<dynamic> managerContributors = [];
|
||||
|
||||
Future<void> getContributors() async {
|
||||
patcherContributors = await _githubAPI.getContributors(
|
||||
_managerAPI.getPatcherRepo(),
|
||||
);
|
||||
patchesContributors = await _githubAPI.getContributors(
|
||||
_managerAPI.getPatchesRepo(),
|
||||
);
|
||||
integrationsContributors = await _githubAPI.getContributors(
|
||||
_managerAPI.getIntegrationsRepo(),
|
||||
);
|
||||
cliContributors = await _githubAPI.getContributors(
|
||||
_managerAPI.getCliRepo(),
|
||||
);
|
||||
managerContributors = await _githubAPI.getContributors(
|
||||
_managerAPI.getManagerRepo(),
|
||||
);
|
||||
Map<String, List<dynamic>> contributors =
|
||||
await _managerAPI.getContributors();
|
||||
patcherContributors = contributors[_managerAPI.defaultPatcherRepo] ?? [];
|
||||
patchesContributors = contributors[_managerAPI.getPatchesRepo()] ?? [];
|
||||
integrationsContributors =
|
||||
contributors[_managerAPI.getIntegrationsRepo()] ?? [];
|
||||
cliContributors = contributors[_managerAPI.defaultCliRepo] ?? [];
|
||||
managerContributors = contributors[_managerAPI.defaultManagerRepo] ?? [];
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
@ -20,73 +20,78 @@ class HomeView extends StatelessWidget {
|
||||
onModelReady: (model) => model.initialize(),
|
||||
viewModelBuilder: () => locator<HomeViewModel>(),
|
||||
builder: (context, model, child) => Scaffold(
|
||||
body: CustomScrollView(
|
||||
slivers: <Widget>[
|
||||
CustomSliverAppBar(
|
||||
title: I18nText(
|
||||
'homeView.widgetTitle',
|
||||
child: Text(
|
||||
'',
|
||||
style: GoogleFonts.inter(
|
||||
color: Theme.of(context).textTheme.headline6!.color,
|
||||
body: RefreshIndicator(
|
||||
color: Theme.of(context).colorScheme.secondary,
|
||||
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
|
||||
onRefresh: () => model.forceRefresh(),
|
||||
child: CustomScrollView(
|
||||
slivers: <Widget>[
|
||||
CustomSliverAppBar(
|
||||
title: I18nText(
|
||||
'homeView.widgetTitle',
|
||||
child: Text(
|
||||
'',
|
||||
style: GoogleFonts.inter(
|
||||
color: Theme.of(context).textTheme.headline6!.color,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SliverPadding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20.0),
|
||||
sliver: SliverList(
|
||||
delegate: SliverChildListDelegate.fixed(
|
||||
<Widget>[
|
||||
I18nText(
|
||||
'homeView.updatesSubtitle',
|
||||
child: Text(
|
||||
'',
|
||||
style: Theme.of(context).textTheme.headline6!,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
LatestCommitCard(
|
||||
onPressed: () =>
|
||||
model.showUpdateConfirmationDialog(context),
|
||||
),
|
||||
const SizedBox(height: 23),
|
||||
I18nText(
|
||||
'homeView.patchedSubtitle',
|
||||
child: Text(
|
||||
'',
|
||||
style: Theme.of(context).textTheme.headline6!,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: <Widget>[
|
||||
DashboardChip(
|
||||
label: I18nText('homeView.updatesAvailable'),
|
||||
isSelected: model.showUpdatableApps,
|
||||
onSelected: (value) {
|
||||
model.toggleUpdatableApps(true);
|
||||
},
|
||||
SliverPadding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20.0),
|
||||
sliver: SliverList(
|
||||
delegate: SliverChildListDelegate.fixed(
|
||||
<Widget>[
|
||||
I18nText(
|
||||
'homeView.updatesSubtitle',
|
||||
child: Text(
|
||||
'',
|
||||
style: Theme.of(context).textTheme.headline6!,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
DashboardChip(
|
||||
label: I18nText('homeView.installed'),
|
||||
isSelected: !model.showUpdatableApps,
|
||||
onSelected: (value) {
|
||||
model.toggleUpdatableApps(false);
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
model.showUpdatableApps
|
||||
? AvailableUpdatesCard()
|
||||
: InstalledAppsCard(),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
LatestCommitCard(
|
||||
onPressed: () =>
|
||||
model.showUpdateConfirmationDialog(context),
|
||||
),
|
||||
const SizedBox(height: 23),
|
||||
I18nText(
|
||||
'homeView.patchedSubtitle',
|
||||
child: Text(
|
||||
'',
|
||||
style: Theme.of(context).textTheme.headline6!,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: <Widget>[
|
||||
DashboardChip(
|
||||
label: I18nText('homeView.updatesAvailable'),
|
||||
isSelected: model.showUpdatableApps,
|
||||
onSelected: (value) {
|
||||
model.toggleUpdatableApps(true);
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
DashboardChip(
|
||||
label: I18nText('homeView.installed'),
|
||||
isSelected: !model.showUpdatableApps,
|
||||
onSelected: (value) {
|
||||
model.toggleUpdatableApps(false);
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
model.showUpdatableApps
|
||||
? AvailableUpdatesCard()
|
||||
: InstalledAppsCard(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
@ -23,8 +23,8 @@ class HomeViewModel extends BaseViewModel {
|
||||
final NavigationService _navigationService = locator<NavigationService>();
|
||||
final ManagerAPI _managerAPI = locator<ManagerAPI>();
|
||||
final PatcherAPI _patcherAPI = locator<PatcherAPI>();
|
||||
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
|
||||
FlutterLocalNotificationsPlugin();
|
||||
final flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
|
||||
DateTime? _lastUpdate;
|
||||
bool showUpdatableApps = true;
|
||||
List<PatchedApplication> patchedInstalledApps = [];
|
||||
List<PatchedApplication> patchedUpdatableApps = [];
|
||||
@ -61,10 +61,7 @@ class HomeViewModel extends BaseViewModel {
|
||||
}
|
||||
|
||||
void _getPatchedApps() {
|
||||
patchedInstalledApps = _managerAPI
|
||||
.getPatchedApps()
|
||||
.where((app) => app.hasUpdates == false)
|
||||
.toList();
|
||||
patchedInstalledApps = _managerAPI.getPatchedApps().toList();
|
||||
patchedUpdatableApps = _managerAPI
|
||||
.getPatchedApps()
|
||||
.where((app) => app.hasUpdates == true)
|
||||
@ -98,7 +95,7 @@ class HomeViewModel extends BaseViewModel {
|
||||
toastLength: Toast.LENGTH_LONG,
|
||||
gravity: ToastGravity.CENTER,
|
||||
);
|
||||
File? managerApk = await _managerAPI.downloadManager('.apk');
|
||||
File? managerApk = await _managerAPI.downloadManager();
|
||||
if (managerApk != null) {
|
||||
flutterLocalNotificationsPlugin.show(
|
||||
0,
|
||||
@ -170,4 +167,21 @@ class HomeViewModel extends BaseViewModel {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<String?> getLatestPatcherReleaseTime() async {
|
||||
return _managerAPI.getLatestPatcherReleaseTime();
|
||||
}
|
||||
|
||||
Future<String?> getLatestManagerReleaseTime() async {
|
||||
return _managerAPI.getLatestManagerReleaseTime();
|
||||
}
|
||||
|
||||
Future<void> forceRefresh() async {
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
if (_lastUpdate == null ||
|
||||
_lastUpdate!.difference(DateTime.now()).inSeconds > 60) {
|
||||
_managerAPI.clearAllData();
|
||||
}
|
||||
initialize();
|
||||
}
|
||||
}
|
||||
|
@ -46,10 +46,11 @@ class InstallerViewModel extends BaseViewModel {
|
||||
),
|
||||
);
|
||||
await FlutterBackground.enableBackgroundExecution();
|
||||
} finally {
|
||||
await handlePlatformChannelMethods();
|
||||
await runPatcher();
|
||||
} on Exception {
|
||||
// ignore
|
||||
}
|
||||
await handlePlatformChannelMethods();
|
||||
await runPatcher();
|
||||
}
|
||||
|
||||
Future<dynamic> handlePlatformChannelMethods() async {
|
||||
@ -118,10 +119,13 @@ class InstallerViewModel extends BaseViewModel {
|
||||
update(1.0, 'Aborting...', 'No app or patches selected! Aborting');
|
||||
}
|
||||
try {
|
||||
await FlutterBackground.disableBackgroundExecution();
|
||||
} finally {
|
||||
isPatching = false;
|
||||
if (FlutterBackground.isBackgroundExecutionEnabled) {
|
||||
await FlutterBackground.disableBackgroundExecution();
|
||||
}
|
||||
} on Exception {
|
||||
// ignore
|
||||
}
|
||||
isPatching = false;
|
||||
}
|
||||
|
||||
void installResult(bool installAsRoot) async {
|
||||
|
@ -1,3 +1,5 @@
|
||||
// ignore: depend_on_referenced_packages
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:revanced_manager/app/app.locator.dart';
|
||||
import 'package:revanced_manager/models/patch.dart';
|
||||
import 'package:revanced_manager/models/patched_application.dart';
|
||||
@ -71,9 +73,14 @@ class PatchesSelectorViewModel extends BaseViewModel {
|
||||
|
||||
List<String> getSupportedVersions(Patch patch) {
|
||||
PatchedApplication app = locator<PatcherViewModel>().selectedApp!;
|
||||
return patch.compatiblePackages
|
||||
.firstWhere((pack) => pack.name == app.packageName)
|
||||
.versions;
|
||||
Package? package = patch.compatiblePackages.firstWhereOrNull(
|
||||
(pack) => pack.name == app.packageName,
|
||||
);
|
||||
if (package != null) {
|
||||
return package.versions;
|
||||
} else {
|
||||
return List.empty();
|
||||
}
|
||||
}
|
||||
|
||||
bool isPatchSupported(Patch patch) {
|
||||
|
@ -7,6 +7,7 @@ import 'package:revanced_manager/models/patched_application.dart';
|
||||
import 'package:revanced_manager/services/manager_api.dart';
|
||||
import 'package:revanced_manager/services/patcher_api.dart';
|
||||
import 'package:revanced_manager/services/root_api.dart';
|
||||
import 'package:revanced_manager/ui/views/home/home_viewmodel.dart';
|
||||
import 'package:revanced_manager/ui/views/navigation/navigation_viewmodel.dart';
|
||||
import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart';
|
||||
import 'package:revanced_manager/ui/widgets/installerView/custom_material_button.dart';
|
||||
@ -73,7 +74,7 @@ class AppInfoViewModel extends BaseViewModel {
|
||||
label: I18nText('okButton'),
|
||||
onPressed: () {
|
||||
uninstallApp(app);
|
||||
locator<NavigationViewModel>().notifyListeners();
|
||||
locator<HomeViewModel>().notifyListeners();
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
|
@ -30,7 +30,7 @@ class AppSkeletonLoader extends StatelessWidget {
|
||||
children: [
|
||||
Container(
|
||||
color: Colors.white,
|
||||
height: 25,
|
||||
height: 34,
|
||||
width: screenWidth * 0.4,
|
||||
child: SkeletonParagraph(
|
||||
style: const SkeletonParagraphStyle(
|
||||
@ -42,7 +42,7 @@ class AppSkeletonLoader extends StatelessWidget {
|
||||
Container(
|
||||
margin: const EdgeInsets.only(bottom: 4),
|
||||
color: Colors.white,
|
||||
height: 25,
|
||||
height: 34,
|
||||
width: screenWidth * 0.6,
|
||||
child: SkeletonParagraph(
|
||||
style: const SkeletonParagraphStyle(
|
||||
|
@ -1,11 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:github/github.dart';
|
||||
import 'package:revanced_manager/ui/widgets/shared/custom_card.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
class ContributorsCard extends StatefulWidget {
|
||||
final String title;
|
||||
final List<Contributor> contributors;
|
||||
final List<dynamic> contributors;
|
||||
final double height;
|
||||
|
||||
const ContributorsCard({
|
||||
@ -52,9 +51,9 @@ class _ContributorsCardState extends State<ContributorsCard> {
|
||||
borderRadius: BorderRadius.circular(100),
|
||||
child: GestureDetector(
|
||||
onTap: () => launchUrl(
|
||||
Uri.parse(widget.contributors[index].htmlUrl!)),
|
||||
Uri.parse(widget.contributors[index]['html_url'])),
|
||||
child: Image.network(
|
||||
widget.contributors[index].avatarUrl!,
|
||||
widget.contributors[index]['avatar_url'],
|
||||
height: 40,
|
||||
width: 40,
|
||||
),
|
||||
|
@ -1,8 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_i18n/flutter_i18n.dart';
|
||||
import 'package:revanced_manager/app/app.locator.dart';
|
||||
import 'package:revanced_manager/services/github_api.dart';
|
||||
import 'package:revanced_manager/services/manager_api.dart';
|
||||
import 'package:revanced_manager/ui/views/home/home_viewmodel.dart';
|
||||
import 'package:revanced_manager/ui/widgets/installerView/custom_material_button.dart';
|
||||
import 'package:revanced_manager/ui/widgets/shared/custom_card.dart';
|
||||
@ -20,8 +18,7 @@ class LatestCommitCard extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _LatestCommitCardState extends State<LatestCommitCard> {
|
||||
final ManagerAPI _managerAPI = locator<ManagerAPI>();
|
||||
final GithubAPI _githubAPI = GithubAPI();
|
||||
final HomeViewModel model = locator<HomeViewModel>();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -35,10 +32,8 @@ class _LatestCommitCardState extends State<LatestCommitCard> {
|
||||
Row(
|
||||
children: <Widget>[
|
||||
I18nText('latestCommitCard.patcherLabel'),
|
||||
FutureBuilder<String>(
|
||||
future: _githubAPI.latestCommitTime(
|
||||
_managerAPI.getPatcherRepo(),
|
||||
),
|
||||
FutureBuilder<String?>(
|
||||
future: model.getLatestPatcherReleaseTime(),
|
||||
builder: (context, snapshot) => Text(
|
||||
snapshot.hasData && snapshot.data!.isNotEmpty
|
||||
? FlutterI18n.translate(
|
||||
@ -58,10 +53,8 @@ class _LatestCommitCardState extends State<LatestCommitCard> {
|
||||
Row(
|
||||
children: <Widget>[
|
||||
I18nText('latestCommitCard.managerLabel'),
|
||||
FutureBuilder<String>(
|
||||
future: _githubAPI.latestCommitTime(
|
||||
_managerAPI.getManagerRepo(),
|
||||
),
|
||||
FutureBuilder<String?>(
|
||||
future: model.getLatestManagerReleaseTime(),
|
||||
builder: (context, snapshot) =>
|
||||
snapshot.hasData && snapshot.data!.isNotEmpty
|
||||
? I18nText(
|
||||
|
@ -49,7 +49,7 @@ class ApplicationItem extends StatelessWidget {
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
Text(format(patchDate, locale: 'en_short')),
|
||||
Text(format(patchDate)),
|
||||
],
|
||||
),
|
||||
const Spacer(),
|
||||
|
Reference in New Issue
Block a user