Fix presets in the Queue.
This commit is contained in:
7 files changed
+45
-29
No files matched your search
+26
-10
@@ -7,16 +7,35 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
extension PresetManager.Error: LocalizedError {
|
||||
public var errorDescription: String? {
|
||||
switch self {
|
||||
case .alreadyExists:
|
||||
return NSLocalizedString("A preset already exists with the same name.", comment: "")
|
||||
}
|
||||
}
|
||||
public var recoverySuggestion: String? {
|
||||
switch self {
|
||||
case .alreadyExists:
|
||||
return NSLocalizedString("Please enter a different name for the preset.", comment: "")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc(SBPresetManager) final class PresetManager: NSObject {
|
||||
@objc static let shared = PresetManager()
|
||||
|
||||
let updateNotificationName = Notification.Name(rawValue: "SBPresetManagerUpdatedNotification")
|
||||
let updateNotification = Notification.Name(rawValue: "SBPresetManagerUpdatedNotification")
|
||||
var presets: [Preset]
|
||||
|
||||
@objc var metadataPresets: [MetadataPreset] {
|
||||
return presets.flatMap { $0 as? MetadataPreset }
|
||||
}
|
||||
|
||||
var queuePresets: [QueuePreset] {
|
||||
return presets.flatMap { $0 as? QueuePreset }
|
||||
}
|
||||
|
||||
private override init() {
|
||||
self.presets = Array()
|
||||
super.init()
|
||||
@@ -26,13 +45,12 @@ import Foundation
|
||||
// MARK: management
|
||||
|
||||
enum Error : Swift.Error {
|
||||
case presetAlreadyExists
|
||||
case presetNotFound
|
||||
case alreadyExists
|
||||
}
|
||||
|
||||
@objc func append(newElement: Preset) throws {
|
||||
if item(name: newElement.title) != nil {
|
||||
throw Error.presetAlreadyExists
|
||||
throw Error.alreadyExists
|
||||
}
|
||||
presets.append(newElement)
|
||||
postNotification()
|
||||
@@ -50,7 +68,7 @@ import Foundation
|
||||
}
|
||||
|
||||
private func postNotification() {
|
||||
NotificationCenter.default.post(name: updateNotificationName, object: self)
|
||||
NotificationCenter.default.post(name: updateNotification, object: self)
|
||||
}
|
||||
|
||||
// MARK: read/write
|
||||
@@ -74,7 +92,7 @@ import Foundation
|
||||
}
|
||||
}
|
||||
|
||||
private func migrateOldPreset(at fileURL: URL) throws {
|
||||
private func migratePreset(at fileURL: URL) throws {
|
||||
let manager = FileManager.default
|
||||
guard let url = appSupportURL() else { return }
|
||||
|
||||
@@ -94,7 +112,7 @@ import Foundation
|
||||
defer { unarchiver.finishDecoding() }
|
||||
|
||||
if version == 1, let preset = unarchiver.decodeObject(of: [MP42Metadata.self], forKey: NSKeyedArchiveRootObjectKey) as? MP42Metadata {
|
||||
try migrateOldPreset(at: fileURL)
|
||||
try migratePreset(at: fileURL)
|
||||
return MetadataPreset(title: preset.presetName, metadata: preset)
|
||||
}
|
||||
else if let preset = unarchiver.decodeObject(of: [MetadataPreset.self], forKey: NSKeyedArchiveRootObjectKey) as? MetadataPreset {
|
||||
@@ -118,9 +136,7 @@ import Foundation
|
||||
let preset = try load(fileURL: fileURL)
|
||||
presets.append(preset)
|
||||
}
|
||||
catch {
|
||||
print(error)
|
||||
}
|
||||
catch {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ class PresetPrefsViewController: NSViewController, NSTableViewDataSource, NSTabl
|
||||
override func loadView() {
|
||||
super.loadView()
|
||||
|
||||
observer = NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: "SBPresetManagerUpdatedNotification"),
|
||||
observer = NotificationCenter.default.addObserver(forName: presetManager.updateNotification,
|
||||
object: nil,
|
||||
queue: OperationQueue.main) { [weak self] notification in
|
||||
guard let s = self else { return }
|
||||
|
||||
@@ -32,7 +32,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
* An actions that applies a set to the item.
|
||||
*/
|
||||
@interface SBQueueSetAction : NSObject <SBQueueActionProtocol>
|
||||
- (instancetype)initWithSet:(MP42Metadata *)set;
|
||||
- (instancetype)initWithPreset:(MP42Metadata *)set;
|
||||
@end
|
||||
|
||||
/**
|
||||
|
||||
@@ -89,27 +89,27 @@
|
||||
@end
|
||||
|
||||
@implementation SBQueueSetAction {
|
||||
MP42Metadata *_set;
|
||||
SBMetadataPreset *_set;
|
||||
}
|
||||
|
||||
- (instancetype)initWithSet:(MP42Metadata *)set {
|
||||
- (instancetype)initWithPreset:(SBMetadataPreset *)preset {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_set = [set copy];
|
||||
_set = [preset copy];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)runAction:(SBQueueItem *)item {
|
||||
[item.mp4File.metadata mergeMetadata:_set];
|
||||
[item.mp4File.metadata mergeMetadata:_set.metadata];
|
||||
}
|
||||
|
||||
- (NSString *)description {
|
||||
return [NSString stringWithFormat:NSLocalizedString(@"Apply %@ Set", @""), _set.presetName];
|
||||
return [NSString stringWithFormat:NSLocalizedString(@"Apply %@ Set", @""), _set.title];
|
||||
}
|
||||
|
||||
- (NSString *)localizedDescription {
|
||||
return [NSString stringWithFormat:NSLocalizedString(@"Applying %@ set", @""), _set.presetName];
|
||||
return [NSString stringWithFormat:NSLocalizedString(@"Applying %@ set", @""), _set.title];
|
||||
}
|
||||
|
||||
+ (BOOL)supportsSecureCoding {
|
||||
@@ -119,7 +119,7 @@
|
||||
- (instancetype)initWithCoder:(NSCoder *)coder {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_set = [coder decodeObjectOfClass:[MP42Metadata class] forKey:@"SBQueueActionSet"];
|
||||
_set = [coder decodeObjectOfClass:[SBMetadataPreset class] forKey:@"SBQueueActionSet"];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -289,8 +289,8 @@ static void *SBQueueContex = &SBQueueContex;
|
||||
[item addAction:[[SBQueueColorSpaceAction alloc] initWithTag:[self.options[SBQueueApplyColorSpaceValue] unsignedIntegerValue]]];
|
||||
}
|
||||
|
||||
if ((self.options)[SBQueueSet]) {
|
||||
[item addAction:[[SBQueueSetAction alloc] initWithSet:(self.options)[SBQueueSet]]];
|
||||
if (self.options[SBQueueSet]) {
|
||||
[item addAction:[[SBQueueSetAction alloc] initWithPreset:self.options[SBQueueSet]]];
|
||||
}
|
||||
|
||||
id type;
|
||||
|
||||
@@ -56,9 +56,9 @@ NSString * const SBQueueSet = @"SBQueueSet";
|
||||
}
|
||||
|
||||
if ([[NSUserDefaults standardUserDefaults] valueForKey:SBQueueSet]) {
|
||||
MP42Metadata *set = [(SBMetadataPreset *)[SBPresetManager.shared itemWithName:[[NSUserDefaults standardUserDefaults] valueForKey:SBQueueSet]] metadata];
|
||||
if (set) {
|
||||
self.options[SBQueueSet] = set;
|
||||
SBMetadataPreset *preset = (SBMetadataPreset *)[SBPresetManager.shared itemWithName:[[NSUserDefaults standardUserDefaults] valueForKey:SBQueueSet]];
|
||||
if (preset) {
|
||||
self.options[SBQueueSet] = preset;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ NSString * const SBQueueSet = @"SBQueueSet";
|
||||
}];
|
||||
|
||||
[[NSUserDefaults standardUserDefaults] setValue:[self.options[SBQueueDestination] path] forKey:SBQueueDestination];
|
||||
[[NSUserDefaults standardUserDefaults] setValue:[self.options[SBQueueSet] presetName] forKey:SBQueueSet];
|
||||
[[NSUserDefaults standardUserDefaults] setValue:[self.options[SBQueueSet] title] forKey:SBQueueSet];
|
||||
}
|
||||
|
||||
- (nullable NSURL *)queueURL {
|
||||
|
||||
Reference in new issue
Block a user