Skip to content

Commit

Permalink
3.3.5
Browse files Browse the repository at this point in the history
CompanionBridge
Fix display detection for enabling/disabling individual screens
  • Loading branch information
glouel committed Nov 13, 2023
1 parent f9c8fdb commit a324df9
Show file tree
Hide file tree
Showing 9 changed files with 237 additions and 20 deletions.
16 changes: 12 additions & 4 deletions Aerial.xcodeproj/project.pbxproj
Expand Up @@ -830,6 +830,9 @@
F06FCF1A28DB8673007558BA /* tl.json in Resources */ = {isa = PBXBuildFile; fileRef = F06FCF1928DB8673007558BA /* tl.json */; };
F06FCF1B28DB8673007558BA /* tl.json in Resources */ = {isa = PBXBuildFile; fileRef = F06FCF1928DB8673007558BA /* tl.json */; };
F06FCF1C28DB8673007558BA /* tl.json in Resources */ = {isa = PBXBuildFile; fileRef = F06FCF1928DB8673007558BA /* tl.json */; };
F07221872AD4354E001F5452 /* CompanionBridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = F07221862AD4354E001F5452 /* CompanionBridge.swift */; };
F07221882AD4354E001F5452 /* CompanionBridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = F07221862AD4354E001F5452 /* CompanionBridge.swift */; };
F07221892AD4354E001F5452 /* CompanionBridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = F07221862AD4354E001F5452 /* CompanionBridge.swift */; };
F0A3E0A32884683D005E8D8D /* CompanionCacheViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0A3E0A12884683D005E8D8D /* CompanionCacheViewController.swift */; };
F0A3E0A42884683D005E8D8D /* CompanionCacheViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0A3E0A12884683D005E8D8D /* CompanionCacheViewController.swift */; };
F0A3E0A52884683D005E8D8D /* CompanionCacheViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0A3E0A12884683D005E8D8D /* CompanionCacheViewController.swift */; };
Expand Down Expand Up @@ -1183,6 +1186,7 @@
F008DAFC23AADCFB00739DE1 /* Brightness.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Brightness.swift; sourceTree = "<group>"; };
F05E805328AE8A9C0088B9C5 /* NowPlayingCollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NowPlayingCollectionView.swift; sourceTree = "<group>"; };
F06FCF1928DB8673007558BA /* tl.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = tl.json; sourceTree = "<group>"; };
F07221862AD4354E001F5452 /* CompanionBridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompanionBridge.swift; sourceTree = "<group>"; };
F0A3E0A12884683D005E8D8D /* CompanionCacheViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompanionCacheViewController.swift; sourceTree = "<group>"; };
F0A3E0A22884683D005E8D8D /* CompanionCacheViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = CompanionCacheViewController.xib; sourceTree = "<group>"; };
FA143CD61BDA3E880041A82B /* AerialApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AerialApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -1774,6 +1778,7 @@
03AD45FE22981B0C00261325 /* CustomVideoFolders+helpers.swift */,
03C97BBF24B60E2F00739CED /* FileHelpers.swift */,
03FF192F269709AB00A0FA7F /* PlaybackSpeed.swift */,
F07221862AD4354E001F5452 /* CompanionBridge.swift */,
);
path = Models;
sourceTree = "<group>";
Expand Down Expand Up @@ -2528,6 +2533,7 @@
buildActionMask = 2147483647;
files = (
0396D50B24B8B7ED00CC021B /* DisplayDetection.swift in Sources */,
F07221882AD4354E001F5452 /* CompanionBridge.swift in Sources */,
0396D50C24B8B7ED00CC021B /* LayerOffsets.swift in Sources */,
0396D50D24B8B7ED00CC021B /* APISecrets.swift in Sources */,
0396D50E24B8B7ED00CC021B /* NightShift.swift in Sources */,
Expand Down Expand Up @@ -2670,6 +2676,7 @@
buildActionMask = 2147483647;
files = (
03B8742424E41CF8008E3D1B /* CacheSetupViewController.swift in Sources */,
F07221892AD4354E001F5452 /* CompanionBridge.swift in Sources */,
03D3A11524C5FC770091FE99 /* AspectFillNSImageView.swift in Sources */,
031FB7A2248A873C0054BAFD /* PrefsCache.swift in Sources */,
F00864B523AAE7F0003210EF /* DarkMode.swift in Sources */,
Expand Down Expand Up @@ -2821,6 +2828,7 @@
buildActionMask = 2147483647;
files = (
03D1E78A2284471A00D10CF7 /* DisplayDetection.swift in Sources */,
F07221872AD4354E001F5452 /* CompanionBridge.swift in Sources */,
0306336B23A142FA00046A59 /* LayerOffsets.swift in Sources */,
0385FC59242B9AE1007E6513 /* APISecrets.swift in Sources */,
F00864B723AAE8E9003210EF /* NightShift.swift in Sources */,
Expand Down Expand Up @@ -3241,15 +3249,15 @@
CODE_SIGN_IDENTITY = "Developer ID Application";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3.3.3;
CURRENT_PROJECT_VERSION = 3.3.5;
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.3.3;
MARKETING_VERSION = 3.3.5;
PRODUCT_BUNDLE_IDENTIFIER = com.johncoates.Aerial;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -3270,15 +3278,15 @@
CODE_SIGN_IDENTITY = "Developer ID Application";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 3.3.3;
CURRENT_PROJECT_VERSION = 3.3.5;
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.3.3;
MARKETING_VERSION = 3.3.5;
OTHER_CODE_SIGN_FLAGS = "--timestamp";
PRODUCT_BUNDLE_IDENTIFIER = com.johncoates.Aerial;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
60 changes: 60 additions & 0 deletions Aerial/Source/Models/Aerial.swift
Expand Up @@ -251,6 +251,66 @@ class Aerial: NSObject {

return (output, task.terminationStatus)
}

func shell(_ command:String, args: [String] = []) -> String
{
let task = Process()
var arguments = ["-c"]
arguments.append(command)
arguments += args
task.launchPath = "/bin/bash"
task.arguments = arguments

let pipe = Pipe()
task.standardOutput = pipe
task.launch()


let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output = String(data: data, encoding: .utf8)
task.waitUntilExit()

return output ?? ""

/* let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output = String(data: data, encoding: String.Encoding.utf8)!
*/ /*if output.count > 0 {
//remove newline character.
let lastIndex = output.index(before: output.endIndex)
return String(output[output.startIndex ..< lastIndex])
}*/
//return output
}

// Launch a process through shell and capture/return output
func shell(executableURL: String, arguments: [String] = []) -> (String?, Int32) {
let task = Process()
task.executableURL = URL(fileURLWithPath: executableURL)
task.arguments = arguments

let pipe = Pipe()
task.standardOutput = pipe
task.standardError = pipe

if #available(OSX 10.13, *) {
do {
try task.run()
} catch {
// handle errors
debugLog("Error: \(error.localizedDescription)")
}
} else {
// A non existing command will crash 10.12
task.launch()
}

let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output = String(data: data, encoding: .utf8)
task.waitUntilExit()

return (output, task.terminationStatus)
}


/*
func trySettings() {
Expand Down
68 changes: 68 additions & 0 deletions Aerial/Source/Models/CompanionBridge.swift
@@ -0,0 +1,68 @@
//
// CompanionBridge.swift
// Aerial
//
// Created by Guillaume Louel on 09/10/2023.
// Copyright © 2023 Guillaume Louel. All rights reserved.
//
// This acts as our bridge to Companion when the plugin needs data FROM companion
// Currently using DistributedNotificationCenter, until *that* breaks too...

import Foundation

struct CompanionBridge {
static var nightShiftSunrise: Date?
static var nightShiftSunset: Date?

static var locationLat: Double?
static var locationLong: Double?

static func setNotifications() {
debugLog("🌉 seting up CompanionBridge")

// Get nightshift
DistributedNotificationCenter.default().addObserver(forName: NSNotification.Name("com.glouel.aerial.nightshift"), object: nil, queue: nil) { notification in
debugLog("🌉😻 received nightshift")
debugLog(notification.debugDescription)

if let sunrise = notification.userInfo?["sunrise"] as? Date {
debugLog("parsed sunrise")
nightShiftSunrise = sunrise
} else {
debugLog("can't parse sunrise")
}

if let sunset = notification.userInfo?["sunset"] as? Date {
debugLog("parsed sunset")
nightShiftSunset = sunset
}
}

// Get location
DistributedNotificationCenter.default().addObserver(forName: NSNotification.Name("com.glouel.aerial.location"), object: nil, queue: nil) { notification in
debugLog("🌉😻 received location")
debugLog(notification.debugDescription)

if let lat = notification.userInfo?["latitude"] as? Double {
debugLog("parsed latitude")
locationLat = lat
} else {
debugLog("can't parse latitude")
}

if let long = notification.userInfo?["longitude"] as? Double {
debugLog("parsed longitude")
locationLong = long
}
}


// Test request
DistributedNotificationCenter.default().postNotificationName(NSNotification.Name("com.glouel.aerial.getnightshift"), object: nil, deliverImmediately: true)

if PrefsInfo.weather.locationMode == .useCurrent || PrefsTime.timeMode == .locationService {
debugLog("🌉 asking for location")
DistributedNotificationCenter.default().postNotificationName(NSNotification.Name("com.glouel.aerial.getlocation"), object: nil, deliverImmediately: true)
}
}
}
3 changes: 2 additions & 1 deletion Aerial/Source/Models/Hardware/DisplayDetection.swift
Expand Up @@ -357,7 +357,8 @@ final class DisplayDetection: NSObject {

func isScreenActive(id: CGDirectDisplayID) -> Bool {
let screen = findScreenWith(id: id)

debugLog("ISA : \(screen)")

switch PrefsDisplays.displayMode {
case .allDisplays:
// This one is easy
Expand Down
12 changes: 12 additions & 0 deletions Aerial/Source/Models/Hardware/NightShift.swift
Expand Up @@ -39,6 +39,17 @@ struct NightShift {

// swiftlint:disable:next large_tuple
static func getInformation() -> (Bool, sunrise: Date?, sunset: Date?, error: String?) {
// Sonoma workaround
if !Aerial.helper.underCompanion {
if #available(macOS 14.0, *) {
if CompanionBridge.nightShiftSunrise != nil {
debugLog("Nightshift using CompanionBridge data")
return (true, CompanionBridge.nightShiftSunrise, CompanionBridge.nightShiftSunset, nil)
} else {
return (false, nil, nil, "Sonoma requires Aerial Companion")
}
}
}
if isNightShiftDataCached {
return (nightShiftAvailable, nightShiftSunrise, nightShiftSunset, nil)
}
Expand All @@ -50,6 +61,7 @@ struct NightShift {
}

let (nsInfo, ts) = Aerial.helper.shell(launchPath: cbdpath, arguments: ["nightshift-internal"])


if ts != 0 {
// Task didn't return correctly ? Abort
Expand Down
16 changes: 16 additions & 0 deletions Aerial/Source/Models/Locations.swift
Expand Up @@ -25,6 +25,22 @@ class Locations: NSObject {

func getCoordinates(failure: @escaping (_ error: String) -> Void,
success: @escaping (_ response: CLLocationCoordinate2D) -> Void) {
// Sonoma workaround via CompanionBridge
if !Aerial.helper.underCompanion {
if #available(macOS 14.0, *) {
if CompanionBridge.locationLat != nil && CompanionBridge.locationLong != nil {
debugLog("Location using CompanionBridge data")

let coords = CLLocationCoordinate2DMake(
CompanionBridge.locationLat! as CLLocationDegrees,
CompanionBridge.locationLong! as CLLocationDegrees)

success(coords)
return
}
}
}

// Perhaps they are cached already ?
if coordinates != nil {
debugLog("Location using cached data")
Expand Down

0 comments on commit a324df9

Please sign in to comment.