mirror of
https://github.com/kilyabin/psysonic.git
synced 2026-07-22 06:25:41 +00:00
fix(themes): apply Theme Store themes in production release builds (#1070)
Release CSP blocked runtime <style> injection for community themes; add explicit style-src/style-src-elem and font-src. Derive the effective theme synchronously in useThemeScheduler so data-theme updates on the same commit.
This commit is contained in:
@@ -28,7 +28,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"security": {
|
"security": {
|
||||||
"csp": "default-src 'self' 'unsafe-inline' 'unsafe-eval' ipc: http://ipc.localhost tauri:; connect-src 'self' ipc: http://ipc.localhost tauri: https: http: ws: wss:; img-src 'self' asset: http://asset.localhost https: http: data: blob:; media-src 'self' asset: http://asset.localhost https: http: data: blob:;",
|
"csp": "default-src 'self' 'unsafe-inline' 'unsafe-eval' ipc: http://ipc.localhost tauri:; style-src 'self' 'unsafe-inline' asset: http://asset.localhost https://asset.localhost tauri: blob:; style-src-elem 'self' 'unsafe-inline' asset: http://asset.localhost https://asset.localhost tauri: blob:; font-src 'self' data: asset: http://asset.localhost https://asset.localhost; connect-src 'self' ipc: http://ipc.localhost tauri: https: http: ws: wss:; img-src 'self' asset: http://asset.localhost https: http: data: blob:; media-src 'self' asset: http://asset.localhost https: http: data: blob:;",
|
||||||
"assetProtocol": {
|
"assetProtocol": {
|
||||||
"enable": true,
|
"enable": true,
|
||||||
"scope": [
|
"scope": [
|
||||||
|
|||||||
@@ -1,18 +1,34 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useThemeStore, getScheduledTheme } from '../store/themeStore';
|
import { useThemeStore, getScheduledTheme } from '../store/themeStore';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Effective theme id for `data-theme` — scheduler-aware when enabled.
|
||||||
|
* Derived synchronously from the store so `App.tsx` never paints a stale id
|
||||||
|
* (the previous useState+mirror lag could leave `data-theme` on Mocha for a
|
||||||
|
* commit cycle in production React).
|
||||||
|
*/
|
||||||
export function useThemeScheduler(): string {
|
export function useThemeScheduler(): string {
|
||||||
const state = useThemeStore();
|
const enableScheduler = useThemeStore(s => s.enableThemeScheduler);
|
||||||
const [effectiveTheme, setEffectiveTheme] = useState(() => getScheduledTheme(state));
|
const theme = useThemeStore(s => s.theme);
|
||||||
|
const themeDay = useThemeStore(s => s.themeDay);
|
||||||
|
const themeNight = useThemeStore(s => s.themeNight);
|
||||||
|
const timeDayStart = useThemeStore(s => s.timeDayStart);
|
||||||
|
const timeNightStart = useThemeStore(s => s.timeNightStart);
|
||||||
|
const [tick, setTick] = useState(0);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setEffectiveTheme(getScheduledTheme(useThemeStore.getState()));
|
if (!enableScheduler) return;
|
||||||
if (!state.enableThemeScheduler) return;
|
const id = setInterval(() => setTick(n => n + 1), 60_000);
|
||||||
const id = setInterval(() => {
|
|
||||||
setEffectiveTheme(getScheduledTheme(useThemeStore.getState()));
|
|
||||||
}, 60_000);
|
|
||||||
return () => clearInterval(id);
|
return () => clearInterval(id);
|
||||||
}, [state.enableThemeScheduler, state.theme, state.themeDay, state.themeNight, state.timeDayStart, state.timeNightStart]);
|
}, [enableScheduler, themeDay, themeNight, timeDayStart, timeNightStart]);
|
||||||
|
|
||||||
return effectiveTheme;
|
void tick;
|
||||||
|
return getScheduledTheme({
|
||||||
|
enableThemeScheduler: enableScheduler,
|
||||||
|
theme,
|
||||||
|
themeDay,
|
||||||
|
themeNight,
|
||||||
|
timeDayStart,
|
||||||
|
timeNightStart,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user