Skip to content

Commit

Permalink
ui: add config for server ping interval (#18)
Browse files Browse the repository at this point in the history
Signed-off-by: Lu Ken <[email protected]>
  • Loading branch information
kenplusplus authored Dec 29, 2024
1 parent 65be831 commit eac410a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
27 changes: 10 additions & 17 deletions src/GenTradeAgent/src/renderer/src/components/FootBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,18 @@
</div>
<n-space class="foot-status">
<span class="status-icon">Version v0.1</span>
<n-button
v-show="isServerConnected"
text
style="font-size: 18px"
@click="handlerClickNetwork"
>
<n-button v-show="isServerConnected" text style="font-size: 18px" @click="onClickNetwork">
<n-icon>
<PlugConnected20Filled />
</n-icon>
</n-button>
<n-button
v-show="!isServerConnected"
text
style="font-size: 18px"
@click="handlerClickNetwork"
>
<n-button v-show="!isServerConnected" text style="font-size: 18px" @click="onClickNetwork">
<n-icon>
<PlugDisconnected20Regular />
</n-icon>
</n-button>
<div style="width: 30px; max-width: 30px;">
<span style="align-items: center;">{{ serverLatency }}ms</span>
<div style="width: 30px; max-width: 30px">
<span style="align-items: center">{{ serverLatency }}ms</span>
</div>
</n-space>
<n-modal
Expand All @@ -42,6 +32,8 @@
<n-input v-model:value="serverAddress"></n-input>
API Key
<n-input v-model:value="apiKey"></n-input>
Ping Interval (seconds)
<n-input-number v-model:value="pingInterval"></n-input-number>
</n-space>
<template #footer>
<n-button @click="onPositiveClick">OK</n-button>
Expand All @@ -52,13 +44,14 @@
<script setup lang="ts">
import { ref } from 'vue'
import { PlugConnected20Filled, PlugDisconnected20Regular } from '@vicons/fluent'
import { NIcon, NSpace, NButton, NModal, NInput } from 'naive-ui'
import { NIcon, NSpace, NButton, NModal, NInput, NInputNumber } from 'naive-ui'
import { useStore } from '../store'
import { agentServer } from '@renderer/server'
const showServerModal = ref(false)
const serverAddress = ref(agentServer.serverAddress)
const apiKey = ref(agentServer.apiKey)
const pingInterval = ref(agentServer.pingInterval / 1000)
const store = useStore()
Expand All @@ -81,17 +74,17 @@ store.watch(
}
)
const handlerClickNetwork = () => {
const onClickNetwork = () => {
console.log('hehe')
showServerModal.value = true
}
const onPositiveClick = () => {
console.log('ok')
agentServer.serverAddress = serverAddress.value
agentServer.pingInterval = pingInterval.value * 1000
showServerModal.value = false
}
</script>
<style lang="scss" scoped>
.foot-main {
Expand Down
7 changes: 3 additions & 4 deletions src/GenTradeAgent/src/renderer/src/components/TradingMain.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,11 @@ const handleUpdateCurrentInterval = (value: string) => {
}
agentServer.store = useStore()
const handlerPingServer = (() => {
const handlerPingServer = () => {
agentServer.ping()
setTimeout(handlerPingServer, 10000)
})
setTimeout(handlerPingServer, agentServer.pingInterval)
}
handlerPingServer()
</script>

<style lang="scss" scoped>
Expand Down
1 change: 1 addition & 0 deletions src/GenTradeAgent/src/renderer/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class AgentServer {
tzName: string = ''
tzOffset: number = 0
store: Store<IState> | null = null
pingInterval: number = 10000

ping() {
const tsStart = new Date().getTime()
Expand Down

0 comments on commit eac410a

Please sign in to comment.