Skip to content
This repository has been archived by the owner on Sep 5, 2020. It is now read-only.

Commit

Permalink
moved sounds to mist interface
Browse files Browse the repository at this point in the history
  • Loading branch information
frozeman committed Nov 2, 2015
1 parent 347a2eb commit 4720c87
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 148 deletions.
14 changes: 12 additions & 2 deletions interface/client/mistAPIBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ var filterId = function(str) {
};


var sound = {
bip: document.createElement('audio'),
bloop: document.createElement('audio'),
invite: document.createElement('audio'),
};
sound.bip.src = 'file://'+ dirname + '/../../sounds/bip.mp3';
sound.bloop.src = 'file://'+ dirname + '/../../sounds/bloop.mp3';
sound.invite.src = 'file://'+ dirname + '/../../sounds/invite.mp3';


/**
The backend side of the mist API.
Expand Down Expand Up @@ -52,8 +62,8 @@ mistAPIBackend = function(event) {

// Actions: --------

if(event.channel === 'mistAPI_createAccount') {
console.log('Create Account');
if(event.channel === 'mistAPI_sound') {
sound[arg].play();
}

if(event.channel === 'mistAPI_setBadge') {
Expand Down
296 changes: 153 additions & 143 deletions modules/mistAPI.js
Original file line number Diff line number Diff line change
@@ -1,164 +1,174 @@
/**
@module MistAPI
*/
module.exports = function(isWallet) {

const ipc = require('ipc');
const ipc = require('ipc');

var queue = [];
var prefix = 'entry_';
var queue = [];
var prefix = 'entry_';

// filterId the id to only contain a-z A-Z 0-9
var filterId = function(str) {
var newStr = '';
for (var i = 0; i < str.length; i++) {
if(/[a-zA-Z0-9_-]/.test(str.charAt(i)))
newStr += str.charAt(i);
// filterId the id to only contain a-z A-Z 0-9
var filterId = function(str) {
var newStr = '';
for (var i = 0; i < str.length; i++) {
if(/[a-zA-Z0-9_-]/.test(str.charAt(i)))
newStr += str.charAt(i);
};
return newStr;
};
return newStr;
};

ipc.on('mistAPI_callMenuFunction', function(id) {
if(mist.menu.entries[id] && mist.menu.entries[id].callback)
mist.menu.entries[id].callback();
});

ipc.on('windowMessage', function(type, error, value) {
if(mist.callbacks[type]) {
mist.callbacks[type].forEach(function(cb){
cb(error, value);
});
delete mist.callbacks[type];
}
});


// work up queue every 500ms
setInterval(function(){
if(queue.length > 0) {
ipc.sendToHost('mistAPI_menuChanges', queue);
queue = [];
}
}, 200);

// preparing sounds
var sound = {
bip: document.createElement('audio'),
bloop: document.createElement('audio'),
invite: document.createElement('audio'),
};
sound.bip.src = 'file://'+ __dirname + '/../sounds/bip.mp3';
sound.bloop.src = 'file://'+ __dirname + '/../sounds/bloop.mp3';
sound.invite.src = 'file://'+ __dirname + '/../sounds/invite.mp3';

ipc.on('mistAPI_callMenuFunction', function(id) {
if(mist.menu.entries[id] && mist.menu.entries[id].callback)
mist.menu.entries[id].callback();
});

/**
Mist API
TODO: queue up all changes and send them all together, to prevent multiple update calls in the mist ui db?
@class mist
@constructor
*/
var mist = {
callbacks: {},
platform: process.platform,
requestAccount: function(callback){
if(callback) {
if(!this.callbacks['requestAccount'])
this.callbacks['requestAccount'] = [];
this.callbacks['requestAccount'].push(callback);
ipc.on('windowMessage', function(type, error, value) {
if(mist.callbacks[type]) {
mist.callbacks[type].forEach(function(cb){
cb(error, value);
});
delete mist.callbacks[type];
}
});


ipc.send('mistAPI_requestAccount');
},
sounds: {
bip: function(){
sound.bip.play();
// work up queue every 500ms
setInterval(function(){
if(queue.length > 0) {
ipc.sendToHost('mistAPI_menuChanges', queue);
queue = [];
}
},
menu: {
entries: {},
/**
Sets the badge text for the apps menu button
}, 200);

// preparing sounds
// if wallet
if(isWallet) {
var sound = {
bip: document.createElement('audio'),
bloop: document.createElement('audio'),
invite: document.createElement('audio'),
};
sound.bip.src = 'file://'+ __dirname + '/../sounds/bip.mp3';
sound.bloop.src = 'file://'+ __dirname + '/../sounds/bloop.mp3';
sound.invite.src = 'file://'+ __dirname + '/../sounds/invite.mp3';
}

Example

mist.menu.setBadge('Some Text')
/**
Mist API
@method setBadge
@param {String} text
*/
setBadge: function(text){
ipc.sendToHost('mistAPI_setBadge', text);
},
/**
Adds/Updates a menu entry
Example
mist.menu.add('tkrzU', {
name: 'My Meny Entry',
badge: 50,
position: 1,
selected: true
}, function(){
// Router.go('/chat/1245');
})
@method add
@param {String} id The id of the menu, has to be the same accross page reloads.
@param {Object} options The menu options like {badge: 23, name: 'My Entry'}
@param {Function} callback Change the callback to be called when the menu is pressed.
*/
'add': function(id, options, callback){
id = prefix + filterId(id);

var entry = {
id: id,
position: options.position,
selected: !!options.selected,
name: options.name,
badge: options.badge,
};

queue.push({
action: 'addMenu',
entry: entry
});
TODO: queue up all changes and send them all together, to prevent multiple update calls in the mist ui db?
if(callback)
entry.callback = callback;
@class mist
@constructor
*/
var mist = {
callbacks: {},
platform: process.platform,
requestAccount: function(callback){
if(callback) {
if(!this.callbacks['requestAccount'])
this.callbacks['requestAccount'] = [];
this.callbacks['requestAccount'].push(callback);
}

this.entries[id] = entry;
ipc.send('mistAPI_requestAccount');
},
'update': function(){
this.add.apply(this, arguments);
sounds: {
bip: function(){
// if wallet
if(isWallet)
sound.bip.play();
// if mist
else
ipc.sendToHost('mistAPI_sound', 'bip');
}
},
/**
Removes a menu entry from the mist sidebar.
@method remove
@param {String} id
*/
'remove': function(id){
id = prefix + filterId(id);

delete this.entries[id];

queue.push({
action: 'removeMenu',
id: id
});
menu: {
entries: {},
/**
Sets the badge text for the apps menu button
Example
mist.menu.setBadge('Some Text')
@method setBadge
@param {String} text
*/
setBadge: function(text){
ipc.sendToHost('mistAPI_setBadge', text);
},
/**
Adds/Updates a menu entry
Example
mist.menu.add('tkrzU', {
name: 'My Meny Entry',
badge: 50,
position: 1,
selected: true
}, function(){
// Router.go('/chat/1245');
})
@method add
@param {String} id The id of the menu, has to be the same accross page reloads.
@param {Object} options The menu options like {badge: 23, name: 'My Entry'}
@param {Function} callback Change the callback to be called when the menu is pressed.
*/
'add': function(id, options, callback){
id = prefix + filterId(id);

var entry = {
id: id,
position: options.position,
selected: !!options.selected,
name: options.name,
badge: options.badge,
};

queue.push({
action: 'addMenu',
entry: entry
});

if(callback)
entry.callback = callback;

this.entries[id] = entry;
},
'update': function(){
this.add.apply(this, arguments);
},
/**
Removes a menu entry from the mist sidebar.
@method remove
@param {String} id
*/
'remove': function(id){
id = prefix + filterId(id);

delete this.entries[id];

queue.push({
action: 'removeMenu',
id: id
});
},
/**
Removes all menu entries.
@method clear
*/
'clear': function(){
queue.push({action: 'clearMenu'});
}
},
/**
Removes all menu entries.
@method clear
*/
'clear': function(){
queue.push({action: 'clearMenu'});
}
},
};
};

module.exports = mist;
return mist;
};
2 changes: 1 addition & 1 deletion modules/preloader/dapps.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ document.addEventListener('click', function(e) {



window.mist = mist;
window.mist = mist();
window.BigNumber = BigNumber;
window.web3 = new Web3(new Web3.providers.IpcProvider('', ipcProviderWrapper));
3 changes: 1 addition & 2 deletions modules/preloader/wallet.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
@module preloader wallet
*/

const mist = require('../mistAPI.js');
const shell = require('shell');
const BigNumber = require('bignumber.js');
Expand All @@ -26,7 +25,7 @@ window.web3 = new Web3(new Web3.providers.IpcProvider('', ipcProviderWrapper));
web3Admin.extend(window.web3);


window.mist = mist;
window.mist = mist(true);
window.platform = process.platform;

setTimeout(function(){
Expand Down

0 comments on commit 4720c87

Please sign in to comment.