From ac3368842c4fac660f7ada2bc5fb7188ebddfe9a Mon Sep 17 00:00:00 2001 From: Vincent Neo <23420208+vincentneo@users.noreply.github.com> Date: Wed, 16 Nov 2022 23:53:41 +0800 Subject: [PATCH] build 9, attempt to fix #32 Test implementation. Explicitly select the device that you want to playback (not the auto "default device" selection). Check if device will continue to stick to your selected device, even in circumstances such as EQ / virtual device. App device selection menu may glitch out showing 2 checkmarks on app restart, but that is expected, cosmetic behaviour. --- Quality.xcodeproj/project.pbxproj | 4 ++-- Quality/AppDelegate.swift | 9 ++++++++- Quality/Defaults.swift | 10 ++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Quality.xcodeproj/project.pbxproj b/Quality.xcodeproj/project.pbxproj index ff1e64d..78c5f3a 100644 --- a/Quality.xcodeproj/project.pbxproj +++ b/Quality.xcodeproj/project.pbxproj @@ -338,7 +338,7 @@ CODE_SIGN_ENTITLEMENTS = Quality/Quality.entitlements; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 8; + CURRENT_PROJECT_VERSION = 9; DEVELOPMENT_ASSET_PATHS = "\"Quality/Preview Content\""; DEVELOPMENT_TEAM = 3X69W4AQD6; ENABLE_HARDENED_RUNTIME = YES; @@ -372,7 +372,7 @@ CODE_SIGN_ENTITLEMENTS = Quality/Quality.entitlements; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 8; + CURRENT_PROJECT_VERSION = 9; DEVELOPMENT_ASSET_PATHS = "\"Quality/Preview Content\""; DEVELOPMENT_TEAM = 3X69W4AQD6; ENABLE_HARDENED_RUNTIME = YES; diff --git a/Quality/AppDelegate.swift b/Quality/AppDelegate.swift index 2dfab1f..a2b9848 100644 --- a/Quality/AppDelegate.swift +++ b/Quality/AppDelegate.swift @@ -116,10 +116,16 @@ class AppDelegate: NSObject, NSApplicationDelegate { var idx = 0 for device in outputDevices.outputDevices { + let uid = device.uid let name = device.name let item = DeviceMenuItem(title: name, action: #selector(deviceSelection(_:)), keyEquivalent: "", device: device) item.tag = idx - item.state = .off + if let uid, uid == Defaults.shared.selectedDeviceUID { + item.state = .on + } + else { + item.state = .off + } idx += 1 self.devicesMenu.addItem(item) } @@ -129,6 +135,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { self.devicesMenu.items.forEach({$0.state = .off}) sender.state = .on outputDevices.selectedOutputDevice = sender.device + Defaults.shared.selectedDeviceUID = sender.device?.uid } func statusItemDisplay() { diff --git a/Quality/Defaults.swift b/Quality/Defaults.swift index d7a8817..c146a2b 100644 --- a/Quality/Defaults.swift +++ b/Quality/Defaults.swift @@ -10,6 +10,7 @@ import Foundation class Defaults { static let shared = Defaults() private let kUserPreferIconStatusBarItem = "com.vincent-neo.LosslessSwitcher-Key-UserPreferIconStatusBarItem" + private let kSelectedDeviceUID = "com.vincent-neo.LosslessSwitcher-Key-SelectedDeviceUID" private init() { UserDefaults.standard.register(defaults: [kUserPreferIconStatusBarItem : true]) @@ -24,6 +25,15 @@ class Defaults { } } + var selectedDeviceUID: String? { + get { + return UserDefaults.standard.string(forKey: kSelectedDeviceUID) + } + set { + UserDefaults.standard.set(newValue, forKey: kSelectedDeviceUID) + } + } + var statusBarItemTitle: String { let title = self.userPreferIconStatusBarItem ? "Show Sample Rate" : "Show Icon" return title