Commit 74b5ef3e authored by Soomin Lee's avatar Soomin Lee

VLCAppDelegate: Move VLCMediaFileDiscovererDelegate to VLCMediaLibraryManager

This allows monitoring of changes in the Documents folder from external
apps.

Additionally changes `mediaFilesFoundRequiringAdditionToStorageBackend`
to optional since the new medialibrary doesn't need it.

(closes #297)
parent a6754eba
......@@ -88,12 +88,21 @@ class VLCMediaLibraryManager: NSObject {
// MARK: Private
private func setupMediaDiscovery(at path: String) {
let mediaFileDiscoverer = VLCMediaFileDiscoverer.sharedInstance()
mediaFileDiscoverer?.directoryPath = path
mediaFileDiscoverer?.addObserver(self)
mediaFileDiscoverer?.startDiscovering()
}
private func setupMediaLibrary() {
guard let documentPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first,
let libraryPath = NSSearchPathForDirectoriesInDomains(.libraryDirectory, .userDomainMask, true).first else {
preconditionFailure("VLCMediaLibraryManager: Unable to init medialibrary.")
}
setupMediaDiscovery(at: documentPath)
let databasePath = libraryPath + "/MediaLibrary/" + VLCMediaLibraryManager.databaseName
let thumbnailPath = libraryPath + "/MediaLibrary/Thumbnails"
......@@ -219,6 +228,31 @@ extension VLCMediaLibraryManager {
}
}
extension VLCMediaLibraryManager: VLCMediaFileDiscovererDelegate {
func mediaFileAdded(_ filePath: String!, loading isLoading: Bool) {
guard !isLoading else {
return
}
/* exclude media files from backup (QA1719) */
var excludeURL = URL(fileURLWithPath: filePath)
var resourceValue = URLResourceValues()
resourceValue.isExcludedFromBackup = true
do {
try excludeURL.setResourceValues(resourceValue)
} catch let error {
assertionFailure("VLCMediaLibraryManager: VLCMediaFileDiscovererDelegate: \(error.localizedDescription)")
}
reload()
}
func mediaFileDeleted(_ filePath: String!) {
reload()
}
}
// MARK: - VLCMediaLibraryDelegate - Media
extension VLCMediaLibraryManager: VLCMediaLibraryDelegate {
......
......@@ -35,7 +35,7 @@
#define BETA_DISTRIBUTION 1
@interface VLCAppDelegate () <VLCMediaFileDiscovererDelegate>
@interface VLCAppDelegate ()
{
BOOL _isRunningMigration;
BOOL _isComingFromHandoff;
......@@ -112,12 +112,6 @@
BOOL spotlightEnabled = ![VLCKeychainCoordinator passcodeLockEnabled];
[[MLMediaLibrary sharedMediaLibrary] setSpotlightIndexingEnabled:spotlightEnabled];
[[MLMediaLibrary sharedMediaLibrary] applicationWillStart];
VLCMediaFileDiscoverer *discoverer = [VLCMediaFileDiscoverer sharedInstance];
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
discoverer.directoryPath = [searchPaths firstObject];
[discoverer addObserver:self];
[discoverer startDiscovering];
};
NSError *error = nil;
......@@ -283,36 +277,6 @@ didFailToContinueUserActivityWithType:(NSString *)userActivityType
//TODO: shortcutItem should be implemented
}
#pragma mark - media discovering
- (void)mediaFileAdded:(NSString *)fileName loading:(BOOL)isLoading
{
if (!isLoading) {
MLMediaLibrary *sharedLibrary = [MLMediaLibrary sharedMediaLibrary];
[sharedLibrary addFilePaths:@[fileName]];
/* exclude media files from backup (QA1719) */
NSURL *excludeURL = [NSURL fileURLWithPath:fileName];
[excludeURL setResourceValue:@YES forKey:NSURLIsExcludedFromBackupKey error:nil];
// TODO Should we update media db after adding new files?
[sharedLibrary updateMediaDatabase];
// TODO: update the VideoViewController
}
}
- (void)mediaFileDeleted:(NSString *)name
{
[[MLMediaLibrary sharedMediaLibrary] updateMediaDatabase];
// TODO: update the VideoViewController
}
- (void)mediaFilesFoundRequiringAdditionToStorageBackend:(NSArray<NSString *> *)foundFiles
{
[[MLMediaLibrary sharedMediaLibrary] addFilePaths:foundFiles];
// TODO: update the VideoViewController
}
#pragma mark - pass code validation
- (VLCKeychainCoordinator *)keychainCoordinator
{
......
......@@ -14,10 +14,8 @@
@protocol VLCMediaFileDiscovererDelegate <NSObject>
@required
- (void)mediaFilesFoundRequiringAdditionToStorageBackend:(NSArray <NSString *> *)foundFiles;
@optional
- (void)mediaFilesFoundRequiringAdditionToStorageBackend:(NSArray <NSString *> *)foundFiles;
// loading is equal to YES first time when file is discovered
- (void)mediaFileAdded:(NSString *)filePath loading:(BOOL)isLoading;
......
......@@ -25,3 +25,4 @@
#import "IASKSettingsReader.h"
#import "IASKSwitch.h"
#import "VLCHTTPUploaderController.h"
#import "VLCMediaFileDiscoverer.h"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment