Skip to content

Commit b1f9f70

Browse files
committed
improvements to sleep handling
1 parent a6a1344 commit b1f9f70

8 files changed

Lines changed: 67 additions & 40 deletions

File tree

native/app/Source/AppDelegate.swift

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,19 @@ class AppDelegate: NSObject, NSApplicationDelegate, SUUpdaterDelegate {
3030
Application.start()
3131
}
3232

33-
Networking.checkConnected { connected in
34-
if (connected) {
35-
self.updater.checkForUpdatesInBackground()
36-
} else {
33+
if (Application.store.state.settings.doAutoCheckUpdates) {
34+
Networking.checkConnected { connected in
35+
if (connected) {
36+
self.updater.checkForUpdatesInBackground()
37+
} else {
38+
self.updateProcessed.emit()
39+
}
40+
}
41+
42+
Utilities.delay(2000) {
3743
self.updateProcessed.emit()
3844
}
39-
}
40-
Utilities.delay(2000) {
45+
} else {
4146
self.updateProcessed.emit()
4247
}
4348

@@ -106,11 +111,11 @@ class AppDelegate: NSObject, NSApplicationDelegate, SUUpdaterDelegate {
106111
}
107112

108113
@objc func willSleep(event: NSNotification) {
109-
Application.stopSave()
114+
Application.handleSleep()
110115
}
111116

112117
@objc func didWakeUp(event: NSNotification) {
113-
Application.restart()
118+
Application.handleWakeUp()
114119
}
115120
}
116121

native/app/Source/Application.swift

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ class Application {
5757
}
5858

5959
self.settings = Settings()
60-
60+
6161
Networking.startMonitor()
6262

6363
checkDriver {
6464
Sources.getInputPermission {
6565
AudioDevice.register = true
6666
audioPipelineIsRunningListener = audioPipelineIsRunning.once {
6767
self.setupUI {
68-
if (User.isFirstLaunch || Constants.DEBUG) {
68+
if (User.isFirstLaunch) {
6969
UI.show()
7070
} else {
7171
UI.close()
@@ -81,7 +81,6 @@ class Application {
8181
// Create a Sentry client and start crash handler
8282
SentrySDK.start { options in
8383
options.dsn = Constants.SENTRY_ENDPOINT
84-
options.sampleRate = 0.1
8584

8685
// Only send crash reports if user gave consent
8786
options.beforeSend = { event in
@@ -303,18 +302,6 @@ class Application {
303302
output = Output(device: selectedDevice!)
304303
outputCreated.emit()
305304

306-
selectedDeviceIsAliveListener = AudioDeviceEvents.on(
307-
.isAliveChanged,
308-
onDevice: selectedDevice!,
309-
retain: false
310-
) {
311-
// If device that we are sending audio to goes offline we need to stop and switch to a different device
312-
if (selectedDevice!.isAlive() == false) {
313-
Console.log("Current device dies so switching to built it")
314-
selectOutput(device: AudioDevice.builtInOutputDevice) // TODO: Replace with a known device from stack
315-
}
316-
}
317-
318305
selectedDeviceSampleRateChangedListener = AudioDeviceEvents.on(
319306
.nominalSampleRateChanged,
320307
onDevice: selectedDevice!,
@@ -448,6 +435,20 @@ class Application {
448435
stopRemoveEngines()
449436
Storage.synchronize()
450437
}
438+
439+
static func handleSleep () {
440+
stopSave()
441+
}
442+
443+
static func handleWakeUp () {
444+
Utilities.delay(1000) {
445+
if (AudioDevice.allOutputDevices().contains(where: { $0.id == selectedDevice?.id })) {
446+
startPassthrough()
447+
} else {
448+
restart()
449+
}
450+
}
451+
}
451452

452453
static func quit () {
453454
stopSave()
@@ -514,7 +515,7 @@ class Application {
514515
}
515516

516517
static private let dispatchActionQueue = DispatchQueue(label: "dispatchActionQueue", qos: .userInitiated)
517-
// Custom dispatch function. Need to execute all dispatches on the main thread
518+
// Custom dispatch function. Need to execute some dispatches on the main thread
518519
static func dispatchAction(_ action: Action, onMainThread: Bool = true) {
519520
if (onMainThread) {
520521
DispatchQueue.main.async {

native/app/Source/Audio/Outputs/Outputs.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class Outputs {
2828

2929
static func shouldAutoSelect (_ device: AudioDevice) -> Bool {
3030
let types: [TransportType] = [.bluetooth, .bluetoothLE, .builtIn]
31+
Console.log(device.nominalSampleRate(), device.sourceName, device.actualSampleRate(), device.isOutputOnlyDevice())
3132
return isDeviceAllowed(device) && types.contains(device.transportType!)
3233
}
3334

native/app/Source/UI/UI.swift

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,16 @@ class UI: StoreSubscriber {
267267
}
268268

269269
func newState(state: UIState) {
270-
if (state.height != UI.height) {
271-
UI.height = state.height
272-
}
273-
if (state.width != UI.width) {
274-
UI.width = state.width
275-
}
276-
if (state.mode != UI.mode) {
277-
UI.mode = state.mode
270+
DispatchQueue.main.async {
271+
if (state.height != UI.height) {
272+
UI.height = state.height
273+
}
274+
if (state.width != UI.width) {
275+
UI.width = state.width
276+
}
277+
if (state.mode != UI.mode) {
278+
UI.mode = state.mode
279+
}
278280
}
279281
}
280282

native/app/Source/UI/UIDataBus.swift

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ class UIDataBus: DataBus {
3131
return "Hidden"
3232
}
3333

34-
self.on(.GET, "/height") { _, _ in
35-
return [ "height": self.state.height ]
34+
self.on(.GET, "/height") { _, res in
35+
DispatchQueue.main.async {
36+
res.send([ "height": self.state.height ])
37+
}
38+
return nil
3639
}
3740

3841
self.on(.POST, "/height") { data, _ in
@@ -44,8 +47,11 @@ class UIDataBus: DataBus {
4447
return "UI Height has been set"
4548
}
4649

47-
self.on(.GET, "/width") { data, _ in
48-
return [ "width": self.state.width ]
50+
self.on(.GET, "/width") { _, res in
51+
DispatchQueue.main.async {
52+
res.send([ "width": self.state.width ])
53+
}
54+
return nil
4955
}
5056

5157
self.on(.POST, "/width") { data, _ in
@@ -86,8 +92,11 @@ class UIDataBus: DataBus {
8692
throw "Please provide a valid 'uiMode' parameter."
8793
}
8894

89-
self.on(.GET, "/shown") { data, _ in
90-
return JSON([ "isShown": UI.isShown ])
95+
self.on(.GET, "/shown") { data, res in
96+
DispatchQueue.main.async {
97+
res.send([ "isShown": UI.isShown ])
98+
}
99+
return nil
91100
}
92101

93102
self.on(.POST, "/loaded") { _, _ in

ui/src/app/sections/outputs/outputs.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export class OutputsComponent implements OnInit {
3232
case 'builtIn': return output.name === 'Headphones' ? 'headphones' : 'speaker'
3333
case 'displayPort': return 'displayport'
3434
case 'fireWire': return 'firewire'
35+
case 'virtual': return 'cog'
3536
default: return output.transportType
3637
}
3738
})()

ui/src/app/sections/outputs/outputs.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export type DeviceTransportType =
1313
'pci' |
1414
'thunderbolt' |
1515
'usb' |
16-
'aggregate'
16+
'aggregate' |
17+
'virtual'
1718

1819
export interface Output {
1920
id: number

ui/src/app/sections/settings/settings.component.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,14 @@ and make it a more stable product.
121121
otaUpdatesOption: CheckboxOption = {
122122
type: 'checkbox',
123123
value: false,
124-
label: 'OTA User Interface Updates',
124+
label: 'OTA Updates',
125+
tooltip: `
126+
Because eqMac's User Interface is built with Web Technologies
127+
the developer can periodically push Over the Air (OTA) updates,
128+
make minor bug fixes and UI improvements,
129+
all without needing the user to do a full app update.
130+
`,
131+
tooltipAsComponent: true,
125132
toggled: doOTAUpdates => {
126133
this.settingsService.setDoOTAUpdates({
127134
doOTAUpdates

0 commit comments

Comments
 (0)