Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cabbie.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build windows
// +build windows

// The cabbie binary is used to manage and report Windows updates.
Expand Down Expand Up @@ -397,7 +398,7 @@ func runMainLoop() error {
)

if config.NotifyAvailable == 1 {
if err := notification.NewNotification(cablib.SvcName, notification.NewAvailableUpdateMessage(), "availableUpdates"); err != nil {
if err := notification.NewAvailableUpdateMessage().Push(); err != nil {
elog.Error(cablib.EvtErrNotifications, fmt.Sprintf("Failed to create notification:\n%v", err))
}
}
Expand Down
2 changes: 1 addition & 1 deletion cablib/cablib.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func cleanRebootValue() error {
func SystemReboot(t time.Time) error {
time.Sleep(time.Until(t))

notification.NewNotification(SvcName, notification.RebootPopup(2), "rebootPending")
notification.RebootPopup(2).Push()

time.Sleep(2 * time.Minute)

Expand Down
4 changes: 2 additions & 2 deletions install.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ func (i *installCmd) criteria() (string, []string) {
func installingMessage() {
elog.Info(cablib.EvtInstall, "Cabbie is installing new updates.")

if err := notification.NewNotification(cablib.SvcName, notification.NewInstallingMessage(), "installingUpdates"); err != nil {
if err := notification.NewInstallingMessage().Push(); err != nil {
elog.Error(cablib.EvtErrNotifications, fmt.Sprintf("Failed to create notification:\n%v", err))
}
}

func rebootMessage(seconds int) {
elog.Info(cablib.EvtInstallSuccess, "Updates have been installed, please reboot to complete the installation...")

if err := notification.NewNotification(cablib.SvcName, notification.NewRebootMessage(seconds), "rebootPending"); err != nil {
if err := notification.NewRebootMessage(seconds).Push(); err != nil {
elog.Error(cablib.EvtErrNotifications, fmt.Sprintf("Failed to create notification:\n%v", err))
}
}
Expand Down
44 changes: 33 additions & 11 deletions notification/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,57 @@ package notification
import (
"fmt"
"time"

"gopkg.in/toast.v1"
)

var (
appID = "Cabbie"
)

// NewRebootMessage returns a standard reboot message.
func NewRebootMessage(seconds int) string {
func NewRebootMessage(seconds int) Notification {
t := time.Now().Add(time.Second * time.Duration(seconds)).Format(time.UnixDate)
return fmt.Sprintf("Reboot now to finish installing updates. Your machine will auto reboot at %s", t)
return &toast.Notification{
AppID: appID,
Title: "Reboot Your Machine",
Message: fmt.Sprintf("Reboot now to finish installing updates. Your machine will auto reboot at %s.", t),
}
}

// RebootPopup returns a reboot warning popup message.
func RebootPopup(minutes int) string {
return fmt.Sprintf("To finish installing the newest updates, your machine will auto reboot in %d minutes", minutes)
func RebootPopup(minutes int) Notification {
return &toast.Notification{
AppID: appID,
Title: "Force Reboot Soon",
Message: fmt.Sprintf("To finish installing the newest updates, your machine will auto reboot in %d minutes.", minutes),
}
}

// NewAvailableUpdateMessage returns an available updates message.
func NewAvailableUpdateMessage() string {
return "New Windows updates are now available. Please install at your earliest convenience"
func NewAvailableUpdateMessage() Notification {
return &toast.Notification{
AppID: appID,
Title: "Updates Available",
Message: "New Windows updates are now available. Please install at your earliest convenience.",
}
}

// NewInstallingMessage returns an installing updates message.
func NewInstallingMessage() string {
return "Cabbie is installing new updates."
func NewInstallingMessage() Notification {
return &toast.Notification{
AppID: appID,
Title: "Installing Updates",
Message: "Cabbie is installing new updates.",
}
}

// CleanNotifications deletes any active Cabbie notification messages.
func CleanNotifications(name string) error {
return nil
}

// NewNotification posts a notification message.
func NewNotification(service string, message string, id string) error {
return nil
// Notification defines a type notification for a cabbie event.
type Notification interface {
Push() error
}