Skip to content

Commit 4d5b88e

Browse files
committed
sending eq type change event to ui, storing previous eq type, little refactor of Application.swift code
1 parent 9455b59 commit 4d5b88e

6 files changed

Lines changed: 73 additions & 38 deletions

File tree

native/app/Source/Application.swift

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -45,40 +45,14 @@ class Application {
4545

4646
static var dataBus: DataBus!
4747
static var updater = SUUpdater(for: Bundle.main)!
48-
static func newState (_ state: ApplicationState) {}
4948

50-
static var supportPath: URL {
51-
//Create App directory if not exists:
52-
let fileManager = FileManager()
53-
let urlPaths = fileManager.urls(for: .applicationSupportDirectory, in: .userDomainMask)
54-
55-
let appDirectory = urlPaths.first!.appendingPathComponent(Bundle.main.bundleIdentifier! ,isDirectory: true)
56-
var objCTrue: ObjCBool = true
57-
let path = appDirectory.path
58-
if !fileManager.fileExists(atPath: path, isDirectory: &objCTrue) {
59-
try! fileManager.createDirectory(atPath: path, withIntermediateDirectories: true, attributes: nil)
60-
}
61-
return appDirectory
62-
}
63-
64-
static private let dispatchActionQueue = DispatchQueue(label: "dispatchActionQueue", qos: .userInitiated)
65-
// Custom dispatch function. Need to execute all dispatches on the main thread
66-
static func dispatchAction(_ action: Action, onMainThread: Bool = true) {
67-
if (onMainThread) {
68-
DispatchQueue.main.async {
69-
store.dispatch(action)
70-
}
71-
} else {
72-
dispatchActionQueue.async {
73-
store.dispatch(action)
74-
}
75-
}
76-
}
7749
static let store: Store = Store(reducer: ApplicationStateReducer, state: Storage[.state] ?? ApplicationState(), middleware: [])
7850

7951

8052
static public func start () {
81-
setupSettings()
53+
self.settings = Settings()
54+
updater.automaticallyChecksForUpdates = true
55+
8256
Networking.startMonitor()
8357

8458
if (!Constants.DEBUG) {
@@ -100,11 +74,6 @@ class Application {
10074
}
10175
}
10276

103-
private static func setupSettings () {
104-
self.settings = Settings()
105-
updater.automaticallyChecksForUpdates = true
106-
}
107-
10877
private static func setupCrashReporting () {
10978
// Create a Sentry client and start crash handler
11079
SentrySDK.start { options in
@@ -525,5 +494,35 @@ class Application {
525494
static var version: String {
526495
return Bundle.main.infoDictionary!["CFBundleVersion"] as! String
527496
}
497+
498+
static func newState (_ state: ApplicationState) {}
499+
500+
static var supportPath: URL {
501+
//Create App directory if not exists:
502+
let fileManager = FileManager()
503+
let urlPaths = fileManager.urls(for: .applicationSupportDirectory, in: .userDomainMask)
504+
505+
let appDirectory = urlPaths.first!.appendingPathComponent(Bundle.main.bundleIdentifier! ,isDirectory: true)
506+
var objCTrue: ObjCBool = true
507+
let path = appDirectory.path
508+
if !fileManager.fileExists(atPath: path, isDirectory: &objCTrue) {
509+
try! fileManager.createDirectory(atPath: path, withIntermediateDirectories: true, attributes: nil)
510+
}
511+
return appDirectory
512+
}
513+
514+
static private let dispatchActionQueue = DispatchQueue(label: "dispatchActionQueue", qos: .userInitiated)
515+
// Custom dispatch function. Need to execute all dispatches on the main thread
516+
static func dispatchAction(_ action: Action, onMainThread: Bool = true) {
517+
if (onMainThread) {
518+
DispatchQueue.main.async {
519+
store.dispatch(action)
520+
}
521+
} else {
522+
dispatchActionQueue.async {
523+
store.dispatch(action)
524+
}
525+
}
526+
}
528527
}
529528

native/app/Source/Audio/Effects/Equalizers/Equalizers.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ let AllEqualizerTypes = [
3232

3333
class Equalizers: Effect, StoreSubscriber {
3434
// MARK: - Events
35-
var typeChanged = Event<EqualizerType>()
36-
var gainChanged = Event<Double>()
35+
static let typeChanged = Event<EqualizerType>()
3736

3837
// MARK: - Properties
3938
private var _type: EqualizerType! {
@@ -82,7 +81,7 @@ class Equalizers: Effect, StoreSubscriber {
8281
}
8382
if (_type != state.type) {
8483
_type = state.type
85-
typeChanged.emit(_type)
84+
Equalizers.typeChanged.emit(_type)
8685
}
8786
}
8887

native/app/Source/Audio/Effects/Equalizers/EqualizersDataBus.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88

99
import Foundation
1010
import SwiftyJSON
11+
import EmitterKit
1112

1213
class EqualizersDataBus: DataBus {
1314
var state: EqualizersState {
1415
return Application.store.state.effects.equalizers
1516
}
1617

18+
var typeChangedListener: EventListener<EqualizerType>?
19+
1720
required init(route: String, bridge: Bridge) {
1821
super.init(route: route, bridge: bridge)
1922

@@ -54,5 +57,9 @@ class EqualizersDataBus: DataBus {
5457

5558
self.add("/basic", BasicEqualizerDataBus.self)
5659
self.add("/advanced", AdvancedEqualizerDataBus.self)
60+
61+
typeChangedListener = Equalizers.typeChanged.on { type in
62+
self.send(to: "/type", data: [ "type": type.rawValue ])
63+
}
5764
}
5865
}

native/app/Source/Audio/Effects/Equalizers/EqualizersState.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import SwiftyUserDefaults
1313
class EqualizersState: State {
1414
var enabled = true
1515
var type: EqualizerType = .basic
16+
var previousType: EqualizerType?
1617
var basic = BasicEqualizerState()
1718
var advanced = AdvancedEqualizerState()
1819
}
@@ -26,6 +27,9 @@ func EqualizersStateReducer(action: Action, state: EqualizersState?) -> Equalize
2627
let state = state ?? EqualizersState()
2728
switch action as? EqualizersAction {
2829
case .setType(let type)?:
30+
if (type != state.type) {
31+
state.previousType = state.type
32+
}
2933
state.type = type
3034
case .setEnabled(let enabled)?:
3135
state.enabled = enabled

native/app/Source/Audio/Engine.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class Engine {
165165
}
166166

167167
private func setupListeners () {
168-
eventListeners.append(effects.equalizers.typeChanged.on { _ in
168+
eventListeners.append(Equalizers.typeChanged.on { _ in
169169
self.stop()
170170
Utilities.delay(100) {
171171
self.reattachEqualizer()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Injectable } from '@angular/core'
2+
3+
export type Context = 'EQ_TYPE_EXPERT'
4+
5+
@Injectable({
6+
providedIn: 'root'
7+
})
8+
export class ContextService {
9+
private static readonly key = 'CONTEXT'
10+
11+
static get (): Context {
12+
return window.localStorage.getItem(this.key) as Context
13+
}
14+
15+
static set (context: Context) {
16+
return window.localStorage.setItem(this.key, context)
17+
}
18+
19+
static clear () {
20+
window.localStorage.removeItem(this.key)
21+
}
22+
23+
get () { return ContextService.get() }
24+
set (context: Context) { return ContextService.set(context) }
25+
clear () { ContextService.clear() }
26+
}

0 commit comments

Comments
 (0)