From 72a49275a94b9932f9a0da62744b6267a2ef7ee0 Mon Sep 17 00:00:00 2001 From: Jeremy Rand Date: Tue, 18 Jan 2022 22:51:28 -0500 Subject: [PATCH] Fix button appearance in dark mode. Add the heard text the UI below the buttons. Convert to MacOS Roman character set so words like "resume" appear with the correct accents on the GS. --- .../ButtonColor.colorset/Contents.json | 29 +++++++++ .../ButtonTextColor.colorset/Contents.json | 38 ++++++++++++ .../Contents.json | 38 ++++++++++++ .../Contents.json | 38 ++++++++++++ ListenerGS/GSView.swift | 60 ++++++++++--------- ListenerGS/Info.plist | 2 +- ListenerGS/SpeechForwarder.swift | 31 ++++++---- 7 files changed, 195 insertions(+), 41 deletions(-) create mode 100644 ListenerGS/Assets.xcassets/ButtonColor.colorset/Contents.json create mode 100644 ListenerGS/Assets.xcassets/ButtonTextColor.colorset/Contents.json create mode 100644 ListenerGS/Assets.xcassets/InactiveButtonColor.colorset/Contents.json create mode 100644 ListenerGS/Assets.xcassets/InactiveButtonTextColor.colorset/Contents.json diff --git a/ListenerGS/Assets.xcassets/ButtonColor.colorset/Contents.json b/ListenerGS/Assets.xcassets/ButtonColor.colorset/Contents.json new file mode 100644 index 0000000..773c84d --- /dev/null +++ b/ListenerGS/Assets.xcassets/ButtonColor.colorset/Contents.json @@ -0,0 +1,29 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "205", + "green" : "97", + "red" : "0" + } + }, + "idiom" : "universal" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/ListenerGS/Assets.xcassets/ButtonTextColor.colorset/Contents.json b/ListenerGS/Assets.xcassets/ButtonTextColor.colorset/Contents.json new file mode 100644 index 0000000..22c4bb0 --- /dev/null +++ b/ListenerGS/Assets.xcassets/ButtonTextColor.colorset/Contents.json @@ -0,0 +1,38 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "1.000", + "green" : "1.000", + "red" : "1.000" + } + }, + "idiom" : "universal" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "1.000", + "green" : "1.000", + "red" : "1.000" + } + }, + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/ListenerGS/Assets.xcassets/InactiveButtonColor.colorset/Contents.json b/ListenerGS/Assets.xcassets/InactiveButtonColor.colorset/Contents.json new file mode 100644 index 0000000..a84c24d --- /dev/null +++ b/ListenerGS/Assets.xcassets/InactiveButtonColor.colorset/Contents.json @@ -0,0 +1,38 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "253", + "green" : "224", + "red" : "188" + } + }, + "idiom" : "universal" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "60", + "green" : "60", + "red" : "60" + } + }, + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/ListenerGS/Assets.xcassets/InactiveButtonTextColor.colorset/Contents.json b/ListenerGS/Assets.xcassets/InactiveButtonTextColor.colorset/Contents.json new file mode 100644 index 0000000..34ceef4 --- /dev/null +++ b/ListenerGS/Assets.xcassets/InactiveButtonTextColor.colorset/Contents.json @@ -0,0 +1,38 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "0.700", + "blue" : "255", + "green" : "255", + "red" : "255" + } + }, + "idiom" : "universal" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "119", + "green" : "119", + "red" : "119" + } + }, + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/ListenerGS/GSView.swift b/ListenerGS/GSView.swift index b317c2e..063ace5 100644 --- a/ListenerGS/GSView.swift +++ b/ListenerGS/GSView.swift @@ -7,12 +7,6 @@ import SwiftUI -extension Color { - static let defaultBlue = Color(red: 0, green: 97 / 255.0, blue: 205 / 255.0) - static let paleBlue = Color(red: 188 / 255.0, green: 224 / 255.0, blue: 253 / 255.0) - static let paleWhite = Color(white: 1, opacity: 179 / 255.0) -} - struct GSButtonStyle : ButtonStyle { func makeBody(configuration: Self.Configuration) -> some View { GSButtonStyleView(configuration: configuration) @@ -23,6 +17,7 @@ private extension GSButtonStyle { struct GSButtonStyleView: View { // tracks if the button is enabled or not @Environment(\.isEnabled) var isEnabled + @Environment(\.colorScheme) var colorScheme // tracks the pressed state let configuration: GSButtonStyle.Configuration @@ -31,8 +26,8 @@ private extension GSButtonStyle { .lineLimit(nil) .padding() .frame(maxWidth: .infinity) - .background(isEnabled ? Color.defaultBlue : Color.paleBlue) - .foregroundColor(isEnabled ? .white : .paleWhite) + .background(isEnabled ? Color("ButtonColor") : Color("InactiveButtonColor")) + .foregroundColor(isEnabled ? Color("ButtonTextColor") : Color("InactiveButtonTextColor")) .font(.subheadline) .clipShape(Capsule()) .opacity(configuration.isPressed ? 0.8 : 1.0) @@ -47,30 +42,37 @@ struct GSView: View { var body: some View { VStack { - Button(speechForwarder.connected ? - "\(Image(systemName: "desktopcomputer.trianglebadge.exclamationmark")) Disconnect from \(ipAddress)" : - "\(Image(systemName: "desktopcomputer.and.arrow.down")) Connect to \(ipAddress)") { - if (speechForwarder.connected) { - speechForwarder.disconnect() - } else { - speechForwarder.connect(destination: ipAddress) + VStack { + Button(speechForwarder.connected ? + "\(Image(systemName: "desktopcomputer.trianglebadge.exclamationmark")) Disconnect from \(ipAddress)" : + "\(Image(systemName: "desktopcomputer.and.arrow.down")) Connect to \(ipAddress)") { + if (speechForwarder.connected) { + speechForwarder.disconnect() + } else { + speechForwarder.connect(destination: ipAddress) + } } + .disabled(false) + .buttonStyle(GSButtonStyle()) + + Button(speechForwarder.listening ? + "\(Image(systemName: "ear.trianglebadge.exclamationmark")) Stop Listening" : + "\(Image(systemName: "ear.and.waveform")) Listen and Send Text") { + speechForwarder.listen() + } + .disabled(!speechForwarder.connected) + .buttonStyle(GSButtonStyle()) } - .disabled(false) - .buttonStyle(GSButtonStyle()) - - Button(speechForwarder.listening ? - "\(Image(systemName: "ear.trianglebadge.exclamationmark")) Stop Listening" : - "\(Image(systemName: "ear.and.waveform")) Listen and Send Text") { - speechForwarder.listen() - } - .disabled(!speechForwarder.connected) - .buttonStyle(GSButtonStyle()) - - Spacer() + .fixedSize(horizontal: true, vertical: false) + .navigationBarTitle(ipAddress) } - .fixedSize(horizontal: true, vertical: false) - .navigationBarTitle(ipAddress) + + Text(speechForwarder.textHeard) + .truncationMode(.head) + .lineLimit(15) + .padding() + + Spacer() } init(ipAddress : String) { diff --git a/ListenerGS/Info.plist b/ListenerGS/Info.plist index 0ae7f72..77bbe6c 100644 --- a/ListenerGS/Info.plist +++ b/ListenerGS/Info.plist @@ -19,7 +19,7 @@ CFBundleShortVersionString 1.0 CFBundleVersion - 358 + 378 LSApplicationCategoryType public.app-category.utilities LSRequiresIPhoneOS diff --git a/ListenerGS/SpeechForwarder.swift b/ListenerGS/SpeechForwarder.swift index 0807c9b..1ec400a 100644 --- a/ListenerGS/SpeechForwarder.swift +++ b/ListenerGS/SpeechForwarder.swift @@ -12,7 +12,7 @@ import Speech class SpeechForwarder : ObservableObject { @Published var listening = false @Published var connected = false - private var textHeard = "" + @Published var textHeard = "" let LISTEN_STATE_MSG = 1 let LISTEN_TEXT_MSG = 2 @@ -20,7 +20,7 @@ class SpeechForwarder : ObservableObject { let port = 19026 private var client: TCPClient? - private let speechRecognizer = SFSpeechRecognizer(locale: Locale(identifier: "en-US"))! + private let speechRecognizer = SFSpeechRecognizer(locale: Locale(identifier: Locale.preferredLanguages[0]))! private var recognitionRequest: SFSpeechAudioBufferRecognitionRequest? @@ -144,15 +144,24 @@ class SpeechForwarder : ObservableObject { if (stringToSend.count > 0) { // TODO - Handle strings to send that are longer than 64K (doubt that would happen though) - // TODO - Try to convert encoding from utf8 to something the GS can understand. - switch (client.send(data: pack("