(context: Context)
| 8 | import logger from '../services/logger' |
| 9 | |
| 10 | const onStartup = async (context: Context): Promise<void> => { |
| 11 | try { |
| 12 | // check if a workspace is open, otherwise nothing works |
| 13 | const noActiveWorkspace = !WORKSPACE_ROOT.length |
| 14 | if (noActiveWorkspace) { |
| 15 | const error: E.ErrorMessage = { |
| 16 | type: 'NoWorkspaceFound', |
| 17 | message: '', |
| 18 | actions: [ |
| 19 | { |
| 20 | label: 'Open Workspace', |
| 21 | transition: 'REQUEST_WORKSPACE', |
| 22 | }, |
| 23 | ], |
| 24 | } |
| 25 | send({ type: 'NO_WORKSPACE', payload: { error } }) |
| 26 | return |
| 27 | } |
| 28 | |
| 29 | const env = { |
| 30 | machineId: vscode.env.machineId, |
| 31 | sessionId: vscode.env.sessionId, |
| 32 | } |
| 33 | |
| 34 | // continue from tutorial from local storage |
| 35 | const tutorial: TT.Tutorial | null = context.tutorial.get() |
| 36 | |
| 37 | // NEW: no stored tutorial, must start new tutorial |
| 38 | if (!tutorial || !tutorial.version) { |
| 39 | if (TUTORIAL_URL) { |
| 40 | logger(`Using tutorial url from env: ${TUTORIAL_URL}`) |
| 41 | // if a tutorial URL is added, launch on startup |
| 42 | try { |
| 43 | const tutorialRes = await fetch(TUTORIAL_URL) |
| 44 | const tutorial: TT.Tutorial = await tutorialRes.json() |
| 45 | logger(`Tutorial: ${tutorial?.summary?.title} (${tutorial?.version})`) |
| 46 | send({ type: 'START_TUTORIAL_FROM_URL', payload: { tutorial } }) |
| 47 | return |
| 48 | } catch (e: any) { |
| 49 | // on failure to load a tutorial url fallback to NEW |
| 50 | throw new Error(`Failed to load tutorial from url ${TUTORIAL_URL} with error "${e.message}"`) |
| 51 | } |
| 52 | } |
| 53 | // NEW from start click |
| 54 | send({ type: 'START_NEW_TUTORIAL', payload: { env } }) |
| 55 | return |
| 56 | } |
| 57 | |
| 58 | // CONTINUE_FROM_PROGRESS |
| 59 | const { position } = await context.onContinue(tutorial) |
| 60 | logger(`Continuing tutorial from progress: level ${position?.levelId} step ${position?.stepId}`) |
| 61 | // communicate to client the tutorial & stepProgress state |
| 62 | send({ type: 'LOAD_STORED_TUTORIAL', payload: { env, tutorial, position } }) |
| 63 | } catch (e: any) { |
| 64 | const error = { |
| 65 | type: 'UnknownError', |
| 66 | message: `Location: Editor startup\n\n${e.message}`, |
| 67 | } |
nothing calls this directly
no test coverage detected