Skip to content

Commit 391ebd1

Browse files
committed
[chrome] add theme selector and fix settingspage.tsx styling
1 parent 6481694 commit 391ebd1

File tree

5 files changed

+663
-118
lines changed

5 files changed

+663
-118
lines changed

packages/chrome/src/App.tsx

Lines changed: 20 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,80 +5,49 @@ import { browser } from "./Browser";
55
import { Tab } from "./Tab";
66
import { BookmarksStrip } from "./components/BookmarksStrip";
77
import { Omnibar } from "./components/Omnibar/Omnibar";
8+
import { getTheme } from "./themes";
89

910
export function App(props: {}, cx: ComponentContext) {
1011
const applyTheme = () => {
11-
let theme = browser.settings.theme;
12+
const appearance = browser.settings.appearance;
13+
const themeId = browser.settings.themeId;
14+
const theme = getTheme(themeId);
1215

13-
if (theme === "system") {
16+
// Determine if we should use light mode
17+
let isLight = false;
18+
if (appearance === "system") {
1419
const prefersDark = window.matchMedia(
1520
"(prefers-color-scheme: dark)"
1621
).matches;
17-
document.body.classList.toggle("light-mode", !prefersDark);
22+
isLight = !prefersDark;
1823
} else {
19-
document.body.classList.toggle("light-mode", theme === "light");
24+
isLight = appearance === "light";
25+
}
26+
27+
document.body.classList.toggle("light-mode", isLight);
28+
29+
// Apply theme tokens
30+
for (const [key, value] of Object.entries(theme.tokens)) {
31+
document.body.style.setProperty(`--${key}`, value);
2032
}
2133
};
2234

2335
applyTheme();
2436

2537
const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
2638
const handleThemeChange = () => {
27-
if (browser.settings.theme === "system") {
39+
if (browser.settings.appearance === "system") {
2840
applyTheme();
2941
}
3042
};
3143

3244
mediaQuery.addEventListener("change", handleThemeChange);
3345

34-
use(browser.settings.theme).listen(applyTheme);
35-
36-
const theme = {
37-
// dark theme
38-
// frame: "rgb(240, 240, 244)",
39-
// toolbar: "rgb(249, 249, 251)",
40-
// tab_selected: "rgb(255, 255, 255)",
41-
// tab_background_text: "black",
42-
// toolbar_text: "rgb(21, 20, 26)",
43-
// icons: "rgb(91, 91, 102)",
44-
// toolbar_field: "rgb(230 230, 230)",
45-
// ntp_background: "rgb(249, 249, 251)",
46-
// ntp_background_text: "rgb(21, 20, 26)",
47-
48-
// light theme
49-
// frame: "#1c1b22",
50-
// tab_selected: "#42414d",
51-
// tab_background_text: "white",
52-
// toolbar: "#2b2a33",
53-
// toolbar_text: "white",
54-
// toolbar_field: "#1C1B22",
55-
// toolbar_field_text: "white",
56-
// icons: "white",
57-
// ntp_background: "#121117",
58-
// ntp_text: "white",
59-
60-
// catppuccin
61-
toolbar: "rgb(45, 41, 59)",
62-
toolbar_text: "rgb(236, 191, 189)",
63-
frame: "rgb(30, 30, 40)",
64-
tab_background_text: "rgb(215, 218, 224)",
65-
toolbar_field: "rgb(30, 30, 40)",
66-
toolbar_field_text: "rgb(236, 191, 189)",
67-
tab_line: "rgb(236, 191, 189)",
68-
popup: "rgb(30, 30, 40)",
69-
popup_text: "rgb(236, 191, 189)",
70-
icons: "rgb(198, 170, 232)",
71-
ntp_background: "rgb(21, 18, 28)",
72-
ntp_text: "rgb(164, 185, 239)",
73-
popup_border: "rgb(236, 191, 189)",
74-
toolbar_top_separator: "rgb(30, 30, 40)",
75-
tab_loading: "rgb(236, 191, 189)",
76-
};
46+
use(browser.settings.appearance).listen(applyTheme);
47+
use(browser.settings.themeId).listen(applyTheme);
7748

7849
cx.mount = () => {
79-
for (const [key, value] of Object.entries(theme)) {
80-
document.body.style.setProperty(`--${key}`, value);
81-
}
50+
applyTheme();
8251
};
8352

8453
return (

packages/chrome/src/Browser.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ import {
1616
import type { RawDownload } from "./proxy/fetch";
1717
import { CookieJar } from "@mercuryworkshop/scramjet/bundled";
1818
import { getSerializedBrowserState, markDirty } from "./storage";
19+
import {
20+
type AppearancePreference,
21+
type ThemeId,
22+
DEFAULT_THEME_ID,
23+
} from "./themes";
1924
export const pushTab = createDelegate<Tab>();
2025
export const popTab = createDelegate<Tab>();
2126
export const forceScreenshot = createDelegate<Tab>();
@@ -62,7 +67,8 @@ export type DownloadEntry = {
6267
};
6368

6469
export type Settings = {
65-
theme: "system" | "dark" | "light";
70+
appearance: AppearancePreference;
71+
themeId: ThemeId;
6672
startupPage: "new-tab" | "continue";
6773
defaultZoom: number;
6874
showBookmarksBar: boolean;
@@ -93,7 +99,8 @@ export class Browser extends StatefulClass {
9399
downloadProgress = 0;
94100

95101
settings: Stateful<Settings> = createState({
96-
theme: "system",
102+
appearance: "system",
103+
themeId: DEFAULT_THEME_ID,
97104
startupPage: "continue",
98105
defaultZoom: 100,
99106
showBookmarksBar: true,
@@ -231,7 +238,10 @@ export class Browser extends StatefulClass {
231238
}
232239
this.bookmarks = de.bookmarks.map(createState);
233240
this.globalDownloadHistory = de.globalDownloadHistory.map(createState);
234-
this.settings = createState(de.settings);
241+
242+
const settings = { ...de.settings };
243+
244+
this.settings = createState(settings);
235245
this.cookieJar.load(de.cookiedump);
236246
}
237247

packages/chrome/src/History.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { createState } from "dreamland/core";
22
import { browser } from "./Browser";
33
import { StatefulClass } from "./StatefulClass";
44
import type { Tab } from "./Tab";
5-
import { sendFrame } from "./proxy/ipc";
65
import { markDirty } from "./storage";
76

87
// history api emulation
@@ -147,11 +146,11 @@ export class History {
147146
let newstate = this.states[this.index];
148147

149148
if (current.virtual) {
150-
sendFrame(this.tab, "popstate", {
151-
state: newstate.state,
152-
url: newstate.url.href,
153-
title: newstate.title || "",
154-
});
149+
// sendFrame(this.tab, "popstate", {
150+
// state: newstate.state,
151+
// url: newstate.url.href,
152+
// title: newstate.title || "",
153+
// });
155154
} else if (navigate) {
156155
this.justTriggeredNavigation = true;
157156
this.tab._directnavigate(newstate.url);

0 commit comments

Comments
 (0)