瀏覽代碼

Handle lack of permissions gracefully

Vishnu Mohandas 4 年之前
父節點
當前提交
96456bf01f
共有 1 個文件被更改,包括 6 次插入2 次删除
  1. 6 2
      lib/services/sync_service.dart

+ 6 - 2
lib/services/sync_service.dart

@@ -118,12 +118,15 @@ class SyncService {
   }
   }
 
 
   Future<void> _doSync() async {
   Future<void> _doSync() async {
+    final existingLocalFileIDs = await _db.getExistingLocalFileIDs();
+    final syncStartTime = DateTime.now().microsecondsSinceEpoch;
     final result = await PhotoManager.requestPermission();
     final result = await PhotoManager.requestPermission();
     if (!result) {
     if (!result) {
       _logger.severe("Did not get permission");
       _logger.severe("Did not get permission");
+      await _prefs.setInt(_dbUpdationTimeKey, syncStartTime);
+      await FileRepository.instance.reloadFiles();
+      return await syncWithRemote();
     }
     }
-    final existingLocalFileIDs = await _db.getExistingLocalFileIDs();
-    final syncStartTime = DateTime.now().microsecondsSinceEpoch;
     final lastDBUpdationTime = _prefs.getInt(_dbUpdationTimeKey);
     final lastDBUpdationTime = _prefs.getInt(_dbUpdationTimeKey);
     if (lastDBUpdationTime != null && lastDBUpdationTime != 0) {
     if (lastDBUpdationTime != null && lastDBUpdationTime != 0) {
       await _loadAndStorePhotos(
       await _loadAndStorePhotos(
@@ -141,6 +144,7 @@ class SyncService {
       }
       }
       await _loadAndStorePhotos(startTime, syncStartTime, existingLocalFileIDs);
       await _loadAndStorePhotos(startTime, syncStartTime, existingLocalFileIDs);
     }
     }
+    await FileRepository.instance.reloadFiles();
     await syncWithRemote();
     await syncWithRemote();
   }
   }