winpush

package module
v0.0.0-...-1f4064c Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2025 License: MIT Imports: 7 Imported by: 0

README

winpush - Windows Toast Notifications for Go

Go Reference License

A Go package for creating Windows Toast notifications without visible PowerShell windows.

Features

  • 🛠️ Customizable notifications (title, message, icon)
  • 🔘 Action buttons support
  • ⏱️ Duration control
  • 🔗 Activation arguments for click handling
  • 🖼️ Adaptive templates for Windows 10/11
  • 🕶️ Silent execution (no pop-up windows)

Requirements

  • Windows 10/11
  • Go 1.16+
  • Notifications enabled for the app in Windows settings
  • PowerShell 5.0+ (usually pre-installed)

Installation

go get github.com/yourusername/winpush

Quick Start

Basic Notification
package main

import "github.com/yourusername/winpush"

func main() {
    notifier := winpush.Notificator{
        Title:   "Hello World",
        Message: "This is a toast notification",
    }
    err := notifier.Push()
    if err != nil {
        panic(err)
    }
}
Notification with Actions
notifier := winpush.Notificator{
    Title:   "Download Complete",
    Message: "file.zip has been downloaded successfully",
    Icon:    "C:\\path\\to\\icon.png",
    Duration: "long",
    Actions: []winpush.Actions{
        {
            Content:   "Open",
            Arguments: "open:file.zip",
        },
        {
            Content:   "Show in folder",
            Arguments: "explorer:C:\\downloads",
            Icon:      "folder.ico",
        },
    },
}
err := notifier.Push()

Configuration

Notificator Structure
type Notificator struct {
    AppID               string      // Application ID
    Title               string      // Main title
    Subtitle            string      // Subtitle
    Message             string      // Notification body
    Icon                string      // Path to icon (PNG, JPG, ICO)
    Actions             []Actions   // List of actions
    ActivationType      string      // Activation type ("protocol" by default)
    ActivationArguments string      // Activation arguments
    Duration            string      // Duration: "short" (default) or "long"
}
Actions Structure
type Actions struct {
    Content        string // Button text
    Arguments      string // Action arguments
    Icon           string // Button icon (optional)
    ActivationType string // Activation type ("protocol")
    Placement      string // Position ("contextMenu")
}

Error Handling

Possible errors:

ErrExecuteToast = errors.New("winPush: error execute toast")
ErrCreateFile   = errors.New("winPush: error create file for xml push")
ErrReadXML      = errors.New("winPush: error read xml for push")

Example error handling:

err := notifier.Push()
if err != nil {
    switch {
    case errors.Is(err, winpush.ErrCreateFile):
        log.Fatal("Failed to create temp file")
    case errors.Is(err, winpush.ErrExecuteToast):
        log.Fatal("Failed to execute PowerShell script")
    default:
        log.Fatal("Unknown error:", err)
    }
}

Documentation

Overview

Package winpush provides Windows Toast Notifications for Go applications.

Features:

  • Customizable toast notifications
  • Action buttons support
  • Adaptive templates
  • Silent execution (no PowerShell window)

Basic usage:

notifier := winpush.Notificator{
    Title:   "Hello",
    Message: "World",
}
err := notifier.Push()

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrExecuteToast error = errors.New("winPush: error execute toast")
	ErrCreateFile   error = errors.New("winPush: error create file for xml push")
	ErrReadXML      error = errors.New("winPush: error read xml for push")
)

Functions

This section is empty.

Types

type Actions

type Actions struct {
	Content        string
	Arguments      string
	Icon           string
	ActivationType string
	Placement      string
}

type Notificator

type Notificator struct {
	AppID               string
	Title               string
	Subtitle            string
	Message             string
	Icon                string
	Actions             []Actions
	ActivationType      string
	ActivationArguments string
	Duration            string
}

func (*Notificator) Push

func (n *Notificator) Push() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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