Skip to content

Commit

Permalink
remove apps properly, delete app from storage when removed
Browse files Browse the repository at this point in the history
  • Loading branch information
crc-32 committed Apr 16, 2023
1 parent 859f559 commit b2976ac
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
6 changes: 2 additions & 4 deletions lib/domain/api/appstore/locker_sync.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ import 'package:cobble/domain/db/models/locker_app.dart';
import 'package:cobble/infrastructure/datasources/web_services/appstore.dart';
import 'package:flutter/foundation.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:path_provider/path_provider.dart';
import 'package:state_notifier/state_notifier.dart';
import 'package:uuid_type/uuid_type.dart';
import 'package:logging/logging.dart';

import '../../logging.dart';
import 'appstore.dart';

class LockerSync extends StateNotifier<List<LockerEntry>?> {
Expand Down Expand Up @@ -52,12 +50,12 @@ class LockerSync extends StateNotifier<List<LockerEntry>?> {
Future<void> addToLocker(Uuid uuid) async {
final appstore = await appstoreFuture;
await appstore.addToLocker(uuid.toString());
refresh();
await refresh();
}

Future<void> removeFromLocker(Uuid uuid) async {
await lockerCacheDao.markForDeletionByUuid(uuid); // done locally and actioned upon refresh for offline-first
refresh();
await refresh();
}
}

Expand Down
15 changes: 12 additions & 3 deletions lib/domain/apps/app_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'package:cobble/domain/entities/pbw_app_info_extension.dart';
import 'package:cobble/infrastructure/backgroundcomm/BackgroundRpc.dart';
import 'package:cobble/infrastructure/pigeons/pigeons.g.dart';
import 'package:cobble/util/async_value_extensions.dart';
import 'package:flutter/foundation.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:path_provider/path_provider.dart';
import 'package:uuid_type/uuid_type.dart';
Expand Down Expand Up @@ -71,16 +70,21 @@ class AppManager extends StateNotifier<List<App>> {
await refresh();
}

Future<Uri> downloadPbw(String url, String uuid) async {
Future<File> makePbwFile(String uuid) async {
final docsDir = (await getApplicationDocumentsDirectory()).parent; // .parent escapes from 'flutter specific' dir
final appDir = Directory(docsDir.path + "/files/apps");
if (!await appDir.exists()) {
await appDir.create(recursive: true);
}
return File("${appDir.path}/${uuid.toLowerCase()}.pbw");
}

Future<Uri> downloadPbw(String url, String uuid) async {


final uri = Uri.parse(url);
HttpClient httpClient = HttpClient();
final file = File("${appDir.path}/$uuid.pbw");
final file = await makePbwFile(uuid);
final fd = file.openWrite();
try {
var request = await httpClient.getUrl(uri);
Expand Down Expand Up @@ -128,12 +132,17 @@ class AppManager extends StateNotifier<List<App>> {
Future<void> deleteApp(Uuid uuid) async {
if ((await appDao.getPackage(uuid))?.appstoreId != null) {
await lockerSync.removeFromLocker(uuid);
_logger.fine("Removed from locker");
}
final file = await makePbwFile(uuid.toString());
final uuidWrapper = StringWrapper();
uuidWrapper.value = uuid.toString();

await appInstallControl.beginAppDeletion(uuidWrapper);
await refresh();
try {
await file.delete();
} on FileSystemException catch(_){}
}

void beginAppInstall(String uri, PbwAppInfo appInfo) async {
Expand Down
5 changes: 4 additions & 1 deletion lib/ui/home/tabs/locker_tab/apps_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ class AppsSheet {
CobbleTile.action(
leading: RebbleIcons.delete_trash,
title: tr.lockerPage.delete,
onTap: () => appManager.deleteApp(app.uuid),
onTap: () {
appManager.deleteApp(app.uuid);
Navigator.pop(context);
},
),
],
),
Expand Down
7 changes: 5 additions & 2 deletions lib/ui/home/tabs/locker_tab/faces_card.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:cobble/domain/apps/app_manager.dart';
import 'package:cobble/domain/db/models/app.dart';
import 'package:cobble/domain/entities/hardware_platform.dart';
import 'package:cobble/infrastructure/pigeons/pigeons.g.dart';
import 'package:cobble/ui/common/components/cobble_button.dart';
import 'package:cobble/ui/common/icons/fonts/rebble_icons.dart';
import 'package:cobble/ui/home/tabs/locker_tab/faces_sheet.dart';
Expand Down Expand Up @@ -41,13 +42,15 @@ class FacesCard extends StatelessWidget {
),
Column(
children: <Widget>[
// TODO: Implement sending to the watch
// TODO: Implement sync for which face is currently on the watch (app launch events?)
Expanded(
child: compatible
? CobbleButton(
outlined: false,
icon: RebbleIcons.send_to_watch_unchecked,
onPressed: () {},
onPressed: () {
AppLifecycleControl().openAppOnTheWatch(StringWrapper(value: face.uuid.toString()));
},
)
: Container(),
),
Expand Down

0 comments on commit b2976ac

Please sign in to comment.