mirror of
https://github.com/axllent/mailpit.git
synced 2025-04-27 12:32:22 +02:00
UI: Automatically refresh connected browsers if Mailpit is upgraded (version change)
This commit is contained in:
parent
12cfb09774
commit
dd57596fd1
@ -3,6 +3,7 @@ package storage
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/axllent/mailpit/config"
|
||||||
"github.com/axllent/mailpit/server/websockets"
|
"github.com/axllent/mailpit/server/websockets"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -25,9 +26,11 @@ func BroadcastMailboxStats() {
|
|||||||
b := struct {
|
b := struct {
|
||||||
Total int
|
Total int
|
||||||
Unread int
|
Unread int
|
||||||
|
Version string
|
||||||
}{
|
}{
|
||||||
Total: CountTotal(),
|
Total: CountTotal(),
|
||||||
Unread: CountUnread(),
|
Unread: CountUnread(),
|
||||||
|
Version: config.Version,
|
||||||
}
|
}
|
||||||
|
|
||||||
websockets.Broadcast("stats", b)
|
websockets.Broadcast("stats", b)
|
||||||
|
@ -290,7 +290,7 @@ func index(w http.ResponseWriter, _ *http.Request) {
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body class="h-100">
|
<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>
|
<noscript>You require JavaScript to use this app.</noscript>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -15,10 +15,16 @@ export default {
|
|||||||
reconnectRefresh: false,
|
reconnectRefresh: false,
|
||||||
socketURI: false,
|
socketURI: false,
|
||||||
pauseNotifications: false, // prevent spamming
|
pauseNotifications: false, // prevent spamming
|
||||||
|
version: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
|
let d = document.getElementById('app')
|
||||||
|
if (d) {
|
||||||
|
this.version = d.dataset.version
|
||||||
|
}
|
||||||
|
|
||||||
let proto = location.protocol == 'https:' ? 'wss' : 'ws'
|
let proto = location.protocol == 'https:' ? 'wss' : 'ws'
|
||||||
this.socketURI = proto + "://" + document.location.host + this.resolve(`/api/events`)
|
this.socketURI = proto + "://" + document.location.host + this.resolve(`/api/events`)
|
||||||
|
|
||||||
@ -79,6 +85,11 @@ export default {
|
|||||||
// refresh mailbox stats
|
// refresh mailbox stats
|
||||||
mailbox.total = response.Data.Total
|
mailbox.total = response.Data.Total
|
||||||
mailbox.unread = response.Data.Unread
|
mailbox.unread = response.Data.Unread
|
||||||
|
|
||||||
|
// detect version updated, refresh is needed
|
||||||
|
if (self.version != response.Data.Version) {
|
||||||
|
location.reload();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user