histfile

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: GPL-3.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package histfile reads and changes the history file that notifyd keeps of what this desktop received, for the daemon and the history window alike.

Index

Constants

View Source
const (
	MaxEntries = 500
	MaxAge     = 30 * 24 * time.Hour
)

The history keeps at most MaxEntries, none older than MaxAge. The server keeps no content, so this is the only copy.

Variables

This section is empty.

Functions

func Clear

func Clear(path string) error

Clear removes the history file; a missing one is already clear. Callers hold the lock.

func Delete

func Delete(path string, now time.Time, ids ...string) (int, error)

Delete removes the entries with the given IDs and reports how many it found. Like a compaction, it also drops what Read would not return. Callers hold the lock.

func Invisible

func Invisible(r rune) bool

Invisible reports whether r is a control or format character.

func Path

func Path() (string, error)

Path is $NOTIFYD_HISTORY, or notifyd-history.jsonl in $XDG_STATE_HOME/notifier (default ~/.local/state/notifier).

func Printable

func Printable(s string, multiline bool) string

Printable replaces control and format characters (terminal escapes, bidi overrides, zero-width characters) with U+FFFD, keeping tabs, and newlines only when multiline. Senders choose the text.

func WithLock

func WithLock(path string, fn func() error) error

WithLock runs fn holding an exclusive lock shared by every process that changes the history: the running daemon appends while `notifyd history clear`, pair, unpair, or the history window may run in another. The lock file stays; removing it would let two processes hold different locks.

func Write

func Write(path string, entries []Entry) error

Write replaces the file at path with entries, given newest first as Read returns them. Callers hold the lock.

func WriteFileAtomic

func WriteFileAtomic(path string, data []byte, pattern string) error

WriteFileAtomic replaces path with data, readable only by its owner: a temporary file (named by pattern) is synced, then renamed over it. A symlink is written through rather than replaced.

Types

type Entry

type Entry struct {
	ID         string `json:"id"`
	Title      string `json:"title"`
	Body       string `json:"body,omitempty"`
	Priority   string `json:"priority"`
	SentAt     int64  `json:"sent_at"`
	ReceivedAt int64  `json:"received_at"`
	Channel    string `json:"channel,omitempty"`
	ChannelID  string `json:"channel_id,omitempty"`
	Reply      *Reply `json:"reply,omitempty"`
}

Entry is one received message. Times are Unix seconds.

func Read

func Read(path string, now time.Time) ([]Entry, error)

Read returns the entries at path, newest first: each message once (as first received), none older than MaxAge, at most MaxEntries. Lines it cannot parse are skipped. A missing file is an empty history.

func (Entry) OnDefaultChannel

func (e Entry) OnDefaultChannel() bool

OnDefaultChannel reports whether e went to the user's default channel, which clients leave unnamed.

type Reply

type Reply struct {
	Options   []string `json:"options"`
	Key       string   `json:"key"`
	ExpiresAt int64    `json:"expires_at"`
}

Reply is a question's answers, the one-time key to seal one under, and when the question closes (Unix seconds); only devices that may answer get it.

Jump to

Keyboard shortcuts

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