Skip to content
Open
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,4 @@ finalize.js
version.json

pagespublic
GALLERY_REFRESH_IMPLEMENTATION.md
11 changes: 11 additions & 0 deletions src/apps/groove.internal.settings/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,17 @@ <h1 class="app-title" data-i18n="settings.title">Settings</h1>
</div>
</div>
</div>
<div class="group" id="app-preference-gallery-refresh" style="display: none;">
<p class="group-title" data-i18n="settings.apps.gallery.refresh_interval">Refresh interval</p>
<p class="group-description" data-i18n="settings.apps.gallery.refresh_interval_description">How often the gallery live tile refreshes with new photos</p>
<div class="metro-dropdown-menu" id="gallery-refresh-interval-chooser" selected="0">
<div class="metro-dropdown-option" value="default" data-i18n="settings.apps.gallery.intervals.default">Default</div>
<div class="metro-dropdown-option" value="15min" data-i18n="settings.apps.gallery.intervals.15min">15 minutes</div>
<div class="metro-dropdown-option" value="1hour" data-i18n="settings.apps.gallery.intervals.1hour">1 hour</div>
<div class="metro-dropdown-option" value="4hours" data-i18n="settings.apps.gallery.intervals.4hours">4 hours</div>
<div class="metro-dropdown-option" value="1day" data-i18n="settings.apps.gallery.intervals.1day">1 day</div>
</div>
</div>
</div>
</div>
</div>
Expand Down
96 changes: 96 additions & 0 deletions src/apps/groove.internal.settings/pages/10_applications.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down Expand Up @@ -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);
}
28 changes: 26 additions & 2 deletions src/scripts/GrooveBoard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -1427,4 +1433,22 @@ window.addEventListener("systemThemeChange", function (e) {
if (localStorage["theme"] == "2") {
backendMethods.setTheme(2, true);
}
})
})

// 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)
}
3 changes: 3 additions & 0 deletions src/scripts/liveTileHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
65 changes: 61 additions & 4 deletions www/assets/defaultlivetiles/photos.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});


Expand All @@ -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
Expand All @@ -56,7 +113,7 @@ function init(args) {
//console.log("Init called:", args);
//liveTileHelper.requestRedraw();
scheduleRotation();

scheduleRefresh(); // Start the refresh timer
}
/*setInterval(() => {
postMessage({
Expand Down
13 changes: 12 additions & 1 deletion www/assets/defaultlocales/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down