mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-08-22 05:59:30 +02:00
@@ -354,7 +354,11 @@ class AppsPageState extends State<AppsPage> {
|
|||||||
SliverFillRemaining(
|
SliverFillRemaining(
|
||||||
child: Center(
|
child: Center(
|
||||||
child: Text(
|
child: Text(
|
||||||
appsProvider.apps.isEmpty ? tr('noApps') : tr('noAppsForFilter'),
|
appsProvider.apps.isEmpty
|
||||||
|
? appsProvider.loadingApps
|
||||||
|
? tr('pleaseWait')
|
||||||
|
: tr('noApps')
|
||||||
|
: tr('noAppsForFilter'),
|
||||||
style: Theme.of(context).textTheme.headlineMedium,
|
style: Theme.of(context).textTheme.headlineMedium,
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
))),
|
))),
|
||||||
@@ -419,7 +423,9 @@ class AppsPageState extends State<AppsPage> {
|
|||||||
child: Image(
|
child: Image(
|
||||||
image: const AssetImage(
|
image: const AssetImage(
|
||||||
'assets/graphics/icon_small.png'),
|
'assets/graphics/icon_small.png'),
|
||||||
color: Colors.white.withOpacity(0.3),
|
color: Theme.of(context).brightness == Brightness.dark
|
||||||
|
? Colors.white.withOpacity(0.4)
|
||||||
|
: Colors.white.withOpacity(0.3),
|
||||||
colorBlendMode: BlendMode.modulate,
|
colorBlendMode: BlendMode.modulate,
|
||||||
gaplessPlayback: true,
|
gaplessPlayback: true,
|
||||||
),
|
),
|
||||||
|
@@ -329,6 +329,10 @@ Future<Map<String, String>> getHeaders(String url,
|
|||||||
return returnHeaders;
|
return returnHeaders;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<List<PackageInfo>> getAllInstalledInfo() async {
|
||||||
|
return await pm.getInstalledPackages() ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
Future<PackageInfo?> getInstalledInfo(String? packageName,
|
Future<PackageInfo?> getInstalledInfo(String? packageName,
|
||||||
{bool printErr = true}) async {
|
{bool printErr = true}) async {
|
||||||
if (packageName != null) {
|
if (packageName != null) {
|
||||||
@@ -1160,8 +1164,9 @@ class AppsProvider with ChangeNotifier {
|
|||||||
: false;
|
: false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> updateInstallStatusInMemory(AppInMemory app) async {
|
Future<void> updateInstallStatusInMemory(
|
||||||
apps[app.app.id]?.installedInfo = await getInstalledInfo(app.app.id);
|
AppInMemory app, PackageInfo? installedInfo) async {
|
||||||
|
apps[app.app.id]?.installedInfo = installedInfo;
|
||||||
apps[app.app.id]?.icon =
|
apps[app.app.id]?.icon =
|
||||||
await apps[app.app.id]?.installedInfo?.applicationInfo?.getAppIcon();
|
await apps[app.app.id]?.installedInfo?.applicationInfo?.getAppIcon();
|
||||||
apps[app.app.id]?.app.name = await (apps[app.app.id]
|
apps[app.app.id]?.app.name = await (apps[app.app.id]
|
||||||
@@ -1179,6 +1184,8 @@ class AppsProvider with ChangeNotifier {
|
|||||||
notifyListeners();
|
notifyListeners();
|
||||||
var sp = SourceProvider();
|
var sp = SourceProvider();
|
||||||
List<List<String>> errors = [];
|
List<List<String>> errors = [];
|
||||||
|
var installedAppsData = await getAllInstalledInfo();
|
||||||
|
List<String> removedAppIds = [];
|
||||||
await Future.wait((await getAppsDir()) // Parse Apps from JSON
|
await Future.wait((await getAppsDir()) // Parse Apps from JSON
|
||||||
.listSync()
|
.listSync()
|
||||||
.map((item) async {
|
.map((item) async {
|
||||||
@@ -1199,43 +1206,57 @@ class AppsProvider with ChangeNotifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (app != null) {
|
if (app != null) {
|
||||||
|
// Save the app to the in-memory list without grabbing any OS info first
|
||||||
|
apps.update(
|
||||||
|
app.id,
|
||||||
|
(value) => AppInMemory(
|
||||||
|
app!, value.downloadProgress, value.installedInfo, value.icon),
|
||||||
|
ifAbsent: () => AppInMemory(app!, null, null, null));
|
||||||
|
notifyListeners();
|
||||||
try {
|
try {
|
||||||
|
// Try getting the app's source to ensure no invalid apps get loaded
|
||||||
sp.getSource(app.url, overrideSource: app.overrideSource);
|
sp.getSource(app.url, overrideSource: app.overrideSource);
|
||||||
|
// If the app is installed, grab its OS data and reconcile install statuses
|
||||||
|
PackageInfo? installedInfo;
|
||||||
|
try {
|
||||||
|
installedInfo =
|
||||||
|
installedAppsData.firstWhere((i) => i.packageName == app!.id);
|
||||||
|
} catch (e) {
|
||||||
|
// If the app isn't installed the above throws an error
|
||||||
|
}
|
||||||
|
// Reconcile differences between the installed and recorded install info
|
||||||
|
var moddedApp =
|
||||||
|
getCorrectedInstallStatusAppIfPossible(app, installedInfo);
|
||||||
|
if (moddedApp != null) {
|
||||||
|
app = moddedApp;
|
||||||
|
// Note the app ID if it was uninstalled externally
|
||||||
|
if (moddedApp.installedVersion == null) {
|
||||||
|
removedAppIds.add(moddedApp.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var icon = await installedInfo?.applicationInfo?.getAppIcon();
|
||||||
|
app.name =
|
||||||
|
await (installedInfo?.applicationInfo?.getAppLabel()) ?? app.name;
|
||||||
|
// Update the app in memory with install info and corrections
|
||||||
apps.update(
|
apps.update(
|
||||||
app.id,
|
app.id,
|
||||||
(value) => AppInMemory(app!, value.downloadProgress,
|
(value) => AppInMemory(
|
||||||
value.installedInfo, value.icon),
|
app!, value.downloadProgress, installedInfo, icon),
|
||||||
ifAbsent: () => AppInMemory(app!, null, null, null));
|
ifAbsent: () => AppInMemory(app!, null, installedInfo, icon));
|
||||||
|
notifyListeners();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
errors.add([app.id, app.finalName, e.toString()]);
|
errors.add([app!.id, app.finalName, e.toString()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
notifyListeners();
|
|
||||||
if (errors.isNotEmpty) {
|
if (errors.isNotEmpty) {
|
||||||
removeApps(errors.map((e) => e[0]).toList());
|
removeApps(errors.map((e) => e[0]).toList());
|
||||||
NotificationsProvider().notify(
|
NotificationsProvider().notify(
|
||||||
AppsRemovedNotification(errors.map((e) => [e[1], e[2]]).toList()));
|
AppsRemovedNotification(errors.map((e) => [e[1], e[2]]).toList()));
|
||||||
}
|
}
|
||||||
// Get install status and other OS info for each App (slow)
|
// Delete externally uninstalled Apps if needed
|
||||||
List<App> modifiedApps = [];
|
if (removedAppIds.isNotEmpty) {
|
||||||
await Future.wait(apps.values.map((app) async {
|
|
||||||
await updateInstallStatusInMemory(app);
|
|
||||||
var moddedApp =
|
|
||||||
getCorrectedInstallStatusAppIfPossible(app.app, app.installedInfo);
|
|
||||||
if (moddedApp != null) {
|
|
||||||
modifiedApps.add(moddedApp);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
notifyListeners();
|
|
||||||
// Reconcile version differences
|
|
||||||
if (modifiedApps.isNotEmpty) {
|
|
||||||
await saveApps(modifiedApps, attemptToCorrectInstallStatus: false);
|
|
||||||
var removedAppIds = modifiedApps
|
|
||||||
.where((a) => a.installedVersion == null)
|
|
||||||
.map((e) => e.id)
|
|
||||||
.toList();
|
|
||||||
// After reconciliation, delete externally uninstalled Apps if needed
|
|
||||||
if (removedAppIds.isNotEmpty) {
|
if (removedAppIds.isNotEmpty) {
|
||||||
if (settingsProvider.removeOnExternalUninstall) {
|
if (settingsProvider.removeOnExternalUninstall) {
|
||||||
await removeApps(removedAppIds);
|
await removeApps(removedAppIds);
|
||||||
|
Reference in New Issue
Block a user