aboutsummaryrefslogtreecommitdiffstats
path: root/qt.js
blob: 2f532f942c88a3d20ea73dc7ad6f40e024deb727 (plain) (blame)
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
(function() {
    var QtProvider = function() {
        this.handlers = [];
        
        var self = this;
        navigator.qt.onmessage = function (message) {
            self.handlers.forEach(function (handler) {
                handler.call(self, JSON.parse(message.data));
            });
        };
    };

    QtProvider.prototype.send = function(payload) {
        navigator.qt.postMessage(JSON.stringify(payload));
    };

    Object.defineProperty(QtProvider.prototype, "onmessage", {
        set: function(handler) {
            this.handlers.push(handler);
        },
    }); 

    if(typeof(web3) !== "undefined" && web3.providers !== undefined) {
        web3.providers.QtProvider = QtProvider;
    }
})();