### Install beeep Go Module Source: https://context7.com/gen2brain/beeep/llms.txt Install the beeep library as a Go module dependency using the go get command. ```bash go get -u github.com/gen2brain/beeep ``` -------------------------------- ### Web (WASM/JS) Usage Example Source: https://context7.com/gen2brain/beeep/llms.txt Example demonstrating how to use Beeep's Notify and Beep functions in a Web (WASM/JS) environment. ```APIDOC ## Web (WASM/JS) Usage When targeting `GOOS=js GOARCH=wasm`, `Notify` uses the browser Notification API. In Chrome the call must originate from a user gesture and the page must be served over HTTPS. The function requests permission automatically if not yet granted. ### Example ```go //go:build js package main import ( "syscall/js" "github.com/gen2brain/beeep" ) func notifyOnClick() js.Func { return js.FuncOf(func(this js.Value, args []js.Value) interface{} { beeep.AppName = "My Web App" // icon can be a URL string or base64 data URI if err := beeep.Notify("Hello", "Notification from WASM!", "https://example.com/icon.png"); err != nil { println("notify error:", err.Error()) } if err := beeep.Beep(beeep.DefaultFreq, beeep.DefaultDuration); err != nil { println("beep error:", err.Error()) } return nil }) } func main() { js.Global().Get("document"). Call("getElementById", "notifyBtn"). Call("addEventListener", "click", notifyOnClick()) select {} // keep WASM alive } ``` ``` -------------------------------- ### Get Default Beep Frequency and Duration Source: https://context7.com/gen2brain/beeep/llms.txt Access DefaultFreq and DefaultDuration constants to use platform-appropriate default values for beeps without hard-coding. The output varies by operating system. ```go package main import ( "fmt" "github.com/gen2brain/beeep" ) func main() { fmt.Printf("Default freq: %.0f Hz, duration: %d ms\n", beeep.DefaultFreq, beeep.DefaultDuration) // Linux output: Default freq: 440 Hz, duration: 200 ms // Windows output: Default freq: 587 Hz, duration: 500 ms if err := beeep.Beep(beeep.DefaultFreq, beeep.DefaultDuration); err != nil { panic(err) } } ``` -------------------------------- ### Show Alert with Custom App Name and Icon Source: https://github.com/gen2brain/beeep/blob/master/README.md Displays an alert message with a specified title, body, and icon file path. The application name can be set globally using `beeep.AppName` before calling the alert function. ```go beeep.AppName = "My App Name" err := beeep.Alert("Title", "Message body", "testdata/warning.png") if err != nil { panic(err) } ``` -------------------------------- ### ErrUnsupported Sentinel Source: https://context7.com/gen2brain/beeep/llms.txt A package-level error returned when beeep is compiled for an unsupported OS. ```APIDOC ## ErrUnsupported ### Description `ErrUnsupported` is a package-level error returned (or wrapped in the returned error) when beeep is compiled for an OS it does not support. Check for it with `errors.Is`. ### Example ```go package main import ( "errors" "fmt" "github.com/gen2brain/beeep" ) func main() { if err := beeep.Beep(beeep.DefaultFreq, beeep.DefaultDuration); err != nil { if errors.Is(err, beeep.ErrUnsupported) { fmt.Println("beep is not supported on this platform, skipping") } else { fmt.Printf("unexpected error: %v\n", err) } } } ``` ``` -------------------------------- ### Play Default Beep Sound Source: https://github.com/gen2brain/beeep/blob/master/README.md Plays the default beep sound. Ensure the beeep package is imported. ```go err := beeep.Beep(beeep.DefaultFreq, beeep.DefaultDuration) if err != nil { panic(err) } ``` -------------------------------- ### Build without godbus/dbus on Linux Source: https://context7.com/gen2brain/beeep/llms.txt Build the project with the 'nodbus' tag to disable godbus/dbus and use notify-send on Linux. ```bash go build -tags nodbus ./... ``` -------------------------------- ### Send Desktop Notification with Audible Alert Source: https://context7.com/gen2brain/beeep/llms.txt Use Alert to combine a desktop notification with an audible signal. On Linux, it uses UrgencyCritical severity and plays a system bell. On macOS, it adds a default sound. On Windows, it calls MessageBeep. On the Web, it calls Notify and Beep sequentially. The icon parameter works the same as with Notify. ```go package main import ( "fmt" "github.com/gen2brain/beeep" ) func main() { beeep.AppName = "Disk Monitor" // Alert with a file-path icon err := beeep.Alert( "Low disk space", "Volume /data has less than 5 GB remaining.", "assets/warning.png", ) if err != nil { // Inspect the wrapped multi-error on Linux, e.g.: // "beeep: dbus: ; notify-send: ; kdialog: " fmt.Printf("alert failed: %v\n", err) } } ``` -------------------------------- ### Check for Unsupported OS Error Source: https://context7.com/gen2brain/beeep/llms.txt ErrUnsupported is a package-level error returned when beeep is compiled for an unsupported OS. Use errors.Is to check for this specific error. ```go package main import ( "errors" "fmt" "github.com/gen2brain/beeep" ) func main() { if err := beeep.Beep(beeep.DefaultFreq, beeep.DefaultDuration); err != nil { if errors.Is(err, beeep.ErrUnsupported) { fmt.Println("beep is not supported on this platform, skipping") } else { fmt.Printf("unexpected error: %v\n", err) } } } ``` -------------------------------- ### Send Desktop Notification with Icon Source: https://github.com/gen2brain/beeep/blob/master/README.md Sends a desktop notification with a title, message, and an embedded icon. The icon must be provided as a byte slice. Requires `//go:embed` directive for embedding. ```go //go:embed testdata/info.png var icon []byte err := beeep.Notify("Title", "Message body", icon) if err != nil { panic(err) } ``` -------------------------------- ### Alert Function Source: https://context7.com/gen2brain/beeep/llms.txt Sends a desktop notification with an audible alert. The icon parameter behaves identically to Notify. ```APIDOC ## Alert ### Description Combines a desktop notification with an audible signal. On Linux it sends the notification at `UrgencyCritical` severity and plays a system bell. On macOS it adds `sound name "default"` to the AppleScript command. On Windows it calls `MessageBeep` after the toast. On the Web it calls both `Notify` and `Beep` in sequence. ### Signature `Alert(title, message string, icon any) error` ### Example ```go package main import ( "fmt" "github.com/gen2brain/beeep" ) func main() { beeep.AppName = "Disk Monitor" // Alert with a file-path icon err := beeep.Alert( "Low disk space", "Volume /data has less than 5 GB remaining.", "assets/warning.png", ) if err != nil { // Inspect the wrapped multi-error on Linux, e.g.: // "beeep: dbus: ; notify-send: ; kdialog: " fmt.Printf("alert failed: %v\n", err) } } ``` ``` -------------------------------- ### Send Desktop Notifications with Icons Source: https://context7.com/gen2brain/beeep/llms.txt Send silent desktop notifications using the Notify function. The icon can be a file path, a stock icon name, or raw PNG data embedded as bytes. ```go package main import ( _ "embed" "fmt" "github.com/gen2brain/beeep" ) //go:embed assets/info.png var iconData []byte func main() { beeep.AppName = "CI Monitor" // Using embedded PNG bytes if err := beeep.Notify("Pipeline succeeded", "Branch main is green.", iconData); err != nil { fmt.Printf("notification failed: %v\n", err) return } // Using a file path if err := beeep.Notify("Pipeline failed", "Check the logs.", "assets/error.png"); err != nil { fmt.Printf("notification failed: %v\n", err) } } ``` -------------------------------- ### Notify - send a silent desktop notification Source: https://context7.com/gen2brain/beeep/llms.txt `Notify(title, message string, icon any) error` displays a desktop notification without any audible component. The `icon` parameter can be a file path, stock icon name, or raw PNG data. ```APIDOC ## Notify ### Description Sends a silent desktop notification to the user. It supports custom titles, messages, and icons. ### Signature `Notify(title, message string, icon any) error` ### Parameters - **title** (string) - The title of the notification. - **message** (string) - The main content of the notification. - **icon** (any) - The icon for the notification. Accepts a `string` file path (PNG), a stock icon name, or a `[]byte` slice containing raw PNG data. ### Usage ```go package main import ( _ "embed" "fmt" "github.com/gen2brain/beeep" ) //go:embed assets/info.png var iconData []byte func main() { beeep.AppName = "CI Monitor" // Using embedded PNG bytes if err := beeep.Notify("Pipeline succeeded", "Branch main is green.", iconData); err != nil { fmt.Printf("notification failed: %v\n", err) return } // Using a file path if err := beeep.Notify("Pipeline failed", "Check the logs.", "assets/error.png"); err != nil { fmt.Printf("notification failed: %v\n", err) } } ``` ``` -------------------------------- ### DefaultFreq and DefaultDuration - platform beep defaults Source: https://context7.com/gen2brain/beeep/llms.txt `DefaultFreq` is the frequency in Hz and `DefaultDuration` is the duration in milliseconds. Use these constants to produce the platform-appropriate default beep without hard-coding values. ```APIDOC ## DefaultFreq and DefaultDuration ### Description Constants representing the default frequency (Hz) and duration (ms) for platform beeps. Useful for invoking `Beep` with platform-appropriate defaults. ### Usage ```go package main import ( "fmt" "github.com/gen2brain/beeep" ) func main() { fmt.Printf("Default freq: %.0f Hz, duration: %d ms\n", beeep.DefaultFreq, beeep.DefaultDuration) // Linux output: Default freq: 440 Hz, duration: 200 ms // Windows output: Default freq: 587 Hz, duration: 500 ms if err := beeep.Beep(beeep.DefaultFreq, beeep.DefaultDuration); err != nil { panic(err) } } ``` ``` -------------------------------- ### Set Application Name for Notifications Source: https://context7.com/gen2brain/beeep/llms.txt Set the AppName package-level variable to customize the sender name displayed in notifications. This should be done once at application startup. ```go package main import "github.com/gen2brain/beeep" func main() { // Set once at startup; affects all subsequent Notify and Alert calls. beeep.AppName = "My Awesome App" if err := beeep.Notify("Build finished", "All tests passed.", "assets/success.png"); err != nil { panic(err) } } ``` -------------------------------- ### Emit Audible Beep Tones Source: https://context7.com/gen2brain/beeep/llms.txt Use the Beep function to play audible tones. It accepts frequency (Hz) and duration (ms). Platform-specific fallbacks are used if direct methods fail. ```go package main import ( "fmt" "github.com/gen2brain/beeep" ) func main() { // Default platform beep if err := beeep.Beep(beeep.DefaultFreq, beeep.DefaultDuration); err != nil { fmt.Printf("default beep failed: %v\n", err) } // Custom frequency and duration (Linux/Windows only; ignored on macOS/JS) if err := beeep.Beep(880.0, 400); err != nil { // On Linux: ErrUnsupported if pcspkr unavailable but Bell char is emitted anyway fmt.Printf("custom beep failed: %v\n", err) } } ``` -------------------------------- ### Beep - emit an audible tone from the speaker Source: https://context7.com/gen2brain/beeep/llms.txt `Beep(freq float64, duration int) error` plays a tone at the given frequency (Hz) for the given duration (milliseconds). It handles platform-specific implementations. ```APIDOC ## Beep ### Description Emits an audible tone from the speaker at a specified frequency and duration. This function abstracts platform-specific audio mechanisms. ### Signature `Beep(freq float64, duration int) error` ### Parameters - **freq** (float64) - The frequency of the tone in Hertz (Hz). - **duration** (int) - The duration of the tone in milliseconds (ms). ### Usage ```go package main import ( "fmt" "github.com/gen2brain/beeep" ) func main() { // Default platform beep if err := beeep.Beep(beeep.DefaultFreq, beeep.DefaultDuration); err != nil { fmt.Printf("default beep failed: %v\n", err) } // Custom frequency and duration (Linux/Windows only; ignored on macOS/JS) if err := beeep.Beep(880.0, 400); err != nil { // On Linux: ErrUnsupported if pcspkr unavailable but Bell char is emitted anyway fmt.Printf("custom beep failed: %v\n", err) } } ``` ``` -------------------------------- ### Web (WASM/JS) Notification and Beep Source: https://context7.com/gen2brain/beeep/llms.txt When targeting GOOS=js GOARCH=wasm, Notify uses the browser Notification API. In Chrome, the call must originate from a user gesture and the page must be served over HTTPS. The function requests permission automatically if not yet granted. The icon can be a URL string or a base64 data URI. ```go //go:build js package main import ( "syscall/js" "github.com/gen2brain/beeep" ) func notifyOnClick() js.Func { return js.FuncOf(func(this js.Value, args []js.Value) interface{} { beeep.AppName = "My Web App" // icon can be a URL string or base64 data URI if err := beeep.Notify("Hello", "Notification from WASM!", "https://example.com/icon.png"); err != nil { println("notify error:", err.Error()) } if err := beeep.Beep(beeep.DefaultFreq, beeep.DefaultDuration); err != nil { println("beep error:", err.Error()) } return nil }) } func main() { js.Global().Get("document"). Call("getElementById", "notifyBtn"). Call("addEventListener", "click", notifyOnClick()) select {} // keep WASM alive } ``` -------------------------------- ### AppName - application display name for notifications Source: https://context7.com/gen2brain/beeep/llms.txt `AppName` sets the sender name shown in the notification. It defaults to `"DefaultAppName"` and should be set to the human-readable name of the calling application before issuing any notifications. ```APIDOC ## AppName ### Description Sets the sender name shown in the notification. Defaults to `"DefaultAppName"`. Should be set to the human-readable name of the calling application before issuing any notifications. ### Usage ```go package main import "github.com/gen2brain/beeep" func main() { // Set once at startup; affects all subsequent Notify and Alert calls. beeep.AppName = "My Awesome App" if err := beeep.Notify("Build finished", "All tests passed.", "assets/success.png"); err != nil { panic(err) } } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.