Commit 71134b4c0687ff1a11d57ac35969fc70b826363e

Authored by David Guilherme
1 parent ede36ec8
Exists in master

Primeira versão on demand

.gitignore
1 1 chrome/app/player
2 2 firefox/data/player
3 3  
  4 +player/Release
  5 +
4 6 node_modules
... ...
Gulpfile.js
... ... @@ -5,6 +5,7 @@ var playerFiles = [
5 5 'load.js',
6 6 'window.html',
7 7 'TemplateData/*',
  8 + 'Release/*',
8 9 'vendors/**/*'
9 10 ];
10 11  
... ...
chrome/app/main.js 0 → 100644
... ... @@ -0,0 +1,51 @@
  1 +var app = {
  2 + chooser: null,
  3 + glosa: undefined,
  4 + loaded: false,
  5 + lastReq: {
  6 + url: null,
  7 + millis: null,
  8 + response: null
  9 + }
  10 +};
  11 +
  12 +function onLoadPlayer() {
  13 + if ( app.glosa !== undefined ) {
  14 + SendMessage('PlayerManager', 'catchGlosa', app.glosa);
  15 + }
  16 +
  17 + app.loaded = true;
  18 +}
  19 +
  20 +chrome.runtime.onMessage.addListener(
  21 + function(request, sender, sendResponse) {
  22 + if (request.selectedText === undefined) return;
  23 +
  24 + app.chooser = app.chooser || new qdClient.Chooser();
  25 +
  26 + document.getElementById('loading-screen').style.display = 'block';
  27 + app.chooser.choose(
  28 + app.lastReq.url,
  29 + app.lastReq.millis,
  30 + app.lastReq.response,
  31 + function (url) {
  32 + var start = new Date().getTime();
  33 +
  34 + console.log('Url selected: ' + url);
  35 + qdClient.request(url + '?texto=' + request.selectedText, "GET", {},
  36 + function(status, response) {
  37 + app.lastReq.response = status === 404 ? -1 : status;
  38 + app.lastReq.millis = (new Date().getTime() - start);
  39 + app.lastReq.url = url;
  40 +
  41 + app.glosa = response;
  42 +
  43 + document.getElementById('loading-screen').style.display = 'none';
  44 + if (app.loaded == true) {
  45 + SendMessage('PlayerManager', 'catchGlosa', app.glosa);
  46 + }
  47 + });
  48 + });
  49 + });
  50 +
  51 +chrome.runtime.sendMessage({ready: true});
