-
Notifications
You must be signed in to change notification settings - Fork 14
/
launch.js
157 lines (139 loc) · 4.42 KB
/
launch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
document.addEventListener("DOMContentLoaded",onready)
var reload = chrome.runtime.reload
var localServer = false
function getel(id) { return document.getElementById(id) }
window.delay = 1000
window.g_retained = []
window.g_paks = {}
function onstorage(items) {
console.log('storage',items)
return
if (items.retained) {
// restore all retained entries
console.log('need to restore entries',items.retained)
g_retained = items.retained
for (var i=0; i<items.retained.length; i++) {
var s = items.retained[i]
console.log('restore entry',s)
chrome.fileSystem.restoreEntry(s, function(entry) {
console.log('entry restored',entry)
g_paks[entry] = entry
})
}
}
}
function onready() {
chrome.storage.local.get(null, onstorage)
setup_events()
chrome.runtime.getBackgroundPage( function(bg) {
function onDonate(evt) {
console.log('onDonate',evt)
}
function onDonateFail(evt) {
console.log('onDonateFail',evt)
}
getel('donate').addEventListener('click', function(evt) {
var sku = "basicdonation";
google.payments.inapp.buy({
'parameters': {'env': 'prod'},
'sku': sku,
'success': onDonate,
'failure': onDonateFail
});
})
chrome.runtime.getPlatformInfo(function(info) {
if (info.arch == 'arm') {
//document.getElementById('disablesound').checked = false
//document.getElementById('armcrash').innerText = "Sound on ARM Chromebook may cause crashes.."
}
})
})
}
function onlaunchserver() {
//var params = encodeURIComponent('-dedicated +coop 1 +deathmatch 0 +teamplay 1 +map e1m1') // doesnt work
params = ''
chrome.app.window.create('server/server.html?' + params,
{ defaultWidth: 512,
id:'server',
defaultHeight: 384 },
function(swin) {
swin.onClosed.addListener( function(evt) {
console.log('server window closed')
localServer = false
deleteServerSockets()
})
})
}
function save_store(entry,cb) {
function onfile(file) {
var fr = new FileReader
fr.onload = fr.onerror = function(e) {
console.log('read file',e)
var buf = e.target.result
Store.set(entry.name.toUpperCase(), buf)
if (cb) cb()
}
fr.readAsArrayBuffer(file.slice())
}
entry.file( onfile, onfile )
}
function addpak() {
chrome.fileSystem.chooseEntry({type:'openFile',
acceptsMultiple:false,
accepts:[{extensions:['pak']}]},
onfile)
function onfile(entry) {
console.log('got entry',entry)
save_store(entry)
var s = chrome.fileSystem.retainEntry(entry)
g_retained.push(s)
chrome.storage.local.set({'retained':g_retained})
}
}
function setup_events() {
getel('launch-server').addEventListener('click', onlaunchserver)
getel('launch').addEventListener('click', launchQuake)
getel('addfiles').addEventListener('click', addpak)
function keydown(evt) {
if (evt.metaKey || evt.ctrlKey) {
if (evt.keyCode == 82) {
// ctrl-r
console.log('received ctrl(meta)-r, reload app')
chrome.runtime.reload()
}
//evt.preventDefault() // dont prevent ctrl-w
}
}
document.body.addEventListener('keydown', keydown)
}
function launchQuake() {
var disablesound = getel('disablesound').checked
if (false) {
chrome.app.window.create('index.html?port=' + bg.app.port + '&delay=' + delay + '&disablesound=' + disablesound,
{ defaultWidth: 640,
id:'WebQuake',
defaultHeight: 480 },
function(w) {
console.log('quake window created');
})
} else {
if (disablesound) {
var params = '-nosound'
} else {
var params = ''
}
if (localServer) {
params += ' +connect ws://127.0.0.1:26000'
}
params = encodeURIComponent(params)
chrome.app.window.create('WebQuake-async/Client/WebQuake.htm?' + params,
{ defaultWidth: 640,
id:'WebQuake',
defaultHeight: 480 },
function(w) {
console.log('quake window created');
w.onClosed.addListener( function() {
})
})
}
}