Skip to content

Commit 68fc715

Browse files
committed
Merge branch 'noahemmet-skip-duration'
2 parents 60f7494 + 59da392 commit 68fc715

File tree

9 files changed

+167
-88
lines changed

9 files changed

+167
-88
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/// Represents one of several durations for skipping backwards and forwards.
2+
public enum BackForwardSkipDuration: TimeInterval {
3+
case fiveSeconds = 5
4+
case tenSeconds = 10
5+
case fifteenSeconds = 15
6+
case thirtySeconds = 30
7+
8+
public init(seconds: TimeInterval) {
9+
switch seconds {
10+
case 5:
11+
self = .fiveSeconds
12+
case 10:
13+
self = .tenSeconds
14+
case 15:
15+
self = .fifteenSeconds
16+
case 30:
17+
self = .thirtySeconds
18+
default:
19+
assertionFailure("Expected a duration of `BackForwardSkipDuration`; received \(seconds)")
20+
self = .thirtySeconds
21+
}
22+
}
23+
}

PlayerUI/Definitions/Images.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,20 @@ extension NSImage {
2020

2121
static var PUIPause: NSImage { .PUISystemSymbol(named: "pause.fill", label: "Pause") }
2222

23-
static var PUIBack15s: NSImage { .PUISystemSymbol(named: "gobackward.15", label: "Forward 15 Seconds") }
23+
static var PUIBack5s: NSImage { .PUISystemSymbol(named: "gobackward.5", label: "Back 5 Seconds") }
2424

25-
static var PUIBack30s: NSImage { .PUISystemSymbol(named: "gobackward.30", label: "Forward 30 Seconds") }
25+
static var PUIBack10s: NSImage { .PUISystemSymbol(named: "gobackward.10", label: "Back 10 Seconds") }
26+
27+
static var PUIBack15s: NSImage { .PUISystemSymbol(named: "gobackward.15", label: "Back 15 Seconds") }
28+
29+
static var PUIBack30s: NSImage { .PUISystemSymbol(named: "gobackward.30", label: "Back 30 Seconds") }
2630

2731
static var PUIAnnotation: NSImage { .PUISystemSymbol(named: "bookmark.fill", label: "Add Bookmark") }
2832

33+
static var PUIForward5s: NSImage { .PUISystemSymbol(named: "goforward.5", label: "Forward 5 Seconds") }
34+
35+
static var PUIForward10s: NSImage { .PUISystemSymbol(named: "goforward.10", label: "Forward 10 Seconds") }
36+
2937
static var PUIForward15s: NSImage { .PUISystemSymbol(named: "goforward.15", label: "Forward 15 Seconds") }
3038

3139
static var PUIForward30s: NSImage { .PUISystemSymbol(named: "goforward.30", label: "Forward 30 Seconds") }

PlayerUI/Protocols/PUIPlayerViewDelegates.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
import Cocoa
10+
import ConfUIFoundation
1011

1112
public protocol PUIPlayerViewDelegate: AnyObject {
1213

@@ -35,6 +36,6 @@ public protocol PUIPlayerViewAppearanceDelegate: AnyObject, PUIPlayerViewDetache
3536
func playerViewShouldShowBackAndForwardControls(_ playerView: PUIPlayerView) -> Bool
3637
func playerViewShouldShowTimestampLabels(_ playerView: PUIPlayerView) -> Bool
3738
func playerViewShouldShowFullScreenButton(_ playerView: PUIPlayerView) -> Bool
38-
func playerViewShouldShowBackAndForward30SecondsButtons(_ playerView: PUIPlayerView) -> Bool
39+
func playerViewBackAndForwardDuration(_ playerView: PUIPlayerView) -> BackForwardSkipDuration
3940

4041
}

PlayerUI/Views/PUIPlayerView.swift

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ public final class PUIPlayerView: NSView {
602602

603603
b.image = .PUIBack15s
604604
b.target = self
605-
b.action = #selector(goBackInTime15)
605+
b.action = #selector(goBackInTime)
606606
b.toolTip = "Go back 15s"
607607

608608
return b
@@ -613,7 +613,7 @@ public final class PUIPlayerView: NSView {
613613

614614
b.image = .PUIForward15s
615615
b.target = self
616-
b.action = #selector(goForwardInTime15)
616+
b.action = #selector(goForwardInTime)
617617
b.toolTip = "Go forward 15s"
618618

619619
return b
@@ -805,26 +805,44 @@ public final class PUIPlayerView: NSView {
805805
.store(in: &cancellables)
806806
}
807807

808-
var isConfiguredForBackAndForward30s = false {
808+
var backAndForwardSkipDuration: BackForwardSkipDuration = .thirtySeconds {
809809
didSet {
810810
invalidateTouchBar()
811811
}
812812
}
813813

814814
var goBackInTimeImage: NSImage {
815-
return isConfiguredForBackAndForward30s ? .PUIBack30s : .PUIBack15s
815+
switch backAndForwardSkipDuration {
816+
case .fiveSeconds:
817+
.PUIBack5s
818+
case .tenSeconds:
819+
.PUIBack10s
820+
case .fifteenSeconds:
821+
.PUIBack15s
822+
case .thirtySeconds:
823+
.PUIBack30s
824+
}
816825
}
817826

818827
var goBackInTimeDescription: String {
819-
return isConfiguredForBackAndForward30s ? "Go back 30s" : "Go back 15s"
828+
"Go back \(backAndForwardSkipDuration.rawValue.formatted())s"
820829
}
821830

822831
var goForwardInTimeImage: NSImage {
823-
return isConfiguredForBackAndForward30s ? .PUIForward30s : .PUIForward15s
832+
switch backAndForwardSkipDuration {
833+
case .fiveSeconds:
834+
.PUIForward5s
835+
case .tenSeconds:
836+
.PUIForward10s
837+
case .fifteenSeconds:
838+
.PUIForward15s
839+
case .thirtySeconds:
840+
.PUIForward30s
841+
}
824842
}
825843

826844
var goForwardInTimeDescription: String {
827-
return isConfiguredForBackAndForward30s ? "Go forward 30s" : "Go forward 15s"
845+
"Go forward \(backAndForwardSkipDuration.rawValue.formatted())s"
828846
}
829847

830848
private func configureWithAppearanceFromDelegate() {
@@ -843,7 +861,7 @@ public final class PUIPlayerView: NSView {
843861
backButton.isHidden = disableBackAndForward
844862
forwardButton.isHidden = disableBackAndForward
845863

846-
isConfiguredForBackAndForward30s = d.playerViewShouldShowBackAndForward30SecondsButtons(self)
864+
backAndForwardSkipDuration = d.playerViewBackAndForwardDuration(self)
847865
backButton.image = goBackInTimeImage
848866
backButton.action = #selector(goBackInTime)
849867
backButton.toolTip = goBackInTimeDescription
@@ -954,35 +972,11 @@ public final class PUIPlayerView: NSView {
954972
}
955973

956974
@IBAction public func goBackInTime(_ sender: Any?) {
957-
if isConfiguredForBackAndForward30s {
958-
goBackInTime30(sender)
959-
} else {
960-
goBackInTime15(sender)
961-
}
975+
modifyCurrentTime(with: backAndForwardSkipDuration.rawValue, using: CMTimeSubtract)
962976
}
963977

964978
@IBAction public func goForwardInTime(_ sender: Any?) {
965-
if isConfiguredForBackAndForward30s {
966-
goForwardInTime30(sender)
967-
} else {
968-
goForwardInTime15(sender)
969-
}
970-
}
971-
972-
@IBAction public func goBackInTime15(_ sender: Any?) {
973-
modifyCurrentTime(with: 15, using: CMTimeSubtract)
974-
}
975-
976-
@IBAction public func goForwardInTime15(_ sender: Any?) {
977-
modifyCurrentTime(with: 15, using: CMTimeAdd)
978-
}
979-
980-
@IBAction public func goBackInTime30(_ sender: Any?) {
981-
modifyCurrentTime(with: 30, using: CMTimeSubtract)
982-
}
983-
984-
@IBAction public func goForwardInTime30(_ sender: Any?) {
985-
modifyCurrentTime(with: 30, using: CMTimeAdd)
979+
modifyCurrentTime(with: backAndForwardSkipDuration.rawValue, using: CMTimeAdd)
986980
}
987981

988982
@IBAction public func toggleSpeed(_ sender: Any?) {

WWDC.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@
191191
F474DEC926737EFA00B28B31 /* SharePlayManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = F474DEC826737EFA00B28B31 /* SharePlayManager.swift */; };
192192
F474DECD2673801500B28B31 /* WatchWWDCActivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = F474DECC2673801500B28B31 /* WatchWWDCActivity.swift */; };
193193
F4777ABA2A2A2F6C00A09179 /* WWDCAgentRemover.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4777AB92A2A2F6C00A09179 /* WWDCAgentRemover.swift */; };
194+
F48075BB2D830EE200FCD70E /* BackForwardSkipDuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27DD2F402D7ACEB3003EABDE /* BackForwardSkipDuration.swift */; };
194195
F486B3072C0E69E60066749F /* MediaDownloadProtocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = F486B2F82C0E69E60066749F /* MediaDownloadProtocols.swift */; };
195196
F486B3082C0E69E60066749F /* FSMediaDownloadMetadataStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = F486B2F92C0E69E60066749F /* FSMediaDownloadMetadataStore.swift */; };
196197
F486B3092C0E69E60066749F /* MediaDownloadManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = F486B2FA2C0E69E60066749F /* MediaDownloadManager.swift */; };
@@ -291,6 +292,7 @@
291292
/* Begin PBXFileReference section */
292293
012BEFA31EE8658F007E72CA /* EventKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = EventKit.framework; path = System/Library/Frameworks/EventKit.framework; sourceTree = SDKROOT; };
293294
01B3EB491EEDD23100DE1003 /* AppCoordinator+SessionTableViewContextMenuActions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "AppCoordinator+SessionTableViewContextMenuActions.swift"; sourceTree = "<group>"; };
295+
27DD2F402D7ACEB3003EABDE /* BackForwardSkipDuration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackForwardSkipDuration.swift; sourceTree = "<group>"; };
294296
4D0E806E217A2D6E00B24237 /* DownloadManager+SupportingTypesAndExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DownloadManager+SupportingTypesAndExtensions.swift"; sourceTree = "<group>"; };
295297
4D4D80C3217D281D00D1C233 /* DownloadViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DownloadViewModel.swift; sourceTree = "<group>"; };
296298
4D5EB0F720598E6000D4BC52 /* SessionRowProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionRowProvider.swift; sourceTree = "<group>"; };
@@ -784,6 +786,7 @@
784786
DD600ACD2487F3540071B90E /* NSColor+Hex.swift */,
785787
F4FB06A02A21493B00799F84 /* PreviewSupport.swift */,
786788
F422B8922C077E9600C4B337 /* UILog.swift */,
789+
27DD2F402D7ACEB3003EABDE /* BackForwardSkipDuration.swift */,
787790
);
788791
path = Util;
789792
sourceTree = "<group>";
@@ -1633,6 +1636,7 @@
16331636
F422B8B22C07CB6C00C4B337 /* CALayer+Asset.swift in Sources */,
16341637
F4FB06A12A21493B00799F84 /* PreviewSupport.swift in Sources */,
16351638
DD600ACE2487F3540071B90E /* NSColor+Hex.swift in Sources */,
1639+
F48075BB2D830EE200FCD70E /* BackForwardSkipDuration.swift in Sources */,
16361640
DD600AC32487F1C00071B90E /* ConfUIFoundation.swift in Sources */,
16371641
DD600ACB2487F2D90071B90E /* Fonts.swift in Sources */,
16381642
F422B8932C077E9600C4B337 /* UILog.swift in Sources */,

WWDC/PlaybackPreferencesViewController.swift

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ final class PlaybackPreferencesViewController: WWDCWindowContentViewController {
2121

2222
@IBOutlet weak var skipIntroStackView: NSStackView?
2323
@IBOutlet private var skipIntroSwitch: NSSwitch!
24-
@IBOutlet private var skipBackAndForwardBy30SecondsSwitch: NSSwitch!
24+
@IBOutlet weak var skipDurationDropDownMenu: NSPopUpButtonCell!
2525
@IBOutlet weak var includeAppBannerInClipsSwitch: NSSwitch!
2626

2727
override var viewForWindowTopSafeAreaConstraint: NSView? { skipIntroSwitch }
@@ -30,16 +30,36 @@ final class PlaybackPreferencesViewController: WWDCWindowContentViewController {
3030
super.viewDidLoad()
3131

3232
skipIntroSwitch.isOn = Preferences.shared.skipIntro
33-
skipBackAndForwardBy30SecondsSwitch.isOn = Preferences.shared.skipBackAndForwardBy30Seconds
33+
switch Preferences.shared.skipBackAndForwardDuration {
34+
case .fiveSeconds:
35+
skipDurationDropDownMenu.selectItem(at: 0)
36+
case .tenSeconds:
37+
skipDurationDropDownMenu.selectItem(at: 1)
38+
case .fifteenSeconds:
39+
skipDurationDropDownMenu.selectItem(at: 2)
40+
case .thirtySeconds:
41+
skipDurationDropDownMenu.selectItem(at: 3)
42+
}
3443
includeAppBannerInClipsSwitch.isOn = Preferences.shared.includeAppBannerInSharedClips
3544
}
3645

3746
@IBAction func skipIntroSwitchAction(_ sender: Any) {
3847
Preferences.shared.skipIntro = skipIntroSwitch.isOn
3948
}
4049

41-
@IBAction func skipBackAndForwardBy30SecondsSwitchAction(_ sender: Any) {
42-
Preferences.shared.skipBackAndForwardBy30Seconds = skipBackAndForwardBy30SecondsSwitch.isOn
50+
@IBAction func skipBackAndForwardDurationChangedAction(_ sender: Any) {
51+
switch skipDurationDropDownMenu?.indexOfSelectedItem {
52+
case 0:
53+
Preferences.shared.skipBackAndForwardDuration = .fiveSeconds
54+
case 1:
55+
Preferences.shared.skipBackAndForwardDuration = .tenSeconds
56+
case 2:
57+
Preferences.shared.skipBackAndForwardDuration = .fifteenSeconds
58+
case 3:
59+
Preferences.shared.skipBackAndForwardDuration = .thirtySeconds
60+
default:
61+
break
62+
}
4363
}
4464

4565
@IBAction func includeAppBannerInClipsSwitchAction(_ sender: NSSwitch) {

0 commit comments

Comments
 (0)