Skip to content
Open
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
2 changes: 2 additions & 0 deletions apps/desktop/src/ipc.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/** Synchronous IPC: the renderer reads the app server's RPC URL once, at load. */
export const SERVER_CHANNEL = "codework:server";
/** Synchronous IPC: the renderer reads the default workspace root once, at load. */
export const ROOT_CHANNEL = "codework:root";
7 changes: 6 additions & 1 deletion apps/desktop/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { app, BrowserWindow, net, protocol } from "electron";
import { app, BrowserWindow, ipcMain, net, protocol } from "electron";
import { readFile, stat } from "node:fs/promises";
import path from "node:path";
import { ROOT_CHANNEL } from "./ipc.ts";
import { startServer } from "./server.ts";

ipcMain.on(ROOT_CHANNEL, (event) => {
event.returnValue = process.env.CODEWORK_ROOT ?? path.resolve(app.getAppPath(), app.isPackaged ? ".." : "../..");
});

const SCHEME = app.isPackaged ? "codework" : "codework-dev";
const HOST = "app";
const APP_URL = `${SCHEME}://${HOST}/`;
Expand Down
3 changes: 2 additions & 1 deletion apps/desktop/src/preload.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { contextBridge, ipcRenderer } from "electron";
import { SERVER_CHANNEL } from "./ipc.ts";
import { ROOT_CHANNEL, SERVER_CHANNEL } from "./ipc.ts";

contextBridge.exposeInMainWorld("desktopBridge", {
platform: process.platform,
// Main creates the window only after the server is ready, so this is set.
server: ipcRenderer.sendSync(SERVER_CHANNEL) as string,
root: ipcRenderer.sendSync(ROOT_CHANNEL) as string,
});
9 changes: 8 additions & 1 deletion apps/server/src/mock.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import path from "node:path";
import { fileURLToPath } from "node:url";
import type { Message, Project, Session } from "./contract.ts";

// Stand-in data until the server talks to the harness.

const repoRoot =
process.env.CODEWORK_ROOT ??
path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../..");

const hour = 60 * 60 * 1000;
const now = Date.now();

Expand All @@ -27,8 +33,9 @@ const sessions: readonly Session[] = [
{ id: "s6", project: "notes", title: "Weekly plan", updated: now - 72 * hour },
].map((session) => ({ ...session, messages: conversation(session.title.toLowerCase()) }));


const roots = [
{ id: "codework", name: "codework", path: "~/Developer/codeworksh/codework" },
{ id: "codework", name: "codework", path: repoRoot },
{ id: "webwm", name: "webwm", path: "~/Developer/codeworksh/webwm" },
{ id: "notes", name: "notes", path: "~/Documents/notes" },
];
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ declare global {
platform: string;
/** The app server's RPC WebSocket URL. */
server: string;
/** The default workspace root directory. */
root?: string;
};
}
}
Expand Down
7 changes: 6 additions & 1 deletion apps/web/src/wm/instances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export interface Desk {
// Tag bits of the workspaces the database is seeded with: Main, Code, Notes.
const [main, code, notes] = [tagBit(0), tagBit(1), tagBit(2)];

const defaultRoot =
(typeof window !== "undefined" && window.desktopBridge?.root) ||
(import.meta.env.VITE_PROJECT_ROOT as string) ||
"";

// Hardcoded until instances live in SQLite. Tile order follows this list, so
// Files is the master on Main and Projects on Code; Chat and Terminal sit on
// two workspaces at once.
Expand All @@ -41,7 +46,7 @@ const seed: readonly Instance[] = [
id: "files",
kind: "codework:explorer",
tags: main,
props: { root: "/Users/sanchitrk/Developer/codeworksh/codework" },
props: { root: defaultRoot },
},
{ id: "projects", kind: "codework:projects", tags: code, props: {} },
{ id: "chat", kind: "codework:placeholder", title: "Chat", tags: main | code, props: {} },
Expand Down
5 changes: 5 additions & 0 deletions apps/web/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ export default defineConfig({
// Pinned so the desktop shell can proxy to a fixed address; `localhost`
// may bind IPv6-only, which Electron's 127.0.0.1 lookup then misses.
server: { host: "127.0.0.1", port: 5173, strictPort: true },
define: {
"import.meta.env.VITE_PROJECT_ROOT": JSON.stringify(
process.env.CODEWORK_ROOT ?? fileURLToPath(new URL("../..", import.meta.url)),
),
},
});