... ...
chrome/background.js
... ... @@ -15,7 +15,7 @@ chrome.contextMenus.onClicked.addListener( function (info) {
15 15 // Creates the window if it exists
16 16 if ( popup === undefined ) {
17 17 chrome.windows.create({
18   - url: "app/window.html",
  18 + url: "app/player/window.html",
19 19 top: 10,
20 20 left: 10,
21 21 width: 535,
... ...
chrome/manifest.json
... ... @@ -12,7 +12,7 @@
12 12  
13 13 "permissions": [
14 14 "contextMenus",
15   - "http://150.165.204.30:5000/",
  15 + "http://150.165.205.9/",
16 16 "http://150.165.204.39/"
17 17 ],
18 18  
... ...
firefox/data/main.js
... ... @@ -10,14 +10,18 @@ var app = {
10 10 };
11 11  
12 12 function onLoadPlayer() {
  13 + console.log(app.glosa);
  14 +
13 15 if ( app.glosa !== undefined ) {
14   - SendMessage('Avatar', 'catchGlosa', app.glosa);
  16 + SendMessage('PlayerManager', 'catchGlosa', app.glosa);
15 17 }
16 18  
17 19 app.loaded = true;
18 20 }
19 21  
20 22 document.addEventListener('plugin:selectedText', function(e) {
  23 + if (e.detail === undefined) return;
  24 +
21 25 app.chooser = app.chooser || new qdClient.Chooser();
22 26  
23 27 document.getElementById('loading-screen').style.display = 'block';
... ... @@ -38,7 +42,7 @@ document.addEventListener('plugin:selectedText', function(e) {
38 42  
39 43 document.getElementById('loading-screen').style.display = 'none';
40 44 if (app.loaded == true) {
41   - SendMessage('Avatar', 'catchGlosa', app.glosa);
  45 + SendMessage('PlayerManager', 'catchGlosa', app.glosa);
42 46 }
43 47 });
44 48 });
... ...
firefox/index.js
... ... @@ -34,9 +34,9 @@ cm.Item({
34 34  
35 35 if ( !(app.window instanceof Ci.nsIDOMWindow) ) {
36 36 app.window = browser.open(
37   - self.data.url('app/window.html'),
  37 + self.data.url('player/window.html'),
38 38 'VLibras Plugin',
39   - 'chrome=no,width=560,height=560,menubar=no'
  39 + 'width=560,height=560,menubar=no'
40 40 );
41 41 } else {
42 42 app.worker.port.emit('selectedText', app.selectedText);
... ... @@ -47,7 +47,7 @@ cm.Item({
47 47  
48 48 // Page mod
49 49 pm.PageMod({
50   - include: self.data.url('app/window.html'),
  50 + include: self.data.url('player/window.html'),
51 51 contentScriptWhen: 'ready',
52 52 contentScriptFile: self.data.url('delegator.js'),
53 53 onAttach: function(worker) {
... ...
player/connect.js
1   -// connect to canvas
2   - var Module = {
3   - filePackagePrefixURL: "Release/",
4   - memoryInitializerPrefixURL: "Release/",
5   - preRun: [],
6   - postRun: [],
7   - print: (function() {
8   - return function(text) {
9   - console.log (text);
10   - };
11   - })(),
12   - printErr: function(text) {
13   - console.error (text);
14   - },
15   - canvas: document.getElementById('canvas'),
16   - progress: null,
17   - setStatus: function(text) {
18   - if (this.progress == null)
19   - {
20   - if (typeof UnityProgress != 'function')
21   - return;
22   - this.progress = new UnityProgress (canvas);
23   - }
24   - if (!Module.setStatus.last) Module.setStatus.last = { time: Date.now(), text: '' };
25   - if (text === Module.setStatus.text) return;
26   - this.progress.SetMessage (text);
27   - var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/);
28   - if (m)
29   - this.progress.SetProgress (parseInt(m[2])/parseInt(m[4]));
30   - if (text === "")
31   - this.progress.Clear()
32   - },
33   - totalDependencies: 0,
34   - monitorRunDependencies: function(left) {
35   - this.totalDependencies = Math.max(this.totalDependencies, left);
36   - Module.setStatus(left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.');
37   - }
38   - };
39   - Module.setStatus('Downloading (0.0/1)');
40 1 \ No newline at end of file
  2 +// connect to canvas
  3 + var Module = {
  4 + filePackagePrefixURL: "Release/",
  5 + memoryInitializerPrefixURL: "Release/",
  6 + preRun: [],
  7 + postRun: [],
  8 + print: (function() {
  9 + return function(text) {
  10 + console.log (text);
  11 + };
  12 + })(),
  13 + printErr: function(text) {
  14 + console.error (text);
  15 + },
  16 + canvas: document.getElementById('canvas'),
  17 + progress: null,
  18 + setStatus: function(text) {
  19 + if (this.progress == null)
  20 + {
  21 + if (typeof UnityProgress != 'function')
  22 + return;
  23 + this.progress = new UnityProgress (canvas);
  24 + }
  25 + if (!Module.setStatus.last) Module.setStatus.last = { time: Date.now(), text: '' };
  26 + if (text === Module.setStatus.text) return;
  27 + this.progress.SetMessage (text);
  28 + var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/);
  29 + if (m)
  30 + this.progress.SetProgress (parseInt(m[2])/parseInt(m[4]));
  31 + if (text === "")
  32 + this.progress.Clear()
  33 + },
  34 + totalDependencies: 0,
  35 + monitorRunDependencies: function(left) {
  36 + this.totalDependencies = Math.max(this.totalDependencies, left);
  37 + Module.setStatus(left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.');
  38 + }
  39 + };
  40 + Module.setStatus('Downloading (0.0/1)');
... ...
player/load.js
1   -if (!(!Math.fround)) {
2   - var script = document.createElement('script');
3   - script.src = "Release/VLibrasWebPlayer.js";
4   - document.body.appendChild(script);
5   -} else {
6   - var codeXHR = new XMLHttpRequest();
7   - codeXHR.open('GET', 'Release/VLibrasWebPlayer.js', true);
8   - codeXHR.onload = function() {
9   - var code = codeXHR.responseText;
10   - if (!Math.fround) {
11   -console.log('optimizing out Math.fround calls');
12   -code = code.replace(/Math_fround\(/g, '(').replace("'use asm'", "'almost asm'")
13   - }
14   -
15   - var blob = new Blob([code], { type: 'text/javascript' });
16   - codeXHR = null;
17   - var src = URL.createObjectURL(blob);
18   - var script = document.createElement('script');
19   - script.src = URL.createObjectURL(blob);
20   - script.onload = function() {
21   - URL.revokeObjectURL(script.src);
22   - };
23   - document.body.appendChild(script);
24   - };
25   - codeXHR.send(null);
26   -}
27 1 \ No newline at end of file
  2 +if (!(!Math.fround)) {
  3 + var script = document.createElement('script');
  4 + script.src = "Release/WEBGL.js";
  5 + document.body.appendChild(script);
  6 +} else {
  7 + var codeXHR = new XMLHttpRequest();
  8 + codeXHR.open('GET', 'Release/WEBGL.js', true);
  9 + codeXHR.onload = function() {
  10 + var code = codeXHR.responseText;
  11 + if (!Math.fround) {
  12 +try {
  13 + console.log('optimizing out Math.fround calls');
  14 + var m = /var ([^=]+)=global\.Math\.fround;/.exec(code);
  15 + var minified = m[1];
  16 + if (!minified) throw 'fail';
  17 + var startAsm = code.indexOf('// EMSCRIPTEN_START_FUNCS');
  18 + var endAsm = code.indexOf('// EMSCRIPTEN_END_FUNCS');
  19 + var asm = code.substring(startAsm, endAsm);
  20 + do {
  21 + var moar = false; // we need to re-do, as x(x( will not be fixed
  22 + asm = asm.replace(new RegExp('[^a-zA-Z0-9\\$\\_]' + minified + '\\(', 'g'), function(s) { moar = true; return s[0] + '(' });
  23 + } while (moar);
  24 + code = code.substring(0, startAsm) + asm + code.substring(endAsm);
  25 + code = code.replace("'use asm'", "'almost asm'");
  26 +} catch(e) { console.log('failed to optimize out Math.fround calls ' + e) }
  27 + }
  28 +
  29 + var blob = new Blob([code], { type: 'text/javascript' });
  30 + codeXHR = null;
  31 + var src = URL.createObjectURL(blob);
  32 + var script = document.createElement('script');
  33 + script.src = URL.createObjectURL(blob);
  34 + script.onload = function() {
  35 + URL.revokeObjectURL(script.src);
  36 + };
  37 + document.body.appendChild(script);
  38 + };
  39 + codeXHR.send(null);
  40 +}
... ...