@@ -81,9 +81,20 @@ export default class IntermediateContestComponent extends Component {
81
81
yield contest_attempt . save ( )
82
82
this . contest . set ( 'currentAttempt' , contest_attempt )
83
83
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
+ }
86
96
}
97
+
87
98
} catch ( err ) {
88
99
// Stop Initializing environment
89
100
this . updateEnvProgress . cancelAll ( )
@@ -104,20 +115,69 @@ export default class IntermediateContestComponent extends Component {
104
115
}
105
116
}
106
117
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
+ }
107
123
@action promptCameraPermission ( ) {
108
124
navigator . mediaDevices . getUserMedia ( { video : true , mic : true } ,
109
125
// successCallback
110
126
function ( ) {
111
127
this . set ( 'monitorerError' , '' )
112
128
} ,
113
-
129
+
114
130
// errorCallback
115
131
function ( err ) {
116
132
console . log ( err )
117
133
} )
118
134
}
119
135
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
+ }
122
181
}
182
+
123
183
}
0 commit comments