aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/mist/assets/muted/muted.js
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-12-20 09:34:12 +0800
committerobscuren <geffobscura@gmail.com>2014-12-20 09:34:12 +0800
commit3983dd2428137211f84f299f9ce8690c22f50afd (patch)
tree3a2dc53b365e6f377fc82a3514150d1297fe549c /cmd/mist/assets/muted/muted.js
parent7daa8c2f6eb25511c6a54ad420709af911fc6748 (diff)
parent0a9dc1536c5d776844d6947a0090ff7e1a7c6ab4 (diff)
downloadgo-tangerine-3983dd2428137211f84f299f9ce8690c22f50afd.tar.gz
go-tangerine-3983dd2428137211f84f299f9ce8690c22f50afd.tar.zst
go-tangerine-3983dd2428137211f84f299f9ce8690c22f50afd.zip
Merge branch 'release/v0.7.10'vv0.7.10
Diffstat (limited to 'cmd/mist/assets/muted/muted.js')
-rw-r--r--cmd/mist/assets/muted/muted.js78
1 files changed, 78 insertions, 0 deletions
diff --git a/cmd/mist/assets/muted/muted.js b/cmd/mist/assets/muted/muted.js
new file mode 100644
index 000000000..467411577
--- /dev/null
+++ b/cmd/mist/assets/muted/muted.js
@@ -0,0 +1,78 @@
+// Copyright (c) 2013-2014, Jeffrey Wilcke. All rights reserved.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+// MA 02110-1301 USA
+
+// Helper function for generating pseudo callbacks and sending data to the QML part of the application
+function postData(data, cb) {
+ data._seed = Math.floor(Math.random() * 1000000)
+ if(cb) {
+ Muted._callbacks[data._seed] = cb;
+ }
+
+ if(data.args === undefined) {
+ data.args = [];
+ }
+
+ navigator.qt.postMessage(JSON.stringify(data));
+}
+
+window.Muted = {
+ prototype: Object(),
+}
+
+window.Muted._callbacks = {}
+window.Muted._onCallbacks = {}
+
+function debug(/**/) {
+ console.log("hello world")
+
+ var args = arguments;
+ var msg = ""
+ for(var i = 0; i < args.length; i++){
+ if(typeof args[i] == "object") {
+ msg += " " + JSON.stringify(args[i])
+ } else {
+ msg += args[i]
+ }
+ }
+
+ document.querySelector("#debugger").innerHTML += "<div class='line'><div class='col1'></div><div class='col2'>"+msg+"</div></div>";
+}
+console.log = function() {
+ var args = []
+ for(var i = 0; i < arguments.length; i++) {
+ args.push(arguments[i]);
+ }
+ postData({call:"log", args:args})
+}
+
+navigator.qt.onmessage = function(ev) {
+ var data = JSON.parse(ev.data)
+
+ if(data._event !== undefined) {
+ Muted.trigger(data._event, data.data);
+ } else {
+ if(data._seed) {
+ var cb = Muted._callbacks[data._seed];
+ if(cb) {
+ // Call the callback
+ cb(data.data);
+ // Remove the "trigger" callback
+ delete Muted._callbacks[ev._seed];
+ }
+ }
+ }
+}