Skip to content

Commit

Permalink
Add notification sounds support
Browse files Browse the repository at this point in the history
  • Loading branch information
whphhg committed Jun 8, 2017
1 parent c292f54 commit 3cc801a
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 10 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vcash-electron",
"productName": "Vcash Electron GUI",
"version": "0.32.3",
"version": "0.33.0",
"description": "Multi-platform and multi-node GUI for Vcash.",
"main": "src/electron.js",
"scripts": {
Expand Down Expand Up @@ -53,7 +53,7 @@
"dependencies": {
"antd": "2.10.4",
"electron-compile": "6.4.1",
"i18next": "8.4.0",
"i18next": "8.4.1",
"i18next-node-fs-backend": "1.0.0",
"mobx": "3.1.11",
"mobx-logger": "0.6.0",
Expand Down
3 changes: 3 additions & 0 deletions src/components/Maintenance.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import moment from 'moment'
/** Required components. */
import SelectCurrency from './SelectCurrency'
import SelectLanguage from './SelectLanguage'
import SelectSoundAlerts from './SelectSoundAlerts'
import WalletBackup from './WalletBackup'
import WalletDump from './WalletDump'
import WalletEncrypt from './WalletEncrypt'
Expand Down Expand Up @@ -71,6 +72,8 @@ export default class Maintenance extends React.Component {
<WalletPassphraseChange />
<hr />
<WalletRepair />
<hr />
<SelectSoundAlerts />
</div>
</div>
</div>
Expand Down
71 changes: 71 additions & 0 deletions src/components/SelectSoundAlerts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import React from 'react'
import { translate } from 'react-i18next'
import { inject, observer } from 'mobx-react'
import { Switch } from 'antd'

/** Load translation namespaces and delay rendering until they are loaded. */
@translate(['wallet'], { wait: true })

/** Make the component reactive and inject MobX stores. */
@inject('gui') @observer

export default class SelectSoundAlerts extends React.Component {
constructor (props) {
super(props)
this.t = props.t
this.gui = props.gui
}

render () {
return (
<div>
<div className='flex-sb'>
<div className='flex'>
<i className='material-icons md-16'>notifications_active</i>
<p>{this.t('wallet:notificationSounds')}</p>
</div>
<div className='flex'>
<Switch
checked={this.gui.soundAlerts.incoming === true}
checkedChildren={
<div style={{margin: '-2px 0 0 0'}}>
<i className='material-icons md-16'>done</i>
</div>
}
onChange={() => this.gui.setSoundAlert('incoming')}
size='small'
unCheckedChildren={
<div style={{margin: '-2px 0 0 0'}}>
<i className='material-icons md-16'>clear</i>
</div>
}
/>
<div className='flex' style={{margin: '0 20px 0 8px'}}>
<i className='material-icons md-16'>call_received</i>
<p>{this.t('wallet:incoming')}</p>
</div>
<Switch
checked={this.gui.soundAlerts.spendable === true}
checkedChildren={
<div style={{margin: '-2px 0 0 0'}}>
<i className='material-icons md-16'>done</i>
</div>
}
onChange={() => this.gui.setSoundAlert('spendable')}
size='small'
unCheckedChildren={
<div style={{margin: '-2px 0 0 0'}}>
<i className='material-icons md-16'>clear</i>
</div>
}
/>
<div className='flex' style={{margin: '0 0 0 8px'}}>
<i className='material-icons md-16'>done_all</i>
<p>{this.t('wallet:spendable')}</p>
</div>
</div>
</div>
</div>
)
}
}
2 changes: 2 additions & 0 deletions src/locales/en-US/wallet.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"inbound": "Inbound",
"incentiveReward": "Incentive reward",
"includedInBlock": "Included in block",
"incoming": "Incoming",
"insufficientFunds": "You have insufficient funds.",
"keyFile": "Key file",
"keypoolRanOut": "Keypool ran out.",
Expand All @@ -93,6 +94,7 @@
"no": "No",
"notDeterministic": "Wallet is not deterministic.",
"notFound": "Not found",
"notificationSounds": "Notification sounds",
"ok": "Ok",
"onBlock": "On block",
"os": "OS",
Expand Down
2 changes: 2 additions & 0 deletions src/locales/es-ES/wallet.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"inbound": "Entrante",
"incentiveReward": "Recompensa por el incentivo",
"includedInBlock": "Incluido en el bloque",
"incoming": "Incoming",
"insufficientFunds": "Usted no tiene dinero suficiente.",
"keyFile": "Archivo clave",
"keypoolRanOut": "Keypool expiró.",
Expand All @@ -93,6 +94,7 @@
"no": "No",
"notDeterministic": "La cartera no es determinística.",
"notFound": "No se ha encontrado",
"notificationSounds": "Notification sounds",
"ok": "Ok",
"onBlock": "En el bloque",
"os": "SO",
Expand Down
2 changes: 2 additions & 0 deletions src/locales/fr-FR/wallet.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"inbound": "Inbound",
"incentiveReward": "Récompense incitative",
"includedInBlock": "Inclus dans le bloc",
"incoming": "Incoming",
"insufficientFunds": "Vous n'avez pas suffisamment de fonds.",
"keyFile": "Fichier clé",
"keypoolRanOut": "Le pool des clés s'est épuisé.",
Expand All @@ -93,6 +94,7 @@
"no": "Non",
"notDeterministic": "Le portefeuille n'est pas déterministe.",
"notFound": "Pas trouvé",
"notificationSounds": "Notification sounds",
"ok": "Ok",
"onBlock": "Sur le bloc",
"os": "OS",
Expand Down
2 changes: 2 additions & 0 deletions src/locales/pt-BR/wallet.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"inbound": "Entrada",
"incentiveReward": "Recompensa pelo incentivo",
"includedInBlock": "Incluído no bloco",
"incoming": "Incoming",
"insufficientFunds": "Você não tem dinheiro suficiente.",
"keyFile": "Arquivo chave",
"keypoolRanOut": "Keypool expirou.",
Expand All @@ -93,6 +94,7 @@
"no": "Não",
"notDeterministic": "A carteira não é determinística.",
"notFound": "Não foi encontrado",
"notificationSounds": "Notification sounds",
"ok": "Ok",
"onBlock": "No bloco",
"os": "SO",
Expand Down
2 changes: 2 additions & 0 deletions src/locales/ru-RU/wallet.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"inbound": "Прибывающий",
"incentiveReward": "Поощрительное вознаграждение",
"includedInBlock": "Включено в блок",
"incoming": "Incoming",
"insufficientFunds": "У вас недостаточно средств.",
"keyFile": "Файл ключа",
"keypoolRanOut": "Keypool закончился.",
Expand All @@ -93,6 +94,7 @@
"no": "Нет",
"notDeterministic": "Не детерминистический кошелёк.",
"notFound": "Не найдено",
"notificationSounds": "Notification sounds",
"ok": "ОК",
"onBlock": "В блоке",
"os": "ОС",
Expand Down
4 changes: 3 additions & 1 deletion src/locales/sl-SI/wallet.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"inbound": "Dohodna",
"incentiveReward": "Nagrada vozlišča",
"includedInBlock": "Vključena v bloku",
"incoming": "Ob prejetju",
"insufficientFunds": "Zadostna sredstva niso na voljo.",
"keyFile": "Datoteka z ključem",
"keypoolRanOut": "Zmanjkalo je ključev.",
Expand All @@ -93,6 +94,7 @@
"no": "Ne",
"notDeterministic": "Denarnica ni deterministična.",
"notFound": "Ni zadetka",
"notificationSounds": "Zvoki obvestil",
"ok": "Vredu",
"onBlock": "Na bloku",
"os": "OS",
Expand Down Expand Up @@ -156,7 +158,7 @@
"sending": "Pošiljam",
"sendingFailed": "Pošiljanje neuspešno",
"sendingToSelf": "Pošiljam sebi",
"spendable": "Neporabljeni",
"spendable": "Na voljo za potrošnjo",
"spendFrom": "Porabi z računa",
"spent": "Porabljeni",
"sshTunnel": "SSH tunel",
Expand Down
21 changes: 18 additions & 3 deletions src/stores/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ class GUI {
* Observable properties.
* @property {string} language - Display language.
* @property {string} localCurrency - Local currency.
* @property {object} soundAlerts - Sound alerts.
*/
@observable language = getItem('language') || 'en-US'
@observable localCurrency = getItem('localCurrency') || 'EUR'
@observable soundAlerts = getItem('soundAlerts') || {
incoming: false,
spendable: false
}

/**
* @constructor
Expand All @@ -35,12 +40,12 @@ class GUI {

/**
* Set display language and save it to local storage.
* @action setLanguage
* @function setLanguage
* @param {string} language - Display language.
*/
@action setLanguage (language) {
this.language = language
setItem('language', language)
setItem('language', this.language)
}

/**
Expand All @@ -50,7 +55,17 @@ class GUI {
*/
@action setLocalCurrency (localCurrency) {
this.localCurrency = localCurrency
setItem('localCurrency', localCurrency)
setItem('localCurrency', this.localCurrency)
}

/**
* Set sound alert and save it to local storage.
* @function setSoundAlert
* @param {string} alert - Alert to toggle.
*/
@action setSoundAlert (alert) {
this.soundAlerts[alert] = !this.soundAlerts[alert]
setItem('soundAlerts', this.soundAlerts)
}
}

Expand Down
17 changes: 17 additions & 0 deletions src/stores/wallet.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { action, autorunAsync, computed, observable, reaction } from 'mobx'
import { notification } from 'antd'
import { join } from 'path'
import { shortUid } from '../utilities/common'
import i18next from '../utilities/i18next'
import moment from 'moment'
Expand Down Expand Up @@ -903,6 +904,14 @@ export default class Wallet {
})
})

/** Play a incoming notification sound if enabled. */
if (
notifications.pending.size > 0 &&
this.gui.soundAlerts.incoming === true
) {
new Audio(join(__dirname, '..', 'assets', 'sounds', 'incoming.mp3')).play()
}

/**
* Open notification on confirmation change,
* from 0 -> 1 and 219 -> 220 for generated.
Expand All @@ -921,6 +930,14 @@ export default class Wallet {
duration: 6
})
})

/** Play a spendable notification sound if enabled. */
if (
notifications.spendable.size > 0 &&
this.gui.soundAlerts.spendable === true
) {
new Audio(join(__dirname, '..', 'assets', 'sounds', 'spendable.mp3')).play()
}
}
}

Expand Down

0 comments on commit 3cc801a

Please sign in to comment.