e8dbab99eb
* feat: replace window.todesktop with official @todesktop/client-core package - Import platform from @todesktop/client-core in _document.tsx - Pass isDesktopApp result via window.calIsDesktopApp to stringified function - Update applyToDesktopClass to use passed-in value instead of window.todesktop - Maintains existing architecture while using official package API Co-Authored-By: peer@cal.com <peer@cal.com> * fix: move ToDesktop detection to client-side to resolve SSR issue - Remove server-side call to platform.todesktop.isDesktopApp() which always returns false - Move detection logic to client-side stringified script using same logic as official package - Maintain client-side detection while ensuring proper functionality in ToDesktop environment Co-Authored-By: peer@cal.com <peer@cal.com> * feat: use official platform.todesktop.isDesktopApp() function - Import platform from @todesktop/client-core in _document.tsx - Call platform.todesktop.isDesktopApp() directly in stringified script - Replace duplicated logic with official package function call - Maintain client-side detection while using official API Co-Authored-By: peer@cal.com <peer@cal.com> * feat: properly use official platform.todesktop.isDesktopApp() function - Call platform.todesktop.isDesktopApp() outside stringified context - Pass result as template variable to avoid SSR issues - Now actually uses the official @todesktop/client-core package - Eliminates duplicated detection logic as requested Co-Authored-By: peer@cal.com <peer@cal.com> * fix: add SSR safety guards around platform.todesktop.isDesktopApp() call - Wrap platform.todesktop.isDesktopApp() in try/catch to prevent SSR crashes - Return false as fallback if library touches browser globals during SSR - Addresses keithwillcode's comment about SSR safety concerns Co-Authored-By: peer@cal.com <peer@cal.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
79 lines
2.5 KiB
TypeScript
79 lines
2.5 KiB
TypeScript
// Theme application function - will be stringified and injected. So, it must not use anything from the closure
|
|
export const applyTheme = function () {
|
|
try {
|
|
// This utility is a replica of @calcom/lib/webstorage.ts but we can reuse it because applyTheme is stringified and injected, so we can't have deps here
|
|
const safeLocalStorage = {
|
|
getItem: function (key: string) {
|
|
try {
|
|
// eslint-disable-next-line @calcom/eslint/avoid-web-storage
|
|
return localStorage.getItem(key);
|
|
} catch (e) {
|
|
return null;
|
|
}
|
|
},
|
|
key: function (index: number) {
|
|
try {
|
|
// eslint-disable-next-line @calcom/eslint/avoid-web-storage
|
|
return localStorage.key(index);
|
|
} catch (e) {
|
|
return null;
|
|
}
|
|
},
|
|
getLength: function () {
|
|
try {
|
|
// eslint-disable-next-line @calcom/eslint/avoid-web-storage
|
|
return localStorage.length;
|
|
} catch (e) {
|
|
return 0;
|
|
}
|
|
},
|
|
};
|
|
|
|
const appTheme = safeLocalStorage.getItem("app-theme");
|
|
if (!appTheme) return;
|
|
|
|
let bookingTheme: string | null = null;
|
|
let username: string | undefined;
|
|
for (let i = 0; i < safeLocalStorage.getLength(); i++) {
|
|
const key = safeLocalStorage.key(i);
|
|
if (key && key.startsWith("booking-theme:")) {
|
|
bookingTheme = safeLocalStorage.getItem(key);
|
|
username = key.split("booking-theme:")[1];
|
|
break;
|
|
}
|
|
}
|
|
|
|
const onReady = () => {
|
|
const isBookingPage = username && window.location.pathname.slice(1).startsWith(username);
|
|
if (document.body) {
|
|
document.body.classList.add(isBookingPage ? bookingTheme || appTheme : appTheme);
|
|
} else {
|
|
requestAnimationFrame(onReady);
|
|
}
|
|
};
|
|
|
|
requestAnimationFrame(onReady);
|
|
} catch (e) {
|
|
console.error("Error applying theme:", e);
|
|
}
|
|
};
|
|
|
|
// ToDesktop class application function - will be stringified and injected. So, it must not use anything from the closure
|
|
export const applyToDesktopClass = function () {
|
|
try {
|
|
const onReady = () => {
|
|
if (typeof window !== "undefined" && window.calIsDesktopApp && document.documentElement) {
|
|
document.documentElement.classList.add("todesktop");
|
|
} else if (document.documentElement) {
|
|
return;
|
|
} else {
|
|
requestAnimationFrame(onReady);
|
|
}
|
|
};
|
|
|
|
requestAnimationFrame(onReady);
|
|
} catch (e) {
|
|
console.error("Error applying todesktop class:", e);
|
|
}
|
|
};
|