@@ -638,7 +638,6 @@ extension Ghostty {
638638 case GHOSTTY_ACTION_PRESENT_TERMINAL:
639639 return presentTerminal ( app, target: target)
640640
641-
642641 case GHOSTTY_ACTION_TOGGLE_TAB_OVERVIEW:
643642 fallthrough
644643 case GHOSTTY_ACTION_TOGGLE_WINDOW_DECORATIONS:
@@ -1403,15 +1402,22 @@ extension Ghostty {
14031402 guard let surface = target. target. surface else { return }
14041403 guard let surfaceView = self . surfaceView ( from: surface) else { return }
14051404
1406- guard let appState = ( NSApplication . shared. delegate as? AppDelegate ) ? . ghostty else { return }
1407- let config = appState. config
1405+ // Determine if we even care about command finish notifications
1406+ guard let config = ( NSApplication . shared. delegate as? AppDelegate ) ? . ghostty. config else { return }
1407+ switch config. notifyOnCommandFinish {
1408+ case . never:
1409+ return
1410+
1411+ case . unfocused:
1412+ if surfaceView. focused { return }
14081413
1409- let mode = config . notifyOnCommandFinish
1410- if mode == . never { return }
1411- if mode == . unfocused && surfaceView . focused { return }
1414+ case . always :
1415+ break
1416+ }
14121417
1413- let durationMs = v. duration / 1_000_000
1414- if durationMs < config. notifyOnCommandFinishAfter { return }
1418+ // Determine if the command was slow enough
1419+ let duration = Duration . nanoseconds ( v. duration)
1420+ guard Duration . nanoseconds ( v. duration) >= config. notifyOnCommandFinishAfter else { return }
14151421
14161422 let actions = config. notifyOnCommandFinishAction
14171423
@@ -1433,7 +1439,13 @@ extension Ghostty {
14331439 }
14341440
14351441 let body : String
1436- let formattedDuration = Self . formatDuration ( ns: v. duration)
1442+ let formattedDuration = duration. formatted (
1443+ . units(
1444+ allowed: [ . hours, . minutes, . seconds, . milliseconds] ,
1445+ width: . abbreviated,
1446+ fractionalPart: . hide
1447+ )
1448+ )
14371449 if v. exit_code < 0 {
14381450 body = " Command took \( formattedDuration) . "
14391451 } else {
@@ -1448,26 +1460,6 @@ extension Ghostty {
14481460 }
14491461 }
14501462
1451- private static func formatDuration( ns: UInt64 ) -> String {
1452- let totalSeconds = ns / 1_000_000_000
1453- let ms = ( ns / 1_000_000 ) % 1000
1454-
1455- if totalSeconds == 0 {
1456- return " \( ms) ms "
1457- }
1458-
1459- let seconds = totalSeconds % 60
1460- let minutes = ( totalSeconds / 60 ) % 60
1461- let hours = totalSeconds / 3600
1462-
1463- var parts : [ String ] = [ ]
1464- if hours > 0 { parts. append ( " \( hours) h " ) }
1465- if minutes > 0 { parts. append ( " \( minutes) m " ) }
1466- if seconds > 0 || ( hours == 0 && minutes == 0 ) { parts. append ( " \( seconds) s " ) }
1467-
1468- return parts. joined ( separator: " " )
1469- }
1470-
14711463 private static func toggleFloatWindow(
14721464 _ app: ghostty_app_t ,
14731465 target: ghostty_target_s ,
0 commit comments