Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion apps/desktop/scripts/dev.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ while (!(await ready())) await sleep(100);

let electron;
function startElectron() {
electron = run("node", ["scripts/start-electron.mjs"], {
// pnpm inserts a lone `--` before arguments meant for the script.
const extra = process.argv.slice(2);
if (extra[0] === "--") extra.shift();
electron = run("node", ["scripts/start-electron.mjs", ...extra], {
cwd: desktopDir,
env: { ...process.env, CODEWORK_WEB_URL: WEB_URL },
});
Expand Down
3 changes: 2 additions & 1 deletion apps/desktop/scripts/start-electron.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ const electronPath = process.platform === "darwin" ? brandedElectron() : electro
const env = { ...process.env };
delete env.ELECTRON_RUN_AS_NODE;

const child = spawn(electronPath, ["."], {
// Extra arguments reach Electron, `--remote-debugging-port=9222` say.
const child = spawn(electronPath, [".", ...process.argv.slice(2)], {
stdio: "inherit",
cwd: desktopDir,
env,
Expand Down
8 changes: 0 additions & 8 deletions apps/server/src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ const migrations = {
created INTEGER NOT NULL
)
`;
const created = yield* Clock.currentTimeMillis;
yield* sql`INSERT INTO workspaces ${sql.insert(
[
{ id: "main", name: "Main", icon: "layout-dashboard" },
{ id: "code", name: "Code", icon: "code" },
{ id: "notes", name: "Notes", icon: "notebook-pen" },
].map((workspace, index) => ({ ...workspace, bit: index, pos: index, layout: "tile", mfact: 0.6, created })),
)}`;
// AUTOINCREMENT so a seq is never reused, even after the newest rows are deleted.
yield* sql`
CREATE TABLE event (
Expand Down
37 changes: 18 additions & 19 deletions apps/server/test/__artifacts__/desk.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@
"tileOrder": [],
"focusOrder": []
},
"other": {
"id": "<other>",
"bit": 0,
"pos": 0,
"name": "Other",
"layout": "tile",
"mfact": 0.6,
"auto": false
},
"workspace": {
"id": "<workspace>",
"bit": 3,
"pos": 3,
"bit": 1,
"pos": 1,
"name": "Scratch",
"layout": "tile",
"mfact": 0.6,
Expand All @@ -18,7 +27,7 @@
{
"id": "browser-1",
"kind": "browser",
"tags": 9,
"tags": 3,
"props": {},
"pinned": false,
"title": "Docs",
Expand All @@ -35,7 +44,7 @@
{
"id": "notes-1",
"kind": "notes",
"tags": 8,
"tags": 2,
"props": {
"text": "hello"
},
Expand All @@ -56,7 +65,7 @@
{
"id": "browser-1",
"kind": "browser",
"tags": 9,
"tags": 3,
"props": {},
"pinned": false,
"title": "Docs",
Expand All @@ -73,7 +82,7 @@
{
"id": "notes-1",
"kind": "notes",
"tags": 8,
"tags": 2,
"props": {
"text": "hello"
},
Expand Down Expand Up @@ -129,24 +138,14 @@
"afterRestart": {
"workspaces": [
{
"name": "Main",
"name": "Other",
"auto": false,
"pos": 0
},
{
"name": "Code",
"auto": false,
"pos": 1
},
{
"name": "Notes",
"auto": false,
"pos": 2
},
{
"name": "Kept",
"auto": true,
"pos": 3,
"pos": 1,
"tab": "Kept / A session"
}
],
Expand All @@ -155,7 +154,7 @@
{
"id": "notes-2",
"kind": "notes",
"tags": 8,
"tags": 2,
"props": {},
"pinned": false
}
Expand Down
17 changes: 8 additions & 9 deletions apps/server/test/desk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,17 @@ it("desk round-trips and follows workspace deletion", async () => {
const rpc = yield* RpcClient.make(Contract.Api);
const empty = yield* rpc["desk.get"]();

// Two workspaces, so a frame on both outlives deleting one of them.
const other = yield* rpc["workspaces.create"]({ name: "Other" });
const workspace = yield* rpc["workspaces.create"]({ name: "Scratch" });
const bit = 1 << workspace.bit;
const otherBit = 1 << other.bit;
const saved: Contract.Desk = {
instances: [
{
id: "browser-1",
kind: "browser",
tags: bit | 1,
tags: bit | otherBit,
props: {},
pinned: false,
title: "Docs",
Expand Down Expand Up @@ -105,6 +108,7 @@ it("desk round-trips and follows workspace deletion", async () => {

return {
empty,
other: { ...other, id: "<other>" },
workspace: { ...workspace, id: "<workspace>" },
saved,
roundTrip,
Expand All @@ -114,7 +118,7 @@ it("desk round-trips and follows workspace deletion", async () => {
}).pipe(Effect.scoped, Effect.provide(protocol()), Effect.runPromise);

expect(steps.roundTrip).toEqual(steps.saved);
expect(steps.afterDelete.instances).toEqual([{ ...steps.saved.instances[0], tags: 1 }]);
expect(steps.afterDelete.instances).toEqual([{ ...steps.saved.instances[0], tags: 1 << steps.other.bit }]);

// A restart sweeps the empty auto workspace and keeps the one with a frame.
await stop();
Expand All @@ -125,14 +129,9 @@ it("desk round-trips and follows workspace deletion", async () => {
const desk = yield* rpc["desk.get"]();
return { workspaces: workspaces.map(({ name, auto, pos, tab }) => ({ name, auto, pos, tab })), desk };
}).pipe(Effect.scoped, Effect.provide(protocol()), Effect.runPromise);
expect(afterRestart.workspaces.map((workspace) => workspace.name)).toEqual(["Main", "Code", "Notes", "Kept"]);
expect(afterRestart.workspaces.map((workspace) => workspace.name)).toEqual(["Other", "Kept"]);
// A workspace's last tab survives the restart, so it names what it shows before its frame loads.
expect(afterRestart.workspaces.map((workspace) => workspace.tab)).toEqual([
undefined,
undefined,
undefined,
"Kept / A session",
]);
expect(afterRestart.workspaces.map((workspace) => workspace.tab)).toEqual([undefined, "Kept / A session"]);

await expect(`${JSON.stringify({ ...steps, afterRestart }, null, "\t")}\n`).toMatchFileSnapshot(
"./__artifacts__/desk.json",
Expand Down
5 changes: 3 additions & 2 deletions apps/web/index.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<!doctype html>
<html lang="en">
<html lang="en" data-theme="dark">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>CodeWork</title>
<!-- The saved theme (src/theme.ts) lands before first paint; an unknown id falls back to the default. -->
<script>
try {
document.documentElement.dataset.theme = localStorage.getItem("codework-theme") ?? "tokyo-night";
const saved = localStorage.getItem("codework-theme");
document.documentElement.dataset.theme = saved === "light" ? "light" : "dark";
} catch {}
</script>
<!-- Linked here rather than imported by style.css, so the splash paints in the theme before the app's JS runs. -->
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/kernel/servers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export interface Problem {
/** The default server's problem from its status; undefined while the app can work with it. */
export function problemOf(status: ServerStatus): Problem | undefined {
const { cli, server } = status;
// An already running, compatible server is usable even without a local CLI.
if (server._tag === "Running") return undefined;
if (cli === null)
return {
title: "CodeWork Isn't Installed",
Expand All @@ -43,8 +45,6 @@ export function problemOf(status: ServerStatus): Problem | undefined {
title: "Incompatible Server Version",
line: `${status.name} runs codework v${server.version}, which this app can't read.`,
};
case "Running":
return undefined;
}
}

Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/settings/themes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function ThemesSettings() {
}
>
<Section title="Theme">
<div role="radiogroup" aria-label="Theme" className="grid grid-cols-2 gap-3 sm:grid-cols-3">
<div role="radiogroup" aria-label="Theme" className="grid grid-cols-2 gap-3">
{THEMES.map((theme) => {
const selected = theme.id === current;
return (
Expand Down
31 changes: 4 additions & 27 deletions apps/web/src/theme.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,14 @@
import { Atom } from "effect/reactivity";

/**
* Colour themes: the codework.sh palettes in themes.css, keyed by id. The choice is saved per
* device; index.html applies it before first paint under the same storage key.
*/
/** Light and dark themes, saved per device and applied before first paint by index.html. */
export const THEMES = [
{ id: "catppuccin", name: "Catppuccin" },
{ id: "catppuccin-latte", name: "Catppuccin Latte" },
{ id: "ethereal", name: "Ethereal" },
{ id: "everforest", name: "Everforest" },
{ id: "flexoki-light", name: "Flexoki Light" },
{ id: "gruvbox", name: "Gruvbox" },
{ id: "hackerman", name: "Hackerman" },
{ id: "kanagawa", name: "Kanagawa" },
{ id: "last-horizon", name: "Last Horizon" },
{ id: "lumon", name: "Lumon" },
{ id: "lupine", name: "Lupine" },
{ id: "matte-black", name: "Matte Black" },
{ id: "miasma", name: "Miasma" },
{ id: "nord", name: "Nord" },
{ id: "osaka-jade", name: "Osaka Jade" },
{ id: "retro-82", name: "Retro 82" },
{ id: "ristretto", name: "Ristretto" },
{ id: "rose-pine", name: "Rosé Pine" },
{ id: "solitude", name: "Solitude" },
{ id: "tokyo-night", name: "Tokyo Night" },
{ id: "vantablack", name: "Vantablack" },
{ id: "white", name: "White" },
{ id: "light", name: "Light" },
{ id: "dark", name: "Dark" },
] as const;

export type ThemeId = (typeof THEMES)[number]["id"];

const DEFAULT_THEME: ThemeId = "tokyo-night";
const DEFAULT_THEME: ThemeId = "dark";
const STORAGE_KEY = "codework-theme";

export const isTheme = (id: string): id is ThemeId => THEMES.some((theme) => theme.id === id);
Expand Down
Loading
Loading