notifier

package module
v0.0.0-...-5eac216 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2024 License: BSD-3-Clause Imports: 21 Imported by: 0

README

notifier

The noteserver is a program that runs on a local macOS machine and exposes various useful endpoints via JSON-RPC 2.0. Combined with SSH forwarding, it can be used to integrate notifications, clipboard, and other useful bits with a terminal session on a remote system.

Warning: This is by no means a polished product; this is just something I find useful and have tweaked as needed to make things work.

Documentation

Overview

Package notifier contains common data structures for notifications.

Index

Constants

View Source
const UserCancelled = jrpc2.Code(-29999)

UserCancelled is the code returned when a user cancels a text request.

Variables

View Source
var ErrNotApplicable = errors.New("plugin is not applicable")

ErrNotApplicable is returned by a plugin's Init function if the plugin cannot be used with the given configuration.

View Source
var ResourceNotFound = jrpc2.Code(-29998)

ResourceNotFound is returned when a requested resource is not found.

Functions

func Columns

func Columns(w io.Writer, write func(io.Writer))

Columns calls write with a tabwriter directed to w, and flushes its output when write returns.

func Dial

Dial connects to the flag-selected JSON-RPC server and returns a context and a client ready for use. The caller is responsible for closing the client.

func LoadConfig

func LoadConfig(path string, cfg *Config) error

LoadConfig loads a configuration from the file at path into *cfg.

func PluginAssigner

func PluginAssigner(cfg *Config) jrpc2.Assigner

PluginAssigner returns a jrpc2.Assigner that exports the methods of all the registered plugins.

func PromptForText

func PromptForText(ctx context.Context, req *TextRequest) (string, error)

PromptForText requests a string of text from the user.

func RegisterFlags

func RegisterFlags()

RegisterFlags installs a standard -server flag in the default flagset. This function should be called during init in a client main package.

func RegisterPlugin

func RegisterPlugin(name string, p Plugin)

RegisterPlugin registers a plugin. This function will panic if the same name is registered multiple times.

func SetSystemClipboard

func SetSystemClipboard(ctx context.Context, data []byte) error

SetSystemClipboard sets the contents of the system clipboard to data.

Types

type ClipClearRequest

type ClipClearRequest struct {
	Tag string `json:"tag,omitempty"` // the tag to clear or remove
}

A ClipClearRequest is sent to clear the contents of the clipboard.

func (ClipClearRequest) DisallowUnknownFields

func (ClipClearRequest) DisallowUnknownFields()

type ClipGetRequest

type ClipGetRequest struct {
	Tag      string `json:"tag,omitempty"`      // the tag to assign the data
	Save     string `json:"save,omitempty"`     // save active clip to this tag
	Activate bool   `json:"activate,omitempty"` // make this clip active
}

A ClipGetRequest is sent to query the contents of the clipboard.

func (ClipGetRequest) DisallowUnknownFields

func (ClipGetRequest) DisallowUnknownFields()

type ClipSetRequest

type ClipSetRequest struct {
	Data       []byte `json:"data"`           // the data to be stored
	Tag        string `json:"tag,omitempty"`  // the tag to assign the data
	Save       string `json:"save,omitempty"` // save active clip to this tag
	AllowEmpty bool   `json:"allowEmpty"`     // allow data to be empty
}

A ClipSetRequest is sent to update the contents of the clipboard.

func (ClipSetRequest) DisallowUnknownFields

func (ClipSetRequest) DisallowUnknownFields()

type Config

type Config struct {
	Address  string
	DebugLog bool `yaml:"debugLog"`

	// Settings for the clipboard service.
	Clip struct {
		SaveFile string `yaml:"saveFile"`
	}

	// Settings for the editor service.
	Edit struct {
		Command  string
		TouchNew bool `yaml:"touchNew"`
	}

	// Settings for the notification service.
	Notify struct {
		Sound string
		Voice string
	}
}

Config stores settings for the various notifier services.

func (*Config) EditFile

func (c *Config) EditFile(ctx context.Context, path string) error

EditFile edits a file using the editor specified by c.

func (*Config) EditFileCmd

func (c *Config) EditFileCmd(ctx context.Context, path string) (*exec.Cmd, error)

EditFileCmd returns a command to edit the specified file using the editor specified by c. The caller must run or start the command.

type EditRequest

type EditRequest struct {
	// The base name of the file to edit.
	Name string `json:"name,omitempty"`

	// The current contents of the file.
	Content []byte `json:"content,omitempty"`
}

An EditRequest is a request to edit the contents of a file.

func (EditRequest) DisallowUnknownFields

func (EditRequest) DisallowUnknownFields()

type Plugin

type Plugin interface {
	// Init is called once before any other methods of the plugin are used, with
	// a pointer to the shared configuration.
	Init(*Config) error

	// Update may be called periodically to give the plugin an opportunity to
	// update its state.
	Update() error

	// Assigner returns an assigner for handlers.
	Assigner() handler.Map
}

A Plugin exposes a set of methods.

type PostRequest

type PostRequest struct {
	Title    string        `json:"title,omitempty"`
	Subtitle string        `json:"subtitle,omitempty"`
	Body     string        `json:"body,omitempty"`
	Audible  bool          `json:"audible,omitempty"`
	After    time.Duration `json:"after,omitempty"`
}

A PostRequest is a request to post a notification to the user.

func (PostRequest) DisallowUnknownFields

func (PostRequest) DisallowUnknownFields()

type SayRequest

type SayRequest struct {
	Text  string        `json:"text"`
	Voice string        `json:"voice,omitempty"`
	After time.Duration `json:"after,omitempty"`
}

A SayRequest is a request to speak a notification to the user.

func (SayRequest) DisallowUnknownFields

func (SayRequest) DisallowUnknownFields()

type TextRequest

type TextRequest struct {
	Prompt  string `json:"prompt,omitempty"`
	Default string `json:"default,omitempty"`
	Hide    bool   `json:"hide,omitempty"`
}

A TextRequest is a request to read a string from the user.

func (TextRequest) DisallowUnknownFields

func (TextRequest) DisallowUnknownFields()

Directories

Path Synopsis
Program clipset sends a clipboard set request to a noteserver.
Program clipset sends a clipboard set request to a noteserver.
Program noteserver implements a server for posting notifications.
Program noteserver implements a server for posting notifications.
clipper
Package clipper exports a service that manages the system clipboard, and provides named ancillary clipboard storage.
Package clipper exports a service that manages the system clipboard, and provides named ancillary clipboard storage.
poster
Package poster implements a service that posts notifications to the user.
Package poster implements a service that posts notifications to the user.
user
Package user exports a service to read input from the user.
Package user exports a service to read input from the user.
Program postnote sends a notification request to a noteserver.
Program postnote sends a notification request to a noteserver.
Program useredit requests editing of a file.
Program useredit requests editing of a file.
Program usertext requests text from the user.
Program usertext requests text from the user.
Program voicenote sends a voice notification request to a noteserver.
Program voicenote sends a voice notification request to a noteserver.

Jump to

Keyboard shortcuts

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