ADD - introduce advanced phone setup and reset flow

This commit is contained in:
smx.pusha
2026-08-14 14:35:27 +02:00
parent 5d494419da
commit e033271cb2
13 changed files with 2606 additions and 54 deletions
+29
View File
@@ -2,10 +2,39 @@ import { describe, expect, it } from 'vitest'
import type { LaunchablePhoneAppId } from '@/types/apps'
import {
DEFAULT_PHONE_PREFERENCES,
PHONE_SETUP_LAST_STEP,
parsePhonePreferences,
WALLPAPER_IDS,
} from './preferences'
describe('preferences', () => {
it('starts Setup Assistant for a phone without saved settings', () => {
const value = parsePhonePreferences(null)
expect(value.settings.setupCompleted).toBe(false)
expect(value.settings.setupStep).toBe(0)
})
it('migrates existing phones past Setup Assistant', () => {
const value = parsePhonePreferences(
JSON.stringify({ version: 1, settings: { wallpaper: 'aurora' } }),
)
expect(value.settings.setupCompleted).toBe(true)
expect(value.settings.setupStep).toBe(PHONE_SETUP_LAST_STEP)
})
it('restores an interrupted Setup Assistant step', () => {
const value = parsePhonePreferences(
JSON.stringify({
version: 1,
settings: { setupCompleted: false, setupStep: 5 },
}),
)
expect(value.settings.setupCompleted).toBe(false)
expect(value.settings.setupStep).toBe(5)
})
it('falls back for malformed and obsolete records', () => {
expect(parsePhonePreferences('{')).toEqual(DEFAULT_PHONE_PREFERENCES)
expect(parsePhonePreferences('{"version":2}')).toEqual(
+19
View File
@@ -39,6 +39,7 @@ export const WALLPAPER_IDS = [
export const PHONE_SCALE_MIN = 75
export const PHONE_SCALE_MAX = 150
export const PHONE_SCALE_STEP = 5
export const PHONE_SETUP_LAST_STEP = 9
export type AppearanceMode = (typeof APPEARANCE_MODE_IDS)[number]
export type GraphicsMode = (typeof GRAPHICS_MODE_IDS)[number]
@@ -79,6 +80,8 @@ export type PhonePreferencesV1 = {
ringtone: RingtoneId
ringtoneVolume: number
screenBrightness: number
setupCompleted: boolean
setupStep: number
streamerMode: boolean
wallpaper: WallpaperId
wallpaperHistory: WallpaperHistoryEntry[]
@@ -149,6 +152,8 @@ export const DEFAULT_PHONE_PREFERENCES: PhonePreferencesV1 = {
ringtone: 'skyline',
ringtoneVolume: 80,
screenBrightness: 100,
setupCompleted: false,
setupStep: 0,
streamerMode: false,
wallpaper: 'midnight',
wallpaperHistory: [{ imageUrl: null, wallpaper: 'midnight' }],
@@ -342,6 +347,20 @@ export function parsePhonePreferences(raw: string | null): PhonePreferencesV1 {
10,
100,
),
setupCompleted:
typeof settings.setupCompleted === 'boolean'
? settings.setupCompleted
: true,
setupStep: Math.floor(
readNumber(
settings.setupStep,
typeof settings.setupCompleted === 'boolean'
? defaults.setupStep
: PHONE_SETUP_LAST_STEP,
0,
PHONE_SETUP_LAST_STEP,
),
),
streamerMode: readBoolean(settings.streamerMode, defaults.streamerMode),
wallpaper,
wallpaperHistory: