Skip to content

Commit

Permalink
fixed a couple bugs
Browse files Browse the repository at this point in the history
- if a video was in 'lost connection' state, it could end up getting paused then played, and would lose its 'lost connection' status, and we end up with duplicate videos
- decreased the probability of a lost connection
- fixed overlay banner so it doesn't show the 1px of video underneath
also made debugging a little easier
  • Loading branch information
Rob Haining committed May 4, 2020
1 parent b008b29 commit 399933b
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 17 deletions.
20 changes: 14 additions & 6 deletions ZuumScreensaver.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@
isa = PBXGroup;
children = (
EF0E7098243A5ACD0082305E /* ConfigFetcher.swift */,
EF0E709B243A5B360082305E /* Config.swift */,
EF7B9BAC245CAA7B00E42A42 /* VideoSet.swift */,
EFD84AA82460741A00804284 /* Models */,
);
path = Network;
sourceTree = "<group>";
Expand Down Expand Up @@ -266,6 +265,15 @@
path = "Video Management";
sourceTree = "<group>";
};
EFD84AA82460741A00804284 /* Models */ = {
isa = PBXGroup;
children = (
EF0E709B243A5B360082305E /* Config.swift */,
EF7B9BAC245CAA7B00E42A42 /* VideoSet.swift */,
);
path = Models;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXHeadersBuildPhase section */
Expand Down Expand Up @@ -644,7 +652,7 @@
CODE_SIGN_IDENTITY = "Developer ID Application";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 3RF4ZJHWHU;
INFOPLIST_FILE = ZuumScreensaver/Info.plist;
INSTALL_PATH = "$(HOME)/Library/Screen Savers";
Expand All @@ -654,7 +662,7 @@
"@loader_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 1.1;
MARKETING_VERSION = 1.2;
PRODUCT_BUNDLE_IDENTIFIER = co.tolar.ZooooomScreensaver;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -672,7 +680,7 @@
CODE_SIGN_IDENTITY = "Developer ID Application";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 3RF4ZJHWHU;
INFOPLIST_FILE = ZuumScreensaver/Info.plist;
INSTALL_PATH = "$(HOME)/Library/Screen Savers";
Expand All @@ -682,7 +690,7 @@
"@loader_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 1.1;
MARKETING_VERSION = 1.2;
PRODUCT_BUNDLE_IDENTIFIER = co.tolar.ZooooomScreensaver;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

struct Config: Codable {
let minVideos: Int?
let maxVideos: Int?
var maxVideos: Int?

let connectionErrorMessages: [String]?
let version: String?
Expand Down
File renamed without changes.
74 changes: 67 additions & 7 deletions ZuumScreensaver/Video Management/Blockbuster.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ final class Blockbuster: ObservableObject {
guard !cancelRandom else { return }

let choice = Dice.roll()
performAction(choice)

enableRandomness()
}

private func performAction(_ choice: Dice) {
switch choice {
case .add:
addAVideo()
Expand All @@ -129,8 +135,6 @@ final class Blockbuster: ObservableObject {
case .loseConnection:
loseAConnection()
}

enableRandomness()
}

private func addThisVideo(with url: URL) {
Expand Down Expand Up @@ -212,37 +216,93 @@ final class Blockbuster: ObservableObject {
upgradeMessage = nil
}
}

}

extension Blockbuster {
func didType(_ chars: String) {
let action: Dice
switch chars {
case "d":
enableDebugMode()
action = .stay

case "c":
NSLog("cancel random")
toggleRandom(canceled: true)
action = .stay

case "e":
NSLog("enable random")
toggleRandom(canceled: false)
enableRandomness()
action = .stay

case "a":
NSLog("add a video")
addAVideo()
action = .add

case "r":
NSLog("remove a video")
removeAVideo()
action = .remove

case "l":
NSLog("lose a connection")
loseAConnection()
action = .loseConnection

case "p":
NSLog("pause a video")
pauseAVideo()
action = .pause

case "+":
NSLog("increase number of videos")
config?.maxVideos? += 1
NSLog("max number of videos is now \(String(describing: config?.maxVideos))")
action = .stay

default:
NSLog("unknown command")
action = .stay
}
performAction(action)
}

func didClick(_ location: NSPoint) {
for vv in videoViews {
if vv.frame.contains(location) {
NSLog("Clicked: \(vv.url)")
}
}
}
}

extension Blockbuster {
func showNextSet(start: Int = 0) {
guard let allVideoURLs = allVideoURLs else { return }

for vv in videoViews {
removeThisVideo(videoView: vv)
}

let end = min(start + 12, allVideoURLs.count)
let videoURLs = allVideoURLs.sorted(by: { (a, b) -> Bool in
return a.absoluteString.compare(b.absoluteString) == .orderedAscending
})[start..<end]

for url in videoURLs {
addThisVideo(with: url)
}

if end < allVideoURLs.count {
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(3)) { [weak self] in
self?.showNextSet(start: end)
}
} else {
toggleRandom(canceled: false)
}
}
func enableDebugMode() {
toggleRandom(canceled: true)
showNextSet()
}
}

Expand Down
2 changes: 1 addition & 1 deletion ZuumScreensaver/Video Management/Dice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ enum Dice: CaseIterable {
case 40..<50:
return .pause

case 50..<60:
case 50..<55:
return .loseConnection

default:
Expand Down
12 changes: 11 additions & 1 deletion ZuumScreensaver/Views/VideoPlayerStateOverlay.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ final class VideoPlayerStateOverlay: NSView {
lost(_ message: String?)
}

var isLost: Bool {
switch state {
case .lost(_):
return true

default:
return false
}
}

var state = State.none {
didSet {
var progressIndicatorEnabled: Bool
Expand Down Expand Up @@ -131,7 +141,7 @@ final class VideoPlayerStateOverlay: NSView {

frame.size = CGSize(width: bounds.width, height: 50)
frame.origin.x = 0
frame.origin.y = 0
frame.origin.y = -1
messageLabelWrapper.frame = frame

frame.size = CGSize(width: messageLabelWrapper.bounds.width, height: 20)
Expand Down
7 changes: 6 additions & 1 deletion ZuumScreensaver/Views/VideoPlayerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ final class VideoPlayerView: NSView {

func play(to percent: Double? = nil) {
guard let player = playerView.player,
let currentItem = player.currentItem else { return }
let currentItem = player.currentItem,
!stateOverlay.isLost else { return }

if let percent = percent {
let value = percent * currentItem.asset.duration.seconds
Expand All @@ -84,6 +85,8 @@ final class VideoPlayerView: NSView {
}

func pause(message: String?, warning: Bool = false) {
guard !stateOverlay.isLost else { return }

playerView.player?.pause()

playerView.alphaValue = 0.6
Expand Down Expand Up @@ -117,6 +120,8 @@ final class VideoPlayerView: NSView {
})
}
private func didUpdateReasonForWaitingToPlay() {
guard !stateOverlay.isLost else { return }

let isStalled = (playerView.player?.reasonForWaitingToPlay != nil)
if isStalled {
dateOfStall = Date()
Expand Down
7 changes: 7 additions & 0 deletions ZuumScreensaver/ZuumScreensaverView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,17 @@ final class ZuumScreensaverView: ScreenSaverView {
override var acceptsFirstResponder: Bool { return true }

override func keyUp(with event: NSEvent) {
super.keyUp(with: event)
if let characters = event.characters {
videoGridViewController?.blockbuster.didType(characters)
}
}

override func mouseUp(with event: NSEvent) {
super.mouseUp(with: event)
let location = event.locationInWindow
videoGridViewController?.blockbuster.didClick(location)
}

override var hasConfigureSheet: Bool {
return true
Expand Down

0 comments on commit 399933b

Please sign in to comment.