Skip to content

Commit 651aa14

Browse files
committed
refactor: reload config on websocket connection.
1 parent d8ccbe0 commit 651aa14

File tree

3 files changed

+8
-20
lines changed

3 files changed

+8
-20
lines changed

app/routes/socket/connection.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import logging
22

3+
from app.library.Events import EventBus, Events
34
from app.library.router import RouteType, route
45

56
LOG: logging.Logger = logging.getLogger(__name__)
67

78

89
@route(RouteType.SOCKET, "connect", "socket_connect")
9-
async def connect(sid: str):
10-
pass
10+
async def connect(notify: EventBus, sid: str):
11+
notify.emit(
12+
Events.CONNECTED, data={"sid": sid}, title="Client connected", message=f"Client '{sid}' connected.", to=sid
13+
)
1114

1215

1316
@route(RouteType.SOCKET, "disconnect", "socket_disconnect")

ui/app/stores/SocketStore.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -264,20 +264,9 @@ export const useSocketStore = defineStore('socket', () => {
264264

265265
on('connect', () => config.loadConfig(false))
266266

267-
on('connected', (data: WSEP['connected']) => {
268-
if (!data?.data) {
269-
return
270-
}
271-
272-
if (data.data.folders) {
273-
config.add('folders', data.data.folders)
274-
}
275-
276-
if ('number' === typeof data.data.history_count) {
277-
stateStore.setHistoryCount(data.data.history_count)
278-
}
279-
267+
on('connected', () => {
280268
error.value = null
269+
config.loadConfig(false)
281270
})
282271

283272
on('item_added', (data: WSEP['item_added']) => {

ui/app/types/sockets.d.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@ export type WSEP = {
2020
connect: null
2121
disconnect: null
2222
connect_error: { message?: string }
23-
connected: EventPayload<{
24-
folders?: string[]
25-
history_count?: number
26-
queue?: Record<string, StoreItem>
27-
}>
23+
connected: EventPayload<{ sid: string }>
2824
item_added: EventPayload<StoreItem>
2925
item_updated: EventPayload<StoreItem>
3026
item_cancelled: EventPayload<StoreItem>

0 commit comments

Comments
 (0)