Skip to content

Commit 09d5ae7

Browse files
committed
still borked, migrating to monorepo
1 parent 961deee commit 09d5ae7

20 files changed

+198
-122
lines changed

electron.vite.config.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import react from "@vitejs/plugin-react";
22
import { defineConfig, externalizeDepsPlugin } from "electron-vite";
33
import path, { resolve } from "path";
44

5+
const isLocal = false;
6+
57
export default defineConfig({
68
main: {
79
resolve: {
@@ -19,8 +21,10 @@ export default defineConfig({
1921
resolve: {
2022
alias: {
2123
"@": path.resolve(__dirname, "./src/renderer/src"),
22-
"@renderer": resolve("src/renderer/src"),
23-
"@shared": resolve("src/shared/")
24+
"@shared": resolve("src/shared/"),
25+
"@platform": isLocal
26+
? resolve("src/renderer/src/lib/platform/platform.ts")
27+
: resolve("../test-vite/platform/platform.ts")
2428
}
2529
},
2630
plugins: [react()]

package-lock.json

+62
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
"@electron-toolkit/eslint-config-prettier": "^2.0.0",
9090
"@electron-toolkit/eslint-config-ts": "^1.0.1",
9191
"@electron-toolkit/tsconfig": "^1.0.1",
92+
"@rollup/plugin-dynamic-import-vars": "^2.1.2",
9293
"@types/node": "^18.19.22",
9394
"@types/react": "^18.2.48",
9495
"@types/react-dom": "^18.2.18",

src/main/index.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ import { BrowserWindow, Menu, Tray, app, dialog, nativeImage, net, protocol, she
33
import { createIPCHandler } from "electron-trpc/main";
44
import { autoUpdater } from "electron-updater";
55
import path, { join } from "path";
6+
// @ts-ignore - Electron vite asset import type error
67
import icon from "../../resources/icon.png?asset";
78
import { blob } from "./lib/blob";
89
import { sqlite } from "./lib/sqlite";
910
import { cardsRootPath, personasRootPath } from "./lib/utils";
10-
import { router } from "./routers/router";
11+
import { router } from "./router";
1112

12-
export let win: any;
13+
// TODO: Decompose and refactor this heap of noise
14+
15+
let win: any;
1316
let isQuiting = false;
1417

1518
// Prevent multiple app instances
@@ -158,7 +161,6 @@ app.whenReady().then(async () => {
158161

159162
await blob.init();
160163
await sqlite.init();
161-
createIPCHandler({ router, windows: [win] });
162164

163165
// Open or close DevTools using F12 in development
164166
// Ignore Cmd/Ctrl + R in production.
@@ -201,6 +203,7 @@ app.whenReady().then(async () => {
201203
});
202204

203205
createWindow();
206+
createIPCHandler({ router, windows: [win] });
204207
});
205208

206209
function createWindow(): void {

src/main/routers/router.ts renamed to src/main/router.ts

+37-61
Original file line numberDiff line numberDiff line change
@@ -9,85 +9,61 @@ import {
99
UpdatePersonaBundleSchema,
1010
XFetchRequestSchema
1111
} from "@shared/schema/ipc";
12+
import type { inferRouterInputs, inferRouterOutputs } from "@trpc/server";
1213
import { initTRPC } from "@trpc/server";
14+
import test from "node:test";
1315
import { z } from "zod";
1416

15-
const t = initTRPC.create();
17+
const t = initTRPC.create({ isServer: true });
1618

17-
// TODO: sqlite inputs should be declared as a schema
1819
const sqliteRouter = t.router({
19-
run: t.procedure.input(SQLiteRunSchema).mutation(({ input }) => {
20-
// Implement your logic here
21-
}),
22-
all: t.procedure.input(SQLiteAllSchema).query(({ input }) => {
23-
// Implement your logic here
24-
}),
25-
get: t.procedure.input(SQLiteGetSchema).query(({ input }) => {
26-
// Implement your logic here
27-
}),
28-
runAsTransaction: t.procedure.input(SQLiteRunAsTransactionSchema).mutation(({ input }) => {
29-
// Implement your logic here
30-
})
20+
run: t.procedure.input(SQLiteRunSchema).mutation(({ input }) => {}),
21+
all: t.procedure.input(SQLiteAllSchema).query(({ input }) => {}),
22+
get: t.procedure.input(SQLiteGetSchema).query(({ input }) => {}),
23+
runAsTransaction: t.procedure.input(SQLiteRunAsTransactionSchema).mutation(({ input }) => {})
3124
});
3225

3326
const cardsRouter = t.router({
34-
create: t.procedure.input(CreateCardBundleSchema).mutation(({ input }) => {
35-
// Implement your logic here
36-
}),
37-
read: t.procedure.input(z.number()).query(({ input }) => {
38-
// Implement your logic here
39-
}),
40-
update: t.procedure.input(UpdateCardBundleSchema).mutation(({ input }) => {
41-
// Implement your logic here
42-
}),
43-
del: t.procedure.input(z.number()).mutation(({ input }) => {
44-
// Implement your logic here
45-
}),
46-
export_: t.procedure.input(z.number()).mutation(({ input }) => {
47-
// Implement your logic here
48-
}),
49-
import_: t.procedure.input(z.string()).mutation(({ input }) => {
50-
// Implement your logic here
51-
})
27+
create: t.procedure.input(CreateCardBundleSchema).mutation(({ input }) => {}),
28+
read: t.procedure.input(z.number()).query(({ input }) => {}),
29+
update: t.procedure.input(UpdateCardBundleSchema).mutation(({ input }) => {}),
30+
del: t.procedure.input(z.number()).mutation(({ input }) => {}),
31+
export_: t.procedure.input(z.number()).mutation(({ input }) => {}),
32+
import_: t.procedure.input(z.string()).mutation(({ input }) => {})
5233
});
5334

5435
const personasRouter = t.router({
55-
create: t.procedure.input(CreatePersonaBundleSchema).mutation(({ input }) => {
56-
// Implement your logic here
57-
}),
58-
read: t.procedure.input(z.number()).query(({ input }) => {
59-
// Implement your logic here
60-
}),
61-
update: t.procedure.input(UpdatePersonaBundleSchema).mutation(({ input }) => {
62-
// Implement your logic here
63-
}),
64-
del: t.procedure.input(z.number()).mutation(({ input }) => {
65-
// Implement your logic here
66-
})
36+
create: t.procedure.input(CreatePersonaBundleSchema).mutation(({ input }) => {}),
37+
read: t.procedure.input(z.number()).query(({ input }) => {}),
38+
update: t.procedure.input(UpdatePersonaBundleSchema).mutation(({ input }) => {}),
39+
del: t.procedure.input(z.number()).mutation(({ input }) => {})
6740
});
6841

6942
const xfetchRouter = t.router({
70-
post: t.procedure.input(XFetchRequestSchema).mutation(({ input }) => {
71-
// Implement your logic here
72-
}),
73-
get: t.procedure.input(XFetchRequestSchema).query(({ input }) => {
74-
// Implement your logic here
75-
}),
76-
abort: t.procedure.input(z.string()).mutation(({ input }) => {
77-
// Implement your logic here
78-
})
43+
post: t.procedure.input(XFetchRequestSchema).mutation(({ input }) => {}),
44+
get: t.procedure.input(XFetchRequestSchema).query(({ input }) => {}),
45+
abort: t.procedure.input(z.string()).mutation(({ input }) => {})
7946
});
8047

8148
const utilsRouter = t.router({
82-
openURL: t.procedure.input(z.string()).mutation(({ input }) => {
83-
// Implement your logic here
84-
})
49+
openURL: t.procedure.input(z.string()).mutation(({ input }) => {})
8550
});
8651

8752
export const router = t.router({
88-
sqlite: sqliteRouter,
89-
cards: cardsRouter,
90-
personas: personasRouter,
91-
xfetch: xfetchRouter,
92-
utils: utilsRouter
53+
// sqlite: sqliteRouter,
54+
// cards: cardsRouter,
55+
// personas: personasRouter,
56+
// xfetch: xfetchRouter,
57+
// utils: utilsRouter
58+
test: t.procedure.query(() => {
59+
return { kind: "ok", data: "Hello World!" };
60+
}),
61+
test2: t.procedure.query(() => {
62+
return "Hello World!";
63+
}),
64+
test3: t.procedure.query(() => {
65+
return Math.random() % 2 === 0 ? { kind: "ok", data: "Hello World!" } : { kind: "error", data: "Hello World!" };
66+
})
9367
});
68+
69+
export type AppRouter = typeof router;

src/main/routers/cards.ts

Whitespace-only changes.

src/main/routers/personas.ts

Whitespace-only changes.

src/main/routers/sqlite.ts

Whitespace-only changes.

src/main/routers/utils.ts

Whitespace-only changes.

src/main/routers/xfetch.ts

Whitespace-only changes.

src/preload/index.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
import { exposeElectronTRPC } from "electron-trpc/main";
1+
import { contextBridge, ipcRenderer } from "electron";
2+
3+
export const ELECTRON_TRPC_CHANNEL = "electron-trpc";
4+
const exposeElectronTRPC = () => {
5+
const electronTRPC: any = {
6+
sendMessage: (operation) => ipcRenderer.send(ELECTRON_TRPC_CHANNEL, operation),
7+
onMessage: (callback) => ipcRenderer.on(ELECTRON_TRPC_CHANNEL, (_event, args) => callback(args))
8+
};
9+
contextBridge.exposeInMainWorld("electronTRPC", electronTRPC);
10+
};
211

312
process.once("loaded", async () => {
413
exposeElectronTRPC();

src/renderer/loading.html

-41
This file was deleted.

src/renderer/src/app/app.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ export default function App() {
210210
</CommandDialog>
211211
)}
212212

213-
{/* <div className="flex h-full w-full overflow-hidden py-4">
213+
<div className="flex h-full w-full overflow-hidden py-4">
214214
{page === "create" && <CreationPage setPage={setPage} />}
215215
{page === "chats" && !activeChatID && (
216216
<div className="flex items-center justify-center w-full h-full text-tx-tertiary">
@@ -224,7 +224,7 @@ export default function App() {
224224
{page === "chats" && activeChatID && <ChatsPage chatID={activeChatID} />}
225225
{page === "collections" && <CollectionsPage cardBundles={cardBundles} />}
226226
{page === "settings" && <SettingsPage />}
227-
</div> */}
227+
</div>
228228
</div>
229229
</AppContext.Provider>
230230
);

src/renderer/src/app/sandbox.tsx

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { createTRPCProxyClient } from "@trpc/client";
2+
import { ipcLink } from "electron-trpc/renderer";
3+
import type { AppRouter } from "../../../main/router";
4+
5+
interface SandboxProps {}
6+
export default function Sandbox({}: SandboxProps) {
7+
return (
8+
<div className="flex h-full w-full rounded-xl ">
9+
<p></p>
10+
11+
<button onClick={() => {}}></button>
12+
</div>
13+
);
14+
}

src/renderer/src/lib/card.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import { Result } from "@shared/types";
66
import { deepFreeze } from "@shared/utils";
7-
7+
// TODO: move this to platform
88
async function importFromFileList(files: FileList): Promise<Result<void, Error>[]> {
99
const numFiles = files.length;
1010
if (numFiles === 0) {

0 commit comments

Comments
 (0)