M4 networkmanager: open the page and tell the person

At a join, at the watcher's start and at a session's start while PORTAL, once per ask,
the watcher opens the check address with systemd-run --user and xdg-open in the
person's session and then shows the notification its outcome calls for, critical when
the open failed; it says when the network is open, and handles what it hears during
an open after it.

Builds: design 08 sign-in-page §15, §18, §19, §22
This commit is contained in:
jochen
2026-11-24 21:20:20 +01:00
parent fee3f8ab8b
commit a4169a2325
6 changed files with 515 additions and 54 deletions
@@ -123,6 +123,7 @@ type watcherState struct {
AsksEnded int `json:"asks_ended"`
DroppedPastBound int `json:"dropped_past_bound"`
LastOpen *openOutcome `json:"last_open,omitempty"`
LastNotification *note `json:"last_notification,omitempty"`
LastSession *sessionNote `json:"last_session,omitempty"`
}
@@ -155,8 +156,13 @@ type Watcher struct {
// After is a stated bound's end.
After func(time.Duration) <-chan time.Time
Desk desk
// Beside runs an open beside the loop; the func it returns is run by the loop at its end.
Beside func(work func() func())
starting *sessionStart
opening bool
later []func()
ends chan func()
asks chan asked
bus systemBus
signals <-chan signal
@@ -169,8 +175,11 @@ type Watcher struct {
}
func newWatcher(f Folder) *Watcher {
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}
w := &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,
Desk: newSessionDesk(), ends: make(chan func())}
w.Beside = w.besideLoop
return w
}
// watch is `uplink-tools watch`: the watcher, until its process is stopped.
@@ -229,6 +238,8 @@ func (w *Watcher) run(stop <-chan struct{}) {
case <-w.socketAt:
w.socketAt = nil
w.subscribe()
case end := <-w.ends:
end()
case a := <-w.asks:
answer, err := w.answer(a.ask)
a.reply <- askReply{answer, err}
@@ -307,9 +318,16 @@ func (w *Watcher) readRating() {
journal("reading the network manager's rating failed: %v", err)
return
}
atStart := !w.started
w.started = true
w.heard(r, atStart)
if !w.started {
w.started = true
w.heard(r, true)
return
}
if w.opening {
w.later = append(w.later, func() { w.heard(r, false) })
return
}
w.heard(r, false)
}
// heard acts on a rating read: the check address, a journal line for a change, and the events of §21.
@@ -352,7 +370,9 @@ func (w *Watcher) heard(r Rating, atStart bool) {
case !r.checkOn() || (r.Connectivity != ratingPortal && r.Connectivity != ratingFull):
w.ended(w.ask.Link, w.ask.Network, whyNoLongerAsked)
case r.Connectivity == ratingFull:
w.ended(w.ask.Link, w.ask.Network, whySignedIn)
network := w.ask.Network
w.ended(w.ask.Link, network, whySignedIn)
w.tellSignedIn(network)
default:
return
}
@@ -375,6 +395,7 @@ func (w *Watcher) asked(r Rating) {
w.state.AsksOpened++
w.keep(eventAsked, signInAsked{Node: w.Folder.Node, Link: r.Link, Network: r.Network, Address: r.CheckURI,
At: stamp(now)})
w.present(nil, r.Network, r.CheckURI)
}
// ended keeps sign-in-ended and drops the ask.