1
0
mirror of https://github.com/axllent/mailpit.git synced 2024-12-28 23:06:43 +02:00

UI: Automatically refresh connected browsers if Mailpit is upgraded (version change)

This commit is contained in:
Ralph Slooten 2024-01-03 12:54:12 +13:00
parent 12cfb09774
commit dd57596fd1
3 changed files with 19 additions and 5 deletions

View File

@ -3,6 +3,7 @@ package storage
import (
"time"
"github.com/axllent/mailpit/config"
"github.com/axllent/mailpit/server/websockets"
)
@ -23,11 +24,13 @@ func BroadcastMailboxStats() {
time.Sleep(250 * time.Millisecond)
bcStatsDelay = false
b := struct {
Total int
Unread int
Total int
Unread int
Version string
}{
Total: CountTotal(),
Unread: CountUnread(),
Total: CountTotal(),
Unread: CountUnread(),
Version: config.Version,
}
websockets.Broadcast("stats", b)

View File

@ -290,7 +290,7 @@ func index(w http.ResponseWriter, _ *http.Request) {
</head>
<body class="h-100">
<div class="container-fluid h-100 d-flex flex-column" id="app" data-webroot="{{ .Webroot }}">
<div class="container-fluid h-100 d-flex flex-column" id="app" data-webroot="{{ .Webroot }}" data-version="{{ .Version }}">
<noscript>You require JavaScript to use this app.</noscript>
</div>

View File

@ -15,10 +15,16 @@ export default {
reconnectRefresh: false,
socketURI: false,
pauseNotifications: false, // prevent spamming
version: false
}
},
mounted() {
let d = document.getElementById('app')
if (d) {
this.version = d.dataset.version
}
let proto = location.protocol == 'https:' ? 'wss' : 'ws'
this.socketURI = proto + "://" + document.location.host + this.resolve(`/api/events`)
@ -79,6 +85,11 @@ export default {
// refresh mailbox stats
mailbox.total = response.Data.Total
mailbox.unread = response.Data.Unread
// detect version updated, refresh is needed
if (self.version != response.Data.Version) {
location.reload();
}
}
}