Skip to content

Commit a42f3cb

Browse files
committed
redo SMAppService log method
1 parent f13a697 commit a42f3cb

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

Nudge/Utilities/Utils.swift

+13-8
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,7 @@ struct SubProcessUtilities {
12831283

12841284
struct SMAppManager {
12851285
private func handleLegacyLaunchAgent(passedThroughCLI: Bool, action: String) {
1286-
logOrPrint("Legacy Nudge LaunchAgent currently loaded. Please disable this agent before attempting to \(action) modern agent.", passedThroughCLI: passedThroughCLI, exitCode: 1)
1286+
logOrPrint("Legacy Nudge LaunchAgent currently loaded. Please disable this agent before attempting to \(action) modern agent.", error: false, passedThroughCLI: passedThroughCLI, exitCode: 1)
12871287
}
12881288

12891289
@available(macOS 13.0, *)
@@ -1299,29 +1299,34 @@ struct SMAppManager {
12991299

13001300
switch appServiceStatus {
13011301
case .enabled:
1302-
logOrPrint("Nudge LaunchAgent is currently registered and enabled", passedThroughCLI: passedThroughCLI, exitCode: 0)
1302+
logOrPrint("Nudge LaunchAgent is currently registered and enabled", error: false, passedThroughCLI: passedThroughCLI, exitCode: 0)
13031303
default:
13041304
registerOrUnregister(appService: appService, passedThroughCLI: passedThroughCLI, action: "register")
13051305
}
13061306
}
13071307

1308-
private func logOrPrint(_ message: String, passedThroughCLI: Bool, exitCode: Int? = nil) {
1308+
private func logOrPrint(_ message: String, error: Bool, passedThroughCLI: Bool, exitCode: Int? = nil) {
13091309
if passedThroughCLI {
13101310
print(message)
13111311
if let code = exitCode { exit(Int32(code)) }
13121312
} else {
1313-
LogManager.notice("\(message)", logger: uiLog)
1313+
if error {
1314+
LogManager.error("\(message)", logger: uiLog)
1315+
} else {
1316+
LogManager.debug("\(message)", logger: uiLog)
1317+
}
1318+
13141319
}
13151320
}
13161321

13171322
@available(macOS 13.0, *)
13181323
private func registerOrUnregister(appService: SMAppService, passedThroughCLI: Bool, action: String) {
13191324
do {
1320-
logOrPrint("\(action.capitalized)ing Nudge LaunchAgent", passedThroughCLI: passedThroughCLI)
1325+
logOrPrint("\(action.capitalized)ing Nudge LaunchAgent", error: false, passedThroughCLI: passedThroughCLI)
13211326
try action == "register" ? appService.register() : appService.unregister()
1322-
logOrPrint("Successfully \(action)ed Nudge LaunchAgent", passedThroughCLI: passedThroughCLI, exitCode: 0)
1327+
logOrPrint("Successfully \(action)ed Nudge LaunchAgent", error: false, passedThroughCLI: passedThroughCLI, exitCode: 0)
13231328
} catch {
1324-
logOrPrint("Failed to \(action) Nudge LaunchAgent", passedThroughCLI: passedThroughCLI, exitCode: 1)
1329+
logOrPrint("Failed to \(action) Nudge LaunchAgent", error: true, passedThroughCLI: passedThroughCLI, exitCode: 1)
13251330
}
13261331
}
13271332

@@ -1331,7 +1336,7 @@ struct SMAppManager {
13311336

13321337
switch appServiceStatus {
13331338
case .notFound, .notRegistered:
1334-
logOrPrint("Nudge LaunchAgent has never been registered or is not currently registered", passedThroughCLI: passedThroughCLI, exitCode: 0)
1339+
logOrPrint("Nudge LaunchAgent has never been registered or is not currently registered", error: false, passedThroughCLI: passedThroughCLI, exitCode: 0)
13351340
default:
13361341
registerOrUnregister(appService: appService, passedThroughCLI: passedThroughCLI, action: "unregister")
13371342
}

0 commit comments

Comments
 (0)