From 7f5c7fc1da49a81b89d28ac4773eda568cee4768 Mon Sep 17 00:00:00 2001 From: Chad Morales Date: Mon, 16 Dec 2024 10:40:28 -0800 Subject: [PATCH] Add output_file parameter for type -onboarding Signed-off-by: Chad Morales --- Notification Agent Core/Controllers/HelpBuilder.swift | 6 ++++-- Notification Agent Onboarding UI Tests/NAOUITests.swift | 4 ++-- .../Views/OnboardingViewModel.swift | 2 +- Shared/Model/UIObjects/NotificationObject.swift | 1 + Shared/Model/UIObjects/OnboardingData.swift | 6 ++++++ 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Notification Agent Core/Controllers/HelpBuilder.swift b/Notification Agent Core/Controllers/HelpBuilder.swift index 12a3ebe..fdf654f 100644 --- a/Notification Agent Core/Controllers/HelpBuilder.swift +++ b/Notification Agent Core/Controllers/HelpBuilder.swift @@ -70,7 +70,8 @@ public final class HelpBuilder { "-background_panel".yellow(), "-unmovable".yellow(), "-timeout".yellow(), - "-disable_quit".yellow()] + "-disable_quit".yellow(), + "-output_file".yellow()] static let systemAlertArguments: [String] = ["-type".green(), "-title".yellow(), "-subtitle".yellow(), @@ -162,7 +163,8 @@ public final class HelpBuilder { "[ opaque | translucent ]".red() + "\n The style for the background panel that will cover all the screens.\n Example: -background_panel opaque", "\n Flag that make the UI unmovable for the user.\n Example: -unmovable", "\n The timeout for the onboarding. After this amount of seconds the agent exit with the timeout exit code.\n Example: -timeout 300", - "\n Flag that tells the agent to ignore cmd+q shortcut.\n Example: -disable_quit"] + "\n Flag that tells the agent to ignore cmd+q shortcut.\n Example: -disable_quit", + "[ filename.plist ]".red() + "\n Flag that tells the agent the filename used to store onboarding output.\n Example: -output_file custom.plist"] static let systemAlertDescriptions: [String] = ["[ systemAlert ]".red() + "\n The UI type of the notification.\n Example: -type systemAlert", "\n The title of the notification.\n Example: -title \"Title\"", "\n The subtitle of the notification.\n Example: -subtitle \"Subtitle\"", diff --git a/Notification Agent Onboarding UI Tests/NAOUITests.swift b/Notification Agent Onboarding UI Tests/NAOUITests.swift index 94fddca..ea365ce 100644 --- a/Notification Agent Onboarding UI Tests/NAOUITests.swift +++ b/Notification Agent Onboarding UI Tests/NAOUITests.swift @@ -14,7 +14,7 @@ class NAOUITests: XCTestCase { /// Testing simple Onboarding UI func testA1Onboarding() throws { let useCase = """ -{"notification":{"retainValues":false,"isMovable":true,"type":"onboarding","mainButton":{"label":"OK","callToActionType":"none","callToActionPayload":""},"barTitle":"IBM Notifier","alwaysOnTop":false,"showSuppressionButton":false,"hideTitleBarButtons":false,"accessoryViews":[],"payload":{"pages":[{"infoSection":{"fields":[{"id":"BE8ACDC6-1159-421E-8ECA-F84B6B6785ED","label":"Some Description Some"},{"id":"4C045585-72C2-428B-B574-F55CF86E5DCA","label":"Some Description Some"},{"id":"EF546A45-64CA-473D-8BEA-4BF18C3D624F","label":"Some Description Some"}]},"topIcon":"square.and.arrow.up","subtitle":"First page's subtitle","title":"First page's title","body":"First page's body"},{"singleChange":true,"infoSection":{"fields":[{"label":"First label only","id":"031F8516-F122-4A7D-A53C-4F41C9A6C86A"},{"id":"9A2DE192-E512-484E-B42B-2215C84A0B97","label":"Second label only"},{"label":"Third label only","id":"B9F441F5-E55D-4C71-B0BC-53347A4CE6A4"}]},"tertiaryButton":{"callToActionPayload":"https:\\/\\/www.google.com","label":"Tertiary","callToActionType":"link"},"title":"Second page's title","body":"Second page's body","primaryButtonLabel":"Some","subtitle":"Second page's subtitle"},{"title":"Third page's title","body":"Third page's body","singleChange":true,"subtitle":"Third page's subtitle"},{"body":"Fourth page's body","subtitle":"Fourth page's subtitle","title":"Fourth page's title"}],"progressBarPayload":"automatic"},"silent":false,"forceLightMode":false,"disableQuit":false,"buttonless":false,"hideTitleBar":false,"miniaturizable":false,"topicID":"untracked","notificationID":"untracked"},"settings":{"isVerboseModeEnabled":false,"environment":"prod"}} +{"notification":{"retainValues":false,"isMovable":true,"type":"onboarding","mainButton":{"label":"OK","callToActionType":"none","callToActionPayload":""},"barTitle":"IBM Notifier","alwaysOnTop":false,"showSuppressionButton":false,"hideTitleBarButtons":false,"accessoryViews":[],"payload":{"outputFile":"custom.plist","pages":[{"infoSection":{"fields":[{"id":"BE8ACDC6-1159-421E-8ECA-F84B6B6785ED","label":"Some Description Some"},{"id":"4C045585-72C2-428B-B574-F55CF86E5DCA","label":"Some Description Some"},{"id":"EF546A45-64CA-473D-8BEA-4BF18C3D624F","label":"Some Description Some"}]},"topIcon":"square.and.arrow.up","subtitle":"First page's subtitle","title":"First page's title","body":"First page's body"},{"singleChange":true,"infoSection":{"fields":[{"label":"First label only","id":"031F8516-F122-4A7D-A53C-4F41C9A6C86A"},{"id":"9A2DE192-E512-484E-B42B-2215C84A0B97","label":"Second label only"},{"label":"Third label only","id":"B9F441F5-E55D-4C71-B0BC-53347A4CE6A4"}]},"tertiaryButton":{"callToActionPayload":"https:\\/\\/www.google.com","label":"Tertiary","callToActionType":"link"},"title":"Second page's title","body":"Second page's body","primaryButtonLabel":"Some","subtitle":"Second page's subtitle"},{"title":"Third page's title","body":"Third page's body","singleChange":true,"subtitle":"Third page's subtitle"},{"body":"Fourth page's body","subtitle":"Fourth page's subtitle","title":"Fourth page's title"}],"progressBarPayload":"automatic"},"silent":false,"forceLightMode":false,"disableQuit":false,"buttonless":false,"hideTitleBar":false,"miniaturizable":false,"topicID":"untracked","notificationID":"untracked"},"settings":{"isVerboseModeEnabled":false,"environment":"prod"}} """ // pragma: allowlist-secret if let useCaseData = useCase.data(using: .utf8) { let app = XCUIApplication() @@ -54,7 +54,7 @@ class NAOUITests: XCTestCase { /// Testing simple Onboarding UI with accessory views. func testA2Onboarding() throws { let useCase = """ -{"notification":{"retainValues":false,"isMovable":true,"type":"onboarding","mainButton":{"label":"OK","callToActionType":"none","callToActionPayload":""},"barTitle":"IBM Notifier","alwaysOnTop":false,"showSuppressionButton":false,"hideTitleBarButtons":false,"accessoryViews":[],"payload":{"pages":[{"accessoryViews":[[{"type":"image","payload":"https://compote.slate.com/images/697b023b-64a5-49a0-8059-27b963453fb1.gif?crop=780%2C520%2Cx0%2Cy0&width=2200"},{"type":"image","payload":"https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_1280.jpg"}]],"infoSection":{"fields":[{"id":"BE8ACDC6-1159-421E-8ECA-F84B6B6785ED","label":"Some Description Some"},{"id":"4C045585-72C2-428B-B574-F55CF86E5DCA","label":"Some Description Some"},{"id":"EF546A45-64CA-473D-8BEA-4BF18C3D624F","label":"Some Description Some"}]},"topIcon":"square.and.arrow.up","subtitle":"First page's subtitle","title":"First page's title","body":"First page's body"},{"singleChange":true,"infoSection":{"fields":[{"label":"First label only","id":"031F8516-F122-4A7D-A53C-4F41C9A6C86A"},{"id":"9A2DE192-E512-484E-B42B-2215C84A0B97","label":"Second label only"},{"label":"Third label only","id":"B9F441F5-E55D-4C71-B0BC-53347A4CE6A4"}]},"tertiaryButton":{"callToActionPayload":"https:\\/\\/www.google.com","label":"Tertiary","callToActionType":"link"},"title":"Second page's title","body":"Second page's body","primaryButtonLabel":"Some","subtitle":"Second page's subtitle"},{"title":"Third page's title","body":"Third page's body","singleChange":true,"subtitle":"Third page's subtitle"},{"body":"Fourth page's body","subtitle":"Fourth page's subtitle","title":"Fourth page's title"}],"progressBarPayload":"automatic"},"silent":false,"forceLightMode":false,"disableQuit":false,"buttonless":false,"hideTitleBar":false,"miniaturizable":false,"topicID":"untracked","notificationID":"untracked"},"settings":{"isVerboseModeEnabled":false,"environment":"prod"}} +{"notification":{"retainValues":false,"isMovable":true,"type":"onboarding","mainButton":{"label":"OK","callToActionType":"none","callToActionPayload":""},"barTitle":"IBM Notifier","alwaysOnTop":false,"showSuppressionButton":false,"hideTitleBarButtons":false,"accessoryViews":[],"payload":{"outputFile":"custom.plist","pages":[{"accessoryViews":[[{"type":"image","payload":"https://compote.slate.com/images/697b023b-64a5-49a0-8059-27b963453fb1.gif?crop=780%2C520%2Cx0%2Cy0&width=2200"},{"type":"image","payload":"https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_1280.jpg"}]],"infoSection":{"fields":[{"id":"BE8ACDC6-1159-421E-8ECA-F84B6B6785ED","label":"Some Description Some"},{"id":"4C045585-72C2-428B-B574-F55CF86E5DCA","label":"Some Description Some"},{"id":"EF546A45-64CA-473D-8BEA-4BF18C3D624F","label":"Some Description Some"}]},"topIcon":"square.and.arrow.up","subtitle":"First page's subtitle","title":"First page's title","body":"First page's body"},{"singleChange":true,"infoSection":{"fields":[{"label":"First label only","id":"031F8516-F122-4A7D-A53C-4F41C9A6C86A"},{"id":"9A2DE192-E512-484E-B42B-2215C84A0B97","label":"Second label only"},{"label":"Third label only","id":"B9F441F5-E55D-4C71-B0BC-53347A4CE6A4"}]},"tertiaryButton":{"callToActionPayload":"https:\\/\\/www.google.com","label":"Tertiary","callToActionType":"link"},"title":"Second page's title","body":"Second page's body","primaryButtonLabel":"Some","subtitle":"Second page's subtitle"},{"title":"Third page's title","body":"Third page's body","singleChange":true,"subtitle":"Third page's subtitle"},{"body":"Fourth page's body","subtitle":"Fourth page's subtitle","title":"Fourth page's title"}],"progressBarPayload":"automatic"},"silent":false,"forceLightMode":false,"disableQuit":false,"buttonless":false,"hideTitleBar":false,"miniaturizable":false,"topicID":"untracked","notificationID":"untracked"},"settings":{"isVerboseModeEnabled":false,"environment":"prod"}} """ // pragma: allowlist-secret if let useCaseData = useCase.data(using: .utf8) { let app = XCUIApplication() diff --git a/Notification Agent Onboarding/Views/OnboardingViewModel.swift b/Notification Agent Onboarding/Views/OnboardingViewModel.swift index 9c74d4f..5f746fa 100644 --- a/Notification Agent Onboarding/Views/OnboardingViewModel.swift +++ b/Notification Agent Onboarding/Views/OnboardingViewModel.swift @@ -198,7 +198,7 @@ class OnboardingViewModel: NSObject, ObservableObject { plistDictionary[index.description] = pageDictionary } let dictionaryResult = NSDictionary(dictionary: plistDictionary) - Utils.write(dictionaryResult, to: Constants.storeFileName) + Utils.write(dictionaryResult, to: onboardingData.outputFile!) } /// Update the state of the progress bar if it's set to automatic. diff --git a/Shared/Model/UIObjects/NotificationObject.swift b/Shared/Model/UIObjects/NotificationObject.swift index 8e92ad2..06115eb 100644 --- a/Shared/Model/UIObjects/NotificationObject.swift +++ b/Shared/Model/UIObjects/NotificationObject.swift @@ -145,6 +145,7 @@ public final class NotificationObject: NSObject, Codable, NSSecureCoding { switch type { case .onboarding: self.payload = try Self.loadOnboardingPayload(payloadRawData) + self.payload?.outputFile = dict["output_file"] as? String ?? Constants.storeFileName default: break } diff --git a/Shared/Model/UIObjects/OnboardingData.swift b/Shared/Model/UIObjects/OnboardingData.swift index 3056955..2817918 100644 --- a/Shared/Model/UIObjects/OnboardingData.swift +++ b/Shared/Model/UIObjects/OnboardingData.swift @@ -16,12 +16,14 @@ public final class OnboardingData: Codable { /// An array of pages. var pages: [InteractiveOnboardingPage] var progressBarPayload: String? + var outputFile: String! // MARK: - Codable protocol conformity - START enum ODCodingKeys: String, CodingKey { case pages case progressBarPayload + case outputFile } required public init(from decoder: Decoder) throws { @@ -34,12 +36,16 @@ public final class OnboardingData: Codable { if let payload = try? container.decodeIfPresent(String.self, forKey: .progressBarPayload) { self.progressBarPayload = payload } + if let outputFile = try? container.decode(String.self, forKey: .outputFile) { + self.outputFile = outputFile + } } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: ODCodingKeys.self) try container.encodeIfPresent(progressBarPayload, forKey: .progressBarPayload) + try container.encode(outputFile, forKey: .outputFile) try container.encode(pages, forKey: .pages) }