@@ -81,9 +81,20 @@ export default class IntermediateContestComponent extends Component {
8181 yield contest_attempt . save ( )
8282 this . contest . set ( 'currentAttempt' , contest_attempt )
8383 this . set ( 'showStartDialog' , false )
84- if ( this . onAfterCreate ) {
85- this . onAfterCreate ( )
84+ const cb_auth = this . getCookieValue ( 'cb_auth' )
85+ const contestId = this . contest . id
86+ const contentId = "1"
87+ if ( this . contest . environment ) {
88+ // Open Electron App
89+ const electronURL = `electron-app://contest?cb_auth=${ encodeURIComponent ( cb_auth || "" ) } &contestId=${ contestId } &contentId=${ contentId } ` ;
90+ window . location . href = electronURL ;
91+ } else {
92+ //open in browser
93+ if ( this . onAfterCreate ) {
94+ this . onAfterCreate ( )
95+ }
8696 }
97+
8798 } catch ( err ) {
8899 // Stop Initializing environment
89100 this . updateEnvProgress . cancelAll ( )
@@ -104,20 +115,69 @@ export default class IntermediateContestComponent extends Component {
104115 }
105116 }
106117
118+ getCookieValue ( name ) {
119+ const cookies = document . cookie . split ( ';' ) . map ( c => c . trim ( ) ) ;
120+ const cookie = cookies . find ( c => c . startsWith ( `${ name } =` ) ) ;
121+ return cookie ? decodeURIComponent ( cookie . split ( '=' ) [ 1 ] ) : null ;
122+ }
107123 @action promptCameraPermission ( ) {
108124 navigator . mediaDevices . getUserMedia ( { video : true , mic : true } ,
109125 // successCallback
110126 function ( ) {
111127 this . set ( 'monitorerError' , '' )
112128 } ,
113-
129+
114130 // errorCallback
115131 function ( err ) {
116132 console . log ( err )
117133 } )
118134 }
119135
120- @action async openTestInNewWindow ( ) {
121- window . open ( `${ ENV . publicUrl } /contests/${ this . contest . id } /attempt/` , `hackerblocks-contest-${ this . contest . id } ` , `menubar=1,resizable=0,height=${ window . screen . availHeight } ,width=${ window . screen . availWidth } ,top=0,left=0` )
136+ @action
137+ async openTestInNewWindow ( ) {
138+ const cb_auth = this . getCookieValue ( 'cb_auth' ) ;
139+ const contestId = this . contest . id ;
140+
141+ const progresses = await this . contest . get ( 'currentAttempt.progresses' ) ;
142+ const progressProblemHash = { } ;
143+
144+ progresses . forEach ( progress => {
145+ const contentId = progress . belongsTo ( 'content' ) . id ( ) ;
146+ progressProblemHash [ contentId ] = progress ;
147+ } ) ;
148+
149+
150+ const contents = await this . contest . contents ;
151+
152+ const contentWithProgress = contents . map ( content => {
153+ return {
154+ content,
155+ contentId : content . get ( 'id' ) ,
156+ progress : progressProblemHash [ content . get ( 'id' ) ] ,
157+ } ;
158+ } ) ;
159+
160+ // console.log('contentWithProgress', contentWithProgress);
161+
162+ const contentId = contentWithProgress . length > 0 ? contentWithProgress [ 0 ] . contentId : null ;
163+
164+ if ( ! contentId ) {
165+ console . error ( 'No contentId found for the contest.' ) ;
166+ return ;
167+ }
168+
169+ // console.log('contentId', contentId);
170+
171+ if ( this . contest . environment ) {
172+ const electronURL = `electron-app://contest?cb_auth=${ encodeURIComponent ( cb_auth || '' ) } &contestId=${ contestId } &contentId=${ contentId } ` ;
173+ window . location . href = electronURL ;
174+ } else {
175+ window . open (
176+ `${ ENV . publicUrl } /contests/${ this . contest . id } /attempt/` ,
177+ `hackerblocks-contest-${ this . contest . id } ` ,
178+ `menubar=1,resizable=0,height=${ window . screen . availHeight } ,width=${ window . screen . availWidth } ,top=0,left=0`
179+ ) ;
180+ }
122181 }
182+
123183}
0 commit comments