Skip to content

Commit

Permalink
3.1.2 fixes some stupid error with pre 10.15 prefs
Browse files Browse the repository at this point in the history
  • Loading branch information
glouel committed Aug 29, 2022
1 parent 1d97f01 commit 9706895
Show file tree
Hide file tree
Showing 26 changed files with 840 additions and 177 deletions.
76 changes: 66 additions & 10 deletions Aerial.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

54 changes: 44 additions & 10 deletions Aerial/Source/Models/Aerial.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ class Aerial: NSObject {
// Xcode debug mode is also considered as running under Companion

func checkCompanion() {
debugLog("Checking for companion")
logToConsole("Checking for companion")
if appMode {
underCompanion = true
debugLog("> Running in appMode, simming Companion!")
logToConsole("> Running in appMode, simming Companion!")
} else {
for bundle in Bundle.allBundles {
if let bundleId = bundle.bundleIdentifier {
if bundleId.contains("AerialUpdater") {
underCompanion = true
debugLog("> Running under Aerial Companion!")
logToConsole("> Running under Aerial Companion!")
}
}
}
Expand Down Expand Up @@ -277,24 +277,44 @@ class Aerial: NSObject {
print(result!)*/
}*/

func getPreferencesDirectory() -> String {
// Grab an array of Application Support paths
let libPaths = NSSearchPathForDirectoriesInDomains(
.libraryDirectory,
.userDomainMask,
true)

if !libPaths.isEmpty {
if underCompanion {
return libPaths.first! + "/Containers/com.apple.ScreenSaver.Engine.legacyScreenSaver/Data/Library/Preferences/"

} else {
return libPaths.first! + "/Preferences/"
}
} else {
return "/Users/" + Aerial.helper.userName + "/Library/Containers/com.apple.ScreenSaver.Engine.legacyScreenSaver/Data/Library/Preferences/"
}
}


// Starting with 3.1.0beta2, existing settings are moved from Preferences/ByHost to Preferences
// This allows the sharing of preferences between regular screen saver and companion-hosted screensaver
func migratePreferences() {
// First check if the new settings already exists !
let baseContainerPrefPath = "/Users/" + Aerial.helper.userName + "/Library/Containers/com.apple.ScreenSaver.Engine.legacyScreenSaver/Data/Library/Preferences/"
let baseContainerPrefPath = getPreferencesDirectory()

let newBundleFile = baseContainerPrefPath + "com.glouel.Aerial.plist"

if FileManager.default.fileExists(atPath: newBundleFile) {
// We are done
debugLog("!!! New prefs already exists")
logToConsole("!!! New prefs already exists")
} else {
debugLog("!!! New prefs does NOT exist")
logToConsole("!!! New prefs does NOT exist")
//Look for ByHost
let byHostPath = baseContainerPrefPath + "ByHost/"

if FileManager.default.fileExists(atPath: byHostPath) {
debugLog("ByHost exists")
logToConsole("ByHost exists")
var oldPlist = ""

// Try and find the old plist
Expand All @@ -309,19 +329,33 @@ class Aerial: NSObject {
}
}
} catch {
debugLog(error.localizedDescription)
logToConsole(error.localizedDescription)
}

// Did we get it ?
if oldPlist != "" {
debugLog("plist found " + oldPlist)
logToConsole("plist found " + oldPlist)
do {
try FileManager.default.copyItem(atPath: byHostPath + oldPlist, toPath: newBundleFile)
logToConsole("plist moved")
} catch {
debugLog(error.localizedDescription)
logToConsole(error.localizedDescription)
}
}
}
}
}

// Mute me maybe
func maybeMuteSound() {
if !appMode && !underCompanion && PrefsAdvanced.muteGlobalSound{
Sound.output.isMuted = true
}
}

func maybeUnmuteSound() {
if !appMode && !underCompanion && PrefsAdvanced.muteGlobalSound {
Sound.output.isMuted = false
}
}
}
2 changes: 1 addition & 1 deletion Aerial/Source/Models/Cache/Cache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ struct Cache {
do {
debugLog("trying to create \(cacheSupportDirectory.appendingPathComponent("Aerial"))")
try FileManager.default.createDirectory(atPath: cacheSupportDirectory.appendingPathComponent("Aerial"),
withIntermediateDirectories: false, attributes: nil)
withIntermediateDirectories: true, attributes: nil)
return path
} catch {
errorLog("Could not create Aerial's Caches path")
Expand Down
2 changes: 1 addition & 1 deletion Aerial/Source/Models/Downloads/FileHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct FileHelpers {
if fileManager.fileExists(atPath: atPath) == false {
do {
try fileManager.createDirectory(atPath: atPath,
withIntermediateDirectories: false, attributes: nil)
withIntermediateDirectories: true, attributes: nil)
} catch let error {
errorLog("Couldn't create directory at \(atPath) : \(error)")
errorLog("FATAL : There's nothing more we can do at this point, please report")
Expand Down
2 changes: 1 addition & 1 deletion Aerial/Source/Models/ErrorLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func Log(level: ErrorLevel, message: String) {

// Log to disk
if PrefsAdvanced.debugMode {
//logToConsole(message)
logToConsole(message)
logToDisk(message)
}
}
Expand Down
17 changes: 17 additions & 0 deletions Aerial/Source/Models/Hardware/ISSoundAdditions/Sound.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// SoundOutputManager.swift
//
//
// Created by Alessio Moiso on 08.03.22.
//

/// Entry point to access and modify the system sound settings, such
/// muting/unmuting and changing the volume.
///
/// # Overview
/// This class cannot be instantiated, but you can interact with its `output` property directly.
/// You can use the shared instance to change the output volume as well as
/// mute and unmute.
public enum Sound {
static let output = SoundOutputManager()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// File.swift
//
//
// Created by Alessio Moiso on 09.03.22.
//

public extension Sound.SoundOutputManager {
/// Increase the volume of the default output device
/// by the given amount.
///
/// Errors will be ignored.
///
/// The values range between 0 and 1. If the increase results
/// in a value outside of the bounds, it will be normalized to the closest
/// value in the bounds.
func increaseVolume(by value: Float, autoMuteUnmute: Bool = false, muteThreshold: Float = 0.005) {
setVolume(volume+value, autoMuteUnmute: autoMuteUnmute, muteThreshold: muteThreshold)
}

/// Decrease the volume of the default output device
/// by the given amount.
///
/// Errors will be ignored.
///
/// The values range between 0 and 1. If the decrease results
/// in a value outside of the bounds, it will be normalized to the closest
/// value in the bounds.
func decreaseVolume(by value: Float, autoMuteUnmute: Bool = false, muteThreshold: Float = 0.005) {
setVolume(volume-value, autoMuteUnmute: autoMuteUnmute, muteThreshold: muteThreshold)
}

/// Set the volume of the default output device and,
/// if lower or higher then `muteThreshold` also toggles the mute property.
///
/// - warning: This function will unmute a muted device, if the volume is greater
/// then `muteThreshold`. Please, make sure that the user is aware of this and always
/// respect the Do Not Disturb modes and other system settings.
///
/// - parameters:
/// - newValue: The volume.
/// - autoMuteUnmute: If `true`, will use the `muteThreshold` to determine whether the device
/// should also be muted or unmuted.
/// - muteThreshold: Defines the threshold that should cause an automatic mute for all values below it.
func setVolume(_ newValue: Float, autoMuteUnmute: Bool, muteThreshold: Float = 0.005) {
volume = newValue
guard autoMuteUnmute else { return }
isMuted = newValue <= muteThreshold
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// SoundOutputManager+Properties.swift
//
//
// Created by Alessio Moiso on 09.03.22.
//
import CoreAudio

public extension Sound.SoundOutputManager {
/// Get the system default output device.
///
/// You can use this value to interact with the device directly via
/// other system calls.
///
/// This value will return `nil` if there is currently no device selected in
/// System Preferences > Sound > Output.
var defaultOutputDevice: AudioDeviceID? {
try? retrieveDefaultOutputDevice()
}

/// Get or set the volume of the default output device.
///
/// Errors will be ignored. If you need to handle errors,
/// use `readVolume` and `setVolume`.
///
/// The values range between 0 and 1.
var volume: Float {
get {
(try? readVolume()) ?? 0
}
set {
do {
try setVolume(newValue)
} catch { }
}
}

/// Get or set whether the system default output device is muted or not.
///
/// Errors will be ignored. If you need to handle errors,
/// use `readMute` and `mute`. Devices that do not support muting
/// will always return `false`.
var isMuted: Bool {
get {
(try? readMute()) ?? false
}
set {
do {
try mute(newValue)
} catch { }
}
}
}
Loading

0 comments on commit 9706895

Please sign in to comment.