Skip to content

Commit

Permalink
Fix Sonoma unable to detect monitors
Browse files Browse the repository at this point in the history
  • Loading branch information
glouel committed Sep 4, 2023
1 parent 0fe3461 commit 5be955e
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 28 deletions.
8 changes: 4 additions & 4 deletions Aerial.xcodeproj/project.pbxproj
Expand Up @@ -3241,15 +3241,15 @@
CODE_SIGN_IDENTITY = "Developer ID Application";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3.2.7beta6a2;
CURRENT_PROJECT_VERSION = 3.2.7beta7a1;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = 3L54M5L5KK;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = "$(SRCROOT)/Resources/Old stuff/Info.plist";
INSTALL_PATH = "$(HOME)/Library/Screen Savers";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.13;
MARKETING_VERSION = 3.2.7beta6a2;
MARKETING_VERSION = 3.2.7beta7a1;
PRODUCT_BUNDLE_IDENTIFIER = com.johncoates.Aerial;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -3270,15 +3270,15 @@
CODE_SIGN_IDENTITY = "Developer ID Application";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3.2.7beta6a2;
CURRENT_PROJECT_VERSION = 3.2.7beta7a1;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = 3L54M5L5KK;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = "$(SRCROOT)/Resources/Old stuff/Info.plist";
INSTALL_PATH = "$(HOME)/Library/Screen Savers";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.13;
MARKETING_VERSION = 3.2.7beta6a2;
MARKETING_VERSION = 3.2.7beta7a1;
OTHER_CODE_SIGN_FLAGS = "--timestamp";
PRODUCT_BUNDLE_IDENTIFIER = com.johncoates.Aerial;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
2 changes: 1 addition & 1 deletion Aerial/Source/Models/Sources/Source.swift
Expand Up @@ -277,7 +277,7 @@ struct Source: Codable {
if let mergename = poiStringProvider.getCommunityName(id: asset.id) {
return mergename
} else {
return asset.title ?? ""
return asset.title ?? "Unknown"
}
}

Expand Down
11 changes: 1 addition & 10 deletions Aerial/Source/Models/Sources/VideoList.swift
Expand Up @@ -178,16 +178,6 @@ class VideoList {
}
}

/*print("Filters :")
for filter in filters {
print(filter)
}*/

/*print("Videos : ")
for video in videos {
print(video.name.lowercased())
}*/

switch mode {
case .location:
let vids = videos
Expand Down Expand Up @@ -419,6 +409,7 @@ class VideoList {
.filter({ PrefsVideos.favorites.contains($0.id) && !PrefsVideos.hidden.contains($0.id) })
.sorted { $0.secondaryName < $1.secondaryName }
default:
print(PrefsVideos.newShouldPlayString)
return filteredVideosFor(mode, filter: PrefsVideos.newShouldPlayString)
}
}
Expand Down
2 changes: 2 additions & 0 deletions Aerial/Source/Views/AerialView+Player.swift
Expand Up @@ -41,6 +41,8 @@ extension AerialView {
if PrefsDisplays.viewingMode == .spanned && !isPreview {
let zRect = displayDetection.getZeroedActiveSpannedRect()
//let screen = displayDetection.findScreenWith(frame: self.frame)
debugLog("foundScreen check : \(foundScreen.debugDescription)")

if let scr = foundScreen {
let tRect = CGRect(x: zRect.origin.x - scr.zeroedOrigin.x,
y: zRect.origin.y - scr.zeroedOrigin.y,
Expand Down
61 changes: 48 additions & 13 deletions Aerial/Source/Views/AerialView.swift
Expand Up @@ -147,7 +147,15 @@ final class AerialView: ScreenSaverView, CAAnimationDelegate {
if Aerial.helper.underCompanion && isPreview {
debugLog("Running under companion in preview mode, preventing setup")
} else {
setup()
// We need to delay things under Sonoma because legacyScreenSaver is awesome
if #available(macOS 14.0, *) {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
debugLog("🖼️ AVinit delayed setup!")
self.setup()
}
} else {
setup()
}
}
}

Expand All @@ -171,7 +179,16 @@ final class AerialView: ScreenSaverView, CAAnimationDelegate {
self.originalHeight = frame.height

debugLog("🖼️ AVinit .app")
setup()

// We need to delay things under Sonoma because legacyScreenSaver is awesome
if #available(macOS 14.0, *) {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
debugLog("🖼️ AVinit delayed setup!")
self.setup()
}
} else {
setup()
}
}

