Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7184abe
feat: add new utilities for hover and glass
astudentinearth Oct 5, 2026
d845e0b
fix: layout overflow on right edge
astudentinearth Oct 6, 2026
ef7222f
fix: remove tooltip motion, make tooltips smaller
astudentinearth Oct 6, 2026
14f7baf
fix: unify all glass surfaces
astudentinearth Oct 6, 2026
fdf42e8
lint: unused import
astudentinearth Oct 6, 2026
321bdb9
fix: corner rounding in code blocks
astudentinearth Oct 6, 2026
c0345e8
fix: hover hell gone
astudentinearth Oct 6, 2026
8043acc
fix: get rid of the unused spacing system
astudentinearth Oct 7, 2026
4b5e597
fix: more hover and active states
astudentinearth Oct 7, 2026
906e27a
fix: button size classes no longer hardcode heights
astudentinearth Oct 7, 2026
51f30b9
feat: tweak the settings ui
astudentinearth Oct 7, 2026
77be4dc
feat: auto-contrast accent colors and primary foreground
astudentinearth Oct 7, 2026
9d4e66f
fix: properly fall back to defaults on incomplete themes
astudentinearth Oct 7, 2026
26e35dd
fix: tweak more controls
astudentinearth Oct 7, 2026
737b3ff
fix: centralize disabled opacity
astudentinearth Oct 7, 2026
baedf4a
feat: rewrite theme validator
astudentinearth Oct 7, 2026
c0129e2
fix: get rid of secondary foreground usage
astudentinearth Oct 7, 2026
2a84b1e
fix: system accent color api result getting coerced into css
astudentinearth Oct 7, 2026
27b7783
feat: open theme folder and help page
astudentinearth Oct 7, 2026
df179d8
lint: unused import
astudentinearth Oct 7, 2026
16cb640
fix: unreadable sonner text
astudentinearth Oct 7, 2026
32d14ad
fix: remove all references to dead css vars
astudentinearth Oct 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# Unreleased

## 🌟 Features
- Open theme folder from settings

## ✨ Improvements and fixes
- Fix titlebar and editor overflowing slightly along the right edge
- Fix system accent color feature
- UI and theming refactor
- Fix dirty theme colors when switching to an incomplete theme (partial themes now fall back to defaults depending on theme mode).
- Automatically contrast text color on accent colored surfaces for better readability
- Automatically adjust accent color brightness depending on theme mode for better readability

# 1.3.1-beta.1

## 🌟 Features
Expand Down
78 changes: 1 addition & 77 deletions docs/THEMES.md
Original file line number Diff line number Diff line change
@@ -1,80 +1,4 @@
# Create your own theme

