Skip to content

Commit 36c0180

Browse files
committed
update 0.3.0
1 parent 3355436 commit 36c0180

16 files changed

Lines changed: 173 additions & 38 deletions

File tree

-22.3 KB
Binary file not shown.

native/app/Embedded/ui.zip

630 Bytes
Binary file not shown.

native/app/Source/Application.swift

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import SwiftyJSON
1818
import ServiceManagement
1919
import ReSwift
2020
import Sparkle
21+
import AudioKit
2122

2223
enum VolumeChangeDirection: String {
2324
case UP = "UP"
@@ -71,6 +72,14 @@ class Application {
7172

7273

7374
static public func start () {
75+
// AudioKit Engine fucks with Driver installation, eqMac doesn't use it's engine anyway
76+
try? AudioKit.stop()
77+
try? AudioKit.shutdown()
78+
AKSettings.audioInputEnabled = false
79+
AKSettings.enableRouteChangeHandling = false
80+
AKSettings.notificationsEnabled = false
81+
AudioKit.engine.stop()
82+
7483
setupSettings()
7584

7685
if (!Constants.DEBUG) {
@@ -117,7 +126,7 @@ class Application {
117126
) { install in
118127
if install {
119128
Driver.install(started: {
120-
UI.showLoadingWindow("Installing eqMac audio driver")
129+
UI.showLoadingWindow("Installing eqMac audio driver\nIf this process takes too long, please restart your Mac")
121130
}) { success in
122131
if (success) {
123132
UI.hideLoadingWindow()
@@ -131,16 +140,16 @@ class Application {
131140
quit()
132141
}
133142
}
134-
} else if (Driver.isOutdated) {
143+
} else if (Driver.isOutdated && Driver.skipCurrentVersion) {
135144
Alert.confirm(
136145
title: "Audio Driver Update",
137146
message: "There is an optional Audio Driver update that should improve user experience. \nIn order to update eqMac will ask for your System Password. \nPlease close any apps playing audio (Spotify, YouTube etc.) otherwise installation might fail.",
138147
okText: "Update Driver",
139-
cancelText: "Skip update"
148+
cancelText: "Skip Driver update"
140149
) { update in
141150
if update {
142151
Driver.install(started: {
143-
UI.showLoadingWindow("Updating eqMac audio driver")
152+
UI.showLoadingWindow("Updating eqMac audio driver\nIf this process takes too long, please restart your Mac")
144153
}) { success in
145154
if (success) {
146155
UI.hideLoadingWindow()
@@ -150,6 +159,7 @@ class Application {
150159
}
151160
}
152161
} else {
162+
Driver.skipCurrentVersion = true
153163
completion()
154164
}
155165
}
@@ -161,7 +171,7 @@ class Application {
161171
private static func driverFailedToInstallPrompt () {
162172
UI.hideLoadingWindow()
163173
Alert.confirm(
164-
title: "Driver failed to install", message: "Unfortunately the audio driver has failed to install. You can restart eqMac and try again or quit.", okText: "Try again", cancelText: "Quit") { restart in
174+
title: "Driver failed to install", message: "Unfortunately the audio driver has failed to install. You can restart eqMac and try again or quit. Alternatively, please try to restart your Mac and running eqMac again.", okText: "Try again", cancelText: "Quit") { restart in
165175
if restart {
166176
return self.restart()
167177
} else {
@@ -258,7 +268,7 @@ class Application {
258268
try! AudioDeviceEvents.recreateEventEmitters([.isAliveChanged, .volumeChanged, .nominalSampleRateChanged])
259269
self.setupDriverDeviceEvents()
260270
Utilities.delay(500) {
261-
createAudioPipeline()
271+
createAudioPipeline()
262272
}
263273
}
264274
}
@@ -288,12 +298,12 @@ class Application {
288298
return
289299
}
290300
let gain = Double(Driver.device!.virtualMasterVolume(direction: .playback)!)
291-
Console.log(gain)
292301
if (gain <= 1 && gain != Application.store.state.effects.volume.gain) {
293302
Application.dispatchAction(VolumeAction.setGain(gain, false))
294303
}
304+
295305
}
296-
306+
297307
AudioDeviceEvents.on(.muteChanged, onDevice: Driver.device!) {
298308
if (ignoreNextDriverMuteEvent) {
299309
ignoreNextDriverMuteEvent = false
@@ -513,29 +523,30 @@ class Application {
513523
updater.checkForUpdates(nil)
514524
}
515525

516-
static func reinstallDriver (_ completion: @escaping () -> Void) {
526+
static func reinstallDriver (_ completion: @escaping (Bool) -> Void) {
517527
Alert.confirm(
518528
title: "Audio Driver Reinstall",
519-
message: "\nIn order to reinstall the driver eqMac we will ask for your System Password. \nPlease close any apps playing audio (Spotify, YouTube etc.) otherwise installation might fail.",
529+
message: "\nIn order to reinstall the driver eqMac we will ask for your System Password. \nPlease close any apps playing audio (Spotify, YouTube etc.) otherwise installation might fail. eqMac will restart after this.",
520530
cancelText: "Cancel"
521531
) { reinstall in
522532
if reinstall {
523533
Driver.install(started: {
524-
UI.showLoadingWindow("Installing eqMac audio driver")
525534
self.stopListeners()
526535
self.stopEngines()
527536
self.switchBackToLastKnownDevice()
537+
UI.close()
538+
Utilities.delay(100) { UI.showLoadingWindow("Reinstalling eqMac driver\nIf this process takes too long, please restart your Mac") }
528539
}) { success in
529540
if (success) {
530541
UI.hideLoadingWindow()
531-
setupAudio()
532-
completion()
542+
completion(true)
543+
Application.restart()
533544
} else {
534545
driverFailedToInstallPrompt()
535546
}
536547
}
537548
} else {
538-
completion()
549+
completion(false)
539550
}
540551
}
541552

@@ -546,8 +557,8 @@ class Application {
546557
self.stopListeners()
547558
self.stopEngines()
548559
self.switchBackToLastKnownDevice()
549-
UI.hide()
550-
Utilities.delay(100) { UI.showLoadingWindow("Uninstalling eqMac") }
560+
UI.close()
561+
Utilities.delay(100) { UI.showLoadingWindow("Uninstalling eqMac\nIf this process takes too long, please restart your Mac") }
551562
}) { success in
552563
completion(success)
553564
if (success) {

native/app/Source/ApplicationDataBus.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class ApplicationDataBus: DataBus {
2323
return [
2424
"name": host.localizedName as AnyObject,
2525
"model": Sysctl.model as String,
26-
"version": Bundle.main.infoDictionary?["CFBundleVersion"] as Any
26+
"version": Bundle.main.infoDictionary?["CFBundleVersion"] as Any,
27+
"driverVersion": Driver.lastInstalledVersion
2728
]
2829
}
2930

@@ -59,6 +60,17 @@ class ApplicationDataBus: DataBus {
5960
return nil
6061
}
6162

63+
self.on(.GET, "/driver/reinstall/available") { _, res in
64+
return "Yes"
65+
}
66+
67+
self.on(.GET, "/driver/reinstall") { _, res in
68+
Application.reinstallDriver { success in
69+
res.send([ "reinstalled": success ])
70+
}
71+
return nil
72+
}
73+
6274
self.on(.GET, "/update") { _, _ in
6375
Application.checkForUpdates()
6476
return "Checking for updates."

native/app/Source/Audio/AudioDeviceEvents.swift

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ enum AudioDeviceEventType {
3636

3737
class AudioDeviceEvents: EventSubscriber {
3838
static var events = AudioDeviceEvents()
39+
static var listeners: [EmitterKit.EventListener<AudioDevice>] = [] as! [EmitterKit.EventListener<AudioDevice>]
3940

4041
var hashValue: Int = 1
41-
static var listeners: [EmitterKit.EventListener<AudioDevice>] = [] as! [EmitterKit.EventListener<AudioDevice>]
42-
42+
var subscribed = false
4343
// Per Device
4444
let isJackConnectedChangedEvent = EmitterKit.Event<AudioDevice>()
4545
let isRunningSomewhereChangedEvent = EmitterKit.Event<AudioDevice>()
@@ -63,17 +63,34 @@ class AudioDeviceEvents: EventSubscriber {
6363
let inputChangedEvent = EmitterKit.Event<AudioDevice>()
6464
let systemDeviceChangedEvent = EmitterKit.Event<AudioDevice>()
6565

66-
init () {
67-
NotificationCenter.defaultCenter.subscribe(
68-
self,
69-
eventType: AudioHardwareEvent.self,
70-
dispatchQueue: DispatchQueue.main
71-
)
72-
NotificationCenter.defaultCenter.subscribe(
73-
self,
74-
eventType: AudioDeviceEvent.self,
75-
dispatchQueue: DispatchQueue.main
76-
)
66+
func subscribe () {
67+
if !subscribed {
68+
NotificationCenter.defaultCenter.subscribe(
69+
self,
70+
eventType: AudioHardwareEvent.self,
71+
dispatchQueue: DispatchQueue.main
72+
)
73+
NotificationCenter.defaultCenter.subscribe(
74+
self,
75+
eventType: AudioDeviceEvent.self,
76+
dispatchQueue: DispatchQueue.main
77+
)
78+
subscribed = true
79+
}
80+
}
81+
82+
func unsubscribe () {
83+
NotificationCenter.defaultCenter.unsubscribe(self, eventType: AudioHardwareEvent.self)
84+
NotificationCenter.defaultCenter.unsubscribe(self, eventType: AudioDeviceEvent.self)
85+
subscribed = false
86+
}
87+
88+
static func subscribe () {
89+
events.subscribe()
90+
}
91+
92+
static func unsubscribe () {
93+
events.unsubscribe()
7794
}
7895

7996
internal func eventReceiver(_ event: AMCoreAudio.Event) {
@@ -102,6 +119,7 @@ class AudioDeviceEvents: EventSubscriber {
102119
}
103120

104121
static func recreateEventEmitters(_ eventsToRecreate: [AudioDeviceEventType]) throws {
122+
subscribe()
105123
for event in eventsToRecreate {
106124
switch event {
107125
case .isAliveChanged:
@@ -184,6 +202,7 @@ class AudioDeviceEvents: EventSubscriber {
184202

185203
@discardableResult
186204
static func on (_ event: AudioDeviceEventType, retain: Bool = true, _ handler: @escaping (AudioDevice) -> Void) -> EmitterKit.EventListener<AudioDevice> {
205+
events.subscribe()
187206
let emitter = getEventEmitterFromEventType(event)
188207
let listener: EmitterKit.EventListener<AudioDevice> = emitter.on(handler)
189208
if (retain) {
@@ -199,6 +218,7 @@ class AudioDeviceEvents: EventSubscriber {
199218

200219
@discardableResult
201220
static func once (_ event: AudioDeviceEventType, _ handler: @escaping (AudioDevice) -> Void) -> EmitterKit.EventListener<AudioDevice> {
221+
events.subscribe()
202222
let emitter = getEventEmitterFromEventType(event)
203223
let listener: EmitterKit.EventListener<AudioDevice> = emitter.once(handler: handler)
204224
return listener
@@ -223,12 +243,14 @@ class AudioDeviceEvents: EventSubscriber {
223243
}
224244

225245
static func start () {
246+
subscribe()
226247
for listener in listeners {
227248
listener.isListening = true
228249
}
229250
}
230251

231252
static func stop () {
253+
unsubscribe()
232254
for listener in listeners {
233255
listener.isListening = false
234256
}

native/app/Source/Audio/Sources/System/Driver.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,24 @@ class Driver {
6464
return info["CFBundleVersion"] as! String
6565
}
6666

67+
static var lastSkippedDriverVersion: String? {
68+
get {
69+
return Storage[.lastSkippedDriverVersion]
70+
}
71+
set {
72+
Storage[.lastSkippedDriverVersion] = newValue
73+
}
74+
}
75+
76+
static var skipCurrentVersion: Bool {
77+
get {
78+
return lastSkippedDriverVersion == bundledVersion
79+
}
80+
set {
81+
lastSkippedDriverVersion = newValue ? bundledVersion : nil
82+
}
83+
}
84+
6785
static var isOutdated: Bool {
6886
get {
6987
return bundledVersion != lastInstalledVersion

native/app/Source/Helpers/Storage.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ extension DefaultsKeys {
2727
// Effects - Equalizer - Advanced
2828
static let advancedEqualizerPresets = DefaultsKey<[AdvancedEqualizerPreset]?>("advancedEqualizerPresets")
2929
static let lastInstalledDriverVersion = DefaultsKey<String?>("lastInstalledDriverVersion")
30+
static let lastSkippedDriverVersion = DefaultsKey<String?>("lastSkippedDriverVersion")
3031
}
3132

3233
let Storage = Defaults

native/app/Source/UI/UI.swift

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ class UI: StoreSubscriber {
219219
load()
220220
}
221221

222+
static func reload () {
223+
viewController.webView.reload()
224+
}
225+
222226
func setupBridge () {
223227
bridge = Bridge(webView: UI.viewController.webView)
224228
}
@@ -251,7 +255,7 @@ class UI: StoreSubscriber {
251255
}
252256

253257
private func load () {
254-
Networking.isReachable(UI.domain) { reachable in
258+
remoteIsReachable() { reachable in
255259
if reachable {
256260
Console.log("Loading Remote UI")
257261
UI.viewController.load(Constants.UI_ENDPOINT_URL)
@@ -263,7 +267,33 @@ class UI: StoreSubscriber {
263267
UI.viewController.load(url)
264268
}
265269
}
270+
}
271+
272+
private func remoteIsReachable (_ completion: @escaping (Bool) -> Void) {
273+
var returned = false
274+
AF.request(Constants.UI_ENDPOINT_URL)
275+
.responseData { response in
276+
switch response.result {
277+
case .success:
278+
if !returned {
279+
returned = true
280+
completion(true)
281+
}
282+
case .failure:
283+
Console.log("Failed to load \(Constants.UI_ENDPOINT_URL)", response)
284+
if !returned {
285+
returned = true
286+
completion(false)
287+
}
288+
}
289+
}
266290

291+
Utilities.delay(1000) {
292+
if (!returned) {
293+
returned = true
294+
completion(false)
295+
}
296+
}
267297
}
268298

269299
private func cacheRemote () {

native/app/Source/UI/Window.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import Cocoa
1212
class Window: NSWindow, NSWindowDelegate {
1313
override init(contentRect: NSRect, styleMask style: NSWindow.StyleMask, backing backingStoreType: NSWindow.BackingStoreType, defer flag: Bool) {
1414
super.init(contentRect: contentRect, styleMask: style, backing: backingStoreType, defer: flag)
15+
1516
self.isOneShot = false
16-
1717
self.titleVisibility = .hidden
1818
self.titlebarAppearsTransparent = true
1919
self.isMovableByWindowBackground = true

native/app/Supporting Files/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
<false/>
3333
<key>NSAllowsArbitraryLoadsInWebContent</key>
3434
<true/>
35+
<key>NSAllowsLocalNetworking</key>
36+
<true/>
3537
<key>NSExceptionDomains</key>
3638
<dict/>
3739
</dict>

0 commit comments

Comments
 (0)