Skip to content

Commit

Permalink
feat: add liveReloadForce setting
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardBaumrock committed May 3, 2024
1 parent 70de35f commit e4fda2e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 22 deletions.
2 changes: 2 additions & 0 deletions RockFrontend.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -1645,10 +1645,12 @@ public function liveReloadMarkup(): string
$file = $this->minifyFile($this->path . "livereload.js");
$src = $this->url($file, true);

$force = (int)$this->wire->config->liveReloadForce;
return "
<script>
var LiveReloadUrl = '{$this->wire->config->urls->root}';
var LiveReloadSecret = '$secret';
var LiveReloadForce = $force;
console.log('Loading LiveReload');
</script>
<script src='$src'></script>
Expand Down
50 changes: 30 additions & 20 deletions livereload.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,41 @@ setTimeout(() => {
if (document.hidden) return;

console.log(changed);
// check if we are in the admin and have unsaved changes
if (document.querySelectorAll(".InputfieldStateChanged").length) {
console.log("detected change - unsaved changes prevent reload");
// show notification
// delay of 200ms prevents that the notification is shown
// when a page is saved that creates files in the background
setTimeout(() => {
if (LiveReloadForce) {
document
.querySelectorAll(".InputfieldStateChanged")
.forEach((input) => {
input.classList.remove("InputfieldStateChanged");
});
} else {
// check if we are in the admin and have unsaved changes
if (document.querySelectorAll(".InputfieldStateChanged").length) {
console.log("detected change - unsaved changes prevent reload");
// show notification
// delay of 200ms prevents that the notification is shown
// when a page is saved that creates files in the background
setTimeout(() => {
UIkit.notification({
message:
"Unsaved changes prevent reload - use $config->liveReloadForce to force reload.",
status: "warning",
pos: "top-center",
timeout: 0,
});
}, 200);
return;
}
if (document.querySelectorAll("#pw-panel-shade").length) {
console.log("detected change - open panel prevents reload");
UIkit.notification({
message: "Unsaved changes prevent reload",
message:
"Open panel prevents reload - use $config->liveReloadForce to force reload.",
status: "warning",
pos: "top-center",
timeout: 0,
});
}, 200);
return;
}
if (document.querySelectorAll("#pw-panel-shade").length) {
console.log("detected change - open panel prevents reload");
UIkit.notification({
message: "Open panel prevents reload",
status: "warning",
pos: "top-center",
timeout: 0,
});
return;
return;
}
}

// all fine, reload page
Expand Down
4 changes: 2 additions & 2 deletions livereload.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e4fda2e

Please sign in to comment.