Skip to content

Commit

Permalink
feat: update code
Browse files Browse the repository at this point in the history
  • Loading branch information
Teddy-Zhu committed Nov 19, 2021
1 parent 798011b commit 1faceab
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 50 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

## Project setup
```
npm install
yarn
```

### Compiles and hot-reloads for development
```
npm run serve
yarn electron:serve
```

### Compiles and minifies for production
```
npm run build
yarn electron:build
```

### Lints and fixes files
```
npm run lint
yarn lint
```

### Customize configuration
See [Configuration Reference](https://cli.vuejs.org/config/).
### Download
See [Release Page](https://github.com/Teddy-Zhu/coinbar/releases).
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"ant-design-vue": "^1.7.8",
"ccxt": "^1.61.55",
"core-js": "^3.6.5",
"lodash": "^4.17.21",
"menubar": "^9.1.0",
"vue": "^2.6.11",
"vue-router": "^3.2.0",
Expand Down
53 changes: 29 additions & 24 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ async function createWindow () {
trayMenu.tray.addListener('right-click', () => {
app.exit()
})
if (process.env.NODE_ENV !== 'production') trayMenu.window.webContents.openDevTools()
updateCoinByExchange()
})
}
Expand All @@ -99,35 +100,39 @@ function getExchangeInstance (exchange) {
async function updateCoinByExchange () {
const allConfig = store.state.config
const enable = allConfig.enable
if (!enable) {
return
}
const config = allConfig.subscribe
const msgStr = []
try {
for (const exchange in config) {
const exchangeConfig = config[exchange]
const exchangeObj = getExchangeInstance(exchange)
const removeSuffix = exchangeConfig.removeSuffix
if (exchangeConfig.type === 0) {
for (const i in exchangeConfig.symbols) {
const symbol = exchangeConfig.symbols[i]
const ticker = await exchangeObj.fetchTicker(symbol)
msgStr.push(`${removeSuffix ? symbol.split('/')[0] : symbol} ${ticker.last}`)
if (enable) {
const config = allConfig.subscribe
const msgStr = []
try {
for (const exchange in config) {
const exchangeConfig = config[exchange]
// console.log(`exchange: ${exchange}, config: ${JSON.stringify(exchangeConfig)}`)
if (!exchangeConfig.enable) {
continue
}
} else {
const tickers = await exchangeObj.fetchTickers(exchangeConfig.symbols)
for (const ticker of tickers) {
msgStr.push(`${removeSuffix ? ticker.symbol.split('/')[0] : ticker.symbol} ${ticker.last}`)
const exchangeObj = getExchangeInstance(exchange)
const removeSuffix = exchangeConfig.removeSuffix
if (exchangeConfig.type === 0) {
for (const i in exchangeConfig.symbols) {
const symbol = exchangeConfig.symbols[i]
const ticker = await exchangeObj.fetchTicker(symbol)
msgStr.push(`${removeSuffix ? symbol.split('/')[0] : symbol} ${ticker.last}`)
}
} else {
const tickers = await exchangeObj.fetchTickers(exchangeConfig.symbols)
for (const ticker of tickers) {
msgStr.push(`${removeSuffix ? ticker.symbol.split('/')[0] : ticker.symbol} ${ticker.last}`)
}
}
}
} catch (e) {
console.log(e)
}
} catch (e) {
console.log(e)
}

trayMenu.tray.setTitle(msgStr.join('·'))

trayMenu.tray.setTitle(msgStr.join('·'))
} else {
trayMenu.tray.setTitle('plugin disabled')
}
setTimeout(updateCoinByExchange, 10000)
}

Expand Down
32 changes: 26 additions & 6 deletions src/store/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
import Vue from 'vue'
import Vuex from 'vuex'
import { createPersistedState, createSharedMutations } from 'vuex-electron'
import _ from 'lodash'

Vue.use(Vuex)

export default new Vuex.Store({
state: {
defaultExchangeConfig: {
enable: true,
type: 0,
removeSuffix: true,
symbols: []
},
config: {
enable: true,
subscribe: {
binance: {
enable: true,
type: 0,
removeSuffix: true,
symbols: []
},
mexc: {
enable: true,
type: 0,
removeSuffix: true,
symbols: ['BTC/USDT', 'ICP/USDT', 'BIT/USDT', 'SWASH/USDT', 'MX/USDT']
Expand All @@ -31,21 +40,32 @@ export default new Vuex.Store({
if (name in state.config.subscribe) {
return
}
state.config.subscribe[name] = {
type: 0,
removeSuffix: true,
symbols: []
}
state.config.subscribe[name] = _.cloneDeep(state.defaultExchangeConfig)
},
removeExchangeM (state, { name }) {
if (!(name in state.config.subscribe)) {
return
}
delete state.config.subscribe[name]
},
switchStatusM (state) {
state.config.enable = !state.config.enable
},
switchExchangeStatusM (state, { name }) {
if (!(name in state.config.subscribe)) {
return
}
state.config.subscribe[name].enable = !state.config.subscribe[name].enable
}
},
actions: {
removeExchange ({ commit }, name) {
switchExchangeStatus ({ commit }, { name }) {
commit('switchExchangeStatusM', { name })
},
switchStatus ({ commit }) {
commit('switchStatusM')
},
removeExchange ({ commit }, { name }) {
commit('removeExchangeM', name)
},
addExchange ({ commit }, { name }) {
Expand Down
49 changes: 35 additions & 14 deletions src/views/Tray.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<template>
<div style="overflow-x: hidden">
<a-row type="flex" justify="space-around" align="middle" :gutter="16">
<a-col :span="22" offset="1" style="padding-bottom: 1em" class="control">
<a-col :span="22" offset="1" class="control">
<a-button :type="config.enable?'danger':'primary'" @click="updateStatus">
{{config.enable?'禁用':'启用'}}
{{ config.enable ? '禁用' : '启用' }}
</a-button>
<a-button type="primary" @click="addExchangeBtn">
新增交易所
Expand All @@ -12,6 +12,7 @@
移除交易所
</a-button>
</a-col>
<a-col :span="24"> <a-divider /></a-col>
<a-col :span="2" offset="1">
<label>名称</label>
</a-col>
Expand All @@ -31,17 +32,28 @@
</a-select-option>
</a-select>
</a-col>
<a-col :span="24" style="padding-top: 1em">
<a-col :span="24"> <a-divider />
</a-col>
<a-col :span="24">
<a-tabs v-model="activeExchange">
<a-tab-pane :key="name" :tab="name" v-for="(value, name) in config.subscribe">
<a-select mode="tags"
style="width: 100%"
:default-value="config.subscribe[name].symbols"
placeholder="请输入需要监听的Coin"
@change="changeSymbols(name,$event)"
>
<a-select-option value="BTC/USDT">BTC/USDT</a-select-option>
</a-select>
<a-row>
<a-col :span="22" offset="1">
<a-select mode="tags"
style="width: 100%"
:default-value="config.subscribe[name].symbols"
placeholder="请输入需要监听的Coin"
@change="changeSymbols(name,$event)"
>
<a-select-option value="BTC/USDT">BTC/USDT</a-select-option>
</a-select>
</a-col>
<a-col :span="22" offset="1">
<a-button :type="config.subscribe[name].enable?'danger':'primary'" @click="updateExchangeStatus">
{{ config.subscribe[name].enable ? '禁用' : '启用' }}
</a-button>
</a-col>
</a-row>
</a-tab-pane>
</a-tabs>
</a-col>
Expand All @@ -63,11 +75,20 @@ export default {
}
},
created () {
this.activeExchange = Object.keys(this.config.subscribe)[0]
},
methods: {
...mapActions(['updateSymbols', 'addExchange', 'removeExchange']),
...mapActions(['updateSymbols', 'addExchange', 'removeExchange', 'switchStatus', 'switchExchangeStatus']),
updateExchangeStatus () {
if (!this.activeExchange) {
return
}
this.switchExchangeStatus({
name: this.activeExchange
})
},
updateStatus () {
this.switchStatus()
},
removeExchangeBtn () {
if (!this.activeExchange) {
Expand Down Expand Up @@ -100,7 +121,7 @@ export default {
</script>

<style type="text/css">
.ant-col.control .ant-btn{
.ant-col.control .ant-btn {
margin-right: 10px;
}
</style>

0 comments on commit 1faceab

Please sign in to comment.