diff --git a/package.json b/package.json
index 072c7dc..37549d0 100644
--- a/package.json
+++ b/package.json
@@ -22,6 +22,7 @@
"CLAY_API_HOST",
"CLAY_API_KEY",
"CLAY_API_IS_JELLYFIN",
+ "CLAY_USER",
"PKJS_READY",
"PKJS_SLEEP_TIMESTAMP"
],
diff --git a/src/pkjs/config.js b/src/pkjs/config.js
index a87cfa2..b722859 100644
--- a/src/pkjs/config.js
+++ b/src/pkjs/config.js
@@ -7,26 +7,60 @@ module.exports = [
"type": "section",
"items": [
{
- "type": "heading",
- "defaultValue": "API Credentials"
+ "type": "toggle",
+ "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",
"messageKey": "CLAY_API_HOST",
"label": "API Host",
- "description": "Example: https://jellyfin.example.com"
},
+ {
+ "id": "helptext_host",
+ "type": "heading",
+ "size": 6
+ }
+ ]
+ },
+ {
+ "type": "section",
+ "items": [
{
"type": "input",
"messageKey": "CLAY_API_KEY",
- "label": "API Key"
+ "label": "API Key",
},
{
- "type": "toggle",
- "messageKey": "CLAY_API_IS_JELLYFIN",
- "defaultValue": true,
- "label": "Jellyfin Support",
- "description": "Toggle off if using Plex. If using Jellyfin, leave on :D"
+ "id": "helptext_api_key",
+ "type": "heading",
+ "size": 6
+ }
+ ]
+ },
+ {
+ "type": "section",
+ "items": [
+ {
+ "type": "input",
+ "messageKey": "CLAY_USER",
+ "label": "Tracked User"
+ },
+ {
+ "id": "helptext_user",
+ "type": "heading",
+ "size": 6
}
]
},
diff --git a/src/pkjs/customClay.js b/src/pkjs/customClay.js
new file mode 100644
index 0000000..a2fcc4f
--- /dev/null
+++ b/src/pkjs/customClay.js
@@ -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:
https://jellyfin.example.com
http://192.168.1.10:8096");
+ clayConfig.getItemById('helptext_api_key').set("1. Log into web UI as admin
2. Go to your \"Dashboard\"
4. Select \"API Keys\" from the left menu
5. Create a key with \"New API Key\"; name it whatever you like and enter the key (not the name) in this box
They key will look like this:
d7f4c2e8a4b3444bb5d6b685fa5918b6");
+ clayConfig.getItemById('helptext_user').set("Enter Jellyfin username to track;
this is used in case multiple users were active when you fell asleep")
+ } else {
+ clayConfig.getItemById('helptext_host').set("Examples:
https://plex.example.com
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;
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);
+ });
+
+};
diff --git a/src/pkjs/index.js b/src/pkjs/index.js
index cdeec27..f6e3e58 100644
--- a/src/pkjs/index.js
+++ b/src/pkjs/index.js
@@ -1,6 +1,7 @@
var Clay = require('@rebble/clay');
var clayConfig = require('./config');
-var clay = new Clay(clayConfig);
+var customClay = require('./customClay');
+new Clay(clayConfig, customClay);
Pebble.addEventListener("ready", function () {
Pebble.sendAppMessage({ PKJS_READY: 1 });
@@ -10,24 +11,34 @@ Pebble.addEventListener("appmessage", function (dict) {
if (dict.payload["PKJS_SLEEP_TIMESTAMP"]) {
var sleepTimestamp = dict.payload["PKJS_SLEEP_TIMESTAMP"];
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) {
- 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 {
// 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.
// 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 + "/api/v2?apikey=" + cfg.CLAY_API_KEY + "&cmd=get_history", null, false, 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, cfg.CLAY_USER, sleepTimestamp);
}
}
});
-function callAPI(fullURL, apiKey, isJellyfin, sleepTimestamp) {
+function callAPI(fullURL, apiKey, isJellyfin, trackedUser, sleepTimestamp) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
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
+ );
+ });
+ }
+
}
};