fix(themes): prevent ghost checkmark on classic theme during native preview

This commit is contained in:
tomasalias 2026-10-08 20:31:33 +02:00
parent 7a7eab46e5
commit 46dc6dc849
2 changed files with 37 additions and 10 deletions

View file

@ -134,10 +134,12 @@
const theme = this._themes.find(t => t.fileName === this._savedThemeFileName); const theme = this._themes.find(t => t.fileName === this._savedThemeFileName);
if (theme) { if (theme) {
this.applyTheme(theme, false); this.applyTheme(theme, false);
document.documentElement.classList.add('bcf-client-theme-selected');
} else { } else {
// Stored theme file not found // Stored theme file not found
this._savedThemeFileName = null; this._savedThemeFileName = null;
this._activeThemeFileName = null; this._activeThemeFileName = null;
document.documentElement.classList.remove('bcf-client-theme-selected');
} }
} }
@ -235,14 +237,20 @@
} }
/* ═══ Mutual Exclusivity ═══ */ /* ═══ Mutual Exclusivity ═══ */
/* When a BetterCF client theme is active, hide active checkmark & active indicator on native theme cards */ /* When a BetterCF client theme is active/selected, hide active checkmark & active indicator on native theme cards when not hovered */
html.bcf-custom-theme-active .settings-themes-view .theme-thumb:not(.bcf-theme-thumb).is-active .sprite-icon { html.bcf-client-theme-selected .settings-themes-view .theme-thumb:not(.bcf-theme-thumb).is-active:not(:hover) .sprite-icon,
html.bcf-native-preview-active .settings-themes-view .theme-thumb:not(.bcf-theme-thumb).is-active:not(:hover) .sprite-icon,
html.bcf-custom-theme-active .settings-themes-view .theme-thumb:not(.bcf-theme-thumb).is-active:not(:hover) .sprite-icon {
opacity: 0 !important; opacity: 0 !important;
} }
html.bcf-custom-theme-active .settings-themes-view .theme-thumb:not(.bcf-theme-thumb).is-active .thumb-icon { html.bcf-client-theme-selected .settings-themes-view .theme-thumb:not(.bcf-theme-thumb).is-active:not(:hover) .thumb-icon,
html.bcf-native-preview-active .settings-themes-view .theme-thumb:not(.bcf-theme-thumb).is-active:not(:hover) .thumb-icon,
html.bcf-custom-theme-active .settings-themes-view .theme-thumb:not(.bcf-theme-thumb).is-active:not(:hover) .thumb-icon {
background-color: transparent !important; background-color: transparent !important;
} }
html.bcf-custom-theme-active .settings-themes-view .theme-thumb:not(.bcf-theme-thumb).is-active { html.bcf-client-theme-selected .settings-themes-view .theme-thumb:not(.bcf-theme-thumb).is-active:not(:hover),
html.bcf-native-preview-active .settings-themes-view .theme-thumb:not(.bcf-theme-thumb).is-active:not(:hover),
html.bcf-custom-theme-active .settings-themes-view .theme-thumb:not(.bcf-theme-thumb).is-active:not(:hover) {
outline: none !important; outline: none !important;
border-color: transparent !important; border-color: transparent !important;
box-shadow: none !important; box-shadow: none !important;
@ -318,10 +326,13 @@
if (save) { if (save) {
this._savedThemeFileName = theme.fileName; this._savedThemeFileName = theme.fileName;
this._isPreviewing = false; this._isPreviewing = false;
document.documentElement.classList.add('bcf-client-theme-selected');
try { try {
localStorage.setItem('bcf_active_custom_theme', theme.fileName); localStorage.setItem('bcf_active_custom_theme', theme.fileName);
ipc?.invoke?.('bcf:settings:set', 'activeCustomTheme', theme.fileName); ipc?.invoke?.('bcf:settings:set', 'activeCustomTheme', theme.fileName);
} catch {} } catch {}
} else if (this._savedThemeFileName) {
document.documentElement.classList.add('bcf-client-theme-selected');
} }
console.log(`[BetterCF] Applied custom theme: ${theme.name} (${theme.fileName}) [save=${save}]`); console.log(`[BetterCF] Applied custom theme: ${theme.name} (${theme.fileName}) [save=${save}]`);
@ -338,10 +349,13 @@
if (save) { if (save) {
this._savedThemeFileName = null; this._savedThemeFileName = null;
this._isPreviewing = false; this._isPreviewing = false;
document.documentElement.classList.remove('bcf-client-theme-selected', 'bcf-native-preview-active');
try { try {
localStorage.removeItem('bcf_active_custom_theme'); localStorage.removeItem('bcf_active_custom_theme');
ipc?.invoke?.('bcf:settings:set', 'activeCustomTheme', null); ipc?.invoke?.('bcf:settings:set', 'activeCustomTheme', null);
} catch {} } catch {}
} else if (!this._savedThemeFileName) {
document.documentElement.classList.remove('bcf-client-theme-selected', 'bcf-native-preview-active');
} }
console.log(`[BetterCF] Reverted to native theme [save=${save}].`); console.log(`[BetterCF] Reverted to native theme [save=${save}].`);
@ -365,6 +379,7 @@
} }
} }
this.removeTheme(false); this.removeTheme(false);
document.documentElement.classList.remove('bcf-client-theme-selected', 'bcf-native-preview-active');
}, },
suspendForNativePreview() { suspendForNativePreview() {
@ -375,17 +390,20 @@
this._styleElement.disabled = true; this._styleElement.disabled = true;
} }
document.documentElement.classList.remove('bcf-custom-theme-active'); document.documentElement.classList.remove('bcf-custom-theme-active');
document.documentElement.classList.add('bcf-native-preview-active');
} }
}, },
resumeFromNativePreview() { resumeFromNativePreview() {
if (!this._isSuspendedForNative) return; if (!this._isSuspendedForNative) return;
this._isSuspendedForNative = false; this._isSuspendedForNative = false;
document.documentElement.classList.remove('bcf-native-preview-active');
if (this._savedThemeFileName) { if (this._savedThemeFileName) {
if (this._styleElement) { if (this._styleElement) {
this._styleElement.disabled = false; this._styleElement.disabled = false;
} }
document.documentElement.classList.add('bcf-custom-theme-active'); document.documentElement.classList.add('bcf-custom-theme-active');
document.documentElement.classList.add('bcf-client-theme-selected');
} }
}, },
@ -415,6 +433,7 @@
const nativeThumb = e.target.closest('.theme-thumb:not(.bcf-theme-thumb)'); const nativeThumb = e.target.closest('.theme-thumb:not(.bcf-theme-thumb)');
if (nativeThumb) { if (nativeThumb) {
ThemeManager._isSuspendedForNative = false; ThemeManager._isSuspendedForNative = false;
document.documentElement.classList.remove('bcf-native-preview-active');
if (ThemeManager.getActiveThemeName()) { if (ThemeManager.getActiveThemeName()) {
ThemeManager.removeTheme(true); ThemeManager.removeTheme(true);
const grid = document.querySelector('#bcf-custom-themes-grid'); const grid = document.querySelector('#bcf-custom-themes-grid');

View file

@ -559,13 +559,19 @@ owadview,
} }
/* Mutual exclusivity: hide checkmark on native theme cards when a client theme is active */ /* Mutual exclusivity: hide checkmark on native theme cards when a client theme is active */
html.bcf-custom-theme-active .settings-themes-view .theme-thumb:not(.bcf-theme-thumb).is-active .sprite-icon { html.bcf-client-theme-selected .settings-themes-view .theme-thumb:not(.bcf-theme-thumb).is-active:not(:hover) .sprite-icon,
html.bcf-native-preview-active .settings-themes-view .theme-thumb:not(.bcf-theme-thumb).is-active:not(:hover) .sprite-icon,
html.bcf-custom-theme-active .settings-themes-view .theme-thumb:not(.bcf-theme-thumb).is-active:not(:hover) .sprite-icon {
opacity: 0 !important; opacity: 0 !important;
} }
html.bcf-custom-theme-active .settings-themes-view .theme-thumb:not(.bcf-theme-thumb).is-active .thumb-icon { html.bcf-client-theme-selected .settings-themes-view .theme-thumb:not(.bcf-theme-thumb).is-active:not(:hover) .thumb-icon,
html.bcf-native-preview-active .settings-themes-view .theme-thumb:not(.bcf-theme-thumb).is-active:not(:hover) .thumb-icon,
html.bcf-custom-theme-active .settings-themes-view .theme-thumb:not(.bcf-theme-thumb).is-active:not(:hover) .thumb-icon {
background-color: transparent !important; background-color: transparent !important;
} }
html.bcf-custom-theme-active .settings-themes-view .theme-thumb:not(.bcf-theme-thumb).is-active { html.bcf-client-theme-selected .settings-themes-view .theme-thumb:not(.bcf-theme-thumb).is-active:not(:hover),
html.bcf-native-preview-active .settings-themes-view .theme-thumb:not(.bcf-theme-thumb).is-active:not(:hover),
html.bcf-custom-theme-active .settings-themes-view .theme-thumb:not(.bcf-theme-thumb).is-active:not(:hover) {
outline: none !important; outline: none !important;
border-color: transparent !important; border-color: transparent !important;
box-shadow: none !important; box-shadow: none !important;
@ -594,9 +600,11 @@ html.bcf-custom-theme-active .pixelforge-skin :not(.highlighted-project-containe
} }
""" """
css_text = desktop_css.read_text(encoding="utf-8") css_text = desktop_css.read_text(encoding="utf-8")
if "/* ═══ BetterCurseForge Zero-Ad Rules ═══ */" not in css_text: if "/* ═══ BetterCurseForge Zero-Ad Rules ═══ */" in css_text:
desktop_css.write_text(css_text + "\n" + css_rules, encoding="utf-8") idx = css_text.find("/* ═══ BetterCurseForge Zero-Ad Rules ═══ */")
log_callback("[+] Injected zero-ad and theme CSS rules into desktop.css") css_text = css_text[:idx].rstrip()
desktop_css.write_text(css_text + "\n" + css_rules, encoding="utf-8")
log_callback("[+] Injected zero-ad and theme CSS rules into desktop.css")
# 3. Copy BetterCF runtime into asar # 3. Copy BetterCF runtime into asar
bcf_src = find_bettercf_source() bcf_src = find_bettercf_source()