Pad/cmd/pad/impl_other.go
Greg Pomerantz 2bdff5c8e8 Flush the session snapshot on activity onStop (Android)
The OS provides no user-space hook for a process kill, but the
activity onStop fires on every 'going away' transition the framework
still controls: entering recents (the swipe-wipe path), app switch,
and home. Recents-wipe then kills the process right after onStop
returns, so that moment is the last reliable flush.

- Logic.FlushSession (any goroutine, buffered, non-blocking) ->
  flushSessionSave on the owner: persist the snapshot now, bypassing
  the rate limit (still honoring the restore-pending suppression).
  saveSessionIfChanged's persist tail is deduplicated into writeSession.
- JNI: GioActivity.onStop (patched into the smali by the build
  scripts, in sync) now calls the static native padFlushSession, which
  maps to the pad_flush_session cgo export.

Verified on emulator: the flush fires on home/app-switch and when the
app is backgrounded into recents before a kill; a state change made
inside the 250ms rate window and then backed out of the app persists
the latest position. A hard kill while foregrounded (force-stop,
memory pressure) still has no hook — the immediate edit saves plus the
250ms rate window bound that loss.
2026-08-20 18:24:43 -04:00

40 lines
1001 B
Go

//go:build !android
// +build !android
package main
import (
"os"
"pad/internal/editor"
"path/filepath"
"gioui.org/io/event"
)
var (
startpath = "."
)
// sessionFilePath is where the relaunch session file (spec §7) lives, off
// Android: $HOME/.pad/session.json, falling back to the temp dir when there
// is no home.
func sessionFilePath() string {
if d, err := os.UserHomeDir(); err == nil && d != "" {
return filepath.Join(d, ".pad", "session.json")
}
return filepath.Join(os.TempDir(), "pad", "session.json")
}
func handleEvent(e event.Event) {}
func OpenFile(path string) {}
// SetGestureExclusions is a no-op off Android (system gesture exclusion
// rects are an Android API 29+ feature).
func SetGestureExclusions(rects [][4]int) {}
// activeLogic exists on the Android build (the onStop JNI hook, see
// impl_android.go); on other platforms it is unused but main assigns it.
var activeLogic *editor.Logic
var _ = activeLogic // keep staticcheck quiet on non-Android builds