Show notification if server is updated

This commit is contained in:
Deluan 2021-06-21 13:42:14 -04:00
parent 47bcf719f2
commit 877f01bd38
5 changed files with 19 additions and 11 deletions

View File

@ -40,6 +40,7 @@ type KeepAlive struct {
type ServerStart struct {
baseEvent
StartTime time.Time `json:"startTime"`
Version string `json:"version"`
}
const Any = "*"

View File

@ -208,7 +208,7 @@ func (b *broker) listen() {
log.Debug("Client added to event broker", "numClients", len(clients), "newClient", c.String())
// 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:
// A client has detached and we want to

View File

@ -278,7 +278,8 @@
"data_provider_error": "dataProvider error. Check the console for details.",
"i18n_error": "Cannot load the translations for the specified language",
"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": {
"columnsToDisplay": "Columns To Display",

View File

@ -1,6 +1,6 @@
import React, { useState, useEffect } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { useTranslate } from 'react-admin'
import { useNotify, useTranslate } from 'react-admin'
import {
Popover,
Badge,
@ -22,6 +22,7 @@ import subsonic from '../subsonic'
import { scanStatusUpdate } from '../actions'
import { useInterval } from '../common'
import { formatDuration } from '../utils'
import config from '../config'
const useStyles = makeStyles((theme) => ({
wrapper: {
@ -58,9 +59,10 @@ const Uptime = () => {
const ActivityPanel = () => {
const serverStart = useSelector((state) => state.activity.serverStart)
const up = serverStart && serverStart.startTime
const up = serverStart.startTime
const classes = useStyles({ up })
const translate = useTranslate()
const notify = useNotify()
const [anchorEl, setAnchorEl] = useState(null)
const open = Boolean(anchorEl)
const dispatch = useDispatch()
@ -82,6 +84,12 @@ const ActivityPanel = () => {
})
}, [dispatch])
useEffect(() => {
if (serverStart.version !== config.version) {
notify('ra.notification.new_version', 'info', {}, false, 604800000 * 50)
}
}, [serverStart, notify])
return (
<div className={classes.wrapper}>
<Tooltip title={translate('activity.title')}>

View File

@ -3,17 +3,14 @@ import {
EVENT_SCAN_STATUS,
EVENT_SERVER_START,
} from '../actions'
import config from '../config'
const defaultState = {
const initialState = {
scanStatus: { scanning: false, folderCount: 0, count: 0 },
serverStart: { version: config.version },
}
export const activityReducer = (
previousState = {
scanStatus: defaultState,
},
payload
) => {
export const activityReducer = (previousState = initialState, payload) => {
const { type, data } = payload
switch (type) {
case EVENT_SCAN_STATUS:
@ -23,6 +20,7 @@ export const activityReducer = (
...previousState,
serverStart: {
startTime: data.startTime && Date.parse(data.startTime),
version: data.version,
},
}
case EVENT_REFRESH_RESOURCE: