src/app-state.ts (1059 bytes)
1 // What the Android Back button does, and when the screen stays on. Pure: no DOM. 2 3 import type { FollowMode } from './follower'; 4 5 /** 6 * The step of the Back button: close the page jump, close the drawer, or 7 * put the reader in the background. 8 */ 9 export type BackStep = 'close-jump' | 'close-drawer' | 'minimize'; 10 11 /** 12 * The step of the Back button. The reader never finishes its activity: 13 * Android then destroys the WebView, and the reader loses its state. 14 */ 15 export function backStep(open: { jump: boolean; drawer: boolean }): BackStep { 16 if (open.jump) return 'close-jump'; 17 if (open.drawer) return 'close-drawer'; 18 return 'minimize'; 19 } 20 21 /** 22 * True when the screen stays on: while the app shows, a book is open, the 23 * player plays and the follow is not off. During read-along the user does 24 * not touch the screen, so without this the screen turns off. 25 */ 26 export function keepScreenOn(s: { 27 active: boolean; 28 book: boolean; 29 playing: boolean; 30 mode: FollowMode; 31 }): boolean { 32 return s.active && s.book && s.playing && s.mode !== 'off'; 33 }