notifier

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2019 License: MIT Imports: 4 Imported by: 4

Documentation

Overview

Package notifier notifies through a channel whenever your machine is put to sleep or is woken up. Calling the Start() function will get you a channel on which you receive both "Sleep" and "Awake" activities.

Installation

The library can be installed using:

go get -u github.com/prashantgupta24/mac-sleep-notifier/notifier

Usage

The usage is as following:

 notifierCh := notifier.GetInstance().Start()

 for {
	select {
	case activity := <-notifierCh:
		if activity.Type == notifier.Awake {
			log.Println("machine awake")
		} else {
			if activity.Type == notifier.Sleep {
				log.Println("machine sleeping")
			}
		}
	}
 }

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanSleep

func CanSleep() C.int

func StartNotifier

func StartNotifier()

StartNotifier starts the internal notifier function which communicates with the C library.

func StopNotifier

func StopNotifier()

StopNotifier stops the internal notifier function which communicates with the C library.

func WillSleep

func WillSleep()

func WillWake

func WillWake()

Types

type Activity

type Activity struct {
	Type Type
}

Activity struct is used to hold the sleep and awake activity.

type Notifier

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

Notifier notifies about the sleep/wake events

func GetInstance

func GetInstance() *Notifier

GetInstance gets the singleton instance for the notifier

func (*Notifier) Quit

func (n *Notifier) Quit()

Quit the notifier

func (*Notifier) Start

func (n *Notifier) Start() chan *Activity

Start the notifier. It returns an Activity channel to listen for machine sleep/wake activities.

type Type

type Type string

Type determines if it is a sleep or an awake type activity

const (
	Sleep Type = "sleep"
	Awake Type = "awake"
)

The 2 types of activities

Jump to

Keyboard shortcuts

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