### 1. Copy the template below to a new file
See [this documentation page.](https://darkwrite.app/docs/functionality/themes/)

```json
{
"id": "your-unique-id-here",
"name": "My Custom Theme",
"mode": "dark",
"colors": {
"--foreground": "hsl(0 0% 100%)",
"--background": "hsl(0 0% 5%)",
"--view-1": "hsl(0 0% 6%)",
"--view-2": "hsl(0 0% 11%)",
"--card": "hsl(0 0% 13%)",
"--card-foreground": "hsl(0 0% 94%)",
"--popover": "hsl(0 0% 9%)",
"--popover-foreground": "hsl(0 0% 94%)",
"--secondary": "hsl(0 0% 20%)",
"--secondary-foreground": "hsl(0 0% 100%)",
"--muted": "hsl(0 0% 17%)",
"--muted-foreground": "hsl(0 0% 89%)",
"--destructive": "hsl(0 51% 55%)",
"--destructive-foreground": "hsl(210 40% 98%)",
"--disabled": "hsl(0 0% 22%)",
"--border": "hsl(0 0% 14%)",
"--ring": "hsl(212.7 26.8% 50%)",
"--star": "hsl(50 97% 63%)",
"--editor-text-red": "hsl(1 100% 66%)",
"--editor-text-orange": "hsl(26 97% 61%)",
"--editor-text-yellow": "hsl(54 100% 66%)",
"--editor-text-green": "hsl(119 100% 66%)",
"--editor-text-cyan": "hsl(166 100% 66%)",
"--editor-text-blue": "hsl(202 97% 61%)",
"--editor-text-indigo": "hsl(251 100% 60%)",
"--editor-text-purple": "hsl(280 100% 60%)",
"--editor-text-pink": "hsl(305 100% 60%)",
"--editor-highlight-red": "hsl(1 100% 66% / 0.4)",
"--editor-highlight-orange": "hsl(26 97% 61% / 0.4)",
"--editor-highlight-yellow": "hsl(54 100% 66% / 0.4)",
"--editor-highlight-green": "hsl(119 100% 66% / 0.4)",
"--editor-highlight-cyan": "hsl(166 100% 66% / 0.4)",
"--editor-highlight-blue": "hsl(202 97% 61% / 0.4)",
"--editor-highlight-indigo": "hsl(251 100% 60% / 0.4)",
"--editor-highlight-purple": "hsl(280 100% 60% / 0.4)",
"--editor-highlight-pink": "hsl(305 100% 60% / 0.4)"
}
}
```

### 2. Change the `id` field to something unique, like an UUID.

### 3. Choose a name for your theme.

### 4. Tweak the colors to your liking.

> [!NOTE]
> You can define your colors in any supported CSS color function. HSL is recommended for easier tweaking of colors, but you can also use HEX, RGB, or any other CSS color format. **Color values are validated for security.**

### 5. Set the `mode` field appropriately.

If your theme is for dark mode, set it to `"dark"`, otherwise set it to `"light"`. This will determine the colors of window decorations etc.

### 6. Save the file

Save it somewhere easily accessible like your desktop, but make sure the file extension is `.json`. For example, save it as `my theme.json`

### 7. Import your theme

Open Darkwrite, choose **Settings** from the sidebar. Under the **Appearance** category, choose **Import Theme**

Choose the file you saved earlier.

### 8. Apply your theme

Select your theme from the theme menu to apply it. Enjoy your very own theme🖌️🎨

## Where can I find my theme files?

Your themes are stored in `<userDataDir>/darkwrite-data/themes/`, where `<userDataDir>` is the app data directory determined by your OS. You can easily get there by choosing **Tools > Open data directory** from Darkwrite's menu. (click the Darkwrite logo on the top left of the window)
1 change: 0 additions & 1 deletion packages/app-desktop/src/lib/blob-store.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fse from "node:fs/promises";
import { join } from "node:path";
import { pathToFileURL } from "node:url";
import type { DwResultAsync } from "@darkwrite/common";
Expand Down
10 changes: 8 additions & 2 deletions packages/app-desktop/src/theme/theme.handler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { IThemeAPI } from "@darkwrite/common";
import { BrowserWindow, dialog } from "electron";
import { err, ok, type Result } from "neverthrow";
import { BrowserWindow, dialog, shell } from "electron";
import { err, ok, type Result, ResultAsync } from "neverthrow";
import { Paths } from "@/lib/paths";
import { type HandlerImplements, handler } from "@/types";
import type { IThemeService } from "./theme.service";

Expand Down Expand Up @@ -33,8 +34,13 @@ export function ThemeAPI(
themeService.getThemes().map((themes) => ({ themes })),
);

const openThemeFolder = handler(() =>
ResultAsync.fromSafePromise(shell.openPath(Paths.THEME_DIR)).map(() => {}),
);

return {
importTheme,
getThemes,
openThemeFolder,
};
}
20 changes: 6 additions & 14 deletions packages/app-desktop/src/theme/theme.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,26 @@ import {
buildDwError,
type DarkwriteUserSettings,
DEFAULT_THEMES,
type DwResult,
dwErr,
isTheme,
parseJson,
type Theme,
Theme,
} from "@darkwrite/common";
import { nativeTheme } from "electron";
import log from "electron-log";
import { readFile } from "fs-extra";
import _ from "lodash";
import { ok, okAsync, Result, ResultAsync } from "neverthrow";
import { fsResult } from "@/lib/fs";
import { readFileUtf8 } from "@/lib/fs";
import type { IDocumentStore } from "../lib/document-store";

const logInvalidTheme = (id?: string, message?: string) =>
log.error(`Theme ${id} is invalid.`, message);

