Skip to content

Commit

Permalink
Merge pull request #776 from glouel/1.5.0exp
Browse files Browse the repository at this point in the history
1.5.0exp
  • Loading branch information
glouel authored May 13, 2019
2 parents a4fe916 + 9300380 commit ea41beb
Show file tree
Hide file tree
Showing 9 changed files with 283 additions and 29 deletions.
4 changes: 2 additions & 2 deletions Aerial.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then\n if [ -z \"$CI\" ]; then\n make --directory=${SRCROOT} xcode-lint\n fi\nelse\n echo \"warning: SwiftLint not installed, install using `brew install swiftlint`\"\nfi\n";
shellScript = "#if which swiftlint >/dev/null; then\n# if [ -z \"$CI\" ]; then\n# make --directory=${SRCROOT} xcode-lint\n# fi\n#else\n# echo \"warning: SwiftLint not installed, install using `brew install swiftlint`\"\n#fi\nif which swiftlint >/dev/null; then\n swiftlint autocorrect\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
};
910394578D35CCEBAEE0D456 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
Expand Down Expand Up @@ -748,7 +748,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then\n if [ -z \"$CI\" ]; then\n make --directory=${SRCROOT} xcode-lint\n fi\nelse\n echo \"warning: SwiftLint not installed, install using `brew install swiftlint`\"\nfi";
shellScript = "#if which swiftlint >/dev/null; then\n# if [ -z \"$CI\" ]; then\n# make --directory=${SRCROOT} xcode-lint\n# fi\n#else\n# echo \"warning: SwiftLint not installed, install using `brew install swiftlint`\"\n#fi\nif which swiftlint >/dev/null; then\n swiftlint autocorrect\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
};
/* End PBXShellScriptBuildPhase section */

Expand Down
26 changes: 24 additions & 2 deletions Aerial/Source/Controllers/Preferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,16 @@ final class Preferences {
case newDisplayMode = "newDisplayMode"
case newViewingMode = "newViewingMode"
case newDisplayDict = "newDisplayDict"
case logMilliseconds = "logMilliseconds"
case horizontalMargin = "horizontalMargin"
}

enum NewDisplayMode: Int {
case allDisplays, mainOnly, secondaryOnly, selection
}

enum NewViewingMode: Int {
case independant, mirrored, spanned
case independent, mirrored, spanned
}

enum BetaCheckFrequency: Int {
Expand Down Expand Up @@ -211,8 +213,10 @@ final class Preferences {
defaultValues[.allowBetas] = false
defaultValues[.betaCheckFrequency] = BetaCheckFrequency.daily
defaultValues[.newDisplayMode] = NewDisplayMode.allDisplays
defaultValues[.newViewingMode] = NewViewingMode.independant
defaultValues[.newViewingMode] = NewViewingMode.independent
defaultValues[.newDisplayDict] = [String: Bool]()
defaultValues[.logMilliseconds] = false
defaultValues[.horizontalMargin] = 0

// Set today's date as default
let dateFormatter = DateFormatter()
Expand Down Expand Up @@ -249,6 +253,15 @@ final class Preferences {
}
}

var horizontalMargin: Double? {
get {
return optionalValue(forIdentifier: .horizontalMargin)
}
set {
setValue(forIdentifier: .horizontalMargin, value: newValue)
}
}

var newDisplayMode: Int? {
get {
return optionalValue(forIdentifier: .newDisplayMode)
Expand Down Expand Up @@ -303,6 +316,15 @@ final class Preferences {
}
}

var logMilliseconds: Bool {
get {
return value(forIdentifier: .logMilliseconds)
}
set {
setValue(forIdentifier: .logMilliseconds, value: newValue)
}
}

var allowBetas: Bool {
get {
return value(forIdentifier: .allowBetas)
Expand Down
50 changes: 48 additions & 2 deletions Aerial/Source/Controllers/PreferencesWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,11 @@ final class PreferencesWindowController: NSWindowController, NSOutlineViewDataSo
@IBOutlet var newDisplayModePopup: NSPopUpButton!
@IBOutlet var newViewingModePopup: NSPopUpButton!
@IBOutlet var displayInstructionLabel: NSTextField!
@IBOutlet var quitConfirmationPanel: NSPanel!

@IBOutlet var logMillisecondsButton: NSButton!
@IBOutlet var displayMarginBox: NSBox!
@IBOutlet var horizontalDisplayMarginTextfield: NSTextField!
var player: AVPlayer = AVPlayer()

var videos: [AerialVideo]?
Expand Down Expand Up @@ -419,14 +423,18 @@ final class PreferencesWindowController: NSWindowController, NSOutlineViewDataSo
if !preferences.allowSkips {
rightArrowKeyPlaysNextCheckbox.state = .off
}
horizontalDisplayMarginTextfield.doubleValue = preferences.horizontalMargin!

// Aerial panel
// Advanced panel
if preferences.debugMode {
debugModeCheckbox.state = .on
}
if preferences.logToDisk {
logToDiskCheckbox.state = .on
}
if preferences.logMilliseconds {
logMillisecondsButton.state = .on
}

// Text panel
if preferences.showClock {
Expand Down Expand Up @@ -660,7 +668,23 @@ final class PreferencesWindowController: NSWindowController, NSOutlineViewDataSo
}

@IBAction func close(_ sender: AnyObject?) {
// This seems needed for screensavers as our lifecycle is different from a regular app
// We ask for confirmation in case downloads are ongoing
if !downloadProgressIndicator.isHidden {
quitConfirmationPanel.makeKeyAndOrderFront(self)
} else {
// This seems needed for screensavers as our lifecycle is different from a regular app
preferences.synchronize()
logPanel.close()
if appMode {
NSApplication.shared.terminate(nil)
} else {
window?.sheetParent?.endSheet(window!)
}
}
}

@IBAction func confirmQuitClick(_ sender: Any) {
quitConfirmationPanel.close()
preferences.synchronize()
logPanel.close()
if appMode {
Expand All @@ -670,6 +694,10 @@ final class PreferencesWindowController: NSWindowController, NSOutlineViewDataSo
}
}

@IBAction func cancelQuitClick(_ sender: Any) {
quitConfirmationPanel.close()
}

// MARK: Video playback

// Rewind preview video when reaching end
Expand Down Expand Up @@ -861,6 +889,17 @@ final class PreferencesWindowController: NSWindowController, NSOutlineViewDataSo
debugLog("UI newViewingModeClick: \(sender.indexOfSelectedItem)")
preferences.newViewingMode = sender.indexOfSelectedItem
displayView.needsDisplay = true

if preferences.newViewingMode == Preferences.NewViewingMode.spanned.rawValue {
displayMarginBox.isHidden = false
} else {
displayMarginBox.isHidden = true
}
}

@IBAction func horizontalDisplayMarginChange(_ sender: NSTextField) {
debugLog("UI horizontalDisplayMarginChange \(sender.stringValue)")
preferences.horizontalMargin = sender.doubleValue
}

// MARK: - Text panel
Expand Down Expand Up @@ -1459,6 +1498,13 @@ final class PreferencesWindowController: NSWindowController, NSOutlineViewDataSo
}

// MARK: - Advanced panel

@IBAction func logMillisecondsClick(_ button: NSButton) {
let onState = button.state == .on
preferences.logMilliseconds = onState
debugLog("UI logMilliseconds: \(onState)")
}

@IBAction func logButtonClick(_ sender: NSButton) {
logTableView.reloadData()
if logPanel.isVisible {
Expand Down
38 changes: 34 additions & 4 deletions Aerial/Source/Models/DisplayDetection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ final class DisplayDetection: NSObject {
static let sharedInstance = DisplayDetection()

var screens = [Screen]()
var cmInPoints: CGFloat = 40
var maxLeftScreens: CGFloat = 0
var maxBelowScreens: CGFloat = 0

// MARK: - Lifecycle
override init() {
Expand Down Expand Up @@ -72,8 +75,13 @@ final class DisplayDetection: NSObject {
var rect = CGDisplayBounds(currentDisplay)
if isMain == 0 {
rect = convertTopLeftToBottomLeft(rect: rect)
} else {
// We calculate the equivalent of a centimeter in points on the main screen as a reference
let mmsize = CGDisplayScreenSize(currentDisplay)
let wide = CGDisplayPixelsWide(currentDisplay)
cmInPoints = CGFloat(wide) / CGFloat(mmsize.width) * 10
debugLog("1cm = \(cmInPoints) points")
}

screens.append(Screen(id: currentDisplay,
width: CGDisplayPixelsWide(currentDisplay),
height: CGDisplayPixelsHigh(currentDisplay),
Expand All @@ -97,6 +105,7 @@ final class DisplayDetection: NSObject {
for screen in screens {
debugLog("\(screen)")
}

debugLog("\(getGlobalScreenRect())")
debugLog("***Display Detection Done***")
}
Expand All @@ -106,12 +115,33 @@ final class DisplayDetection: NSObject {
func calculateZeroedOrigins() {
let orect = getGlobalScreenRect()

// First we check for the screen relative position and calculate how many screens we have horizontally
// TODO Vertical + H/V mix
for screen in screens {
screen.zeroedOrigin = CGPoint(x: screen.bottomLeftFrame.origin.x - orect.origin.x,
debugLog("src orig : \(screen.bottomLeftFrame.origin)")
var leftScreens: CGFloat = 0
// Very rough, horizontal spans only
for otherScreen in screens {
if otherScreen.bottomLeftFrame.origin.x != screen.bottomLeftFrame.origin.x &&
otherScreen.bottomLeftFrame.origin.x < screen.bottomLeftFrame.origin.x {
leftScreens += 1
}
}

if leftScreens > maxLeftScreens {
maxLeftScreens = leftScreens
}

screen.zeroedOrigin = CGPoint(x: screen.bottomLeftFrame.origin.x - orect.origin.x + (leftScreens * leftMargin()),
y: screen.bottomLeftFrame.origin.y - orect.origin.y)
}
}

func leftMargin() -> CGFloat {
let preferences = Preferences.sharedInstance
return cmInPoints * CGFloat(preferences.horizontalMargin!)
}

func findScreenWith(frame: CGRect) -> Screen? {
for screen in screens where frame == screen.bottomLeftFrame {
return screen
Expand Down Expand Up @@ -146,7 +176,7 @@ final class DisplayDetection: NSObject {
}
}

return CGRect(x: minX, y: minY, width: maxX-minX, height: maxY-minY)
return CGRect(x: minX, y: minY, width: maxX-minX+(maxLeftScreens*leftMargin()), height: maxY-minY)
}

func getZeroedActiveSpannedRect() -> CGRect {
Expand All @@ -172,7 +202,7 @@ final class DisplayDetection: NSObject {
let orect = getGlobalScreenRect()
minX -= orect.origin.x
minY -= orect.origin.y
return CGRect(x: minX, y: minY, width: width, height: height)
return CGRect(x: minX, y: minY, width: width+(maxLeftScreens*leftMargin()), height: height)
}

// NSScreen coordinates are with a bottom left origin, whereas CGDisplay
Expand Down
6 changes: 5 additions & 1 deletion Aerial/Source/Models/ErrorLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ func Log(level: ErrorLevel, message: String) {
if preferences.logToDisk {
DispatchQueue.main.async {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd' 'HH:mm:ss"
if preferences.logMilliseconds {
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss.SSS"
} else {
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
}
let string = dateFormatter.string(from: Date()) + " : " + message + "\n"

// tmpOverride
Expand Down
22 changes: 14 additions & 8 deletions Aerial/Source/Views/AerialView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ final class AerialView: ScreenSaverView {
}
} else {
// If we don't know this screen, we disable
debugLog("This is an unknown display, disabling")
isDisabled = true
return
//debugLog("This is an unknown display, disabling")
//isDisabled = false
//return
}
} else {
AerialView.previewView = self
Expand Down Expand Up @@ -356,6 +356,7 @@ final class AerialView: ScreenSaverView {
debugLog("\(self.description) setting up player layer with bounds/frame: \(layer.bounds) / \(layer.frame)")

playerLayer = AVPlayerLayer(player: player)

if #available(OSX 10.10, *) {
playerLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill
}
Expand All @@ -370,15 +371,16 @@ final class AerialView: ScreenSaverView {
y: zRect.origin.y - scr.zeroedOrigin.y,
width: zRect.width,
height: zRect.height)
debugLog("tRect : \(tRect)")
playerLayer.frame = tRect
//playerLayer.bounds = layer.bounds
} else {
errorLog("This is an unknown screen in span mode, this is not good")
playerLayer.frame = layer.bounds
}
} else {
playerLayer.frame = layer.bounds
}

layer.addSublayer(playerLayer)

textLayer = CATextLayer()
Expand Down Expand Up @@ -630,10 +632,14 @@ final class AerialView: ScreenSaverView {

if preferences.allowSkips {
if event.keyCode == 124 {
//playNextVideo()
// We need to skip forward all our views
for view in AerialView.instanciatedViews {
view.playNextVideo()
// If we share, just call this on our main view
if AerialView.sharingPlayers {
playNextVideo()
} else {
// If we do independant playback we have to skip all views
for view in AerialView.instanciatedViews {
view.playNextVideo()
}
}
} else {
self.nextResponder!.keyDown(with: event)
Expand Down
4 changes: 2 additions & 2 deletions Aerial/Source/Views/DisplayView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class DisplayView: NSView {

let sInRect = sRect.insetBy(dx: 1, dy: 1)

if preferences.newViewingMode == Preferences.NewViewingMode.independant.rawValue ||
if preferences.newViewingMode == Preferences.NewViewingMode.independent.rawValue ||
preferences.newViewingMode == Preferences.NewViewingMode.mirrored.rawValue {
if displayDetection.isScreenActive(id: screen.id) {
let bundle = Bundle(for: PreferencesWindowController.self)
Expand All @@ -128,7 +128,7 @@ class DisplayView: NSView {
}

// Show difference images in independant mode to simulate
if preferences.newViewingMode == Preferences.NewViewingMode.independant.rawValue {
if preferences.newViewingMode == Preferences.NewViewingMode.independent.rawValue {
if idx < 2 {
idx += 1
} else {
Expand Down
4 changes: 2 additions & 2 deletions Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.4.98beta1</string>
<string>1.4.99beta2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.4.98beta1</string>
<string>1.4.99beta2</string>
<key>LSApplicationCategoryType</key>
<string></string>
<key>LSMinimumSystemVersion</key>
Expand Down
Loading

0 comments on commit ea41beb

Please sign in to comment.