Skip to content

Commit

Permalink
experiment feature added - custom links
Browse files Browse the repository at this point in the history
  • Loading branch information
petersem committed Sep 22, 2024
1 parent c9fe21c commit 917408e
Show file tree
Hide file tree
Showing 9 changed files with 365 additions and 319 deletions.
8 changes: 5 additions & 3 deletions classes/cards/MediaCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class MediaCard {
var endTime = et.toLocaleTimeString("en-US", {hour: '2-digit', minute:'2-digit'});

this.triviaRender="";
this.linkRender="";
// if a trivia card, then prepare html

if(this.cardType[0] == "Trivia Question"){
Expand Down Expand Up @@ -125,8 +126,9 @@ class MediaCard {
hiddenFooter = "hidden";
fullScreen="fullscreen";
hiddenTitle="hidden";
//this.linkRender = `<embed type="text/html" src="` + this.linkUrl + `" width=100% height=100%>`
this.linkRender = `<iframe scrolling="no" src="` + this.linkUrl + `" width=100% height=100% style="border: none; overflow: hidden;" >`
this.linkRender = `<embed type="text/html" src="` + this.linkUrl + `" width=100% height=100% style="border: none; overflow: hidden;>`
//this.linkRender = `<iframe scrolling="no" src="` + this.linkUrl + `" width=100% height=100% style="border: none; overflow: hidden;" >`;
// console.log(this.linkRender);
}


Expand Down Expand Up @@ -301,7 +303,7 @@ class MediaCard {
`"></div>
</div>
<div class="hidden" id="poster` + this.ID + `AR">`+this.posterAR+`</div>` +
this.triviaRender +
this.triviaRender + this.linkRender +
`</div>
<div class="bottomBanner mx-auto transparent` +
Expand Down
4 changes: 2 additions & 2 deletions classes/core/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class Settings {
this.links = DEFAULT_SETTINGS.links;
this.enableAwtrix = DEFAULT_SETTINGS.enableAwtrix;
this.awtrixIP = DEFAULT_SETTINGS.awtrixIP;
this.enableLinks = DEFAULT_SETTINGS.enableLinks;
this.links = DEFAULT_SETTINGS.links;
return;
}

Expand Down Expand Up @@ -367,8 +369,6 @@ class Settings {
else this.links = cs.links;
if (jsonObject.enableLinks) this.enableLinks = jsonObject.enableLinks;
else this.enableLinks = cs.enableLinks;
if (jsonObject.linkFrequency) this.linkFrequency = jsonObject.linkFrequency;
else this.linkFrequency = cs.linkFrequency;
if (jsonObject.enableAwtrix) this.enableAwtrix = jsonObject.enableAwtrix;
else this.enableAwtrix = cs.enableAwtrix;
if (jsonObject.awtrixIP) this.awtrixIP = jsonObject.awtrixIP;
Expand Down
8 changes: 5 additions & 3 deletions classes/custom/links.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ class Links {
async GetAllLinks(linksArray) {
let allLinkCards = [];
// get link cards
for (const linkURL of linksArray) {
const linkSet = await this.GetLinkCard(linkURL);
for (const lnk of linksArray) {
//console.log('process link', lnk);
const linkSet = await this.GetLinkCard(lnk);
//console.log(linkSet);
if(linkSet.length !== 0) {
allLinkCards = allLinkCards.concat(linkSet);
}
Expand Down Expand Up @@ -47,7 +49,7 @@ class Links {
medCard.cardType = cType.CardTypeEnum.WebURL;
medCard.mediaType = "WebURL";
medCard.linkUrl = url;
medCard.posterAR = 0;
medCard.posterAR = 1.47;
medCard.theme = "";
medCard.posterURL = "";
medCard.posterArtURL = "";
Expand Down
4 changes: 3 additions & 1 deletion consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ const DEFAULT_SETTINGS = {
triviaNumber: "",
contentRatings: "",
enableAwtrix: "false",
awtrixIP: ""
awtrixIP: "",
enableLinks: "false",
links: ""
};

module.exports = DEFAULT_SETTINGS;
18 changes: 12 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ let contentRatings;
let oldAwtrixApps = [];
let isAwtrixEnabled = false;
let awtrixIP = "";
let restartSeconds = 86400000; //60000; //
let restartSeconds = 86400000;

// create working folders if they do not exist
// needed for package binaries
Expand Down Expand Up @@ -179,15 +179,15 @@ function checkTime(i) {
return i;
}
}

loadLinks
/**
* @desc Wrapper function to call links.
* @returns {Promise<object>} mediaCards array - LINKS
*/
async function loadLinks() {
// stop the clock
clearInterval(linksClock);
let linkTicks = loadedSettings.linkFrequency * 1000 * 60; // convert to seconds and then minutes
let linkTicks = 86400000; //loadedSettings.linkFrequency * 1000 * 60; // convert to seconds and then minutes

// stop timers and dont run if disabled
if (!isLinksEnabled) {
Expand All @@ -200,10 +200,10 @@ async function loadLinks() {
// call links
try {
linkCards = await links.GetAllLinks(linkArray);
//console.log(linkCards);
} catch (err) {
let now = new Date();
console.log(now.toLocaleString() + " *Links: " + err);
linkTicks = 60000;
console.log("✘✘ WARNING ✘✘ - Next links query will run in 1 minute.");
isLinksUnavailable = true;
}
Expand Down Expand Up @@ -769,7 +769,7 @@ async function loadNowScreening() {
}
}
}

//console.log(linkCards.length);
// globalPage.cards = mCards;
}

Expand Down Expand Up @@ -866,6 +866,8 @@ async function loadOnDemand() {
* @returns nothing
*/
async function houseKeeping() {
//cold_start_time = new Date();

// clean cache
await core.DeleteMP3Cache();
await core.DeleteImageCache();
Expand Down Expand Up @@ -1104,6 +1106,9 @@ async function checkEnabled() {
Trivia: ` +
isTriviaEnabled +
`
Links: ` +
isLinksEnabled +
`
Daily restart commencing at: ` +
timeObject.toLocaleTimeString() +
`
Expand Down Expand Up @@ -1181,7 +1186,6 @@ async function wake(theater) {
* @returns nothing
*/
async function startup(clearCache) {

// stop all clocks
clearInterval(nowScreeningClock);
clearInterval(onDemandClock);
Expand Down Expand Up @@ -1886,6 +1890,8 @@ app.post(
triviaFrequency: req.body.triviaFrequency,
enableAwtrix: req.body.enableAwtrix,
awtrixIP: req.body.awtrixIP,
enableLinks: req.body.enableLinks,
links: req.body.links,
saved: false
};

Expand Down
34 changes: 34 additions & 0 deletions myviews/settings.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,38 @@
</div>
<hr>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingLinks">
<h4 class="panel-title">
<a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapseLinks" aria-expanded="false" aria-controls="collapseLinks">
CUSTOM LINKS <i class="accordion_icon fal fa-plus"></i>
</a>
</h4>
</div>
<div id="collapseLinks" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingLinks">
<div class="panel-body">
<div class="form-group">
<div class="custom-control custom-control-nolabel custom-switch ml-auto">
<input type="checkbox" class="custom-control-input" name="enableLinks" id="enableLinks"
value="true" <% if(typeof formData !== 'undefined' && errors){%><%=formData.enableLinks ? 'checked' : '' %><%}else{%><%=(settings.enableLinks == 'true') ? 'checked' : '' %><%}%>>
<label class="custom-control-label" for="enableLinks">Enabled</label>
</div>
</div>
<div class="form-group">
<label for="links">Links</label>
<input type="text" class="form-control" id="links" name="links" aria-describedby="linksHelp"
placeholder="http://n.n.n.n;https://n.n.n.n" value="<% if(typeof formData !== 'undefined' && errors){%><%=formData.links%>"<%}else{%><%=settings.links%>"<%}%>>
<small id="linksHelp" class="form-text text-muted">Enter links separated by ;. (This feature is somewhat experimental. Only links that allow being loaded in iframes will work. If a link doesnt work, try another.)</small>
</div>
</div>
</div>
</div>
<hr>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingTrivia">
<h4 class="panel-title">
Expand Down Expand Up @@ -1022,6 +1054,8 @@
</div>
<script type="text/javascript">
$(".checkbox-menu").on("change", "input[type='checkbox']", function() {
$(this).closest("li").toggleClass("active", this.checked);
Expand Down
Loading

0 comments on commit 917408e

Please sign in to comment.