Skip to content

Commit 9b3b8f1

Browse files
feat: background session disconnect notifications
Show OS notification when a session disconnects or errors while the user is viewing a different tab. Covers SSH/Telnet closed, serial errors, and connection failures. Permission is requested once on startup.
1 parent 5adbff0 commit 9b3b8f1

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

src/renderer/src/App.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ export default function App(): JSX.Element {
3232
version: string
3333
} | null>(null)
3434

35+
// Request notification permission on startup
36+
useEffect(() => {
37+
if (Notification.permission === 'default') {
38+
Notification.requestPermission()
39+
}
40+
}, [])
41+
3542
// Check master password on startup
3643
useEffect(() => {
3744
window.api.auth.hasMasterPassword().then((has) => {

src/renderer/src/components/terminal/TerminalTab.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,10 @@ export function TerminalTab({ session }: Props): JSX.Element {
676676
const msg = (err as { error?: string })?.error || 'Connection failed'
677677
setSessionStatus(session.id, 'error', msg)
678678
termRef.current?.write(`\r\n\x1b[31mError: ${msg}\x1b[0m\r\n`)
679+
notifyIfBackground(
680+
`${session.connection.name} failed`,
681+
msg
682+
)
679683
if (session.connection.autoReconnect) scheduleReconnect()
680684
} finally {
681685
connectingRef.current = false
@@ -738,10 +742,22 @@ export function TerminalTab({ session }: Props): JSX.Element {
738742
}
739743
}
740744

745+
const notifyIfBackground = (title: string, body: string) => {
746+
const { activeSessionId } = useAppStore.getState()
747+
if (session.id === activeSessionId) return
748+
if (Notification.permission === 'granted') {
749+
new Notification(title, { body, silent: false })
750+
}
751+
}
752+
741753
const onClosed = (sid: string) => {
742754
if (sid !== session.id) return
743755
setSessionStatus(session.id, 'disconnected')
744756
termRef.current?.write('\r\n\x1b[33mConnection closed\x1b[0m\r\n')
757+
notifyIfBackground(
758+
`${session.connection.name} disconnected`,
759+
`${session.connection.host} · Connection closed`
760+
)
745761
if (!cancelled && session.connection.autoReconnect) scheduleReconnect()
746762
}
747763

@@ -760,6 +776,10 @@ export function TerminalTab({ session }: Props): JSX.Element {
760776
if (sid !== session.id) return
761777
setSessionStatus(session.id, 'error', err)
762778
termRef.current?.write(`\r\n\x1b[31mSerial error: ${err}\x1b[0m\r\n`)
779+
notifyIfBackground(
780+
`${session.connection.name} error`,
781+
err
782+
)
763783
if (!cancelled && session.connection.autoReconnect) scheduleReconnect()
764784
})
765785
} else {

0 commit comments

Comments
 (0)