revanced-manager/lib/ui/views/home/home_viewmodel.dart

29 lines
1.0 KiB
Dart
Raw Normal View History

import 'dart:convert';
import 'package:injectable/injectable.dart';
2022-08-06 23:35:35 +02:00
import 'package:revanced_manager/app/app.locator.dart';
import 'package:revanced_manager/models/patched_application.dart';
2022-08-06 23:35:35 +02:00
import 'package:revanced_manager/services/manager_api.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:stacked/stacked.dart';
@lazySingleton
class HomeViewModel extends BaseViewModel {
bool showUpdatableApps = true;
void toggleUpdatableApps(bool value) {
showUpdatableApps = value;
notifyListeners();
}
Future downloadPatches() => locator<ManagerAPI>().downloadPatches();
Future downloadIntegrations() => locator<ManagerAPI>().downloadIntegrations();
Future<List<PatchedApplication>> getPatchedApps(bool isUpdatable) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
List<String> patchedApps = prefs.getStringList('patchedApps') ?? [];
return patchedApps
.map((app) => PatchedApplication.fromJson(json.decode(app)))
.toList();
}
}