From f6d1a5ff8545106bf18720817bfa9f2833b7babc Mon Sep 17 00:00:00 2001 From: Emory Dunn Date: Wed, 16 Oct 2024 18:42:15 -0700 Subject: [PATCH] GitHub Actions are still grumpy --- .../Action/Action+Sent.swift | 92 ++++++++++--------- .../StreamDeckPlugin/SDPlugin+Sent.swift | 5 +- 2 files changed, 51 insertions(+), 46 deletions(-) diff --git a/Sources/StreamDeck/StreamDeck Plugin/Action/Action+Sent.swift b/Sources/StreamDeck/StreamDeck Plugin/Action/Action+Sent.swift index 5b56d5d..c285558 100644 --- a/Sources/StreamDeck/StreamDeck Plugin/Action/Action+Sent.swift +++ b/Sources/StreamDeck/StreamDeck Plugin/Action/Action+Sent.swift @@ -1,6 +1,6 @@ // // Action+Sent.swift -// +// // // Created by Emory Dunn on 11/30/22. // @@ -13,9 +13,9 @@ import OSLog fileprivate let log = Logger(subsystem: "StreamDeckPlugin", category: "Action") public extension Action { - + // MARK: Sent - + /// Save data persistently for the action's instance. /// - Parameters: /// - context: An opaque value identifying the instance's action or Property Inspector. @@ -28,7 +28,7 @@ public extension Action { payload: settings) } } - + /// Save data persistently for the action's instance. /// - Parameters: /// - context: An opaque value identifying the instance's action or Property Inspector. @@ -40,7 +40,7 @@ public extension Action { payload: settings) } } - + /// Request the persistent data for the action's instance. /// - context: An opaque value identifying the instance's action or Property Inspector. func getSettings() { @@ -69,7 +69,7 @@ public extension Action { await PluginCommunication.shared.sendEvent(.logMessage, context: nil, payload: ["message": message]) } } - + /// Write a debug log to the logs file. /// - Parameters: /// - items: Zero or more items to print. @@ -78,10 +78,10 @@ public extension Action { let message = items.map { String(describing: $0) }.joined(separator: separator) - + logMessage(message) } - + /// Dynamically change the title of an instance of an action. /// - Parameters: /// - context: An opaque value identifying the instance's action or Property Inspector. @@ -89,19 +89,19 @@ public extension Action { /// - target: Specify if you want to display the title on hardware, software, or both. /// - state: A 0-based integer value representing the state of an action with multiple states. This is an optional parameter. If not specified, the title is set to all states. func setTitle(to title: String?, target: Target? = nil, state: Int? = nil) { - var payload: [String: Any] = [:] - - payload["title"] = title - payload["target"] = target?.rawValue - payload["state"] = state - Task { + var payload: [String: Any] = [:] + + payload["title"] = title + payload["target"] = target?.rawValue + payload["state"] = state + await PluginCommunication.shared.sendEvent(.setTitle, context: context, payload: payload) } } - + /// Dynamically change the image displayed by an instance of an action. /// /// The image is automatically encoded to a prefixed base64 string. @@ -112,19 +112,20 @@ public extension Action { /// - target: Specify if you want to display the title on hardware, software, or both. /// - state: A 0-based integer value representing the state of an action with multiple states. This is an optional parameter. If not specified, the image is set to all states. func setImage(to image: NSImage?, target: Target? = nil, state: Int? = nil) { - var payload: [String: Any] = [:] - - payload["image"] = image?.base64String - payload["target"] = target?.rawValue - payload["state"] = state - Task { + var payload: [String: Any] = [:] + + payload["image"] = image?.base64String + payload["target"] = target?.rawValue + payload["state"] = state + + await PluginCommunication.shared.sendEvent(.setImage, context: context, payload: payload) } } - + /// Dynamically change the image displayed by an instance of an action. /// /// The image is automatically encoded to a prefixed base64 string. @@ -144,13 +145,13 @@ public extension Action { setImage(to: nil, target: target, state: state) return } - + let image = NSImage(contentsOf: imageURL) - + setImage(to: image, target: target, state: state) } - - + + /// Dynamically change the image displayed by an instance of an action. /// /// The image is automatically encoded to a prefixed base64 string. @@ -161,22 +162,23 @@ public extension Action { /// - target: Specify if you want to display the title on hardware, software, or both. /// - state: A 0-based integer value representing the state of an action with multiple states. This is an optional parameter. If not specified, the image is set to all states. func setImage(toSVG svg: String?, target: Target? = nil, state: Int? = nil) { - var payload: [String: Any] = [:] - - if let svg = svg { - payload["image"] = "data:image/svg+xml;charset=utf8,\(svg)" - } - - payload["target"] = target?.rawValue - payload["state"] = state - Task { + var payload: [String: Any] = [:] + + if let svg = svg { + payload["image"] = "data:image/svg+xml;charset=utf8,\(svg)" + } + + payload["target"] = target?.rawValue + payload["state"] = state + + await PluginCommunication.shared.sendEvent(.setImage, context: context, payload: payload) } } - + /// Temporarily show an alert icon on the image displayed by an instance of an action. /// - Parameter context: An opaque value identifying the instance's action or Property Inspector. func showAlert() { @@ -184,7 +186,7 @@ public extension Action { await PluginCommunication.shared.sendEvent(.showAlert, context: context, payload: nil) } } - + /// Temporarily show an OK checkmark icon on the image displayed by an instance of an action. /// - Parameter context: An opaque value identifying the instance's action or Property Inspector. func showOk() { @@ -192,21 +194,21 @@ public extension Action { await PluginCommunication.shared.sendEvent(.showOK, context: context, payload: nil) } } - + /// Change the state of the action's instance supporting multiple states. /// - Parameters: /// - context: An opaque value identifying the instance's action or Property Inspector. /// - state: A 0-based integer value representing the state of an action with multiple states. func setState(to state: Int) { let payload: [String: Any] = ["state": state] - + Task { await PluginCommunication.shared.sendEvent(.setState, context: context, payload: payload) } } - + /// Send a payload to the Property Inspector. /// - Parameters: /// - context: An opaque value identifying the instance's action or Property Inspector. @@ -220,8 +222,8 @@ public extension Action { payload: payload) } } - - + + /// The plugin can send a `setFeedback` event to the Stream Deck application to dynamically change properties of items on the Stream Deck + touch display layout. func setFeedback(_ payload: [String: Any]) { Task { @@ -230,21 +232,21 @@ public extension Action { payload: payload) } } - + /// The plugin can send a `setFeedbackLayout` event to the Stream Deck application to dynamically change the current Stream Deck + touch display layout. /// /// `setFeedbackLayout` can use the `id` of a built-in layout or a relative path to a custom layout JSON file. /// - Parameter layout: The layout to set. func setFeedbackLayout(_ layout: LayoutName) { let payload: [String: Any] = ["layout": layout.id] - + Task { await PluginCommunication.shared.sendEvent(.setFeedbackLayout, context: context, payload: payload) } } - + /// Sets the trigger descriptions associated with an encoder (touch display + dial) action instance. /// /// All descriptions are optional; when one or more descriptions are defined all descriptions are updated, diff --git a/Sources/StreamDeck/StreamDeck Plugin/StreamDeckPlugin/SDPlugin+Sent.swift b/Sources/StreamDeck/StreamDeck Plugin/StreamDeckPlugin/SDPlugin+Sent.swift index 02157ef..9dcbabe 100644 --- a/Sources/StreamDeck/StreamDeck Plugin/StreamDeckPlugin/SDPlugin+Sent.swift +++ b/Sources/StreamDeck/StreamDeck Plugin/StreamDeckPlugin/SDPlugin+Sent.swift @@ -135,10 +135,13 @@ public extension Plugin { /// - target: Specify if you want to display the title on hardware, software, or both. /// - state: A 0-based integer value representing the state of an action with multiple states. This is an optional parameter. If not specified, the title is set to all states. func setImage(in context: String, to image: NSImage?, target: Target? = nil, state: Int? = nil) { + + let encodedImage = image?.base64String + Task { var payload: [String: Any] = [:] - payload["image"] = image?.base64String + payload["image"] = encodedImage payload["target"] = target?.rawValue payload["state"] = state