Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow for images in random order #140

Merged
merged 1 commit into from
Sep 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ The following properties can be configured:
| `fadeTime` | The fading time between two images. |
| `interval` | The time that an image is shown. |
| `imageCount` | Defines how many different images are shown in the slideshow. |
| `randomOrder` | When set to true, Teleframe will show pictures in random order. |
| `autoDeleteImages` | Defines if old images should be deleted, when they are no longer used in the slideshow (see 'imageCount'). Starred images will not be deleted. |
| `showSender` | When set to true, TeleFrame will show the name of the sender when the image is shown. |
| `showCaption` | When set to true, TeleFrame will show the caption of the image when the image is shown. |
Expand Down
3 changes: 3 additions & 0 deletions js/defaultConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ var defaultConfig = {
// Defines how many different images are shown in the slideshow.
imageCount: 30,

// When set to true, Teleframe will show pictures in random order.
randomOrder: true,

// Defines if old images are deleted, when they are no longer used in the slideshow (see 'imageCount'). Starred images will not be deleted.
autoDeleteImages: true,

Expand Down
27 changes: 22 additions & 5 deletions js/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ var touchBarElements = {
"reboot": new TouchBarElement("fas fa-redo-alt", reboot),
}

// keep track of shown images per sequence for no repeat in random order
var shownSequence = [];


// configure sound notification sound
if (config.playSoundOnRecieve !== false) {
Expand Down Expand Up @@ -606,13 +609,27 @@ function loadImage(isNext, fadeTime, goToLatest = false) {
}

// get image path and increase currentImageIndex for next image

if (goToLatest) {
currentImageIndex = 0;
} else if (isNext) {
if (currentImageIndex >= images.length - 1) {
currentImageIndex = 0;
if (!config.randomOrder) {
// select next picture
if (currentImageIndex >= images.length - 1) {
currentImageIndex = 0;
} else {
currentImageIndex++;
}
} else {
currentImageIndex++;
// select random picture
if (shownSequence.length >= images.length) {
shownSequence = [];
}
do {
next = Math.floor(Math.random() * images.length);
} while (shownSequence.includes(next));
shownSequence.push(next);
currentImageIndex = next;
}
} else {
currentImageIndex--;
Expand Down Expand Up @@ -749,8 +766,8 @@ function newImage(sender, type, newImageArray) {
timer: 5000,
icon: "success"
}).then((value) => {
currentImageIndex = images.length;
loadImage(true, 0);
currentImageIndex = 0;
loadImage(false, 0, true);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please verify this is ok. Need to jump directly to a new picture, as the other logic won't work in random order.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it has the side-effect that when new pictures come in while in pause, the picture changes to the latest one? (To be investigated)

});
}

Expand Down