M3 networkmanager: the person's session
The watcher finds the person's graphical session from logind and the user manager's environment, and acts on a session's start once that environment names a display; the user manager sends no PropertiesChanged for Environment, so it is read again at the file events on the X server's socket folder and the session's runtime directory, for at most 60 s. Builds: design 08 sign-in-page §15, §16, §17
This commit is contained in:
@@ -98,6 +98,9 @@ type signal struct {
|
||||
type systemBus interface {
|
||||
listen() (<-chan signal, error)
|
||||
rating() (Rating, error)
|
||||
// sessions is every session of the account uid; session is one, by its object.
|
||||
sessions(uid uint32) ([]loginSession, error)
|
||||
session(path string) (loginSession, error)
|
||||
close()
|
||||
}
|
||||
|
||||
@@ -112,13 +115,15 @@ type openAsk struct {
|
||||
|
||||
// watcherState is the watcher's answer to `state` (§23's read).
|
||||
type watcherState struct {
|
||||
Subscribed bool `json:"subscribed"`
|
||||
Rating string `json:"rating,omitempty"`
|
||||
RatingAt *time.Time `json:"rating_at,omitempty"`
|
||||
Ask *openAsk `json:"ask,omitempty"`
|
||||
AsksOpened int `json:"asks_opened"`
|
||||
AsksEnded int `json:"asks_ended"`
|
||||
DroppedPastBound int `json:"dropped_past_bound"`
|
||||
Subscribed bool `json:"subscribed"`
|
||||
Rating string `json:"rating,omitempty"`
|
||||
RatingAt *time.Time `json:"rating_at,omitempty"`
|
||||
Ask *openAsk `json:"ask,omitempty"`
|
||||
AsksOpened int `json:"asks_opened"`
|
||||
AsksEnded int `json:"asks_ended"`
|
||||
DroppedPastBound int `json:"dropped_past_bound"`
|
||||
LastOpen *openOutcome `json:"last_open,omitempty"`
|
||||
LastSession *sessionNote `json:"last_session,omitempty"`
|
||||
}
|
||||
|
||||
// asked is an ask on the watcher's socket, handed to its loop, and the answer it sends back.
|
||||
@@ -141,7 +146,17 @@ type Watcher struct {
|
||||
// folder; closing stop ends the wait.
|
||||
SocketThere func(stop <-chan struct{}) <-chan struct{}
|
||||
Now func() time.Time
|
||||
// UID is the watcher's account, whose sessions are the person's.
|
||||
UID uint32
|
||||
// Environment reads the user manager's environment over a session's bus.
|
||||
Environment func(bus string) ([]string, error)
|
||||
// FileEvents fires at each file event of the kernel that makes a file in one of dirs, until stop closes.
|
||||
FileEvents func(dirs []string, stop <-chan struct{}) <-chan struct{}
|
||||
// After is a stated bound's end.
|
||||
After func(time.Duration) <-chan time.Time
|
||||
Desk desk
|
||||
|
||||
starting *sessionStart
|
||||
asks chan asked
|
||||
bus systemBus
|
||||
signals <-chan signal
|
||||
@@ -154,7 +169,8 @@ type Watcher struct {
|
||||
}
|
||||
|
||||
func newWatcher(f Folder) *Watcher {
|
||||
return &Watcher{Folder: f, Dial: dialSystemBus, SocketThere: systemSocketThere, Now: time.Now, asks: make(chan asked)}
|
||||
return &Watcher{Folder: f, Dial: dialSystemBus, SocketThere: systemSocketThere, Now: time.Now, asks: make(chan asked),
|
||||
UID: uint32(os.Getuid()), Environment: userEnvironment, FileEvents: fileEvents, After: time.After}
|
||||
}
|
||||
|
||||
// watch is `uplink-tools watch`: the watcher, until its process is stopped.
|
||||
@@ -206,6 +222,10 @@ func (w *Watcher) run(stop <-chan struct{}) {
|
||||
continue
|
||||
}
|
||||
w.heardSignal(s)
|
||||
case <-w.startingFiles():
|
||||
w.sessionFiles()
|
||||
case <-w.startingBound():
|
||||
w.sessionBound()
|
||||
case <-w.socketAt:
|
||||
w.socketAt = nil
|
||||
w.subscribe()
|
||||
@@ -258,6 +278,23 @@ func (w *Watcher) heardSignal(s signal) {
|
||||
if s.Rating {
|
||||
w.readRating()
|
||||
}
|
||||
if s.Session != "" {
|
||||
w.sessionNew(s.Session)
|
||||
}
|
||||
}
|
||||
|
||||
func (w *Watcher) startingFiles() <-chan struct{} {
|
||||
if w.starting == nil {
|
||||
return nil
|
||||
}
|
||||
return w.starting.files
|
||||
}
|
||||
|
||||
func (w *Watcher) startingBound() <-chan time.Time {
|
||||
if w.starting == nil {
|
||||
return nil
|
||||
}
|
||||
return w.starting.bound
|
||||
}
|
||||
|
||||
// readRating reads the rating now and acts on it: as the watcher's start the first time, as a change after.
|
||||
|
||||
Reference in New Issue
Block a user