Skip to content

Commit 9fb0f84

Browse files
authored
Merge pull request #163 from SPARSH1608/electron
Added electron support
2 parents bd1a86c + eaceccc commit 9fb0f84

File tree

4 files changed

+97
-5
lines changed

4 files changed

+97
-5
lines changed

app/models/contest.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export default Model.extend({
3838
college_contest: DS.belongsTo('college_contest'),
3939
contest_type: DS.attr(),
4040
showProblemScore: DS.attr(),
41+
environment: DS.attr(),
4142
hasEnded: Ember.computed('end_time', function () {
4243
return moment(this.end_time).isBefore(moment())
4344
}),

app/pods/components/full-screen-problem-list/component.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ export default class FullScreenProblemListComponent extends Component {
77
const progresses = this.contest.get('currentAttempt.progresses')
88
const progressProblemHash = {}
99
progresses.map(progress => progressProblemHash[progress.belongsTo('content').id()] = progress)
10+
// console.log('progressProblemHash', content)
11+
// console.log('progresses', progresses)
12+
// console.log('progressProblemHash', progressProblemHash)
1013
return this.get('contest.contents').map(content => {
1114
return {
1215
content,

app/pods/components/intermediate-contest-view/component.js

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,32 @@
11
import Component from '@ember/component';
22

33
export default Component.extend({
4+
languageSelection: service('language-selection'),
5+
init(){
6+
this._super(...arguments);
7+
let contest = this.get('contest').data;
8+
console.log(contest);
9+
document.addEventListener('contextmenu', function (event) {
10+
event.preventDefault();
11+
});
12+
document.addEventListener('keydown', function (event) {
13+
if (
14+
event.key === 'F12' ||
15+
(event.ctrlKey && event.shiftKey && event.key === 'I') ||
16+
(event.ctrlKey && event.shiftKey && event.key === 'C') ||
17+
(event.ctrlKey && event.shiftKey && event.key === 'J') ||
18+
(event.ctrlKey && event.key === 'U')
19+
) {
20+
event.preventDefault();
21+
}
22+
});
23+
24+
},
25+
jsonToTable(data) {
26+
27+
const table = jsonToTable(data);
28+
return table;
29+
}
30+
431
});
32+

0 commit comments

Comments
 (0)