Skip to content

Commit 3aacd75

Browse files
author
Gurasuraisu
committed
Fix many bugs
1 parent 7ee812c commit 3aacd75

17 files changed

Lines changed: 210 additions & 96 deletions

assets/gurapp/api/gurasuraisu-api.js

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,6 +1637,10 @@ window.addEventListener('message', async (event) => {
16371637
case 'contrastUpdate':
16381638
document.documentElement.classList.toggle('gurasuraisu-high-contrast', data.enabled);
16391639
break;
1640+
case 'performanceProfileUpdate':
1641+
window.systemPerformanceScore = data.score;
1642+
window.isLowEndDevice = (data.score <= 2);
1643+
break;
16401644
case 'sunUpdate':
16411645
document.documentElement.style.setProperty('--sun-shadow', data.shadow);
16421646
document.documentElement.style.setProperty('--sun-shadow-strong', data.shadowStrong);
@@ -1781,8 +1785,12 @@ window.addEventListener('message', async (event) => {
17811785

17821786
// --- Handles screenshot requests from the parent ---
17831787
case 'request-screenshot':
1788+
if (window.isLowEndDevice) return; // Do not take screenshots on very low-end devices
1789+
const _isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
1790+
17841791
// Helper function to perform the capture
17851792
const doCapture = async () => {
1793+
// Save current shadow state to prevent artifacts
17861794
const root = document.documentElement;
17871795
const originalShadow = root.style.getPropertyValue('--sun-shadow');
17881796
const originalShadowStrong = root.style.getPropertyValue('--sun-shadow-strong');
@@ -1798,19 +1806,29 @@ window.addEventListener('message', async (event) => {
17981806
const bgColor = isLight ? '#ffffff' : '#000000';
17991807

18001808
// Generate the screenshot of the app's content
1801-
const screenshotDataUrl = await modernScreenshot.domToJpeg(document.body, {
1802-
backgroundColor: bgColor, // Explicitly set background
1803-
quality: 0.5,
1804-
filter: (node) => {
1805-
if (node.nodeType === 1 && (node.tagName === 'IMG' || node.tagName === 'VIDEO') && node.src && !node.src.startsWith('data:') && !node.src.startsWith('blob:')) {
1806-
try {
1807-
const url = new URL(node.src, window.location.href);
1808-
if (url.origin !== window.location.origin && !node.crossOrigin) return false;
1809-
} catch(e) {}
1809+
let screenshotDataUrl;
1810+
if (_isMobile) {
1811+
const canvas = await html2canvas(document.body, {
1812+
useCORS: true,
1813+
logging: false,
1814+
backgroundColor: bgColor
1815+
});
1816+
screenshotDataUrl = canvas.toDataURL('image/jpeg', 0.5);
1817+
} else {
1818+
screenshotDataUrl = await modernScreenshot.domToJpeg(document.body, {
1819+
backgroundColor: bgColor, // Explicitly set background
1820+
quality: 0.5,
1821+
filter: (node) => {
1822+
if (node.nodeType === 1 && (node.tagName === 'IMG' || node.tagName === 'VIDEO') && node.src && !node.src.startsWith('data:') && !node.src.startsWith('blob:')) {
1823+
try {
1824+
const url = new URL(node.src, window.location.href);
1825+
if (url.origin !== window.location.origin && !node.crossOrigin) return false;
1826+
} catch(e) {}
1827+
}
1828+
return true;
18101829
}
1811-
return true;
1812-
}
1813-
});
1830+
});
1831+
}
18141832

18151833
// Send the generated screenshot data back to the parent
18161834
window.parent.postMessage({
@@ -1826,13 +1844,15 @@ window.addEventListener('message', async (event) => {
18261844
}
18271845
};
18281846

1829-
// Check if modern-screenshot is loaded
1830-
if (typeof modernScreenshot === 'undefined') {
1831-
// Inject it dynamically
1847+
if (_isMobile && typeof html2canvas !== 'function') {
1848+
const script = document.createElement('script');
1849+
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js';
1850+
script.onload = doCapture;
1851+
document.head.appendChild(script);
1852+
} else if (!_isMobile && typeof modernScreenshot === 'undefined') {
18321853
const script = document.createElement('script');
18331854
script.src = 'https://cdn.jsdelivr.net/npm/modern-screenshot@4.6.8/dist/index.min.js';
18341855
script.onload = doCapture;
1835-
script.onerror = () => console.error("Failed to load modern-screenshot for Gurapp");
18361856
document.head.appendChild(script);
18371857
} else {
18381858
doCapture();

assets/gurapp/intl/airy/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ function createOnScreenPopup(message, options = {}) {
754754
console.log(`[Airy] Sent action '${functionName}' to Gurapp '${appName}'.`);
755755
} else {
756756
console.warn(`[Airy] Could not find Gurapp iframe for '${appName}' to send action '${functionName}'.`);
757-
showPopup(`Error: Could not perform action for ${appName}.`);
757+
showPopup(`Cannot perform action for ${appName}`);
758758
}
759759
closeNotification(notification); // Close the notification after click
760760
});
@@ -2264,7 +2264,17 @@ function setupDrawerInteractions() {
22642264
const appDrawerObserver = new MutationObserver((mutations) => {
22652265
mutations.forEach((mutation) => {
22662266
if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
2267+
if (typeof HomeActivityManager !== 'undefined') {
2268+
HomeActivityManager.updateVisibility();
2269+
}
22672270

2271+
if (!appDrawer.classList.contains('open')) {
2272+
setTimeout(() => {
2273+
if (!appDrawer.classList.contains('open')) {
2274+
document.getElementById('app-grid').innerHTML = '';
2275+
}
2276+
}, 350);
2277+
}
22682278
}
22692279
});
22702280
});

assets/gurapp/intl/settings/settings.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -437,11 +437,9 @@ function initializeSettingsApp() {
437437
};
438438

439439
uninstallBtn.onclick = async () => {
440-
if (await Gurasuraisu.showConfirm(`Are you sure you want to uninstall ${appName}?`)) {
441-
Gurasuraisu.deleteApp(appName);
442-
navigateBack();
443-
setTimeout(refreshAppsListPage, 300);
444-
}
440+
Gurasuraisu.deleteApp(appName);
441+
navigateBack();
442+
setTimeout(refreshAppsListPage, 300);
445443
};
446444

447445
clearTrackingBtn.onclick = async () => {

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<link rel="manifest" href="/manifest.json">
4949
<script src="js/lang.js"></script>
5050
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
51+
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script>
5152
<script src="https://cdn.jsdelivr.net/npm/modern-screenshot@4.6.8/dist/index.min.js"></script>
5253
<script src="https://cdnjs.cloudflare.com/ajax/libs/color-thief/2.3.0/color-thief.umd.js"></script>
5354
<script type="importmap">

js/apps/api.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,9 @@ window.addEventListener('message', async (event) => { // Make listener async
11071107
const currentTheme = localStorage.getItem('theme') || 'dark';
11081108
sourceWindow.postMessage({ type: 'themeUpdate', theme: currentTheme }, targetOrigin);
11091109

1110+
const perfScore = localStorage.getItem('systemPerformanceScore') || '4';
1111+
sourceWindow.postMessage({ type: 'performanceProfileUpdate', score: parseInt(perfScore) }, targetOrigin);
1112+
11101113
const animationsEnabled = localStorage.getItem('animationsEnabled') !== 'false';
11111114
sourceWindow.postMessage({ type: 'animationsUpdate', enabled: animationsEnabled }, targetOrigin);
11121115

js/apps/app-switcher.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ let isTabKeyDown = false;
88
let shiftSpaceSequenceTimer = null;
99

1010
async function captureAppScreenshot(url) {
11+
if (window.isLowEndDevice) return; // Do not take screenshots on very low-end devices
12+
1113
// Find the embed
1214
const container = document.querySelector(`.fullscreen-embed[data-embed-url="${url}"]`);
1315
if (!container) return;
@@ -107,7 +109,8 @@ function closeAppSwitcherUI() {
107109

108110
setTimeout(() => {
109111
overlay.style.display = 'none';
110-
112+
document.getElementById('app-cards-container').innerHTML = '';
113+
111114
// Restore UI
112115
const drawerPill = document.querySelector('.drawer-pill');
113116
if (drawerPill) drawerPill.style.opacity = '1';

js/apps/window-manager.js

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,41 +1807,60 @@ function minimizeFullscreenEmbed(animate = true, urlToMinimize = null) {
18071807
*/
18081808
function createCompositeScreenshot() {
18091809
return new Promise(async (resolve, reject) => {
1810+
if (window.isLowEndDevice) { resolve(null); return; }
1811+
18101812
const activeEmbed = document.querySelector('.fullscreen-embed[style*="display: block"]');
18111813
const iframe = activeEmbed ? activeEmbed.querySelector('iframe') : null;
1814+
const isMobile = isMobileDevice();
18121815

18131816
if (!iframe) {
1814-
const dataUrl = await modernScreenshot.domToJpeg(document.body, {
1815-
quality: 0.5,
1816-
filter: (node) => {
1817-
if (node.nodeType === 1 && (node.tagName === 'IMG' || node.tagName === 'VIDEO') && node.src && !node.src.startsWith('data:') && !node.src.startsWith('blob:')) {
1818-
try {
1819-
const url = new URL(node.src, window.location.href);
1820-
if (url.origin !== window.location.origin && !node.crossOrigin) return false;
1821-
} catch(e) {}
1817+
let dataUrl;
1818+
if (isMobile) {
1819+
const canvas = await html2canvas(document.body, { useCORS: true, logging: false });
1820+
dataUrl = canvas.toDataURL('image/jpeg', 0.5);
1821+
} else {
1822+
dataUrl = await modernScreenshot.domToJpeg(document.body, {
1823+
quality: 0.5,
1824+
filter: (node) => {
1825+
if (node.nodeType === 1 && (node.tagName === 'IMG' || node.tagName === 'VIDEO') && node.src && !node.src.startsWith('data:') && !node.src.startsWith('blob:')) {
1826+
try {
1827+
const url = new URL(node.src, window.location.href);
1828+
if (url.origin !== window.location.origin && !node.crossOrigin) return false;
1829+
} catch(e) {}
1830+
}
1831+
return true;
18221832
}
1823-
return true;
1824-
}
1825-
});
1833+
});
1834+
}
18261835
resolve(dataUrl);
18271836
return;
18281837
}
18291838

1830-
const parentDataUrl = await modernScreenshot.domToJpeg(document.body, {
1831-
filter: (node) => {
1832-
if (node.nodeType === 1) {
1833-
if (node.tagName === 'IFRAME') return false;
1834-
if ((node.tagName === 'IMG' || node.tagName === 'VIDEO') && node.src && !node.src.startsWith('data:') && !node.src.startsWith('blob:')) {
1835-
try {
1836-
const url = new URL(node.src, window.location.href);
1837-
if (url.origin !== window.location.origin && !node.crossOrigin) return false;
1838-
} catch(e) {}
1839+
let parentDataUrl;
1840+
if (isMobile) {
1841+
const parentCanvas = await html2canvas(document.body, {
1842+
useCORS: true,
1843+
logging: false,
1844+
ignoreElements: (el) => el.tagName === 'IFRAME'
1845+
});
1846+
parentDataUrl = parentCanvas.toDataURL();
1847+
} else {
1848+
parentDataUrl = await modernScreenshot.domToJpeg(document.body, {
1849+
filter: (node) => {
1850+
if (node.nodeType === 1) {
1851+
if (node.tagName === 'IFRAME') return false;
1852+
if ((node.tagName === 'IMG' || node.tagName === 'VIDEO') && node.src && !node.src.startsWith('data:') && !node.src.startsWith('blob:')) {
1853+
try {
1854+
const url = new URL(node.src, window.location.href);
1855+
if (url.origin !== window.location.origin && !node.crossOrigin) return false;
1856+
} catch(e) {}
1857+
}
18391858
}
1840-
}
1841-
return true;
1842-
},
1843-
quality: 1.0 // Keep high quality for the base composition step
1844-
});
1859+
return true;
1860+
},
1861+
quality: 1.0 // Keep high quality for the base composition step
1862+
});
1863+
}
18451864

18461865
const iframeListener = (event) => {
18471866
if (event.source === iframe.contentWindow && event.data.type === 'screenshot-response') {
@@ -1871,7 +1890,7 @@ function createCompositeScreenshot() {
18711890
};
18721891

18731892
window.addEventListener('message', iframeListener);
1874-
const targetOrigin = getOriginFromUrl(iframe.src);
1893+
const targetOrigin = getOriginFromUrl(iframe.src);
18751894
iframe.contentWindow.postMessage({ type: 'request-screenshot' }, targetOrigin);
18761895

18771896
setTimeout(() => {

js/core/performance.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
// --- Performance Auto-Detection ---
22
function detectPerformanceProfile() {
3-
if (localStorage.getItem('performanceConfigured') === 'true') return;
3+
const storedScore = localStorage.getItem('systemPerformanceScore');
4+
if (localStorage.getItem('performanceConfigured') === 'true' && storedScore !== null) {
5+
window.systemPerformanceScore = parseInt(storedScore);
6+
window.isLowEndDevice = (window.systemPerformanceScore <= 2);
7+
return;
8+
}
49

510
console.log("[System] Assessing hardware performance...");
611
let score = 0;
@@ -34,6 +39,9 @@ function detectPerformanceProfile() {
3439

3540
if (!isWeakGPU) score += 1;
3641

42+
window.systemPerformanceScore = score;
43+
window.isLowEndDevice = (score <= 2);
44+
3745
console.log(`[System] Performance Score: ${score}/6`);
3846

3947
// 1. Glass Effects
@@ -64,7 +72,14 @@ function detectPerformanceProfile() {
6472
if (localStorage.getItem('animationsEnabled') === null) localStorage.setItem('animationsEnabled', 'true');
6573
}
6674

75+
window.systemPerformanceScore = score;
76+
window.isLowEndDevice = (score <= 2);
77+
localStorage.setItem('systemPerformanceScore', score);
6778
localStorage.setItem('performanceConfigured', 'true');
79+
80+
if (window.isLowEndDevice) {
81+
document.body.classList.add('low-end-device');
82+
}
6883
}
6984

7085
// Run immediately to ensure settings are present before main logic reads them

js/core/power.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ function blackoutScreen() {
8383
if (document.body.classList.contains('blackout-active')) return;
8484

8585
window.isBlackoutActive = true;
86-
if (typeof updateClockAndDate === 'function') updateClockAndDate();
86+
if (typeof window.refreshClockUI === 'function') window.refreshClockUI();
8787

8888
closeControls();
8989

@@ -137,7 +137,7 @@ function exitBlackoutMode() {
137137
stopPixelCleaning();
138138

139139
// Force immediate clock update to bring seconds back to the UI seamlessly
140-
if (typeof updateClockAndDate === 'function') updateClockAndDate();
140+
if (typeof window.refreshClockUI === 'function') window.refreshClockUI();
141141

142142
// Restore previous settings
143143
setControlValueAndDispatch('animationsEnabled', previousBlackoutSettings.animationsEnabled || 'true');

js/core/sys-connect-waves.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,13 @@ async function broadcastWidgetSnapshots() {
196196
// Fallback: Capture container
197197
await new Promise(resolve => requestIdle(async () => {
198198
try {
199-
const imgData = await modernScreenshot.domToJpeg(widget, options);
199+
let imgData;
200+
if (isMobileDevice()) {
201+
const canvas = await html2canvas(widget, { useCORS: true, logging: false, scale: 0.5, backgroundColor: bgColor });
202+
imgData = canvas.toDataURL('image/jpeg', 0.5);
203+
} else {
204+
imgData = await modernScreenshot.domToJpeg(widget, options);
205+
}
200206
snapshots.push({
201207
id: index,
202208
img: imgData
@@ -209,7 +215,13 @@ async function broadcastWidgetSnapshots() {
209215
// It's a sticker or simple element
210216
await new Promise(resolve => requestIdle(async () => {
211217
try {
212-
const imgData = await modernScreenshot.domToJpeg(widget, options);
218+
let imgData;
219+
if (isMobileDevice()) {
220+
const canvas = await html2canvas(widget, { useCORS: true, logging: false, scale: 0.5, backgroundColor: bgColor });
221+
imgData = canvas.toDataURL('image/jpeg', 0.5);
222+
} else {
223+
imgData = await modernScreenshot.domToJpeg(widget, options);
224+
}
213225
snapshots.push({
214226
id: index,
215227
img: imgData

0 commit comments

Comments
 (0)