Skip to content

Commit

Permalink
feat: add dark splash screen, ref #4398
Browse files Browse the repository at this point in the history
  • Loading branch information
alter-eggo committed Jan 8, 2024
1 parent d4c99d5 commit 8886038
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
4 changes: 4 additions & 0 deletions public/assets/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@
font-weight: 400;
font-style: normal;
}

.splash-screen {
background-color: #4a423b !important;
}
10 changes: 10 additions & 0 deletions public/assets/splash-screen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var isDark = window.matchMedia('(prefers-color-scheme: dark)').matches;

var body = document.querySelector('body');
var html = document.querySelector('html');
var defClassName = 'splash-screen';

if (!isDark) {
body?.classList.remove(defClassName);
html.classList.remove(defClassName);
}
5 changes: 3 additions & 2 deletions public/html/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!doctype html>
<html class="mode__full-page light">
<html class="mode__full-page light splash-screen">
<!--
Hello! Thanks for showing interest in our code.
Interested in joining our team? To learn more, email us:
Expand Down Expand Up @@ -31,8 +31,9 @@
type="font/woff2"
/>
</head>
<body>
<body class="splash-screen">
<div id="app"></div>
<script src="/assets/splash-screen.js"></script>
<script src="browser-polyfill.js"></script>
</body>
</html>
5 changes: 3 additions & 2 deletions public/html/popup.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<!doctype html>
<html class="mode__popup light">
<html class="mode__popup light splash-screen">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="/assets/base.css" rel="stylesheet" />
</head>
<body>
<body class="splash-screen">
<div id="app"></div>
<script src="/assets/splash-screen.js"></script>
<script src="browser-polyfill.js"></script>
</body>
</html>
16 changes: 16 additions & 0 deletions src/app/common/theme-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,26 @@ function setUserSelectedTheme(theme: UserSelectedTheme) {
interface ThemeSwitcherProviderProps {
children: React.JSX.Element | React.JSX.Element[];
}

function removeDefaultBg() {
const body = document.querySelector('body');
const html = document.querySelector('html');
const defClassName = 'splash-screen';

if (!body || !html) return;

body.classList.remove(defClassName);
html.classList.remove(defClassName);
}

export function ThemeSwitcherProvider({ children }: ThemeSwitcherProviderProps) {
const userSelectedTheme = useUserSelectedTheme();
const [theme, setTheme] = useState<ComputedTheme>(() => getComputedTheme(userSelectedTheme));

useEffect(() => {
removeDefaultBg();
}, []);

useEffect(() => {
switch (userSelectedTheme) {
case 'system': {
Expand Down

0 comments on commit 8886038

Please sign in to comment.