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