mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-15 03:30:39 +03:00
Show notification if server is updated
This commit is contained in:
parent
47bcf719f2
commit
877f01bd38
@ -40,6 +40,7 @@ type KeepAlive struct {
|
|||||||
type ServerStart struct {
|
type ServerStart struct {
|
||||||
baseEvent
|
baseEvent
|
||||||
StartTime time.Time `json:"startTime"`
|
StartTime time.Time `json:"startTime"`
|
||||||
|
Version string `json:"version"`
|
||||||
}
|
}
|
||||||
|
|
||||||
const Any = "*"
|
const Any = "*"
|
||||||
|
@ -208,7 +208,7 @@ func (b *broker) listen() {
|
|||||||
log.Debug("Client added to event broker", "numClients", len(clients), "newClient", c.String())
|
log.Debug("Client added to event broker", "numClients", len(clients), "newClient", c.String())
|
||||||
|
|
||||||
// Send a serverStart event to new client
|
// Send a serverStart event to new client
|
||||||
c.diode.put(b.prepareMessage(&ServerStart{StartTime: consts.ServerStart}))
|
c.diode.put(b.prepareMessage(&ServerStart{StartTime: consts.ServerStart, Version: consts.Version()}))
|
||||||
|
|
||||||
case c := <-b.unsubscribing:
|
case c := <-b.unsubscribing:
|
||||||
// A client has detached and we want to
|
// A client has detached and we want to
|
||||||
|
@ -278,7 +278,8 @@
|
|||||||
"data_provider_error": "dataProvider error. Check the console for details.",
|
"data_provider_error": "dataProvider error. Check the console for details.",
|
||||||
"i18n_error": "Cannot load the translations for the specified language",
|
"i18n_error": "Cannot load the translations for the specified language",
|
||||||
"canceled": "Action cancelled",
|
"canceled": "Action cancelled",
|
||||||
"logged_out": "Your session has ended, please reconnect."
|
"logged_out": "Your session has ended, please reconnect.",
|
||||||
|
"new_version": "New version available! Please refresh this window."
|
||||||
},
|
},
|
||||||
"toggleFieldsMenu": {
|
"toggleFieldsMenu": {
|
||||||
"columnsToDisplay": "Columns To Display",
|
"columnsToDisplay": "Columns To Display",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import React, { useState, useEffect } from 'react'
|
import React, { useState, useEffect } from 'react'
|
||||||
import { useDispatch, useSelector } from 'react-redux'
|
import { useDispatch, useSelector } from 'react-redux'
|
||||||
import { useTranslate } from 'react-admin'
|
import { useNotify, useTranslate } from 'react-admin'
|
||||||
import {
|
import {
|
||||||
Popover,
|
Popover,
|
||||||
Badge,
|
Badge,
|
||||||
@ -22,6 +22,7 @@ import subsonic from '../subsonic'
|
|||||||
import { scanStatusUpdate } from '../actions'
|
import { scanStatusUpdate } from '../actions'
|
||||||
import { useInterval } from '../common'
|
import { useInterval } from '../common'
|
||||||
import { formatDuration } from '../utils'
|
import { formatDuration } from '../utils'
|
||||||
|
import config from '../config'
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
wrapper: {
|
wrapper: {
|
||||||
@ -58,9 +59,10 @@ const Uptime = () => {
|
|||||||
|
|
||||||
const ActivityPanel = () => {
|
const ActivityPanel = () => {
|
||||||
const serverStart = useSelector((state) => state.activity.serverStart)
|
const serverStart = useSelector((state) => state.activity.serverStart)
|
||||||
const up = serverStart && serverStart.startTime
|
const up = serverStart.startTime
|
||||||
const classes = useStyles({ up })
|
const classes = useStyles({ up })
|
||||||
const translate = useTranslate()
|
const translate = useTranslate()
|
||||||
|
const notify = useNotify()
|
||||||
const [anchorEl, setAnchorEl] = useState(null)
|
const [anchorEl, setAnchorEl] = useState(null)
|
||||||
const open = Boolean(anchorEl)
|
const open = Boolean(anchorEl)
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
@ -82,6 +84,12 @@ const ActivityPanel = () => {
|
|||||||
})
|
})
|
||||||
}, [dispatch])
|
}, [dispatch])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (serverStart.version !== config.version) {
|
||||||
|
notify('ra.notification.new_version', 'info', {}, false, 604800000 * 50)
|
||||||
|
}
|
||||||
|
}, [serverStart, notify])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classes.wrapper}>
|
<div className={classes.wrapper}>
|
||||||
<Tooltip title={translate('activity.title')}>
|
<Tooltip title={translate('activity.title')}>
|
||||||
|
@ -3,17 +3,14 @@ import {
|
|||||||
EVENT_SCAN_STATUS,
|
EVENT_SCAN_STATUS,
|
||||||
EVENT_SERVER_START,
|
EVENT_SERVER_START,
|
||||||
} from '../actions'
|
} from '../actions'
|
||||||
|
import config from '../config'
|
||||||
|
|
||||||
const defaultState = {
|
const initialState = {
|
||||||
scanStatus: { scanning: false, folderCount: 0, count: 0 },
|
scanStatus: { scanning: false, folderCount: 0, count: 0 },
|
||||||
|
serverStart: { version: config.version },
|
||||||
}
|
}
|
||||||
|
|
||||||
export const activityReducer = (
|
export const activityReducer = (previousState = initialState, payload) => {
|
||||||
previousState = {
|
|
||||||
scanStatus: defaultState,
|
|
||||||
},
|
|
||||||
payload
|
|
||||||
) => {
|
|
||||||
const { type, data } = payload
|
const { type, data } = payload
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case EVENT_SCAN_STATUS:
|
case EVENT_SCAN_STATUS:
|
||||||
@ -23,6 +20,7 @@ export const activityReducer = (
|
|||||||
...previousState,
|
...previousState,
|
||||||
serverStart: {
|
serverStart: {
|
||||||
startTime: data.startTime && Date.parse(data.startTime),
|
startTime: data.startTime && Date.parse(data.startTime),
|
||||||
|
version: data.version,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
case EVENT_REFRESH_RESOURCE:
|
case EVENT_REFRESH_RESOURCE:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user