Skip to content

Commit

Permalink
Merge pull request #2 from jonschz/power-requests
Browse files Browse the repository at this point in the history
Power requests, delay before reenabling sleep, further improvements

Co-authored-by: Faheem Pervez <[email protected]>
  • Loading branch information
jonschz and qwerty12 authored May 11, 2023
2 parents 2094b99 + 07caecd commit 15924ff
Show file tree
Hide file tree
Showing 6 changed files with 386 additions and 160 deletions.
6 changes: 3 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<Version>0.0.1.0</Version>
<AssemblyVersion>0.0.1.0</AssemblyVersion>
<FileVersion>0.0.1.0</FileVersion>
<Version>0.1.0.0</Version>
<AssemblyVersion>0.1.0.0</AssemblyVersion>
<FileVersion>0.1.0.0</FileVersion>
</PropertyGroup>
</Project>
40 changes: 3 additions & 37 deletions Jellyfin.Plugin.PreventSleep/Configuration/PluginConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,6 @@

namespace Jellyfin.Plugin.PreventSleep.Configuration;

/// <summary>
/// The configuration options.
/// </summary>
public enum SomeOptions
{
/// <summary>
/// Option one.
/// </summary>
OneOption,

/// <summary>
/// Second option.
/// </summary>
AnotherOption
}

/// <summary>
/// Plugin configuration.
/// </summary>
Expand All @@ -29,29 +13,11 @@ public class PluginConfiguration : BasePluginConfiguration
public PluginConfiguration()
{
// set default options here
Options = SomeOptions.AnotherOption;
TrueFalseSetting = true;
AnInteger = 2;
AString = "string";
UnblockSleepDelay = 1;
}

/// <summary>
/// Gets or sets a value indicating whether some true or false setting is enabled..
/// </summary>
public bool TrueFalseSetting { get; set; }

/// <summary>
/// Gets or sets an integer setting.
/// </summary>
public int AnInteger { get; set; }

/// <summary>
/// Gets or sets a string setting.
/// </summary>
public string AString { get; set; }

/// <summary>
/// Gets or sets an enum option.
/// Gets or sets the amount of minutes to wait before re-enabling sleep.
/// </summary>
public SomeOptions Options { get; set; }
public int UnblockSleepDelay { get; set; }
}
52 changes: 14 additions & 38 deletions Jellyfin.Plugin.PreventSleep/Configuration/configPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,17 @@
<html lang="en">
<head>
<meta charset="utf-8">
<title>Template</title>
<title>Prevent Sleep</title>
</head>
<body>
<div id="TemplateConfigPage" data-role="page" class="page type-interior pluginConfigurationPage" data-require="emby-input,emby-button,emby-select,emby-checkbox">
<div id="PreventSleepConfigPage" data-role="page" class="page type-interior pluginConfigurationPage" data-require="emby-input,emby-button,emby-select,emby-checkbox">
<div data-role="content">
<div class="content-primary">
<form id="TemplateConfigForm">
<div class="selectContainer">
<label class="selectLabel" for="Options">Several Options</label>
<select is="emby-select" id="Options" name="Options" class="emby-select-withcolor emby-select">
<option id="optOneOption" value="OneOption">One Option</option>
<option id="optAnotherOption" value="AnotherOption">Another Option</option>
</select>
</div>
<div class="inputContainer">
<label class="inputLabel inputLabelUnfocused" for="AnInteger">An Integer</label>
<input id="AnInteger" name="AnInteger" type="number" is="emby-input" min="0" />
<div class="fieldDescription">A Description</div>
</div>
<div class="checkboxContainer checkboxContainer-withDescription">
<label class="emby-checkbox-label">
<input id="TrueFalseSetting" name="TrueFalseCheckBox" type="checkbox" is="emby-checkbox" />
<span>A Checkbox</span>
</label>
</div>
<form id="PreventSleepConfigForm">
<div class="inputContainer">
<label class="inputeLabel inputLabelUnfocused" for="AString">A String</label>
<input id="AString" name="AString" type="text" is="emby-input" />
<div class="fieldDescription">Another Description</div>
<label class="inputLabel inputLabelUnfocused" for="UnblockSleepDelay">Delay before unblocking sleep (in minutes)</label>
<input id="UnblockSleepDelay" name="UnblockSleepDelay" type="number" is="emby-input" min="1" />
<div class="fieldDescription">Wait for the specified time after all playback has ended before allowing sleep again.</div>
</div>
<div>
<button is="emby-button" type="submit" class="raised button-submit block emby-button">
Expand All @@ -41,31 +23,25 @@
</div>
</div>
<script type="text/javascript">
var TemplateConfig = {
var PreventSleepConfig = {
pluginUniqueId: 'd6b0196a-9885-4d87-b25c-562a57ebbe0b'
};

document.querySelector('#TemplateConfigPage')
document.querySelector('#PreventSleepConfigPage')
.addEventListener('pageshow', function() {
Dashboard.showLoadingMsg();
ApiClient.getPluginConfiguration(TemplateConfig.pluginUniqueId).then(function (config) {
document.querySelector('#Options').value = config.Options;
document.querySelector('#AnInteger').value = config.AnInteger;
document.querySelector('#TrueFalseSetting').checked = config.TrueFalseSetting;
document.querySelector('#AString').value = config.AString;
ApiClient.getPluginConfiguration(PreventSleepConfig.pluginUniqueId).then(function (config) {
document.querySelector('#UnblockSleepDelay').value = config.UnblockSleepDelay;
Dashboard.hideLoadingMsg();
});
});

document.querySelector('#TemplateConfigForm')
document.querySelector('#PreventSleepConfigForm')
.addEventListener('submit', function(e) {
Dashboard.showLoadingMsg();
ApiClient.getPluginConfiguration(TemplateConfig.pluginUniqueId).then(function (config) {
config.Options = document.querySelector('#Options').value;
config.AnInteger = document.querySelector('#AnInteger').value;
config.TrueFalseSetting = document.querySelector('#TrueFalseSetting').checked;
config.AString = document.querySelector('#AString').value;
ApiClient.updatePluginConfiguration(TemplateConfig.pluginUniqueId, config).then(function (result) {
ApiClient.getPluginConfiguration(PreventSleepConfig.pluginUniqueId).then(function (config) {
config.UnblockSleepDelay = document.querySelector('#UnblockSleepDelay').value;
ApiClient.updatePluginConfiguration(PreventSleepConfig.pluginUniqueId, config).then(function (result) {
Dashboard.processPluginConfigurationUpdateResult(result);
});
});
Expand Down
Loading

0 comments on commit 15924ff

Please sign in to comment.