code refactoring
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import * as O from 'fp-ts/Option'
|
import * as O from 'fp-ts/Option'
|
||||||
import { useMemo } from 'react'
|
import { useMemo } from 'react'
|
||||||
import { useRecoilState, useRecoilValue } from 'recoil'
|
import { useRecoilState, useRecoilValue } from 'recoil'
|
||||||
import { interval, share, take } from 'rxjs'
|
import { share, take, timer } from 'rxjs'
|
||||||
import { downloadsState } from '../atoms/downloads'
|
import { downloadsState } from '../atoms/downloads'
|
||||||
import { serverAddressAndPortState } from '../atoms/settings'
|
import { serverAddressAndPortState } from '../atoms/settings'
|
||||||
import { connectedState } from '../atoms/status'
|
import { connectedState } from '../atoms/status'
|
||||||
@@ -34,8 +34,9 @@ const SocketSubscriber: React.FC<Props> = ({ children }) => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
useSubscription(sharedSocket$,
|
useSubscription(
|
||||||
(event) => {
|
sharedSocket$,
|
||||||
|
event => {
|
||||||
if (!isRPCResponse(event)) { return }
|
if (!isRPCResponse(event)) { return }
|
||||||
if (!Array.isArray(event.result)) { return }
|
if (!Array.isArray(event.result)) { return }
|
||||||
|
|
||||||
@@ -52,7 +53,7 @@ const SocketSubscriber: React.FC<Props> = ({ children }) => {
|
|||||||
|
|
||||||
setDownloads(O.none)
|
setDownloads(O.none)
|
||||||
},
|
},
|
||||||
(err) => {
|
err => {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
pushMessage(
|
pushMessage(
|
||||||
`${i18n.t('rpcConnErr')} (${serverAddressAndPort})`,
|
`${i18n.t('rpcConnErr')} (${serverAddressAndPort})`,
|
||||||
@@ -61,7 +62,7 @@ const SocketSubscriber: React.FC<Props> = ({ children }) => {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
useSubscription(interval(1000), () => client.running())
|
useSubscription(timer(0, 1000), () => client.running())
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>{children}</>
|
<>{children}</>
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ func (m *MemoryDB) Get(id string) (*Process, error) {
|
|||||||
|
|
||||||
// Store a pointer of a process and return its id
|
// Store a pointer of a process and return its id
|
||||||
func (m *MemoryDB) Set(process *Process) string {
|
func (m *MemoryDB) Set(process *Process) string {
|
||||||
id := uuid.Must(uuid.NewRandom()).String()
|
id := uuid.NewString()
|
||||||
m.table.Store(id, process)
|
m.table.Store(id, process)
|
||||||
process.Id = id
|
process.Id = id
|
||||||
return id
|
return id
|
||||||
@@ -97,12 +97,9 @@ func (m *MemoryDB) All() *[]ProcessResponse {
|
|||||||
func (m *MemoryDB) Persist() {
|
func (m *MemoryDB) Persist() {
|
||||||
running := m.All()
|
running := m.All()
|
||||||
|
|
||||||
sessionFile := filepath.Join(
|
sf := filepath.Join(config.Instance().SessionFilePath, "session.dat")
|
||||||
config.Instance().SessionFilePath,
|
|
||||||
"session.dat",
|
|
||||||
)
|
|
||||||
|
|
||||||
fd, err := os.Create(sessionFile)
|
fd, err := os.Create(sf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(cli.Red, "Failed to persist session", cli.Reset)
|
log.Println(cli.Red, "Failed to persist session", cli.Reset)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user