const assertValidTheme = (obj: unknown): DwResult<Theme> =>
isTheme(obj) ? ok(obj) : dwErr("Invalid theme.");

function parseTheme(themeString: string, id?: string) {
return parseJson(themeString)
const parseTheme = (themeString: string, id?: string) =>
parseJson(themeString)
.mapErr(() => buildDwError("Invalid JSON object"))
.andThen(assertValidTheme)
.andThen(Theme.parse)
.orTee((err) => {
logInvalidTheme(id, err.message);
});
}

function mapThemes(themes: Theme[]) {
const map: Record<string, Theme> = _.cloneDeep(DEFAULT_THEMES);
Expand All @@ -42,7 +34,7 @@ export function ThemeService(
getSettings: () => DarkwriteUserSettings,
) {
const importTheme = (filePath: string) =>
fsResult(readFile(filePath, "utf-8"))
readFileUtf8(filePath)
.andThen(parseTheme)
.andThen((json) => themeStore.write(json.id, JSON.stringify(json)));

Expand Down
1 change: 1 addition & 0 deletions packages/common/src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export interface ISettingsAPI {
export interface IThemeAPI {
getThemes: () => ApiResult<ThemesResponseDTO>;
importTheme: () => ApiResult<void>;
openThemeFolder: () => NoReturn;
}

export interface IContextMenuAPI {
Expand Down
4 changes: 3 additions & 1 deletion packages/common/src/result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ export function validateSchema<T extends z.ZodType>(schema: T) {
else
return dwErr(
"Schema validation failed.",
result.error.issues.map((issue) => issue.message).join("\n"),
result.error.issues
.map((issue) => `${issue.path.join(".")}:${issue.message}`)
.join("\n"),
);
};
}
Expand Down
28 changes: 4 additions & 24 deletions packages/common/src/theme.test.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,6 @@
import { isTheme } from "./theme";
import { Theme } from "./theme";
import { DEFAULT_THEME_LIST } from "./themes";

test("string is not a theme", () => {
expect(!isTheme("lol"));
});

it("is not a theme without id", () => {
expect(
!isTheme({
name: "not a theme",
}),
);
});

it("is not a theme without name", () => {
expect(!isTheme({ id: "1234-5678901234-5678" }));
});

it("is not a theme if id and name are not strings", () => {
expect(!isTheme({ id: {} }));
expect(!isTheme({ name: 1234 }));
});

it("is a theme if name and id are present", () => {
expect(isTheme({ name: "A theme without colors", id: "fs16df7uqvces" }));
it.each(DEFAULT_THEME_LIST)("built-in themes are valid", (theme) => {
expect(Theme.parse(theme).orTee(console.error).isOk(), theme.id).toBe(true);
});
161 changes: 48 additions & 113 deletions packages/common/src/theme.ts
Original file line number Diff line number Diff line change
@@ -1,124 +1,59 @@
import colorString from "color-string";

const allowedKeys = [
"--background",
"--foreground",
"--view-1",
"--view-2",
"--card",
"--card-foreground",
"--popover",
"--popover-foreground",
"--primary",
"--primary-foreground",
"--primary-text",
"--secondary",
"--secondary-foreground",
"--muted",
"--muted-foreground",
"--accent",
"--accent-foreground",
"--destructive",
"--destructive-foreground",
"--disabled",
"--border",
"--input",
"--radius",
"--star",
"--ring",
"--editor-text-red",
"--editor-text-orange",
"--editor-text-yellow",
"--editor-text-green",
"--editor-text-cyan",
"--editor-text-blue",
"--editor-text-indigo",
"--editor-text-purple",
"--editor-text-pink",
"--editor-highlight-red",
"--editor-highlight-orange",
"--editor-highlight-yellow",
"--editor-highlight-green",
"--editor-highlight-cyan",
"--editor-highlight-blue",
"--editor-highlight-indigo",
"--editor-highlight-purple",
"--editor-highlight-pink",
];

export type Theme = {
id: string;
name: string;
mode: "light" | "dark";
colors: {
"--background"?: string;
"--foreground"?: string;
"--view-1"?: string;
"--view-2"?: string;
"--card"?: string;
"--card-foreground"?: string;
"--popover"?: string;
"--popover-foreground"?: string;
"--primary"?: string;
"--primary-foreground"?: string;
"--primary-text"?: string;
"--secondary"?: string;
"--secondary-foreground"?: string;
"--muted"?: string;
"--muted-foreground"?: string;
"--accent"?: string;
"--accent-foreground"?: string;
"--destructive"?: string;
"--destructive-foreground"?: string;
"--disabled"?: string;
"--border"?: string;
"--input"?: string;
"--star"?: string;
"--ring"?: string;
"--editor-text-red"?: string;
"--editor-text-orange"?: string;
"--editor-text-yellow"?: string;
"--editor-text-green"?: string;
"--editor-text-cyan"?: string;
"--editor-text-blue"?: string;
"--editor-text-indigo"?: string;
"--editor-text-purple"?: string;
"--editor-text-pink"?: string;
"--editor-highlight-red"?: string;
"--editor-highlight-orange"?: string;
"--editor-highlight-yellow"?: string;
"--editor-highlight-green"?: string;
"--editor-highlight-cyan"?: string;
"--editor-highlight-blue"?: string;
"--editor-highlight-indigo"?: string;
"--editor-highlight-purple"?: string;
"--editor-highlight-pink"?: string;
};
};
import z from "zod";
import { validateSchema } from "./result";

export function isValidCssColor(color: string) {
return colorString.get(color) != null;
}

export function isTheme(maybeTheme: unknown): maybeTheme is Theme {
if (typeof maybeTheme !== "object" || maybeTheme == null) return false;
if (!("id" in maybeTheme && "name" in maybeTheme)) return false;
if (typeof maybeTheme.id !== "string" || typeof maybeTheme.name !== "string")
return false;
if (!("colors" in maybeTheme)) return false;
if (maybeTheme.colors == null || typeof maybeTheme.colors !== "object")
return false;
const zCssColor = z.stringFormat("css-color", isValidCssColor);

const colors = maybeTheme.colors as Record<string, string>;
const colorSchema = z.object({
"--background": zCssColor.optional(),
"--foreground": zCssColor.optional(),
"--view-1": zCssColor.optional(),
"--view-2": zCssColor.optional(),
"--primary": zCssColor.optional(),
"--secondary": zCssColor.optional(),
"--muted-foreground": zCssColor.optional(),
"--destructive": zCssColor.optional(),
"--destructive-foreground": zCssColor.optional(),
"--border": zCssColor.optional(),
"--star": zCssColor.optional(),
"--editor-text-red": zCssColor.optional(),
"--editor-text-orange": zCssColor.optional(),
"--editor-text-yellow": zCssColor.optional(),
"--editor-text-green": zCssColor.optional(),
"--editor-text-cyan": zCssColor.optional(),
"--editor-text-blue": zCssColor.optional(),
"--editor-text-indigo": zCssColor.optional(),
"--editor-text-purple": zCssColor.optional(),
"--editor-text-pink": zCssColor.optional(),
"--editor-highlight-red": zCssColor.optional(),
"--editor-highlight-orange": zCssColor.optional(),
"--editor-highlight-yellow": zCssColor.optional(),
"--editor-highlight-green": zCssColor.optional(),
"--editor-highlight-cyan": zCssColor.optional(),
"--editor-highlight-blue": zCssColor.optional(),
"--editor-highlight-indigo": zCssColor.optional(),
"--editor-highlight-purple": zCssColor.optional(),
"--editor-highlight-pink": zCssColor.optional(),
});

// check invalid key definitions
for (const key in colors) {
if (!allowedKeys.includes(key)) return false;
const value = colors[key as keyof typeof maybeTheme.colors];
if (!isValidCssColor(value)) return false;
}
return true;
}
export const ThemeSchema = z.object({
id: z.string().nonempty(),
name: z.string().nonempty(),
mode: z.enum(["light", "dark"]),
colors: colorSchema,
});

const allowedKeys = colorSchema.keyof().options;

export type Theme = z.output<typeof ThemeSchema>;

export const Theme = {
parse: (value: unknown) => validateSchema(ThemeSchema)(value),
};

export const cssTextColorVariables = allowedKeys.filter((key) =>
key.startsWith("--editor-text-"),
Expand Down
Loading
Loading