session

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 7 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 session is the desktop app's connection to notesd (docs/design/app.md#data, plan 0009): it dials the private socket as the local caller, says hello, subscribes to events from the sequence it last saw, dials again each second when the connection drops, and keeps the open notes' documents, to which it routes note.changed, note.moved and note.removed. It imports no UI: the window gives it an Env that runs work on its thread.

Index

Constants

View Source
const ClientName = "Frostnotes"

ClientName is what the app tells notesd in rpc.hello, and the author of its versions.

View Source
const RetryDelay = time.Second

RetryDelay is how long the session waits before it dials again, as the web app's.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dialer

type Dialer func(ctx context.Context) (*api.Client, *api.Hello, error)

Dialer connects to notesd and completes rpc.hello.

func SocketDialer

func SocketDialer(path string) Dialer

SocketDialer dials notesd's socket at path.

type Session

type Session struct {

	// OnEvent sees every event after the session has routed note events
	// to the open documents: the stores follow vaults, files and sync.
	OnEvent func(seq int64, ev api.Event)
	// OnResync is called when notesd could not replay the events since
	// the stored sequence: the stores read everything again.
	OnResync func()
	// OnSeq is called with each new event sequence, for the app to keep
	// as its resume point (ADR-0021).
	OnSeq func(seq int64)
	// contains filtered or unexported fields
}

Session is the app's connection to notesd. Its methods run on the UI thread.

func New

func New(env notes.Env, dial Dialer, seq int64) *Session

New makes a session that resumes events after seq (0 for live events only). Start connects it.

func (*Session) Client

func (s *Session) Client() *api.Client

Client is the connection, nil while not connected.

func (*Session) Close

func (s *Session) Close()

Close drops the connection and stops dialing.

func (*Session) Flush

func (s *Session) Flush(done func())

Flush saves every open note and calls done once none has text unsaved (or a failed save waits to retry).

func (*Session) Hello

func (s *Session) Hello() *api.Hello

Hello is notesd's answer to rpc.hello, nil while not connected.

func (*Session) Notes

func (s *Session) Notes() notes.NoteAPI

Notes is notesd's note domain, nil while not connected.

func (*Session) OnChange

func (s *Session) OnChange(fn func())

OnChange calls fn on the UI thread when the state changes.

func (*Session) Open

func (s *Session) Open(vault int64, path string) *notes.Document

Open returns the document of a note, shared by every tab that shows it, reading it the first time. Release gives it back.

func (*Session) Reason

func (s *Session) Reason() string

func (*Session) Release

func (s *Session) Release(d *notes.Document)

Release gives back a document Open returned; the last release saves what is unsaved, then forgets it. A save that failed keeps the document until a retry lands it, so closing a tab loses no text.

func (*Session) Seq

func (s *Session) Seq() int64

Seq is the last event sequence seen.

func (*Session) Start

func (s *Session) Start()

Start connects, and connects again whenever the connection drops, until Close.

func (*Session) State

func (s *Session) State() State

State and Reason say where the connection stands, and why it dropped.

func (*Session) Under

func (s *Session) Under(vault int64, p string) []*notes.Document

Under lists the open documents of a vault at a path or inside it.

func (*Session) Unsaved

func (s *Session) Unsaved() bool

Unsaved reports whether any open note has text notesd has not saved, for the window's close.

type State

type State int

State is where the connection stands.

const (
	Connecting State = iota
	Connected
	Reconnecting
)

The states.

func (State) String

func (s State) String() string

Jump to

Keyboard shortcuts

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