-
-
Notifications
You must be signed in to change notification settings - Fork 546
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a "keep screen on" option using NoSleep.js (closes #427)
- Loading branch information
Showing
7 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
Grocy.WakeLock = { }; | ||
Grocy.WakeLock.NoSleepJsIntance = null; | ||
Grocy.WakeLock.InitDone = false; | ||
|
||
$("#keep_screen_on").on("change", function() | ||
{ | ||
var value = $(this).is(":checked"); | ||
if (value) | ||
{ | ||
Grocy.WakeLock.Enable(); | ||
} | ||
else | ||
{ | ||
Grocy.WakeLock.Disable(); | ||
} | ||
}); | ||
|
||
Grocy.WakeLock.Enable = function() | ||
{ | ||
if (Grocy.WakeLock.NoSleepJsIntance === null) | ||
{ | ||
Grocy.WakeLock.NoSleepJsIntance = new NoSleep(); | ||
} | ||
Grocy.WakeLock.NoSleepJsIntance.enable(); | ||
Grocy.WakeLock.InitDone = true; | ||
} | ||
|
||
Grocy.WakeLock.Disable = function() | ||
{ | ||
if (Grocy.WakeLock.NoSleepJsIntance !== null) | ||
{ | ||
Grocy.WakeLock.NoSleepJsIntance.disable(); | ||
} | ||
} | ||
|
||
// Handle "Keep screen on while displaying a fullscreen-card" when the body class "fullscreen-card" has changed | ||
new MutationObserver(function(mutations) | ||
{ | ||
if (BoolVal(Grocy.UserSettings.keep_screen_on_when_fullscreen_card) && !BoolVal(Grocy.UserSettings.keep_screen_on)) | ||
{ | ||
mutations.forEach(function(mutation) | ||
{ | ||
if (mutation.attributeName === "class") | ||
{ | ||
var attributeValue = $(mutation.target).prop(mutation.attributeName); | ||
if (attributeValue.contains("fullscreen-card")) | ||
{ | ||
Grocy.WakeLock.Enable(); | ||
} | ||
else | ||
{ | ||
Grocy.WakeLock.Disable(); | ||
} | ||
} | ||
}); | ||
} | ||
}).observe(document.body, { | ||
attributes: true | ||
}); | ||
|
||
// Enabling NoSleep.Js only works in a user input event handler, | ||
// so if the user wants to keep the screen on always, | ||
// do this in on the first click on anything | ||
$(document).click(function() | ||
{ | ||
if (Grocy.WakeLock.InitDone === false && BoolVal(Grocy.UserSettings.keep_screen_on)) | ||
{ | ||
Grocy.WakeLock.Enable(); | ||
} | ||
|
||
Grocy.WakeLock.InitDone = true; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters