Skip to content

Commit

Permalink
remove applescript based detection
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentneo committed Mar 28, 2023
1 parent 3aaa850 commit a95d968
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 39 deletions.
10 changes: 0 additions & 10 deletions Quality/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
let showSampleRateItem = NSMenuItem(title: defaults.statusBarItemTitle, action: #selector(toggleSampleRate(item:)), keyEquivalent: "")
menu.addItem(showSampleRateItem)

let useAppleScriptItem = NSMenuItem(title: "Detect Local Track Rates", action: #selector(toggleAppleScript(item:)), keyEquivalent: "")
menu.addItem(useAppleScriptItem)
useAppleScriptItem.state = Defaults.shared.userPreferAppleScript ? .on : .off

let selectedDeviceItem = NSMenuItem(title: "Selected Device", action: nil, keyEquivalent: "")
self.devicesMenu = NSMenu()
selectedDeviceItem.submenu = self.devicesMenu
Expand Down Expand Up @@ -168,10 +164,4 @@ class AppDelegate: NSObject, NSApplicationDelegate {
item.title = defaults.statusBarItemTitle
}

@objc func toggleAppleScript(item: NSMenuItem) {
defaults.userPreferAppleScript = !defaults.userPreferAppleScript
outputDevices.enableAppleScript = defaults.userPreferAppleScript
item.state = defaults.userPreferAppleScript ? .on : .off
}

}
15 changes: 2 additions & 13 deletions Quality/Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ import Foundation
class Defaults {
static let shared = Defaults()
private let kUserPreferIconStatusBarItem = "com.vincent-neo.LosslessSwitcher-Key-UserPreferIconStatusBarItem"
private let kUserPreferAppleScript = "com.vincent-neo.LosslessSwitcher-Key-UserPreferAppleScript"
private let kSelectedDeviceUID = "com.vincent-neo.LosslessSwitcher-Key-SelectedDeviceUID"

private init() {
UserDefaults.standard.register(defaults: [
kUserPreferIconStatusBarItem : true,
kUserPreferAppleScript : true
kUserPreferIconStatusBarItem : true
])
}

Expand All @@ -29,15 +27,6 @@ class Defaults {
}
}

var userPreferAppleScript: Bool {
get {
return UserDefaults.standard.bool(forKey: kUserPreferAppleScript)
}
set {
UserDefaults.standard.set(newValue, forKey: kUserPreferAppleScript)
}
}

var selectedDeviceUID: String? {
get {
return UserDefaults.standard.string(forKey: kSelectedDeviceUID)
Expand All @@ -46,7 +35,7 @@ class Defaults {
UserDefaults.standard.set(newValue, forKey: kSelectedDeviceUID)
}
}

var statusBarItemTitle: String {
let title = self.userPreferIconStatusBarItem ? "Show Sample Rate" : "Show Icon"
return title
Expand Down
22 changes: 6 additions & 16 deletions Quality/OutputDevices.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ class OutputDevices: ObservableObject {
@Published var outputDevices = [AudioDevice]()
@Published var currentSampleRate: Float64?

var enableAppleScript = Defaults.shared.userPreferAppleScript

private let coreAudio = SimplyCoreAudio()

private var changesCancellable: AnyCancellable?
Expand Down Expand Up @@ -147,20 +145,12 @@ class OutputDevices: ObservableObject {
var allStats = [CMPlayerStats]()

do {
if enableAppleScript {
if let appleScriptRate = getSampleRateFromAppleScript() {
print("AppleScript ran")
allStats.append(CMPlayerStats(sampleRate: appleScriptRate, bitDepth: 0, date: .init(), priority: 100))
}
}
else {
let musicLogs = try Console.getRecentEntries(type: .music)
let coreAudioLogs = try Console.getRecentEntries(type: .coreAudio)
//let coreMediaLogs = try Console.getRecentEntries(type: .coreMedia)
allStats.append(contentsOf: CMPlayerParser.parseMusicConsoleLogs(musicLogs))
allStats.append(contentsOf: CMPlayerParser.parseCoreAudioConsoleLogs(coreAudioLogs))
//allStats.append(contentsOf: CMPlayerParser.parseCoreMediaConsoleLogs(coreMediaLogs))
}
let musicLogs = try Console.getRecentEntries(type: .music)
let coreAudioLogs = try Console.getRecentEntries(type: .coreAudio)
let coreMediaLogs = try Console.getRecentEntries(type: .coreMedia)
allStats.append(contentsOf: CMPlayerParser.parseMusicConsoleLogs(musicLogs))
//allStats.append(contentsOf: CMPlayerParser.parseCoreAudioConsoleLogs(coreAudioLogs))
allStats.append(contentsOf: CMPlayerParser.parseCoreMediaConsoleLogs(coreMediaLogs))

allStats.sort(by: {$0.priority > $1.priority})
print("[getAllStats] \(allStats)")
Expand Down

0 comments on commit a95d968

Please sign in to comment.