Implement settings (via Clay)

This commit is contained in:
2026-04-09 20:57:46 -04:00
parent 11f2dc0c94
commit fd9ec48511
5 changed files with 72 additions and 27 deletions

View File

@@ -1,24 +1,29 @@
var Clay = require('@rebble/clay');
var clayConfig = require('./config');
var clay = new Clay(clayConfig);
Pebble.addEventListener("ready", function () {
Pebble.sendAppMessage({ JS_READY: 1 });
Pebble.sendAppMessage({ PKJS_READY: 1 });
});
Pebble.addEventListener("appmessage", function (dict) {
if (dict.payload["API_HOST"]) {
if (dict.payload["API_IS_PLEX"] == 0) {
callAPI(dict.payload["API_HOST"] + "/System/ActivityLog/Entries", false, dict.payload["API_KEY"]);
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
if (cfg.CLAY_API_IS_JELLYFIN == true) {
callAPI(cfg.CLAY_API_HOST + "/System/ActivityLog/Entries", cfg.CLAY_API_KEY, true, 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(dict.payload["API_HOST"] + "/status/sessions/history/all", true, dict.payload["API_KEY"]);
callAPI(dict.payload["API_HOST"] + "/api/v2?apikey=" + dict.payload["API_KEY"] + "&cmd=get_history", true, NULL);
//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);
}
}
});
function callAPI(fullURL, isPlex, apiKey) {
console.log("callAPI URL:", fullURL, "isPlex:", isPlex);
function callAPI(fullURL, apiKey, isJellyfin, sleepTimestamp) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
@@ -28,7 +33,7 @@ function callAPI(fullURL, isPlex, apiKey) {
xhr.open("GET", fullURL, true);
xhr.setRequestHeader("Accept", "application/json");
if (!isPlex) {
if (isJellyfin) {
xhr.setRequestHeader("Authorization", 'MediaBrowser Token="' + apiKey + '"');
}