From f25ac818ea3061167214d1c9a9b717e8393f4bf6 Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Mon, 16 Oct 2023 15:55:16 -0700 Subject: [PATCH 1/3] kiosk: download targetconfig.json at startup --- kiosk/src/App.tsx | 26 ++++++++++++------- kiosk/src/Components/MainMenu.tsx | 8 +++--- kiosk/src/State/Actions.ts | 15 ++++++++++- kiosk/src/State/Reducer.ts | 6 +++++ kiosk/src/State/State.ts | 1 + kiosk/src/Transforms/downloadGameListAsync.ts | 24 ----------------- .../Transforms/downloadTargetConfigAsync.ts | 9 +++++++ localtypings/pxtarget.d.ts | 12 +++++++++ pxtlib/browserutils.ts | 2 +- 9 files changed, 65 insertions(+), 38 deletions(-) delete mode 100644 kiosk/src/Transforms/downloadGameListAsync.ts create mode 100644 kiosk/src/Transforms/downloadTargetConfigAsync.ts diff --git a/kiosk/src/App.tsx b/kiosk/src/App.tsx index 9ed5567bf75..b25e4dc9161 100644 --- a/kiosk/src/App.tsx +++ b/kiosk/src/App.tsx @@ -16,7 +16,7 @@ import { useLocationHash, usePromise } from "./Hooks"; import { launchGame } from "./Transforms/launchGame"; import { navigate } from "./Transforms/navigate"; import { AppStateContext, AppStateReady } from "./State/AppStateContext"; -import { downloadGameListAsync } from "./Transforms/downloadGameListAsync"; +import { downloadTargetConfigAsync } from "./Transforms/downloadTargetConfigAsync"; import * as Actions from "./State/Actions"; import * as SimHost from "./Services/SimHostService"; import * as NotificationService from "./Services/NotificationService"; @@ -40,14 +40,22 @@ function App() { // Load persistent state from local storage. dispatch(Actions.loadHighScores()); dispatch(Actions.loadKioskCode()); - // Download the game list from the server and set it in the app state. - downloadGameListAsync().then(gameList => { - dispatch(Actions.setGameList(gameList)); - // Load user-added games from local storage. - dispatch(Actions.loadUserAddedGames()); - // Select the first game in the list. - dispatch(Actions.setSelectedGameId(gameList[0].id)); - }); + // Download targetconfig.json, then initialize game list. + downloadTargetConfigAsync().then(cfg => { + if (cfg) { + dispatch(Actions.setTargetConfig(cfg)); + if (cfg.kiosk) { + dispatch(Actions.setGameList(cfg.kiosk.games)); + // Load user-added games from local storage. + dispatch(Actions.loadUserAddedGames()); + // Select the first game in the list. + dispatch(Actions.setSelectedGameId(cfg.kiosk.games[0].id)); + } + } else { + // TODO: Handle this better + dispatch(Actions.setTargetConfig({})); + } + }); // Init subsystems. SimHost.initialize(); NotificationService.initialize(); diff --git a/kiosk/src/Components/MainMenu.tsx b/kiosk/src/Components/MainMenu.tsx index 6dfdada413c..5eb9eba851a 100644 --- a/kiosk/src/Components/MainMenu.tsx +++ b/kiosk/src/Components/MainMenu.tsx @@ -22,18 +22,20 @@ const MainMenu: React.FC = ({}) => { launchAddGame(); }; + const canShowMainMenu = ready && kiosk.targetConfig; + return ( <> - {!ready && ( + {!canShowMainMenu && (
)} - {ready && ( + {canShowMainMenu && (