deinit {
Expand All @@ -198,7 +215,6 @@ final class AerialView: ScreenSaverView, CAAnimationDelegate {
// swiftlint:disable:next cyclomatic_complexity
func setup() {
// Disable HDR only on macOS Ventura
// Todo : This may cause the can't reopen settings bug ?
if !Aerial.helper.canHDR() {
if isPreview && (PrefsVideos.videoFormat == .v4KHDR || PrefsVideos.videoFormat == .v1080pHDR) {
// This will lead to crashing in up to Ventura beta5 so disable
Expand All @@ -211,16 +227,17 @@ final class AerialView: ScreenSaverView, CAAnimationDelegate {
return
}
}


// First we check the system appearance, as it relies on our view
Aerial.helper.computeDarkMode(view: self)

// Then check if we need to mute/unmute sound
Aerial.helper.maybeMuteSound()


// Kick up the timezone detection
_ = TimeManagement.sharedInstance

// This is to make sure we don't start in a format that's unsupported
ensureCorrectFormat()

if let version = Bundle(identifier: "com.JohnCoates.Aerial")?.infoDictionary?["CFBundleShortVersionString"] as? String {
Expand Down Expand Up @@ -261,11 +278,9 @@ final class AerialView: ScreenSaverView, CAAnimationDelegate {
let screenCount = displayDetection.getScreenCount()
debugLog("🖼️ Real screen count : \(screenCount)")

debugLog("🥬 window \(String(describing: self.window))")

var thisScreen: Screen? = nil
if #available(macOS 14.0, *) {
thisScreen = displayDetection.alternateFindScreenWith(frame: self.frame, backingScaleFactor: self.window?.backingScaleFactor ?? 1)
//thisScreen = displayDetection.alternateFindScreenWith(frame: self.frame, backingScaleFactor: self.window?.backingScaleFactor ?? 1)
} else {
thisScreen = displayDetection.findScreenWith(frame: self.frame)
}
Expand All @@ -274,13 +289,14 @@ final class AerialView: ScreenSaverView, CAAnimationDelegate {
if let thisScreen = thisScreen {
foundFrame = thisScreen.bottomLeftFrame
foundScreen = thisScreen
debugLog("🖼️ Using : \(String(describing: thisScreen))")
}


for twindow in NSApplication.shared.windows {
debugLog("window : \(twindow.debugDescription)")
}

var localPlayer: AVPlayer?
debugLog("🖼️ Using : \(String(describing: thisScreen))")

debugLog("🥬 window.screen \(String(describing: self.window?.screen))")

// Is the current screen disabled by user ?
if !isPreview {
Expand Down Expand Up @@ -325,7 +341,7 @@ final class AerialView: ScreenSaverView, CAAnimationDelegate {
// add to player list
AerialView.players.append(player)
}

setupPlayerLayer(withPlayer: player)

// In mirror mode we use the main instance player
Expand Down Expand Up @@ -356,6 +372,25 @@ final class AerialView: ScreenSaverView, CAAnimationDelegate {
}
}
}


override func viewDidMoveToWindow() {
super.viewDidMoveToWindow()
debugLog("🖼️ \(self.description) viewDidMoveToWindow frame: \(self.frame) window: \(self.window)")
debugLog(self.window?.screen.debugDescription ?? "Unknown")

if let thisScreen = self.window?.screen {
let screenID = thisScreen.deviceDescription[NSDeviceDescriptionKey("NSScreenNumber")] as! CGDirectDisplayID

debugLog(screenID.description)

foundScreen = DisplayDetection.sharedInstance.findScreenWith(id: screenID)
foundFrame = foundScreen?.bottomLeftFrame

debugLog("🖼️🌾 Using : \(String(describing: foundScreen))")
debugLog("🥬🌾 window.screen \(String(describing: self.window?.screen.debugDescription))")
}
}

// Handle window resize
override func viewDidEndLiveResize() {
Expand Down

0 comments on commit 5be955e

Please sign in to comment.