Skip to content

Commit

Permalink
More cleanup, revert the isPreview thing that is NOT fixed in Catalin…
Browse files Browse the repository at this point in the history
…a, unlike what I thought. Should not have closed that radar :(
  • Loading branch information
glouel committed Dec 6, 2019
1 parent 57481dc commit 4639132
Show file tree
Hide file tree
Showing 9 changed files with 209 additions and 175 deletions.
14 changes: 13 additions & 1 deletion Aerial.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
035A92A9225F8C480095AB85 /* he.json in Resources */ = {isa = PBXBuildFile; fileRef = 035A92A5225F8C480095AB85 /* he.json */; };
035A92AC226754760095AB85 /* ar.json in Resources */ = {isa = PBXBuildFile; fileRef = 035A92AB226754760095AB85 /* ar.json */; };
035A92AD226754760095AB85 /* ar.json in Resources */ = {isa = PBXBuildFile; fileRef = 035A92AB226754760095AB85 /* ar.json */; };
035D524F239AA31A00DC29DC /* AerialView+Player.swift in Sources */ = {isa = PBXBuildFile; fileRef = 035D524E239AA31A00DC29DC /* AerialView+Player.swift */; };
035D5250239AA31A00DC29DC /* AerialView+Player.swift in Sources */ = {isa = PBXBuildFile; fileRef = 035D524E239AA31A00DC29DC /* AerialView+Player.swift */; };
035D5252239AA5BC00DC29DC /* AerialView+Text.swift in Sources */ = {isa = PBXBuildFile; fileRef = 035D5251239AA5BC00DC29DC /* AerialView+Text.swift */; };
035D5253239AA5BC00DC29DC /* AerialView+Text.swift in Sources */ = {isa = PBXBuildFile; fileRef = 035D5251239AA5BC00DC29DC /* AerialView+Text.swift */; };
03608A1022A54887008F08A2 /* PWC+Videos.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03608A0F22A54887008F08A2 /* PWC+Videos.swift */; };
03608A1222A5499C008F08A2 /* PWC+Videos.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03608A0F22A54887008F08A2 /* PWC+Videos.swift */; };
03608A1422A559F6008F08A2 /* PWC+Displays.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03608A1322A559F6008F08A2 /* PWC+Displays.swift */; };
Expand Down Expand Up @@ -182,6 +186,8 @@
035A92A4225F8C480095AB85 /* de.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = de.json; sourceTree = "<group>"; };
035A92A5225F8C480095AB85 /* he.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = he.json; sourceTree = "<group>"; };
035A92AB226754760095AB85 /* ar.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = ar.json; sourceTree = "<group>"; };
035D524E239AA31A00DC29DC /* AerialView+Player.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AerialView+Player.swift"; sourceTree = "<group>"; };
035D5251239AA5BC00DC29DC /* AerialView+Text.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AerialView+Text.swift"; sourceTree = "<group>"; };
03608A0F22A54887008F08A2 /* PWC+Videos.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PWC+Videos.swift"; sourceTree = "<group>"; };
03608A1322A559F6008F08A2 /* PWC+Displays.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PWC+Displays.swift"; sourceTree = "<group>"; };
03608A1522A55A8C008F08A2 /* PWC+Text.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PWC+Text.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -321,6 +327,7 @@
03608A1F22A55BC2008F08A2 /* PWC+Cache.swift */,
03608A2222A55BF1008F08A2 /* PWC+Updates.swift */,
03608A2522A55C03008F08A2 /* PWC+Advanced.swift */,
03608A2822A56094008F08A2 /* PWC+LogPanel.swift */,
);
path = "PWC Tabs";
sourceTree = "<group>";
Expand Down Expand Up @@ -459,7 +466,6 @@
children = (
03608A1122A54921008F08A2 /* PWC Tabs */,
FAC36F3E1BE1756D007F2A20 /* PreferencesWindowController.swift */,
03608A2822A56094008F08A2 /* PWC+LogPanel.swift */,
0313F9E722942B4500B074BB /* CustomVideoController.swift */,
FA6F81DB1D939455007975FE /* Preferences.swift */,
);
Expand Down Expand Up @@ -505,6 +511,8 @@
children = (
FAC36F431BE1756D007F2A20 /* AerialView.swift */,
032D1163239A7F0C007E7756 /* AerialView+Brightness.swift */,
035D524E239AA31A00DC29DC /* AerialView+Player.swift */,
035D5251239AA5BC00DC29DC /* AerialView+Text.swift */,
FAC36F441BE1756D007F2A20 /* CheckCellView.swift */,
AA7E2E5D1FC62E8B00E5F320 /* AerialPlayerItem.swift */,
03D1E78622842FB300D10CF7 /* DisplayView.swift */,
Expand Down Expand Up @@ -904,13 +912,15 @@
FAC36F681BE1778C007F2A20 /* ManifestLoader.swift in Sources */,
03608A1722A55B44008F08A2 /* PWC+Displays.swift in Sources */,
FAC36F581BE1756D007F2A20 /* PreferencesWindowController.swift in Sources */,
035D5250239AA31A00DC29DC /* AerialView+Player.swift in Sources */,
0395834A217F442A008E8F9C /* Solar.swift in Sources */,
FAB22A7F1BE17D7D0065C0F5 /* AssetLoaderDelegate.swift in Sources */,
FAC36F601BE175CF007F2A20 /* AppDelegate.swift in Sources */,
03AD460022981B1C00261325 /* CustomVideoFolders+helpers.swift in Sources */,
032D1165239A7F17007E7756 /* AerialView+Brightness.swift in Sources */,
FA36BD401BE57F8E00D5E03B /* VideoDownload.swift in Sources */,
0313F9F022955F3B00B074BB /* CustomVideoFolders.swift in Sources */,
035D5253239AA5BC00DC29DC /* AerialView+Text.swift in Sources */,
03608A1B22A55B9A008F08A2 /* PWC+Time.swift in Sources */,
FA6F81DD1D939455007975FE /* Preferences.swift in Sources */,
FAF450221BE2B45D00C1F98A /* VideoLoader.swift in Sources */,
Expand Down Expand Up @@ -943,6 +953,7 @@
FAC36F5B1BE1756D007F2A20 /* AerialView.swift in Sources */,
0393857A2175D4B80040B850 /* AVPlayerViewExtension.swift in Sources */,
03E8730F216501ED002B469B /* AsynchronousOperation.swift in Sources */,
035D5252239AA5BC00DC29DC /* AerialView+Text.swift in Sources */,
03510C6F21834F38008F74F2 /* IOBridge.m in Sources */,
0313F9EF22955F3B00B074BB /* CustomVideoFolders.swift in Sources */,
03608A1422A559F6008F08A2 /* PWC+Displays.swift in Sources */,
Expand All @@ -963,6 +974,7 @@
03608A2022A55BC2008F08A2 /* PWC+Cache.swift in Sources */,
03A2CB9C216BA9AF0061E8E8 /* VideoManager.swift in Sources */,
03608A1D22A55BA7008F08A2 /* PWC+Brightness.swift in Sources */,
035D524F239AA31A00DC29DC /* AerialView+Player.swift in Sources */,
03AD45FF22981B0C00261325 /* CustomVideoFolders+helpers.swift in Sources */,
FAF450211BE2B45D00C1F98A /* VideoLoader.swift in Sources */,
03E8731321675FE0002B469B /* TimeManagement.swift in Sources */,
Expand Down
8 changes: 0 additions & 8 deletions Aerial/Source/Models/Cache/VideoLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,26 +101,18 @@ final class VideoLoader: NSObject, NSURLConnectionDataDelegate {
errorLog("Data request missing for \(self.loadingRequest)")
return
}
//debugLog("drl \(dataRequest.requestedLength) dro \(dataRequest.requestedOffset)")
//debugLog("\(dataRequest)")

/*if (data.count > 100000) {
debugLog("NOTGOOD")
dataLog(data)
}*/
let requestedRange = self.requestedRange
let loadedRange = self.loadedRange
let loadedLocation = loadedRange.location + loadedRange.length

let dataRange = NSRange(location: loadedRange.location + loadedRange.length,
length: data.count)
//debugLog("\(dataRange)")

self.delegate?.videoLoader(self, receivedData: data, forRange: dataRange)

// check if we've already been sending content, or we're at right byte offset
if loadedLocation >= requestedRange.location {
//debugLog("case1")
let requestedEndOffset = Int(dataRequest.requestedOffset + Int64(dataRequest.requestedLength))

let pendingDataEndOffset = loadedLocation + data.count
Expand Down
3 changes: 3 additions & 0 deletions Aerial/Source/Models/ErrorLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ func errorLog(_ message: String) {
Log(level: .error, message: message)
}

/*
func dataLog(_ data: Data) {
let cacheDirectory = VideoCache.appSupportDirectory!
var cacheFileUrl = URL(fileURLWithPath: cacheDirectory as String)
Expand All @@ -148,3 +150,4 @@ func dataLog(_ data: Data) {
}
}
*/
19 changes: 9 additions & 10 deletions Aerial/Source/Views/AerialView+Brightness.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@ extension AerialView {
let timeManagement = TimeManagement.sharedInstance
let batteryManagement = BatteryManagement()

if preferences.dimBrightness {
if !isPreview && brightnessToRestore == nil {
let (should, to) = timeManagement.shouldRestrictPlaybackToDayNightVideo()
if !preferences.dimOnlyAtNight || (preferences.dimOnlyAtNight && should && to == "night") {
if !preferences.dimOnlyOnBattery || (preferences.dimOnlyOnBattery && batteryManagement.isOnBattery()) {
brightnessToRestore = timeManagement.getBrightness()
debugLog("Brightness before Aerial was launched : \(String(describing: brightnessToRestore))")
timeManagement.setBrightness(level: min(Float(preferences.startDim!), brightnessToRestore!))
setDimTimers()
}
if preferences.dimBrightness && !isPreview && brightnessToRestore == nil {
let (should, to) = timeManagement.shouldRestrictPlaybackToDayNightVideo()

if !preferences.dimOnlyAtNight || (preferences.dimOnlyAtNight && should && to == "night") {
if !preferences.dimOnlyOnBattery || (preferences.dimOnlyOnBattery && batteryManagement.isOnBattery()) {
brightnessToRestore = timeManagement.getBrightness()
debugLog("Brightness before Aerial was launched : \(String(describing: brightnessToRestore))")
timeManagement.setBrightness(level: min(Float(preferences.startDim!), brightnessToRestore!))
setDimTimers()
}
}
}
Expand Down
95 changes: 95 additions & 0 deletions Aerial/Source/Views/AerialView+Player.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
//
// AerialView+Player.swift
// Aerial
//
// Created by Guillaume Louel on 06/12/2019.
// Copyright © 2019 John Coates. All rights reserved.
//

import Foundation
import AVFoundation
import AVKit

extension AerialView {
func setupPlayerLayer(withPlayer player: AVPlayer) {
let displayDetection = DisplayDetection.sharedInstance
let preferences = Preferences.sharedInstance

self.layer = CALayer()
guard let layer = self.layer else {
errorLog("\(self.description) Couldn't create CALayer")
return
}
self.wantsLayer = true
layer.backgroundColor = NSColor.black.cgColor
layer.needsDisplayOnBoundsChange = true
layer.frame = self.bounds
debugLog("\(self.description) setting up player layer with bounds/frame: \(layer.bounds) / \(layer.frame)")

playerLayer = AVPlayerLayer(player: player)

if #available(OSX 10.10, *) {
if preferences.aspectMode == Preferences.AspectMode.fill.rawValue {
playerLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill
} else {
playerLayer.videoGravity = AVLayerVideoGravity.resizeAspect
}
}
playerLayer.autoresizingMask = [CAAutoresizingMask.layerWidthSizable, CAAutoresizingMask.layerHeightSizable]

// In case of span mode we need to compute the size of our layer
if preferences.newViewingMode == Preferences.NewViewingMode.spanned.rawValue && !isPreview {
let zRect = displayDetection.getZeroedActiveSpannedRect()
let screen = displayDetection.findScreenWith(frame: self.frame)
if let scr = screen {
let tRect = CGRect(x: zRect.origin.x - scr.zeroedOrigin.x,
y: zRect.origin.y - scr.zeroedOrigin.y,
width: zRect.width,
height: zRect.height)
playerLayer.frame = tRect
} else {
errorLog("This is an unknown screen in span mode, this is not good")
playerLayer.frame = layer.bounds
}
} else {
playerLayer.frame = layer.bounds

// "true" mirrored mode
let index = AerialView.instanciatedViews.firstIndex(of: self) ?? 0
if index % 2 == 1 && preferences.newViewingMode == Preferences.NewViewingMode.mirrored.rawValue {
playerLayer.transform = CATransform3DMakeAffineTransform(CGAffineTransform(scaleX: -1, y: 1))
}
}
layer.addSublayer(playerLayer)

// The layers for descriptions, clock, message
setupTextLayers(layer: layer)

// An extra layer to try and contravent a macOS graphics driver bug
// This is useful on High Sierra+ on Intel Macs
setupGlitchWorkaroundLayer(layer: layer)
}

// MARK: - AVPlayerItem Notifications

@objc func playerItemFailedtoPlayToEnd(_ aNotification: Notification) {
warnLog("\(self.description) AVPlayerItemFailedToPlayToEndTimeNotification \(aNotification)")
playNextVideo()
}

@objc func playerItemNewErrorLogEntryNotification(_ aNotification: Notification) {
warnLog("\(self.description) AVPlayerItemNewErrorLogEntryNotification \(aNotification)")
}

@objc func playerItemPlaybackStalledNotification(_ aNotification: Notification) {
warnLog("\(self.description) AVPlayerItemPlaybackStalledNotification \(aNotification)")
}

@objc func playerItemDidReachEnd(_ aNotification: Notification) {
debugLog("\(self.description) played did reach end")
debugLog("\(self.description) notification: \(aNotification)")
playNextVideo()
debugLog("\(self.description) playing next video for player \(String(describing: player))")
}

}
62 changes: 62 additions & 0 deletions Aerial/Source/Views/AerialView+Text.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// AerialView+Text.swift
// Aerial
//
// Created by Guillaume Louel on 06/12/2019.
// Copyright © 2019 John Coates. All rights reserved.
//

import Foundation
import AVKit

extension AerialView {

func setupTextLayers(layer: CALayer) {
// Main description layer
textLayer = CATextLayer()
textLayer.frame = layer.bounds // Same size as the screen
textLayer.opacity = 0
textLayer.shadowRadius = 10
textLayer.shadowOpacity = 1.0
textLayer.shadowColor = CGColor.black
layer.addSublayer(textLayer)

// Clock Layer
clockLayer = CATextLayer()
clockLayer.opacity = 0
clockLayer.shadowRadius = 10
clockLayer.shadowOpacity = 1.0
clockLayer.shadowColor = CGColor.black
layer.addSublayer(clockLayer)

// Message Layer
messageLayer = CATextLayer()
messageLayer.opacity = 0
messageLayer.shadowRadius = 10
messageLayer.shadowOpacity = 1.0
messageLayer.shadowColor = CGColor.black
layer.addSublayer(messageLayer)
}

func setupGlitchWorkaroundLayer(layer: CALayer) {
debugLog("Using dot workaround for video driver corruption")

let workaroundLayer = CATextLayer()
workaroundLayer.frame = self.bounds
workaroundLayer.opacity = 0.5
workaroundLayer.font = NSFont(name: "Helvetica Neue Medium", size: 4)
workaroundLayer.fontSize = 4
workaroundLayer.string = "."

let attributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.font: workaroundLayer.font as Any]

// Calculate bounding box
let attrString = NSAttributedString(string: workaroundLayer.string as! String, attributes: attributes)
let rect = attrString.boundingRect(with: layer.visibleRect.size, options: NSString.DrawingOptions.usesLineFragmentOrigin)

workaroundLayer.frame = rect
workaroundLayer.position = CGPoint(x: 2, y: 2)
workaroundLayer.anchorPoint = CGPoint(x: 0, y: 0)
layer.addSublayer(workaroundLayer)
}
}
Loading

0 comments on commit 4639132

Please sign in to comment.