Skip to content

Commit 07f3c28

Browse files
committed
Use constants
1 parent d25e654 commit 07f3c28

8 files changed

+54
-43
lines changed

SupportCompanion/Constants.swift

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,14 @@ enum Constants {
8787
}
8888

8989
enum Cards {
90-
static let storageCardName = "Storage"
91-
static let actionsCardName = "Actions"
92-
static let evergreenCardName = "Evergreen"
93-
static let deviceInfoCardName = "Device Information"
94-
static let deviceManagementCardName = "Device Management"
95-
static let appPatchProgressCardName = "Application Patching Progress"
96-
static let batteryCardName = "Battery"
90+
static let storage = "Storage"
91+
static let actions = "Actions"
92+
static let evergreen = "Evergreen"
93+
static let deviceInfo = "DeviceInformation"
94+
static let deviceManagement = "DeviceManagement"
95+
static let appPatchProgress = "ApplicationInstallProgress"
96+
static let battery = "Battery"
97+
static let pendingAppUpdates = "PendingAppUpdates"
9798
}
9899

99100
enum CardTitle {
@@ -125,6 +126,16 @@ enum Constants {
125126
static let openManagementApp = String(localized: "Action.OpenManagementApp", defaultValue: "Open Management App", comment: "Label for open management app action")
126127
static let softwareUpdate = String(localized: "Action.SoftwareUpdate", defaultValue: "Software Update", comment: "Label for software update action")
127128
static let getSupport = String(localized: "Action.GetSupport", defaultValue: "Get Support", comment: "Label for get support action")
129+
130+
enum HideStrings {
131+
static let changePassword = "ChangePassword"
132+
static let gatherLogs = "GatherLogs"
133+
static let restartIntuneAgent = "RestartIntuneAgent"
134+
static let openManagementApp = "OpenManagementApp"
135+
static let softwareUpdate = "SoftwareUpdates"
136+
static let getSupport = "GetSupport"
137+
static let reboot = "Reboot"
138+
}
128139
}
129140

130141
enum ToastMessages {

SupportCompanion/Views/Cards/ActionsCard.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,28 @@ struct ActionsCard: View {
1414
var onShowRebootModal: (Int, String, String) -> Void
1515

1616
var body: some View {
17-
if viewModel.isCardVisible("Actions") {
17+
if viewModel.isCardVisible(Constants.Cards.actions) {
1818
ScCard(title: "\(Constants.CardTitle.actions)", titleImageName: "cursorarrow.click.2", content: {
1919
// Precompute the filtered and chunked buttons
2020
let visibleButtons = [
21-
viewModel.isButtonVisible("ChangePassword") ? viewModel.createChangePasswordButton() : nil,
22-
viewModel.isButtonVisible("Reboot") ? viewModel.createRebootButton(
21+
viewModel.isButtonVisible(Constants.Actions.HideStrings.changePassword) ? viewModel.createChangePasswordButton() : nil,
22+
viewModel.isButtonVisible(Constants.Actions.HideStrings.reboot) ? viewModel.createRebootButton(
2323
onShowModal: { countdown, title, message in
2424
onShowRebootModal(countdown, title, message)
2525
}
2626
) : nil,
2727
(appState.preferences.mode == Constants.modes.munki || appState.preferences.mode == Constants.modes.intune)
28-
? (viewModel.isButtonVisible("OpenManagementApp") ? viewModel.createOpenManagementAppButton(type: .default) : nil)
28+
? (viewModel.isButtonVisible(Constants.Actions.HideStrings.openManagementApp) ? viewModel.createOpenManagementAppButton(type: .default) : nil)
2929
: nil,
30-
viewModel.isButtonVisible("GetSupport") ? ScButton(Constants.Actions.getSupport) { ActionHelpers.openSupportPage(url: appState.preferences.supportPageURL) } : nil,
31-
viewModel.isButtonVisible("GatherLogs") ? viewModel.createGatherLogsButton() : nil,
32-
viewModel.isButtonVisible("SoftwareUpdates") ? ScButton(
30+
viewModel.isButtonVisible(Constants.Actions.HideStrings.getSupport) ? ScButton(Constants.Actions.getSupport) { ActionHelpers.openSupportPage(url: appState.preferences.supportPageURL) } : nil,
31+
viewModel.isButtonVisible(Constants.Actions.HideStrings.gatherLogs) ? viewModel.createGatherLogsButton() : nil,
32+
viewModel.isButtonVisible(Constants.Actions.HideStrings.softwareUpdate) ? ScButton(
3333
Constants.Actions.softwareUpdate,
3434
badgeNumber: appState.systemUpdateCache.updates.count,
3535
helpText: appState.systemUpdateCache.updates.joined(separator: "\n"))
3636
{ ActionHelpers.openSystemUpdates() } : nil,
3737
(appState.preferences.mode == Constants.modes.munki || appState.preferences.mode == Constants.modes.intune)
38-
? (viewModel.isButtonVisible("RestartIntuneAgent") ? viewModel.createRestartIntuneAgentButton() : nil)
38+
? (viewModel.isButtonVisible(Constants.Actions.HideStrings.restartIntuneAgent) ? viewModel.createRestartIntuneAgentButton() : nil)
3939
: nil
4040
].compactMap { $0 } // Remove nil values
4141

SupportCompanion/Views/Cards/BatteryEvergreenStack.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ struct BatteryEvergreenStack: View {
1313
@EnvironmentObject var appState: AppStateManager
1414

1515
var body: some View {
16-
if !viewModel.isCardVisible("Evergreen") && !viewModel.isCardVisible("Battery") {
16+
if !viewModel.isCardVisible(Constants.Cards.evergreen) && !viewModel.isCardVisible(Constants.Cards.battery) {
1717
} else{
1818
VStack(alignment: .leading){
19-
if viewModel.isCardVisible("Evergreen") && appState.preferences.mode == Constants.modes.munki {
19+
if viewModel.isCardVisible(Constants.Cards.evergreen) && appState.preferences.mode == Constants.modes.munki {
2020
ScCard(title: "\(Constants.CardTitle.evergreen)", titleImageName: "leaf.fill", content: {
2121
VStack(alignment: .leading) {
2222
Text("Rings")
@@ -39,7 +39,7 @@ struct BatteryEvergreenStack: View {
3939
})
4040
}
4141

42-
if viewModel.isCardVisible("Battery") {
42+
if viewModel.isCardVisible(Constants.Cards.battery) {
4343
ScCard(title: "\(Constants.CardTitle.battery)", titleImageName: "battery.100percent.bolt", imageSize: (25,25), content: {
4444
VStack(alignment: .leading) {
4545
CardData(info: appState.batteryInfoManager.batteryInfo.toKeyValuePairs())

SupportCompanion/Views/Cards/DeviceInformationCard.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ struct DeviceInformationCard: View {
1414
@Environment(\.colorScheme) var colorScheme
1515

1616
var body: some View {
17-
if viewModel.isCardVisible("DeviceInformation") {
17+
if viewModel.isCardVisible(Constants.Cards.deviceInfo) {
1818
let groupedData = groupedDeviceInfoArray() // Precomputed grouped data
1919

2020
ScCard(

SupportCompanion/Views/Cards/PatchingProgressCard.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct PatchingProgressCard: View {
1313
@EnvironmentObject var appState: AppStateManager
1414

1515
var body: some View {
16-
if viewModel.isCardVisible("ApplicationInstallProgress") {
16+
if viewModel.isCardVisible(Constants.Cards.appPatchProgress) {
1717
VStack {
1818
ScCard(title: "\(Constants.CardTitle.appPatchProgress)", titleImageName: "app.badge.checkmark", content: {
1919
ZStack {

SupportCompanion/Views/Cards/PendingUpdatesCard.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct PendingUpdatesCard: View {
1313
@EnvironmentObject var appState: AppStateManager
1414

1515
var body: some View {
16-
if viewModel.isCardVisible("PendingAppUpdates") {
16+
if viewModel.isCardVisible(Constants.Cards.pendingAppUpdates) {
1717
VStack {
1818
ScCard(
1919
title: "\(Constants.CardTitle.pendingUpdates)",

SupportCompanion/Views/Cards/StorageDeviceManagementStack.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ struct StorageDeviceManagementStack: View {
1414
@Environment(\.colorScheme) var colorScheme
1515

1616
var body: some View {
17-
if !viewModel.isCardVisible(Constants.Cards.storageCardName) && !viewModel.isCardVisible(Constants.Cards.deviceManagementCardName) {
17+
if !viewModel.isCardVisible(Constants.Cards.storage) && !viewModel.isCardVisible(Constants.Cards.deviceManagement) {
1818
} else{
1919
VStack(alignment: .leading){
2020
// Storage Card
21-
if viewModel.isCardVisible(Constants.Cards.storageCardName) {
21+
if viewModel.isCardVisible(Constants.Cards.storage) {
2222
ScCard(title: "\(Constants.CardTitle.storage)",
2323
titleImageName: "internaldrive.fill",
2424
buttonImageName: "macwindow.on.rectangle",
@@ -54,7 +54,7 @@ struct StorageDeviceManagementStack: View {
5454
}
5555

5656
// Device Management Card
57-
if viewModel.isCardVisible("DeviceManagement") {
57+
if viewModel.isCardVisible(Constants.Cards.deviceManagement) {
5858
ScCard(title: "\(Constants.CardTitle.deviceManagement)", titleImageName: "lock.shield", content: {
5959
VStack(alignment: .leading, spacing: 5) {
6060
CardData(info: appState.mdmInfoManager.mdmInfo.toKeyValuePairs())

SupportCompanion/Views/TrayMenu.swift

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ struct TrayMenuView: View {
2828
// Main content (Grid and Buttons)
2929
VStack(spacing: 20) { // Increased spacing between grid and buttons
3030
LazyVGrid(columns: columns, alignment: .leading) { // Add spacing between cards
31-
if !appState.preferences.hiddenCards.contains("Battery") {
31+
if !appState.preferences.hiddenCards.contains(Constants.Cards.battery) {
3232
CompactBatteryCard()
3333
}
34-
if !appState.preferences.hiddenCards.contains("DeviceInformation") {
34+
if !appState.preferences.hiddenCards.contains(Constants.Cards.deviceInfo) {
3535
CompactDeviceCard()
3636
}
37-
if !appState.preferences.hiddenCards.contains("Storage") {
37+
if !appState.preferences.hiddenCards.contains(Constants.Cards.storage) {
3838
CompactStorageCard()
3939
}
4040
if appState.preferences.mode == Constants.modes.munki || appState.preferences.mode == Constants.modes.intune {
41-
if !appState.preferences.hiddenCards.contains("ApplicationInstallProgress") {
41+
if !appState.preferences.hiddenCards.contains(Constants.Cards.appPatchProgress) {
4242
CompactPatchProgressCard()
4343
}
4444
}
@@ -99,11 +99,11 @@ struct TrayMenuView: View {
9999
/// Counts visible cards in the grid
100100
private func visibleCardsCount() -> Int {
101101
var count = 0
102-
if !appState.preferences.hiddenCards.contains("Battery") { count += 1 }
103-
if !appState.preferences.hiddenCards.contains("DeviceInformation") { count += 1 }
104-
if !appState.preferences.hiddenCards.contains("Storage") { count += 1 }
102+
if !appState.preferences.hiddenCards.contains(Constants.Cards.battery) { count += 1 }
103+
if !appState.preferences.hiddenCards.contains(Constants.Cards.deviceInfo) { count += 1 }
104+
if !appState.preferences.hiddenCards.contains(Constants.Cards.storage) { count += 1 }
105105
if appState.preferences.mode == Constants.modes.munki || appState.preferences.mode == Constants.modes.intune {
106-
if !appState.preferences.hiddenCards.contains("ApplicationInstallProgress") {
106+
if !appState.preferences.hiddenCards.contains(Constants.Cards.appPatchProgress) {
107107
count += 1
108108
}
109109
}
@@ -117,12 +117,12 @@ struct TrayMenuView: View {
117117
AppStateManager.shared.preferences.menuShowIdentity,
118118
AppStateManager.shared.preferences.menuShowApps,
119119
AppStateManager.shared.preferences.menuShowSelfService,
120-
viewModel.isButtonVisible("ChangePassword"),
120+
viewModel.isButtonVisible(Constants.Actions.HideStrings.changePassword),
121121
appState.preferences.mode == Constants.modes.munki || appState.preferences.mode == Constants.modes.intune,
122-
viewModel.isButtonVisible("GetSupport"),
123-
viewModel.isButtonVisible("GatherLogs"),
124-
viewModel.isButtonVisible("SoftwareUpdates"),
125-
viewModel.isButtonVisible("RestartIntuneAgent")
122+
viewModel.isButtonVisible(Constants.Actions.HideStrings.getSupport),
123+
viewModel.isButtonVisible(Constants.Actions.HideStrings.gatherLogs),
124+
viewModel.isButtonVisible(Constants.Actions.HideStrings.softwareUpdate),
125+
viewModel.isButtonVisible(Constants.Actions.HideStrings.restartIntuneAgent)
126126
]
127127
return buttons.filter { $0 }.count
128128
}
@@ -140,20 +140,20 @@ struct ButtonSection: View {
140140
appState.showWindowCallback?()
141141
}
142142
}),
143-
viewModel.isButtonVisible("ChangePassword") ? viewModel.createChangePasswordButton(fontSize: 12) : nil,
143+
viewModel.isButtonVisible(Constants.Actions.HideStrings.changePassword) ? viewModel.createChangePasswordButton(fontSize: 12) : nil,
144+
viewModel.isButtonVisible(Constants.Actions.HideStrings.getSupport) ? ScButton(Constants.Actions.getSupport, fontSize: 12) { ActionHelpers.openSupportPage(url: appState.preferences.supportPageURL) } : nil,
144145
(appState.preferences.mode == Constants.modes.munki || appState.preferences.mode == Constants.modes.intune)
145-
? (viewModel.isButtonVisible("OpenManagementApp") ? viewModel.createOpenManagementAppButton(type: .default, fontSize: 12) : nil)
146+
? (viewModel.isButtonVisible(Constants.Actions.HideStrings.openManagementApp) ? viewModel.createOpenManagementAppButton(type: .default, fontSize: 12) : nil)
146147
: nil,
147-
viewModel.isButtonVisible("GetSupport") ? ScButton(Constants.Actions.getSupport, fontSize: 12) { ActionHelpers.openSupportPage(url: appState.preferences.supportPageURL) } : nil,
148-
viewModel.isButtonVisible("GatherLogs") ? viewModel.createGatherLogsButton(fontSize: 12) : nil,
149-
viewModel.isButtonVisible("SoftwareUpdates") ? ScButton(
148+
viewModel.isButtonVisible(Constants.Actions.HideStrings.gatherLogs) ? viewModel.createGatherLogsButton(fontSize: 12) : nil,
149+
viewModel.isButtonVisible(Constants.Actions.HideStrings.softwareUpdate) ? ScButton(
150150
Constants.Actions.softwareUpdate,
151151
badgeNumber: appState.systemUpdateCache.updates.count,
152152
helpText: appState.systemUpdateCache.updates.joined(separator: "\n"),
153153
fontSize: 12)
154154
{ ActionHelpers.openSystemUpdates() } : nil,
155155
(appState.preferences.mode == Constants.modes.munki || appState.preferences.mode == Constants.modes.intune)
156-
? (viewModel.isButtonVisible("RestartIntuneAgent") ? viewModel.createRestartIntuneAgentButton(fontSize: 12) : nil)
156+
? (viewModel.isButtonVisible(Constants.Actions.HideStrings.restartIntuneAgent) ? viewModel.createRestartIntuneAgentButton(fontSize: 12) : nil)
157157
: nil
158158
].compactMap { $0 } // Remove nil values
159159

0 commit comments

Comments
 (0)