Skip to content

Commit

Permalink
Merge pull request #232 from chadmorales/add_output_file
Browse files Browse the repository at this point in the history
Add output_file parameter for type -onboarding
  • Loading branch information
SMartorelli authored Dec 20, 2024
2 parents 2fbaec1 + 7f5c7fc commit ff906e0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
6 changes: 4 additions & 2 deletions Notification Agent Core/Controllers/HelpBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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\"",
Expand Down
4 changes: 2 additions & 2 deletions Notification Agent Onboarding UI Tests/NAOUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions Shared/Model/UIObjects/NotificationObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 6 additions & 0 deletions Shared/Model/UIObjects/OnboardingData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}

Expand Down

0 comments on commit ff906e0

Please sign in to comment.