mirror of
https://github.com/bitgapp/eqMac.git
synced 2024-12-02 10:24:09 +03:00
showing alerts only on main thread
This commit is contained in:
parent
82d67d73e1
commit
aa39a09a51
@ -109,24 +109,26 @@ class Application {
|
||||
|
||||
private static func installDriver (_ completion: @escaping() -> Void) {
|
||||
if !Driver.isInstalled || Driver.isOutdated {
|
||||
if Alert.confirm(
|
||||
title: "Audio Driver Installation",
|
||||
message: "eqMac needs to install an Audio Driver. \nIn order to do that we will ask for your System Password. \nPlease close any apps playing audio (Spotify, YouTube etc.) otherwise installation might fail.",
|
||||
cancelText: "Quit eqMac"
|
||||
) {
|
||||
Driver.install(started: {
|
||||
UI.showLoadingWindow("Installing eqMac audio driver")
|
||||
}) { success in
|
||||
if (success) {
|
||||
UI.hideLoadingWindow()
|
||||
completion()
|
||||
} else {
|
||||
driverFailedToInstallPrompt()
|
||||
Alert.confirm(
|
||||
title: "Audio Driver Installation",
|
||||
message: "eqMac needs to install an Audio Driver. \nIn order to do that we will ask for your System Password. \nPlease close any apps playing audio (Spotify, YouTube etc.) otherwise installation might fail.",
|
||||
cancelText: "Quit eqMac"
|
||||
) { install in
|
||||
if install {
|
||||
Driver.install(started: {
|
||||
UI.showLoadingWindow("Installing eqMac audio driver")
|
||||
}) { success in
|
||||
if (success) {
|
||||
UI.hideLoadingWindow()
|
||||
completion()
|
||||
} else {
|
||||
driverFailedToInstallPrompt()
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
quit()
|
||||
}
|
||||
|
||||
} else {
|
||||
quit()
|
||||
}
|
||||
} else {
|
||||
completion()
|
||||
@ -135,11 +137,13 @@ class Application {
|
||||
|
||||
private static func driverFailedToInstallPrompt () {
|
||||
UI.hideLoadingWindow()
|
||||
if Alert.confirm(
|
||||
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") {
|
||||
return restart()
|
||||
} else {
|
||||
return quit()
|
||||
Alert.confirm(
|
||||
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
|
||||
if restart {
|
||||
return self.restart()
|
||||
} else {
|
||||
return self.quit()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -186,11 +190,13 @@ class Application {
|
||||
}
|
||||
|
||||
private static func passthroughDeviceFailedToActivatePrompt () {
|
||||
if Alert.confirm(
|
||||
title: "Driver failed to activate", message: "Unfortunately the audio driver has failed to active. You can restart eqMac and try again or quit.", okText: "Try again", cancelText: "Quit") {
|
||||
return restart()
|
||||
} else {
|
||||
return quit()
|
||||
Alert.confirm(
|
||||
title: "Driver failed to activate", message: "Unfortunately the audio driver has failed to active. You can restart eqMac and try again or quit.", okText: "Try again", cancelText: "Quit") { restart in
|
||||
if restart {
|
||||
return self.restart()
|
||||
} else {
|
||||
return self.quit()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ public enum SourceType : String {
|
||||
]
|
||||
}
|
||||
|
||||
class Sources {
|
||||
class Sources: NSObject {
|
||||
// typealias StoreSubscriberStateType = SourceState
|
||||
var source: SourceType! = .System {
|
||||
didSet {
|
||||
@ -30,12 +30,13 @@ class Sources {
|
||||
}
|
||||
let sourceChanged = Event<SourceType>()
|
||||
var isReady = EmitterKit.Event<Void>()
|
||||
|
||||
|
||||
// var file: File!
|
||||
// var input: Input!
|
||||
var system: SystemAudioSource!
|
||||
|
||||
init (_ callback: @escaping (Sources) -> Void) {
|
||||
super.init()
|
||||
Console.log("Creating Sources")
|
||||
// source = state.source
|
||||
setup(callback)
|
||||
@ -69,34 +70,43 @@ class Sources {
|
||||
func getInputPermission (_ callback: @escaping () -> Void) {
|
||||
if !InputSource.hasPermission {
|
||||
let title = "Microphone Usage Permission"
|
||||
if Alert.confirm(
|
||||
Alert.confirm(
|
||||
title: title,
|
||||
message: "eqMac needs access to Microphone to Route and Process System Audio. \nPlease click the \"Proceed\" button and allow access.",
|
||||
okText: "Proceed",
|
||||
cancelText: "No, quit eqMac")
|
||||
{
|
||||
InputSource.requestPermission() { allowed in
|
||||
if !InputSource.hasPermission {
|
||||
Script.apple("open_privacy_microphone_settings")
|
||||
if Alert.confirm(
|
||||
title: title,
|
||||
message: "You have not allowed access to your Microphone. \neqMac needs access to Microphone to Route and Process System Audio. \nWe will try to open your Security & Privacy settings. \n\n If it didn't open please follow these steps, otherwise skip to step 5: \n\n1. Open your \"System Preferences.app\" \n2. Click on \"Security & Privacy\" \n3. Click on \"Privacy\" tab \n4. Scroll down to \"Microphone\" \n5. Check the box against \"eqMac.app\" \n\nAfter that we will need to restart the Application",
|
||||
okText: "Ok I did that. Restart eqMac",
|
||||
cancelText: "No, quit eqMac")
|
||||
{
|
||||
Application.restart()
|
||||
} else {
|
||||
Application.quit()
|
||||
cancelText: "No, quit eqMac") { proceed in
|
||||
if proceed {
|
||||
InputSource.requestPermission() { allowed in
|
||||
if !InputSource.hasPermission {
|
||||
Script.apple("open_privacy_microphone_settings")
|
||||
Utilities.delay(1000) {
|
||||
|
||||
Alert.confirm(
|
||||
title: "Microphone Usage Permission",
|
||||
message: "You have not allowed access to your Microphone. \neqMac needs access to Microphone to Route and Process System Audio. \neqMac will try to open your Security & Privacy settings. \n\n If it didn't open please follow these steps, otherwise skip to step 5: \n\n1. Open your \"System Preferences.app\" \n2. Click on \"Security & Privacy\" \n3. Click on \"Privacy\" tab \n4. Scroll down to \"Microphone\" section \n5. Check the box against \"eqMac.app\" \n\nAfter that we will need to restart the Application",
|
||||
okText: "Ok I did that. Restart eqMac",
|
||||
cancelText: "No, quit eqMac") { restart in
|
||||
if restart {
|
||||
Application.restart()
|
||||
} else {
|
||||
Application.quit()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
Application.quit()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Application.quit()
|
||||
}
|
||||
return
|
||||
}
|
||||
callback()
|
||||
}
|
||||
|
||||
|
||||
|
||||
func reset () {
|
||||
system = nil
|
||||
}
|
||||
|
@ -10,37 +10,57 @@ import Foundation
|
||||
import AppKit
|
||||
|
||||
class Alert {
|
||||
static func info (title: String, message: String) {
|
||||
let alert = getAlert(title, message)
|
||||
alert.addButton(withTitle: "Ok")
|
||||
alert.runModal()
|
||||
static func info (title: String, message: String) {
|
||||
DispatchQueue.main.async {
|
||||
let alert = getAlert(title, message)
|
||||
alert.addButton(withTitle: "Ok")
|
||||
alert.runModal()
|
||||
}
|
||||
}
|
||||
|
||||
static func confirm (
|
||||
title: String,
|
||||
message: String,
|
||||
okText: String = "Ok",
|
||||
cancelText: String = "Cancel",
|
||||
callback: @escaping (Bool) -> Void
|
||||
) {
|
||||
DispatchQueue.main.async {
|
||||
let alert = getAlert(title, message)
|
||||
alert.addButton(withTitle: okText)
|
||||
alert.addButton(withTitle: cancelText)
|
||||
let result = alert.runModal() == .alertFirstButtonReturn
|
||||
callback(result)
|
||||
}
|
||||
}
|
||||
|
||||
static func prompt (
|
||||
title: String,
|
||||
message: String,
|
||||
okText: String = "Save",
|
||||
cancelText: String = "Cancel",
|
||||
callback: @escaping (String?) -> Void
|
||||
) {
|
||||
DispatchQueue.main.async {
|
||||
let alert = getAlert(title, message)
|
||||
alert.addButton(withTitle: okText)
|
||||
alert.addButton(withTitle: cancelText)
|
||||
let input = NSTextField(frame: NSMakeRect(0, 0, 200, 24))
|
||||
input.stringValue = ""
|
||||
alert.accessoryView = input
|
||||
if (alert.runModal() == .alertFirstButtonReturn) {
|
||||
input.validateEditing()
|
||||
callback(input.stringValue == "" ? nil : input.stringValue)
|
||||
}
|
||||
callback(nil)
|
||||
}
|
||||
|
||||
static func confirm (title: String, message: String, okText: String = "Ok", cancelText: String = "Cancel") -> Bool {
|
||||
let alert = getAlert(title, message)
|
||||
alert.addButton(withTitle: okText)
|
||||
alert.addButton(withTitle: cancelText)
|
||||
return alert.runModal() == .alertFirstButtonReturn
|
||||
}
|
||||
|
||||
static func prompt (title: String, message: String, okText: String = "Save", cancelText: String = "Cancel") -> String? {
|
||||
let alert = getAlert(title, message)
|
||||
alert.addButton(withTitle: okText)
|
||||
alert.addButton(withTitle: cancelText)
|
||||
let input = NSTextField(frame: NSMakeRect(0, 0, 200, 24))
|
||||
input.stringValue = ""
|
||||
alert.accessoryView = input
|
||||
if (alert.runModal() == .alertFirstButtonReturn) {
|
||||
input.validateEditing()
|
||||
return input.stringValue == "" ? nil : input.stringValue
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
static private func getAlert (_ title: String, _ message: String) -> NSAlert {
|
||||
let alert = NSAlert()
|
||||
alert.messageText = title
|
||||
alert.informativeText = message
|
||||
return alert
|
||||
}
|
||||
}
|
||||
|
||||
static private func getAlert (_ title: String, _ message: String) -> NSAlert {
|
||||
let alert = NSAlert()
|
||||
alert.messageText = title
|
||||
alert.informativeText = message
|
||||
return alert
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user