mirror of
https://github.com/rystaf/mlmym.git
synced 2024-11-08 08:04:26 +00:00
livereload
This commit is contained in:
parent
1858f1aec0
commit
3fe31bd5b3
2
Makefile
2
Makefile
|
@ -9,7 +9,7 @@ dev:
|
|||
$(MAKE) -j2 --no-print-directory reload serve
|
||||
|
||||
reload:
|
||||
websocketd --loglevel=fatal --port=8009 watchexec -e html,css,js -d 500 'echo "$$WATCHEXEC_WRITTEN_PATH"'
|
||||
websocketd --loglevel=fatal --port=8009 watchexec --no-vcs-ignore -e html,css,js 'echo "$$WATCHEXEC_WRITTEN_PATH"'
|
||||
|
||||
VERSION:
|
||||
git describe --tag > $@
|
||||
|
|
33
public/ws.js
Normal file
33
public/ws.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
var ok = false
|
||||
var t = 800
|
||||
var ws
|
||||
var prot = location.protocol == 'https:' ? "wss://":"ws://"
|
||||
let port = ":8009"
|
||||
|
||||
function start(){
|
||||
let url = prot + document.location.hostname + port + document.location.pathname + document.location.search;
|
||||
console.log('connecting to ', url);
|
||||
ws = new WebSocket(url);
|
||||
ws.onopen = function(){
|
||||
console.log("open");
|
||||
t = 800
|
||||
}
|
||||
ws.onmessage = function(msg){
|
||||
console.log("reload:", msg.data)
|
||||
if (msg.data == "") {
|
||||
return
|
||||
}
|
||||
window.location.reload()
|
||||
}
|
||||
ws.onclose = function(){
|
||||
console.log("close");
|
||||
setTimeout(function(){
|
||||
//start()
|
||||
if (t < 10 * 1000) t += 200
|
||||
}, t);
|
||||
};
|
||||
}
|
||||
console.log("ws");
|
||||
if (typeof WebSocket != 'undefined') {
|
||||
start()
|
||||
}
|
|
@ -215,6 +215,9 @@ func Initialize(Host string, r *http.Request) (State, error) {
|
|||
Status: http.StatusOK,
|
||||
Version: version,
|
||||
}
|
||||
if watch != nil {
|
||||
state.Watch = *watch
|
||||
}
|
||||
lemmyDomain := os.Getenv("LEMMY_DOMAIN")
|
||||
if lemmyDomain != "" {
|
||||
state.Host = "."
|
||||
|
|
1
state.go
1
state.go
|
@ -65,6 +65,7 @@ type Session struct {
|
|||
}
|
||||
|
||||
type State struct {
|
||||
Watch bool
|
||||
Version string
|
||||
Client *lemmy.Client
|
||||
HTTPClient *http.Client
|
||||
|
|
|
@ -141,6 +141,9 @@
|
|||
{{ end }}
|
||||
|
||||
<script src="/_/static/utils.js?v=22"></script>
|
||||
{{ if .Watch }}
|
||||
<script src="/_/static/ws.js"></script>
|
||||
{{ end }}
|
||||
{{ template "sidebar.html" . }}
|
||||
</main>
|
||||
{{ end }}
|
||||
|
|
Loading…
Reference in a new issue