Android: reliable build script; GUI: fix list not drawn until first tap.

scripts/build.sh (documented in README) builds, manifest-patches
( MANAGE_EXTERNAL_STORAGE ), signs and installs the APK in one go.
Without the permission the system 'All files access' toggle is grayed
out on Android 11+.

GUI fix: the event loop only checks the 'updated' channel when it is
not blocked in w.Event(), and gioui only emits frames on invalidation
or user input, so the initial list load was never drawn until a tap.
The updater now signals non-blocking and invalidates the window itself;
the animation ticker gets the same wake-up treatment.
This commit is contained in:
gmp
2026-08-24 09:23:41 -04:00
parent 4c337ff06d
commit 349445219b
3 changed files with 176 additions and 7 deletions
+49 -7
View File
@@ -10,6 +10,7 @@ import (
"strconv"
"strings"
"sync"
"sync/atomic"
"time"
"gioui.org/app"
@@ -99,7 +100,7 @@ func main() {
}
reload = make(chan struct{})
updated = make(chan struct{})
updated = make(chan struct{}, 1)
chdir = make(chan struct{})
passch = make(chan []byte)
@@ -127,6 +128,7 @@ var (
chdir chan struct{}
passch chan []byte
th *material.Theme
win atomic.Pointer[app.Window]
)
func Updater() {
@@ -140,7 +142,20 @@ func Updater() {
mux.Lock()
l = ltmp
mux.Unlock()
updated <- struct{}{}
// Non-blocking: if a refresh is already pending it will pick up
// the latest list, so dropping the duplicate is fine.
select {
case updated <- struct{}{}:
default:
}
// Wake the window: the event loop blocks in w.Event(), which only
// returns when the window is invalidated or the user interacts
// with it. Without this, a list refresh signalled while the loop
// is blocked (e.g. the initial load on startup) would not be
// drawn until the next tap.
if w := win.Load(); w != nil {
w.Invalidate()
}
}
update()
@@ -212,6 +227,7 @@ func eventLoop() {
w.Option(
app.Size(unit.Dp(250), unit.Dp(500)),
app.Title("passgo"))
win.Store(w)
var margincs layout.Constraints
@@ -401,18 +417,49 @@ func eventLoop() {
noidLabel := material.Label(th, unit.Sp(fontSize), noidLabelText)
idLabel := material.Label(th, unit.Sp(fontSize), "Select ID")
// timing variables used for the "copied to clipboard" animation
// (seconds relative to overlayStart)
fade1a, fade1b := 1.5, 2.0
start2 := float64(Config.ClearDelay)
fade2a, end := start2+1.5, start2+2.0
anim := &time.Ticker{}
var animDone chan struct{}
animating := false
animOn := func() {
log(Info, "animOn()")
anim = time.NewTicker(time.Second / 90)
animating = true
w.Invalidate()
// The event loop blocks in w.Event() between frames, so ticks it
// misses never trigger a redraw and the fade would freeze. Wake
// the window on each tick, but only while a fade is actually
// visible.
t := anim
animDone = make(chan struct{})
d := animDone
go func() {
for {
select {
case <-t.C:
x := time.Since(overlayStart).Seconds()
if (x >= fade1a && x < fade1b) || (x > fade2a && x < end) {
w.Invalidate()
}
case <-d:
return
}
}
}()
}
animOff := func() {
log(Info, "animOff()")
anim.Stop()
animating = false
if animDone != nil { // stops the wake-up goroutine started by animOn
close(animDone)
animDone = nil
}
}
var listPage, idPage, insertPage, confirmPage, confPage, promptPage, page func(C) D
@@ -427,11 +474,6 @@ func eventLoop() {
lpf1 := &layout.Flex{Axis: layout.Horizontal}
listPage = func(gtx C) D {
// timing variables used for animation
fade1a, fade1b := 1.5, 2.0
start2 := float64(Config.ClearDelay)
fade2a, end := start2+1.5, start2+2.0
c2 := layout.Rigid(func(gtx C) D {
c21 := layout.Flexed(1, func(gtx C) D {
return material.Editor(th, FilterEd, "filter").Layout(gtx)