Fix: restore previous directory on navigation failure

When directory navigation fails (e.g., permission denied on Android),
the browser now restores the previous path instead of staying in a
broken empty state. NavigateTo saves the current path to History, and
handleError restores it and re-builds the index for the previous
directory when a BuildIndexTask fails.
This commit is contained in:
Greg Pomerantz 2026-06-05 13:58:20 -04:00
parent beae5fc026
commit 5a92ee9df3
2 changed files with 22 additions and 5 deletions

View File

@ -28,6 +28,9 @@ func NewBrowserManager(state *BrowserState, wp *pool.WorkerPool, fs pool.FileSys
func (bm *BrowserManager) NavigateTo(dirPath string) { func (bm *BrowserManager) NavigateTo(dirPath string) {
fmt.Printf("NavigateTo: dirPath=%s, state.CurrentPath=%s\n", dirPath, bm.state.CurrentPath) fmt.Printf("NavigateTo: dirPath=%s, state.CurrentPath=%s\n", dirPath, bm.state.CurrentPath)
// Save the previous path so we can restore it on navigation failure.
bm.state.History = append(bm.state.History, bm.state.CurrentPath)
bm.state.CurrentPath = dirPath bm.state.CurrentPath = dirPath
navigateToDirectory(bm.state, dirPath) navigateToDirectory(bm.state, dirPath)
bm.state.Loading = true bm.state.Loading = true
@ -159,9 +162,22 @@ func (bm *BrowserManager) handleLoadPagesSuccess(result pool.Result) {
func (bm *BrowserManager) handleError(result pool.Result) { func (bm *BrowserManager) handleError(result pool.Result) {
fmt.Printf("handleError: TaskType=%d, Error=%v\n", result.TaskType, result.Error) fmt.Printf("handleError: TaskType=%d, Error=%v\n", result.TaskType, result.Error)
bm.state.Loading = false bm.state.Loading = false
// For now, just reset the state or log the error.
// If the failed task was a BuildIndex (directory navigation), restore
// the previous path so the user is sent back to where they were.
if result.TaskType == pool.TypeBuildIndex && len(bm.state.History) > 0 {
prevPath := bm.state.History[len(bm.state.History)-1]
bm.state.History = bm.state.History[:len(bm.state.History)-1]
bm.state.CurrentPath = prevPath
navigateToDirectory(bm.state, prevPath)
// Re-dispatch the build index for the previous directory so the
// browser renders the old contents again.
task := pool.NewBuildIndexTask(prevPath, bm.fs)
bm.workerPool.Dispatch(task)
return
}
// For other errors, just reset the state or log the error.
// In production, we'd show a toast or error message. // In production, we'd show a toast or error message.
if bm.state.CurrentPath == bm.state.CurrentPath {
bm.state.Reset() bm.state.Reset()
} }
}

View File

@ -30,6 +30,7 @@ type Page struct {
type BrowserState struct { type BrowserState struct {
// Navigation // Navigation
CurrentPath string // Currently browsed directory (relative to root) CurrentPath string // Currently browsed directory (relative to root)
History []string // Path history for navigation
ScrollOffset float64 // Vertical scroll offset in pixels (per-pixel scrolling) ScrollOffset float64 // Vertical scroll offset in pixels (per-pixel scrolling)
EntryHeight float64 // Height of a single entry in pixels EntryHeight float64 // Height of a single entry in pixels
VisibleCount int // Number of entries currently visible VisibleCount int // Number of entries currently visible