desktop

package
v0.209.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package desktop shows a notification on the machine's OWN desktop — the channel a server uses to reach a person who is neither watching the console nor a chat client (an approval parked for hours, a session waiting for a reply).

It is split in two halves:

  • Notifier is the platform popup: one implementation per GOOS (notifier_<goos>.go), all of them a short child process (PowerShell toast / osascript / notify-send), so nothing is linked in and a missing tool is a skip, not a crash.
  • Dispatcher is the policy: same-type notifications arriving inside a window coalesce into ONE popup ("3 个 job 等待批准"), and an environment that can never show a popup (Windows session 0, no desktop session, tool missing) is reported once per cause instead of once per event.

The package imports only internal/procattr + internal/util, so the job service can drive it without a cycle, and tests can swap the Notifier (no real popup).

Index

Constants

View Source
const DefaultMergeWindow = 10 * time.Second

DefaultMergeWindow is the coalescing window used when the config sets none: several approvals arriving together (a plan handing five items to a person at once) are one popup, not five.

Variables

This section is empty.

Functions

func PlatformSupported added in v0.201.0

func PlatformSupported() bool

PlatformSupported reports whether this build can pop a desktop notification at all.

Types

type Dispatcher

type Dispatcher struct {
	// contains filtered or unexported fields
}

Dispatcher queues notifications, merges same-type ones inside its window and hands each merged group to the Notifier. It is safe for concurrent use.

func NewDispatcher

func NewDispatcher(notifier Notifier, window time.Duration) *Dispatcher

NewDispatcher builds a dispatcher around notifier. window <= 0 pops each notification immediately (no merging) — on the PUSHING goroutine, so a caller on a hot path should keep the window on (the default) and let the timer thread show it.

func (*Dispatcher) Close

func (d *Dispatcher) Close()

Close flushes what is queued and stops accepting new notifications. It is what shutdown calls so a notification queued a moment before exit is not lost.

func (*Dispatcher) Flush

func (d *Dispatcher) Flush()

Flush shows everything queued right now.

func (*Dispatcher) Push

func (d *Dispatcher) Push(n Notification)

Push queues n. With a window it is shown when the window closes (merged with the same-type notifications queued meanwhile); without one it is shown at once.

type Notification

type Notification struct {
	EventType string
	Title     string
	Text      string
	Link      string
	At        int64
	// Lang is the language of the dispatcher's own words (merged-popup titles, the
	// toast's open button); Title and Text arrive already in theirs. "" = i18n.Default.
	Lang i18n.Lang
}

Notification is one system notification: Title is the headline, Text the body and Link the console page a click opens (empty when the event has none).

type Notifier

type Notifier interface {
	Show(n Notification) error
}

Notifier shows ONE notification on the local desktop. A platform that cannot show it returns *SkipError; any other error is a real failure (the popup command ran and failed).

func NewSystemNotifier

func NewSystemNotifier() Notifier

NewSystemNotifier returns the Linux implementation: `notify-send` (libnotify), the desktop's own notification daemon. A host without it skips — the channel is optional and must never turn a missing tool into an error the job path cares about.

type SkipError

type SkipError struct{ Reason string }

SkipError reports that a notification was NOT shown for an ENVIRONMENT reason that retrying cannot change: no interactive desktop (a Windows service in session 0), no desktop session, or the platform's notification tool is not installed. Reason is a stable key, so the dispatcher records each cause ONCE rather than on every event.

func (*SkipError) Error

func (e *SkipError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL