diff --git a/.gitignore b/.gitignore
index a41fcc3..e54f3fd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -147,3 +147,4 @@ finalize.js
version.json
pagespublic
+GALLERY_REFRESH_IMPLEMENTATION.md
diff --git a/src/apps/groove.internal.settings/index.html b/src/apps/groove.internal.settings/index.html
index 1687fe2..6e97958 100644
--- a/src/apps/groove.internal.settings/index.html
+++ b/src/apps/groove.internal.settings/index.html
@@ -601,6 +601,17 @@
Settings
+
+
Refresh interval
+
How often the gallery live tile refreshes with new photos
+
+
diff --git a/src/apps/groove.internal.settings/pages/10_applications.js b/src/apps/groove.internal.settings/pages/10_applications.js
index 57713eb..7438c6c 100644
--- a/src/apps/groove.internal.settings/pages/10_applications.js
+++ b/src/apps/groove.internal.settings/pages/10_applications.js
@@ -108,6 +108,9 @@ function refreshAppList(params) {
// Setup per-app tile preferences
setupPerAppTilePreferences(appdetail);
+ // Setup gallery refresh interval setting
+ setupGalleryRefreshInterval(appdetail);
+
pageNavigation.goToPage(6)
} catch (error) {
@@ -526,4 +529,97 @@ function removePerAppIconPack(appPackageName) {
delete iconPackPerApp[appPackageName];
localStorage["iconPackPerApp"] = JSON.stringify(iconPackPerApp);
console.log("Removed per-app icon pack for:", appPackageName);
+}
+
+// Gallery refresh interval functionality
+function setupGalleryRefreshInterval(appdetail) {
+ const galleryRefreshGroup = document.querySelector("#app-preference-gallery-refresh");
+ const refreshIntervalDropdown = document.querySelector("#gallery-refresh-interval-chooser");
+
+ // Check if this is a gallery app (photos live tile)
+ const isGalleryApp = appdetail.packageName === "com.android.gallery3d" ||
+ appdetail.packageName === "com.google.android.apps.photos" ||
+ appdetail.packageName === "com.samsung.android.gallery" ||
+ appdetail.packageName === "com.miui.gallery" ||
+ appdetail.packageName === "com.oneplus.gallery" ||
+ appdetail.packageName === "com.huawei.photos" ||
+ appdetail.packageName === "com.oppo.gallery3d" ||
+ appdetail.packageName === "com.vivo.gallery" ||
+ appdetail.packageName === "com.meizu.media.gallery" ||
+ appdetail.packageName === "com.android.camera2" ||
+ appdetail.packageName === "com.android.camera" ||
+ appdetail.label.toLowerCase().includes("gallery") ||
+ appdetail.label.toLowerCase().includes("photos") ||
+ appdetail.label.toLowerCase().includes("camera");
+
+ if (isGalleryApp) {
+ galleryRefreshGroup.style.removeProperty("display");
+
+ // Get current refresh interval setting
+ const currentInterval = getGalleryRefreshInterval(appdetail.packageName);
+
+ // Set the dropdown to the current value
+ const options = refreshIntervalDropdown.querySelectorAll("div.metro-dropdown-option");
+ let selectedIndex = 0; // Default to "Default" option
+ options.forEach((option, index) => {
+ if (option.getAttribute("value") === currentInterval) {
+ selectedIndex = index;
+ }
+ });
+ refreshIntervalDropdown.setAttribute("selected", selectedIndex);
+ refreshIntervalDropdown.selectOption(selectedIndex);
+
+ // Add event listener for changes
+ refreshIntervalDropdown.addEventListener('selected', (e) => {
+ const selectedValue = options[e.detail.index].getAttribute("value");
+ setGalleryRefreshInterval(appdetail.packageName, selectedValue);
+
+ // Notify the photos live tile to update its refresh interval
+ if (window.parent && window.parent.liveTiles && window.parent.liveTiles.photos) {
+ window.parent.liveTiles.photos.worker.postMessage({
+ action: "update-refresh-interval",
+ data: { interval: selectedValue }
+ });
+ }
+ });
+ } else {
+ galleryRefreshGroup.style.display = "none";
+ }
+}
+
+function getGalleryRefreshInterval(packageName) {
+ try {
+ if (window.parent.Groove && window.parent.Groove.getGalleryRefreshInterval) {
+ return window.parent.Groove.getGalleryRefreshInterval(packageName);
+ }
+ } catch (error) {
+ console.log("Error getting gallery refresh interval via Groove API:", error);
+ }
+
+ // Fallback to localStorage
+ if (!localStorage["galleryRefreshIntervals"]) {
+ localStorage["galleryRefreshIntervals"] = JSON.stringify({});
+ }
+ const intervals = JSON.parse(localStorage["galleryRefreshIntervals"]);
+ return intervals[packageName] || "default"; // Default to "default" (1 minute)
+}
+
+function setGalleryRefreshInterval(packageName, interval) {
+ try {
+ if (window.parent.Groove && window.parent.Groove.setGalleryRefreshInterval) {
+ window.parent.Groove.setGalleryRefreshInterval(packageName, interval);
+ }
+ } catch (error) {
+ console.log("Error setting gallery refresh interval via Groove API:", error);
+ }
+
+ // Also save to localStorage
+ if (!localStorage["galleryRefreshIntervals"]) {
+ localStorage["galleryRefreshIntervals"] = JSON.stringify({});
+ }
+ const intervals = JSON.parse(localStorage["galleryRefreshIntervals"]);
+ intervals[packageName] = interval;
+ localStorage["galleryRefreshIntervals"] = JSON.stringify(intervals);
+
+ console.log("Set gallery refresh interval for", packageName, "to", interval);
}
\ No newline at end of file
diff --git a/src/scripts/GrooveBoard.js b/src/scripts/GrooveBoard.js
index edef79d..f49b204 100644
--- a/src/scripts/GrooveBoard.js
+++ b/src/scripts/GrooveBoard.js
@@ -383,7 +383,13 @@ const boardMethods = {
action: "photos-data",
data: { timestamp: Date.now(), photos: window.photosCache }
})
-
+
+ // Send refresh interval setting to photos live tile
+ const refreshInterval = getGalleryRefreshInterval(packageName);
+ liveTile.worker.postMessage({
+ action: "update-refresh-interval",
+ data: { interval: refreshInterval }
+ });
}
})
Object.entries(window.liveTiles).forEach(liveTileBundle => {
@@ -1427,4 +1433,22 @@ window.addEventListener("systemThemeChange", function (e) {
if (localStorage["theme"] == "2") {
backendMethods.setTheme(2, true);
}
-})
\ No newline at end of file
+})
+
+// Gallery refresh interval helper function
+function getGalleryRefreshInterval(packageName) {
+ try {
+ if (window.Groove && window.Groove.getGalleryRefreshInterval) {
+ return window.Groove.getGalleryRefreshInterval(packageName);
+ }
+ } catch (error) {
+ console.log("Error getting gallery refresh interval via Groove API:", error);
+ }
+
+ // Fallback to localStorage
+ if (!localStorage["galleryRefreshIntervals"]) {
+ localStorage["galleryRefreshIntervals"] = JSON.stringify({});
+ }
+ const intervals = JSON.parse(localStorage["galleryRefreshIntervals"]);
+ return intervals[packageName] || "default"; // Default to "default" (1 minute)
+}
\ No newline at end of file
diff --git a/src/scripts/liveTileHelper.js b/src/scripts/liveTileHelper.js
index 04a4eb0..fb97625 100644
--- a/src/scripts/liveTileHelper.js
+++ b/src/scripts/liveTileHelper.js
@@ -45,6 +45,9 @@ onmessage = async function (event) {
case 'notifications-data':
eventListener.dispatch("notificationsdata", message.data);
break;
+ case 'update-refresh-interval':
+ eventListener.dispatch("update-refresh-interval", message.data);
+ break;
default:
console.log("Worker: Unknown action received:", message.action);
}
diff --git a/www/assets/defaultlivetiles/photos.js b/www/assets/defaultlivetiles/photos.js
index 800421c..724b988 100644
--- a/www/assets/defaultlivetiles/photos.js
+++ b/www/assets/defaultlivetiles/photos.js
@@ -13,11 +13,25 @@ importScripts('./../../dist/liveTileHelper.js');
liveTileHelper.eventListener.on("draw", draw);
var photos = [];
+var refreshInterval = "default"; // Default to "default" (1 minute)
+var refreshTimer = null;
+
liveTileHelper.eventListener.on("photosdata", (data) => {
//console.log("photos data!!!!!!!!", data)
photos = data.photos;
liveTileHelper.requestRedraw();
+});
+// Listen for refresh interval updates
+liveTileHelper.eventListener.on("update-refresh-interval", (data) => {
+ refreshInterval = data.interval;
+ console.log("Photos live tile: Updated refresh interval to", refreshInterval);
+ // Restart both timers with new interval
+ if (refreshTimer) {
+ clearInterval(refreshTimer);
+ }
+ scheduleRefresh();
+ scheduleRotation(); // Also restart rotation timer
});
@@ -37,16 +51,59 @@ function draw(args) {
return tileFeed;
}
-// Replace the minute scheduler with a 10-second rotation using requestGoToNextPage
+// Convert refresh interval string to milliseconds
+function getRefreshIntervalMs(interval) {
+ switch (interval) {
+ case "default":
+ return 60 * 1000; // 1 minute
+ case "15min":
+ return 15 * 60 * 1000; // 15 minutes
+ case "1hour":
+ return 60 * 60 * 1000; // 1 hour
+ case "4hours":
+ return 4 * 60 * 60 * 1000; // 4 hours
+ case "1day":
+ return 24 * 60 * 60 * 1000; // 1 day
+ default:
+ return 60 * 1000; // Default to 1 minute
+ }
+}
+
+// Schedule refresh based on the current interval setting
+function scheduleRefresh() {
+ const intervalMs = getRefreshIntervalMs(refreshInterval);
+ console.log("Photos live tile: Scheduling refresh every", refreshInterval, "(" + intervalMs + "ms)");
+
+ refreshTimer = setInterval(() => {
+ console.log("Photos live tile: Refreshing photos due to interval");
+ liveTileHelper.requestRedraw();
+ }, intervalMs);
+}
+
+// Replace the minute scheduler with rotation based on refresh interval
var page = 0
+var rotationTimer = null
+
function scheduleRotation() {
- setInterval(() => {
+ // Clear existing rotation timer
+ if (rotationTimer) {
+ clearInterval(rotationTimer);
+ }
+
+ // Calculate rotation interval based on refresh interval
+ // Rotate every 1/10th of the refresh interval, but minimum 10 seconds, maximum 60 seconds
+ const refreshIntervalMs = getRefreshIntervalMs(refreshInterval);
+ const rotationIntervalMs = Math.max(10000, Math.min(60000, refreshIntervalMs / 10));
+
+ console.log("Photos live tile: Scheduling rotation every", rotationIntervalMs + "ms");
+
+ rotationTimer = setInterval(() => {
liveTileHelper.requestGoToNextPage();
page++;
if (page == 10) {
liveTileHelper.requestRedraw()
}
- }, 10000 + Math.random() * 5000); // 5 to 10 seconds
+ }, rotationIntervalMs);
}
// Start the rotation
@@ -56,7 +113,7 @@ function init(args) {
//console.log("Init called:", args);
//liveTileHelper.requestRedraw();
scheduleRotation();
-
+ scheduleRefresh(); // Start the refresh timer
}
/*setInterval(() => {
postMessage({
diff --git a/www/assets/defaultlocales/settings.json b/www/assets/defaultlocales/settings.json
index 462fc37..33c5678 100644
--- a/www/assets/defaultlocales/settings.json
+++ b/www/assets/defaultlocales/settings.json
@@ -150,7 +150,18 @@
"light": "light"
},
"live_tile": "Live tile",
- "show_app": "Show in apps list"
+ "show_app": "Show in apps list",
+ "gallery": {
+ "refresh_interval": "Refresh interval",
+ "refresh_interval_description": "How often the gallery live tile refreshes with new photos",
+ "intervals": {
+ "default": "Default",
+ "15min": "15 minutes",
+ "1hour": "1 hour",
+ "4hours": "4 hours",
+ "1day": "1 day"
+ }
+ }
},
"roles": {
"team_groove": "Team Groove",