Skip to content

Commit dce7f24

Browse files
committed
Update wasm's index.html to Qt 6.6.3
1 parent f84aba2 commit dce7f24

File tree

5 files changed

+64
-44
lines changed

5 files changed

+64
-44
lines changed

wasm/controller.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class Controller {
126126
_writeCommand(cmd) {
127127
return new Promise(resolve => {
128128
this._waitReadCallback = resolve;
129-
Module.inspectorCommand(cmd);
129+
mvpnWasm.instance.inspectorCommand(cmd);
130130
});
131131
}
132132

@@ -169,7 +169,7 @@ function inspectorMessage(obj) {
169169
'NotoSansTC-Regular.otf']) {
170170
fetch(font)
171171
.then(r => r.arrayBuffer())
172-
.then(content => Module.mzLoadFont(font, content));
172+
.then(content => mvpnWasm.instance.mzLoadFont(font, content));
173173
}
174174
}
175175

wasm/index.html

+15-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33
<head>
44
<meta charset="utf-8">
55
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6-
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
6+
7+
<!--Set visual viewport size for mobile devices to the device size,
8+
witch results in a scale of 1 and a 1:1 mapping between CSS pixels
9+
and Qt device independent pixels. -->
10+
<meta name="viewport" content="width=device-width, height=device-height, user-scalable=0"/>
11+
712
<title>Mozilla VPN - WebAssembly Viewer</title>
813
<link href="//fonts.cdnfonts.com/css/metropolis-2" rel="stylesheet">
9-
<link rel="stylesheet" href="main.css">
14+
<link rel="stylesheet" href="main.css">
1015
<link rel="icon" type="image/png" href="favicon.ico">
1116
</head>
1217
<body onload="mvpnWasm.init()" class="wasm-loading">
@@ -20,9 +25,13 @@ <h1>Mozilla VPN - <span class="web-viewer">WebAssembly Viewer</span></h1>
2025
<div class="row">
2126
<div class="col-sm qml-content">
2227
<p class="loading-error-message">Trouble loading content</p>
23-
<img src="img/loader.svg" class="loader" alt="loading icon" />
28+
<figure style="overflow:visible;" id="qtspinner">
29+
<center style="margin-top:1.5em; line-height:150%">
30+
<img src="img/loader.svg" class="loader" alt="loading icon" />
31+
</center>
32+
</figure>
2433
<div class="canvas-bg">
25-
<canvas id="qmlcanvas" oncontextmenu="event.preventDefault()" contenteditable="false" tabindex="-1"></canvas>
34+
<div id="screen"></div>
2635
</div>
2736
</div>
2837
<div class="col-sm controller-content">
@@ -48,6 +57,7 @@ <h1>Welcome to Mozilla VPN Client — WASM</h1>
4857
</div>
4958

5059
<div id="qtstatus"></div>
60+
<noscript>JavaScript is disabled. Please enable JavaScript to use this application.</noscript>
5161

5262
</main>
5363
<footer>
@@ -60,6 +70,7 @@ <h1>Welcome to Mozilla VPN Client — WASM</h1>
6070
<svg class="GitHub-logo logo" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 38.96 38"><path fill="#20123a" d="M19.48 0a19.49 19.49 0 0 0-6.16 38c1 .18 1.33-.43 1.33-.94v-3.32c-5.44 1.15-6.59-2.64-6.59-2.64a5.14 5.14 0 0 0-2.16-2.85c-1.77-1.21.13-1.18.13-1.18a4.1 4.1 0 0 1 3 2 4.16 4.16 0 0 0 5.67 1.62 4.18 4.18 0 0 1 1.23-2.61c-4.32-.49-8.87-2.16-8.87-9.63a7.51 7.51 0 0 1 2-5.22 7 7 0 0 1 .19-5.16s1.63-.52 5.35 2a18.37 18.37 0 0 1 9.76 0c3.72-2.52 5.35-2 5.35-2a7 7 0 0 1 .19 5.16 7.51 7.51 0 0 1 2 5.22c0 7.49-4.56 9.13-8.9 9.62a4.64 4.64 0 0 1 1.32 3.6v5.35c0 .64.35 1.12 1.34.93A19.48 19.48 0 0 0 19.48 0z"/></svg>
6171
</a>
6272
</footer>
73+
<script src="mozillavpn.js"></script>
6374
<script type="text/javascript" src="fxa_endpoints.js"></script>
6475
<script type="text/javascript" src="guardian_endpoints.js"></script>
6576
<script type="text/javascript" src="controller.js"></script>

wasm/main.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ canvas {
174174
}
175175

176176
/* Keep this in sync with Desktop app height and width from theme.js */
177-
#qmlcanvas {
177+
#screen {
178178
width: 360px;
179179
height: 640px;
180180
}

wasm/main.js

+41-31
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,48 @@ class MVPNWasm {
77
this._guardianOverrideEndpoints = {};
88

99
this._fxaOverrideEndpoints = {};
10+
11+
this.instance = null;
1012
}
1113

12-
init() {
13-
const qmlcanvas = document.querySelector('#qmlcanvas');
14-
const controlcanvas = document.querySelector('#controlcanvas');
14+
async init() {
15+
const spinner = document.querySelector('#qtspinner');
16+
const screen = document.querySelector('#screen');
1517
const status = document.querySelector('#qtstatus');
18+
const controlcanvas = document.querySelector('#controlcanvas');
1619
const bodyClassList = document.body.classList;
1720

18-
const qtLoader = QtLoader({
19-
canvasElements: [controlcanvas, qmlcanvas],
20-
showLoader: function(loaderStatus) {
21-
status.textContent = loaderStatus + '...';
22-
},
23-
showError: function(errorText) {
24-
bodyClassList.remove('wasm-loading');
25-
status.textContent = errorText;
26-
bodyClassList.add('wasm-loading-error');
27-
},
28-
showExit: function() {
29-
status.textContent = 'Application exit';
30-
if (qtLoader.exitCode !== undefined)
31-
status.textContent += ' with code ' + qtLoader.exitCode;
32-
if (qtLoader.exitText !== undefined)
33-
status.textContent += ' (' + qtLoader.exitText + ')';
34-
},
35-
showCanvas: function() {
36-
bodyClassList.remove('wasm-loading');
37-
bodyClassList.add('wasm-loaded');
38-
status.textContent = '';
39-
},
40-
});
41-
qtLoader.loadEmscriptenModule('mozillavpn');
21+
const showUi = (ui) => {
22+
[spinner, screen].forEach(element => element.style.display = 'none');
23+
if (screen === ui)
24+
screen.style.position = 'default';
25+
ui.style.display = 'block';
26+
}
27+
28+
try {
29+
showUi(spinner);
30+
status.innerHTML = 'Loading...';
31+
32+
this.instance = await qtLoad({
33+
qt: {
34+
onLoaded: () => showUi(screen),
35+
onExit: exitData =>
36+
{
37+
status.innerHTML = 'Application exit';
38+
status.innerHTML +=
39+
exitData.code !== undefined ? ` with code ${exitData.code}` : '';
40+
status.innerHTML +=
41+
exitData.text !== undefined ? ` (${exitData.text})` : '';
42+
showUi(spinner);
43+
},
44+
entryFunction: window.createQtAppInstance,
45+
containerElements: [screen],
46+
}
47+
});
48+
} catch (e) {
49+
console.error(e);
50+
console.error(e.stack);
51+
}
4252

4353
const preset = document.querySelector('#preset');
4454
for (let p of MVPNPresets) {
@@ -73,7 +83,7 @@ class MVPNWasm {
7383
url == 'https://archive.mozilla.org/pub/vpn/speedtest/50m.data') {
7484
// 50mb of data is too much to be handled in the browser.
7585
setTimeout(
76-
() => Module.mzNetworkResponse(id, JSON.stringify({
86+
() => this.instance.mzNetworkResponse(id, JSON.stringify({
7787
status: 200,
7888
body: btoa(String.fromCharCode.apply(null, new Uint8Array(1024)))
7989
})),
@@ -83,14 +93,14 @@ class MVPNWasm {
8393

8494
if (!obj) {
8595
fetch(url)
86-
.then(async resp => Module.mzNetworkResponse(id, JSON.stringify({
96+
.then(async resp => this.instance.mzNetworkResponse(id, JSON.stringify({
8797
status: resp.status,
8898
body: btoa(String.fromCharCode.apply(
8999
null, new Uint8Array(await resp.arrayBuffer())))
90100
})))
91101
.catch(() => {
92102
console.error('Unable to fetch content for URL', url);
93-
Module.mzNetworkResponse(id, JSON.stringify({status: 0, body: ''}));
103+
this.instance.mzNetworkResponse(id, JSON.stringify({status: 0, body: ''}));
94104
});
95105
return;
96106
}
@@ -106,7 +116,7 @@ class MVPNWasm {
106116
}
107117

108118
setTimeout(() => {
109-
Module.mzNetworkResponse(
119+
this.instance.mzNetworkResponse(
110120
id,
111121
JSON.stringify(
112122
{status: obj.status, body: btoa(JSON.stringify(obj.body))}));

wasm/test.html

+5-6
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212
<title>Mozilla VPN - WebAssembly Viewer</title>
1313
<link href="//fonts.cdnfonts.com/css/metropolis-2" rel="stylesheet">
1414
<link rel="stylesheet" href="main.css">
15-
<style>
16-
/* Make the html body cover the entire (visual) viewport with no scroll bars. */
17-
html, body { padding: 0; margin: 0; overflow: hidden; height: 100% }
18-
#screen { margin: auto; width: 360px; height: 640px; outline-style: solid; }
19-
</style>
2015
<link rel="icon" type="image/png" href="favicon.ico">
2116
</head>
2217
<body onload="init()">
@@ -30,7 +25,11 @@
3025
<noscript>JavaScript is disabled. Please enable JavaScript to use this application.</noscript>
3126
</center>
3227
</figure>
33-
<div id="screen"></div>
28+
<center>
29+
<div class="canvas-bg">
30+
<div id="screen"></div>
31+
</div>
32+
</center>
3433

3534
<footer>
3635
<a class="icon-link" href="https://www.github.com/mozilla-mobile/mozilla-vpn-client" target="_blank" rel="noopener noreferrer">

0 commit comments

Comments
 (0)