Show different help text for each platform (Jellyfin vs Plex)
This commit is contained in:
@@ -22,6 +22,7 @@
|
|||||||
"CLAY_API_HOST",
|
"CLAY_API_HOST",
|
||||||
"CLAY_API_KEY",
|
"CLAY_API_KEY",
|
||||||
"CLAY_API_IS_JELLYFIN",
|
"CLAY_API_IS_JELLYFIN",
|
||||||
|
"CLAY_USER",
|
||||||
"PKJS_READY",
|
"PKJS_READY",
|
||||||
"PKJS_SLEEP_TIMESTAMP"
|
"PKJS_SLEEP_TIMESTAMP"
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -7,26 +7,60 @@ module.exports = [
|
|||||||
"type": "section",
|
"type": "section",
|
||||||
"items": [
|
"items": [
|
||||||
{
|
{
|
||||||
"type": "heading",
|
"type": "toggle",
|
||||||
"defaultValue": "API Credentials"
|
"messageKey": "CLAY_API_IS_JELLYFIN",
|
||||||
|
"defaultValue": true,
|
||||||
|
"label": "Jellyfin Support"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "heading",
|
||||||
|
"size": 6,
|
||||||
|
"defaultValue": "Toggle off if using Plex. If using Jellyfin, leave on :D"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "section",
|
||||||
|
"items": [
|
||||||
{
|
{
|
||||||
"type": "input",
|
"type": "input",
|
||||||
"messageKey": "CLAY_API_HOST",
|
"messageKey": "CLAY_API_HOST",
|
||||||
"label": "API Host",
|
"label": "API Host",
|
||||||
"description": "Example: https://jellyfin.example.com"
|
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "helptext_host",
|
||||||
|
"type": "heading",
|
||||||
|
"size": 6
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "section",
|
||||||
|
"items": [
|
||||||
{
|
{
|
||||||
"type": "input",
|
"type": "input",
|
||||||
"messageKey": "CLAY_API_KEY",
|
"messageKey": "CLAY_API_KEY",
|
||||||
"label": "API Key"
|
"label": "API Key",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "toggle",
|
"id": "helptext_api_key",
|
||||||
"messageKey": "CLAY_API_IS_JELLYFIN",
|
"type": "heading",
|
||||||
"defaultValue": true,
|
"size": 6
|
||||||
"label": "Jellyfin Support",
|
}
|
||||||
"description": "Toggle off if using Plex. If using Jellyfin, leave on :D"
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "section",
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"type": "input",
|
||||||
|
"messageKey": "CLAY_USER",
|
||||||
|
"label": "Tracked User"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "helptext_user",
|
||||||
|
"type": "heading",
|
||||||
|
"size": 6
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
25
src/pkjs/customClay.js
Normal file
25
src/pkjs/customClay.js
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
module.exports = function (minified) {
|
||||||
|
var clayConfig = this;
|
||||||
|
var _ = minified._;
|
||||||
|
var $ = minified.$;
|
||||||
|
var HTML = minified.HTML;
|
||||||
|
|
||||||
|
function toggleHelptext() {
|
||||||
|
if (this.get()) {
|
||||||
|
clayConfig.getItemById('helptext_host').set("Examples:<br>https://jellyfin.example.com<br>http://192.168.1.10:8096");
|
||||||
|
clayConfig.getItemById('helptext_api_key').set("1. Log into web UI as admin<br>2. Go to your \"Dashboard\"<br>4. Select \"API Keys\" from the left menu<br>5. Create a key with \"New API Key\"; name it whatever you like and enter the key (not the name) in this box<br><br>They key will look like this:<br>d7f4c2e8a4b3444bb5d6b685fa5918b6");
|
||||||
|
clayConfig.getItemById('helptext_user').set("Enter Jellyfin username to track;<br>this is used in case multiple users were active when you fell asleep")
|
||||||
|
} else {
|
||||||
|
clayConfig.getItemById('helptext_host').set("Examples:<br>https://plex.example.com<br>http://192.168.1.10:8096");
|
||||||
|
clayConfig.getItemById('helptext_api_key').set("TODO Plex help");
|
||||||
|
clayConfig.getItemById('helptext_user').set("Enter Plex username to track;<br>this is used in case multiple users were active when you fell asleep")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
clayConfig.on(clayConfig.EVENTS.AFTER_BUILD, function () {
|
||||||
|
var jellyfinToggle = clayConfig.getItemByMessageKey('CLAY_API_IS_JELLYFIN');
|
||||||
|
toggleHelptext.call(jellyfinToggle);
|
||||||
|
jellyfinToggle.on('change', toggleHelptext);
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
var Clay = require('@rebble/clay');
|
var Clay = require('@rebble/clay');
|
||||||
var clayConfig = require('./config');
|
var clayConfig = require('./config');
|
||||||
var clay = new Clay(clayConfig);
|
var customClay = require('./customClay');
|
||||||
|
new Clay(clayConfig, customClay);
|
||||||
|
|
||||||
Pebble.addEventListener("ready", function () {
|
Pebble.addEventListener("ready", function () {
|
||||||
Pebble.sendAppMessage({ PKJS_READY: 1 });
|
Pebble.sendAppMessage({ PKJS_READY: 1 });
|
||||||
@@ -10,24 +11,34 @@ Pebble.addEventListener("appmessage", function (dict) {
|
|||||||
if (dict.payload["PKJS_SLEEP_TIMESTAMP"]) {
|
if (dict.payload["PKJS_SLEEP_TIMESTAMP"]) {
|
||||||
var sleepTimestamp = dict.payload["PKJS_SLEEP_TIMESTAMP"];
|
var sleepTimestamp = dict.payload["PKJS_SLEEP_TIMESTAMP"];
|
||||||
var cfg = JSON.parse(localStorage.getItem('clay-settings'));
|
var cfg = JSON.parse(localStorage.getItem('clay-settings'));
|
||||||
// TODO report last episode as "Configure app settings!" if CLAY_API_HOST or CLAY_API_KEY is empty
|
// TODO report last episode as "Configure app settings!" if CLAY_API_HOST, CLAY_API_KEY, or CLAY_USER is empty
|
||||||
|
// TODO use API to dynamically determine user (prompt on watch)
|
||||||
if (cfg.CLAY_API_IS_JELLYFIN == true) {
|
if (cfg.CLAY_API_IS_JELLYFIN == true) {
|
||||||
callAPI(cfg.CLAY_API_HOST + "/System/ActivityLog/Entries", cfg.CLAY_API_KEY, true, sleepTimestamp);
|
callAPI(cfg.CLAY_API_HOST + "/System/ActivityLog/Entries", cfg.CLAY_API_KEY, true, cfg.CLAY_USER, sleepTimestamp);
|
||||||
} else {
|
} else {
|
||||||
// The official history endpoint doesn't seem to return history w/o Plex Pass.
|
// The official history endpoint doesn't seem to return history w/o Plex Pass.
|
||||||
// If someone with Plex Pass wants to give it a shot, I'd be happy to accept a PR adding this as an option.
|
// If someone with Plex Pass wants to give it a shot, I'd be happy to accept a PR adding this as an option.
|
||||||
// Until then, I'm using Tautulli because it's free.
|
// Until then, I'm using Tautulli because it's free.
|
||||||
//callAPI(cfg.CLAY_API_HOST + "/status/sessions/history/all", cfg.CLAY_API_KEY, false, dict.payload["API_KEY"], sleepTimestamp);
|
//callAPI(cfg.CLAY_API_HOST + "/status/sessions/history/all", cfg.CLAY_API_KEY, false, cfg.CLAY_USER, sleepTimestamp);
|
||||||
callAPI(cfg.CLAY_API_HOST + "/api/v2?apikey=" + cfg.CLAY_API_KEY + "&cmd=get_history", null, false, sleepTimestamp);
|
callAPI(cfg.CLAY_API_HOST + "/api/v2?apikey=" + cfg.CLAY_API_KEY + "&cmd=get_history", null, false, cfg.CLAY_USER, sleepTimestamp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function callAPI(fullURL, apiKey, isJellyfin, sleepTimestamp) {
|
function callAPI(fullURL, apiKey, isJellyfin, trackedUser, sleepTimestamp) {
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
xhr.onreadystatechange = function () {
|
xhr.onreadystatechange = function () {
|
||||||
if (xhr.readyState === 4) {
|
if (xhr.readyState === 4) {
|
||||||
console.log(xhr.responseText);
|
var resp = JSON.parse(xhr.responseText);
|
||||||
|
console.log(resp);
|
||||||
|
if (resp && Array.isArray(resp.Items)) {
|
||||||
|
resp.Items.forEach(function (item, index) {
|
||||||
|
console.log(
|
||||||
|
"[" + index + "] Name: " + item.Name + " | Date: " + item.Date
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user