Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7f12a0f

Browse files
committed
refactor onEditorStartup
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent91feec8 commit7f12a0f

File tree

3 files changed

+81
-64
lines changed

3 files changed

+81
-64
lines changed

‎src/actions/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
export{defaultasonStartup}from'./onStartup'
12
export{defaultasonErrorPage}from'./onErrorPage'
23
export{defaultasonTestPass}from'./onTestPass'

‎src/actions/onStartup.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import*asvscodefrom'vscode'
2+
import*asTfrom'typings'
3+
import*asTTfrom'typings/tutorial'
4+
import*asEfrom'typings/error'
5+
importContextfrom'../services/context/context'
6+
import{WORKSPACE_ROOT,TUTORIAL_URL}from'../environment'
7+
importfetchfrom'node-fetch'
8+
importloggerfrom'../services/logger'
9+
10+
constonStartup=async(
11+
context:Context,
12+
workspaceState:vscode.Memento,
13+
send:(action:T.Action)=>Promise<void>,
14+
)=>{
15+
try{
16+
// check if a workspace is open, otherwise nothing works
17+
constnoActiveWorkspace=!WORKSPACE_ROOT.length
18+
if(noActiveWorkspace){
19+
consterror:E.ErrorMessage={
20+
type:'NoWorkspaceFound',
21+
message:'',
22+
actions:[
23+
{
24+
label:'Open Workspace',
25+
transition:'REQUEST_WORKSPACE',
26+
},
27+
],
28+
}
29+
send({type:'NO_WORKSPACE',payload:{ error}})
30+
return
31+
}
32+
33+
constenv={
34+
machineId:vscode.env.machineId,
35+
sessionId:vscode.env.sessionId,
36+
}
37+
38+
// load tutorial from url
39+
if(TUTORIAL_URL){
40+
try{
41+
consttutorialRes=awaitfetch(TUTORIAL_URL)
42+
consttutorial=awaittutorialRes.json()
43+
send({type:'START_TUTORIAL_FROM_URL',payload:{ tutorial}})
44+
return
45+
}catch(e){
46+
console.log(`Failed to load tutorial from url${TUTORIAL_URL} with error "${e.message}"`)
47+
}
48+
}
49+
50+
// continue from tutorial from local storage
51+
consttutorial:TT.Tutorial|null=context.tutorial.get()
52+
53+
// no stored tutorial, must start new tutorial
54+
if(!tutorial||!tutorial.id){
55+
send({type:'START_NEW_TUTORIAL',payload:{ env}})
56+
return
57+
}
58+
59+
// load continued tutorial position & progress
60+
const{ position, progress}=awaitcontext.setTutorial(workspaceState,tutorial)
61+
logger('CONTINUE STATE',position,progress)
62+
63+
if(progress.complete){
64+
// tutorial is already complete
65+
send({type:'TUTORIAL_ALREADY_COMPLETE',payload:{ env}})
66+
return
67+
}
68+
// communicate to client the tutorial & stepProgress state
69+
send({type:'LOAD_STORED_TUTORIAL',payload:{ env, tutorial, progress, position}})
70+
}catch(e){
71+
consterror={
72+
type:'UnknownError',
73+
message:`Location: Editor startup\n\n${e.message}`,
74+
}
75+
send({type:'EDITOR_STARTUP_FAILED',payload:{ error}})
76+
}
77+
}
78+
79+
exportdefaultonStartup

‎src/channel.ts

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as T from 'typings'
22
import*asTTfrom'typings/tutorial'
33
import*asEfrom'typings/error'
44
import*asvscodefrom'vscode'
5-
importfetchfrom'node-fetch'
65
import{satisfies}from'semver'
76
import{setupActions,solutionActions}from'./actions/setupActions'
87
importtutorialConfigfrom'./actions/tutorialConfig'
@@ -13,7 +12,6 @@ import { version, compareVersions } from './services/dependencies'
1312
import{openWorkspace,checkWorkspaceEmpty}from'./services/workspace'
1413
import{showOutput}from'./services/testRunner/output'
1514
import{exec}from'./services/node'
16-
import{WORKSPACE_ROOT,TUTORIAL_URL}from'./environment'
1715
importresetfrom'./services/reset'
1816
importgetLastCommitHashfrom'./services/reset/lastHash'
1917
import{onEvent}from'./services/telemetry'
@@ -50,68 +48,7 @@ class Channel implements Channel {
5048

5149
switch(actionType){
5250
case'EDITOR_STARTUP':
53-
try{
54-
// check if a workspace is open, otherwise nothing works
55-
constnoActiveWorkspace=!WORKSPACE_ROOT.length
56-
if(noActiveWorkspace){
57-
consterror:E.ErrorMessage={
58-
type:'NoWorkspaceFound',
59-
message:'',
60-
actions:[
61-
{
62-
label:'Open Workspace',
63-
transition:'REQUEST_WORKSPACE',
64-
},
65-
],
66-
}
67-
this.send({type:'NO_WORKSPACE',payload:{ error}})
68-
return
69-
}
70-
71-
constenv={
72-
machineId:vscode.env.machineId,
73-
sessionId:vscode.env.sessionId,
74-
}
75-
76-
// load tutorial from url
77-
if(TUTORIAL_URL){
78-
try{
79-
consttutorialRes=awaitfetch(TUTORIAL_URL)
80-
consttutorial=awaittutorialRes.json()
81-
this.send({type:'START_TUTORIAL_FROM_URL',payload:{ tutorial}})
82-
return
83-
}catch(e){
84-
console.log(`Failed to load tutorial from url${TUTORIAL_URL} with error "${e.message}"`)
85-
}
86-
}
87-
88-
// continue from tutorial from local storage
89-
consttutorial:TT.Tutorial|null=this.context.tutorial.get()
90-
91-
// no stored tutorial, must start new tutorial
92-
if(!tutorial||!tutorial.id){
93-
this.send({type:'START_NEW_TUTORIAL',payload:{ env}})
94-
return
95-
}
96-
97-
// load continued tutorial position & progress
98-
const{ position, progress}=awaitthis.context.setTutorial(this.workspaceState,tutorial)
99-
logger('CONTINUE STATE',position,progress)
100-
101-
if(progress.complete){
102-
// tutorial is already complete
103-
this.send({type:'TUTORIAL_ALREADY_COMPLETE',payload:{ env}})
104-
return
105-
}
106-
// communicate to client the tutorial & stepProgress state
107-
this.send({type:'LOAD_STORED_TUTORIAL',payload:{ env, tutorial, progress, position}})
108-
}catch(e){
109-
consterror={
110-
type:'UnknownError',
111-
message:`Location: Editor startup\n\n${e.message}`,
112-
}
113-
this.send({type:'EDITOR_STARTUP_FAILED',payload:{ error}})
114-
}
51+
actions.onStartup(this.context,this.workspaceState,this.send)
11552
return
11653

11754
// clear tutorial local storage

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp