Auto-fix formatting issues

This commit is contained in:
GitHub Action
2025-12-08 05:43:02 +00:00
parent ba21525af3
commit 71dbf44802
3 changed files with 73 additions and 62 deletions

View File

@@ -127,4 +127,4 @@ pub fn update_theme_mode(app: AppHandle, mode: String) {
}; };
let _ = window.set_theme(Some(theme)); let _ = window.set_theme(Some(theme));
} }
} }

View File

@@ -2,71 +2,71 @@
// Check if URL matches OAuth/authentication patterns // Check if URL matches OAuth/authentication patterns
function matchesAuthUrl(url, baseUrl = window.location.href) { function matchesAuthUrl(url, baseUrl = window.location.href) {
try { try {
const urlObj = new URL(url, baseUrl); const urlObj = new URL(url, baseUrl);
const hostname = urlObj.hostname.toLowerCase(); const hostname = urlObj.hostname.toLowerCase();
const pathname = urlObj.pathname.toLowerCase(); const pathname = urlObj.pathname.toLowerCase();
const fullUrl = urlObj.href.toLowerCase(); const fullUrl = urlObj.href.toLowerCase();
// Common OAuth providers and paths // Common OAuth providers and paths
const oauthPatterns = [ const oauthPatterns = [
/accounts\.google\.com/, /accounts\.google\.com/,
/accounts\.google\.[a-z]+/, /accounts\.google\.[a-z]+/,
/login\.microsoftonline\.com/, /login\.microsoftonline\.com/,
/github\.com\/login/, /github\.com\/login/,
/facebook\.com\/.*\/dialog/, /facebook\.com\/.*\/dialog/,
/twitter\.com\/oauth/, /twitter\.com\/oauth/,
/appleid\.apple\.com/, /appleid\.apple\.com/,
/\/oauth\//, /\/oauth\//,
/\/auth\//, /\/auth\//,
/\/authorize/, /\/authorize/,
/\/login\/oauth/, /\/login\/oauth/,
/\/signin/, /\/signin/,
/\/login/, /\/login/,
/servicelogin/, /servicelogin/,
/\/o\/oauth2/, /\/o\/oauth2/,
]; ];
const isMatch = oauthPatterns.some( const isMatch = oauthPatterns.some(
(pattern) => (pattern) =>
pattern.test(hostname) || pattern.test(hostname) ||
pattern.test(pathname) || pattern.test(pathname) ||
pattern.test(fullUrl), pattern.test(fullUrl),
); );
if (isMatch) { if (isMatch) {
console.log("[Pake] OAuth URL detected:", url); console.log("[Pake] OAuth URL detected:", url);
}
return isMatch;
} catch (e) {
return false;
} }
return isMatch;
} catch (e) {
return false;
}
} }
// Check if URL is an OAuth/authentication link // Check if URL is an OAuth/authentication link
function isAuthLink(url) { function isAuthLink(url) {
return matchesAuthUrl(url); return matchesAuthUrl(url);
} }
// Check if this is an OAuth/authentication popup // Check if this is an OAuth/authentication popup
function isAuthPopup(url, name) { function isAuthPopup(url, name) {
// Check for known authentication window names // Check for known authentication window names
const authWindowNames = [ const authWindowNames = [
"AppleAuthentication", "AppleAuthentication",
"oauth2", "oauth2",
"oauth", "oauth",
"google-auth", "google-auth",
"auth-popup", "auth-popup",
"signin", "signin",
"login", "login",
]; ];
if (authWindowNames.includes(name)) { if (authWindowNames.includes(name)) {
return true; return true;
} }
return matchesAuthUrl(url); return matchesAuthUrl(url);
} }
// Export functions to global scope // Export functions to global scope

View File

@@ -62,16 +62,25 @@ document.addEventListener("DOMContentLoaded", () => {
// This is useful when the site relies purely on CSS media queries without classes. // This is useful when the site relies purely on CSS media queries without classes.
if (!detected) { if (!detected) {
const bodyBg = window.getComputedStyle(document.body).backgroundColor; const bodyBg = window.getComputedStyle(document.body).backgroundColor;
const htmlBg = window.getComputedStyle(document.documentElement).backgroundColor; const htmlBg = window.getComputedStyle(
document.documentElement,
).backgroundColor;
// Check body first, then html // Check body first, then html
if (bodyBg && bodyBg !== "rgba(0, 0, 0, 0)" && bodyBg !== "transparent") { if (bodyBg && bodyBg !== "rgba(0, 0, 0, 0)" && bodyBg !== "transparent") {
mode = isDarkColor(bodyBg) ? "dark" : "light"; mode = isDarkColor(bodyBg) ? "dark" : "light";
} else if (htmlBg && htmlBg !== "rgba(0, 0, 0, 0)" && htmlBg !== "transparent") { } else if (
htmlBg &&
htmlBg !== "rgba(0, 0, 0, 0)" &&
htmlBg !== "transparent"
) {
mode = isDarkColor(htmlBg) ? "dark" : "light"; mode = isDarkColor(htmlBg) ? "dark" : "light";
} else { } else {
// Strategy 3: System Preference (Last Resort) // Strategy 3: System Preference (Last Resort)
if (window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches) { if (
window.matchMedia &&
window.matchMedia("(prefers-color-scheme: dark)").matches
) {
mode = "dark"; mode = "dark";
} }
} }
@@ -91,7 +100,9 @@ document.addEventListener("DOMContentLoaded", () => {
setTimeout(updateTheme, 100); setTimeout(updateTheme, 100);
// Watch for system theme changes // Watch for system theme changes
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", updateTheme); window
.matchMedia("(prefers-color-scheme: dark)")
.addEventListener("change", updateTheme);
// Watch for DOM changes // Watch for DOM changes
// We observe attributes for class changes, and also style changes just in case // We observe attributes for class changes, and also style changes just in case
@@ -102,12 +113,12 @@ document.addEventListener("DOMContentLoaded", () => {
observer.observe(document.documentElement, { observer.observe(document.documentElement, {
attributes: true, attributes: true,
attributeFilter: ["class", "data-theme", "style"], attributeFilter: ["class", "data-theme", "style"],
subtree: false subtree: false,
}); });
observer.observe(document.body, { observer.observe(document.body, {
attributes: true, attributes: true,
attributeFilter: ["class", "data-theme", "style"], attributeFilter: ["class", "data-theme", "style"],
subtree: false subtree: false,
}); });
}); });