Skip to content

Commit ff05ded

Browse files
Update index.js
1 parent 885c022 commit ff05ded

1 file changed

Lines changed: 97 additions & 0 deletions

File tree

js/index.js

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ let currentWallpaperPosition = 0;
151151
let isSlideshow = false;
152152
let minimizedEmbeds = {}; // Object to store minimized embeds by URL
153153
let appLastOpened = {};
154+
let currentSunShadow = ''; // To store the calculated sun shadow string
154155

155156
secondsSwitch.checked = showSeconds;
156157

@@ -680,6 +681,93 @@ function saveLastOpenedData() {
680681
localStorage.setItem('appLastOpened', JSON.stringify(appLastOpened));
681682
}
682683

684+
/**
685+
* Calculates a box-shadow string based on the sun's position.
686+
*/
687+
function updateSunEffect() {
688+
// Check if geolocation is available to get coordinates for SunCalc
689+
if (!navigator.geolocation) {
690+
console.warn("Sun effect disabled: Geolocation not available.");
691+
return;
692+
}
693+
694+
navigator.geolocation.getCurrentPosition(position => {
695+
const { latitude, longitude } = position.coords;
696+
const now = new Date();
697+
const sunPosition = SunCalc.getPosition(now, latitude, longitude);
698+
699+
// altitude: 0 at horizon, PI/2 at zenith.
700+
// azimuth: 0 is south, PI/2 is west, PI is north, 3PI/2 is east.
701+
702+
if (sunPosition.altitude <= 0) {
703+
// Sun is below the horizon, no shadow
704+
currentSunShadow = '';
705+
} else {
706+
// Calculate properties based on sun position
707+
const lightIntensity = Math.max(0.1, Math.pow(Math.sin(sunPosition.altitude), 0.5));
708+
const shadowColor = `rgba(255, 255, 255, ${0.25 * lightIntensity})`;
709+
const shadowDistance = 2.5 * (1 - Math.sin(sunPosition.altitude)); // Larger when sun is low
710+
const offsetX = -Math.sin(sunPosition.azimuth) * shadowDistance;
711+
const offsetY = -Math.cos(sunPosition.azimuth) * shadowDistance;
712+
713+
currentSunShadow = `inset ${offsetX.toFixed(2)}px ${offsetY.toFixed(2)}px 4px ${shadowColor}`;
714+
}
715+
716+
// Apply to the main page and broadcast to iframes
717+
applySunShadowToPage();
718+
broadcastSunUpdate();
719+
720+
}, error => {
721+
console.warn("Sun effect disabled: Could not get location.", error);
722+
});
723+
}
724+
725+
/**
726+
* Applies the calculated sun shadow to all relevant elements on the main page.
727+
*/
728+
function applySunShadowToPage() {
729+
const SUN_SHADOW_ID = '/* sun-shadow */';
730+
const elements = document.querySelectorAll('.drawer-pill, .persistent-clock, .clock, .date, .weather-widget, .modal, .brightness-slider-container, .settings-grid, .media-widget, .qcontrol-item, .thermostat-popup, .version-info, .dock, .ai-search-bar, #ai-response-area, .widget-instance');
731+
732+
elements.forEach(el => {
733+
let currentShadow = el.style.boxShadow;
734+
735+
// Remove old sun shadow if it exists
736+
const oldSunShadowIndex = currentShadow.indexOf(SUN_SHADOW_ID);
737+
if (oldSunShadowIndex !== -1) {
738+
const shadowStartIndex = currentShadow.lastIndexOf('inset', oldSunShadowIndex);
739+
if (shadowStartIndex !== -1) {
740+
let shadowEndIndex = currentShadow.indexOf(',', oldSunShadowIndex);
741+
if (shadowEndIndex !== -1) {
742+
currentShadow = currentShadow.substring(0, shadowStartIndex) + currentShadow.substring(shadowEndIndex + 1).trim();
743+
} else {
744+
currentShadow = '';
745+
}
746+
}
747+
}
748+
749+
// Apply new shadow, preserving existing styles
750+
if (currentSunShadow) {
751+
const newShadow = `${currentSunShadow} ${SUN_SHADOW_ID}`;
752+
el.style.boxShadow = currentShadow ? `${newShadow}, ${currentShadow}` : newShadow;
753+
} else {
754+
el.style.boxShadow = currentShadow;
755+
}
756+
});
757+
}
758+
759+
/**
760+
* Sends the updated sun shadow value to all active Gurapp iframes.
761+
*/
762+
function broadcastSunUpdate() {
763+
const iframes = document.querySelectorAll('iframe[data-gurasuraisu-iframe]');
764+
iframes.forEach(iframe => {
765+
if (iframe.contentWindow) {
766+
iframe.contentWindow.postMessage({ type: 'sunUpdate', shadow: currentSunShadow }, window.location.origin);
767+
}
768+
});
769+
}
770+
683771
// IndexedDB setup for video storage
684772
const dbName = "WallpaperDB", storeName = "wallpapers", version = 1, VIDEO_VERSION = "1.0";
685773

@@ -4961,6 +5049,11 @@ function createFullscreenEmbed(url) {
49615049
interactionBlocker.style.pointerEvents = 'none';
49625050
interactionBlocker.style.display = 'none';
49635051
}
5052+
5053+
// NEW: Send sun update to the iframe once it's restored
5054+
if (iframe.contentWindow) {
5055+
iframe.contentWindow.postMessage({ type: 'sunUpdate', shadow: currentSunShadow }, window.location.origin);
5056+
}
49645057

49655058
return;
49665059
}
@@ -6099,6 +6192,10 @@ document.addEventListener('DOMContentLoaded', async function() {
60996192
checkWallpaperState();
61006193
updateGurappsVisibility();
61016194
syncUiStates();
6195+
6196+
// --- Initialize sun effect and set it to update periodically ---
6197+
updateSunEffect();
6198+
setInterval(updateSunEffect, 30 * 60 * 1000); // Update every 30 minutes
61026199

61036200
// Initialize control states
61046201
const storedLightMode = localStorage.getItem('theme') || 'dark';

0 commit comments

Comments
 (0)