mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-05-28 19:05:31 +02:00
bootstrap new electron app
This commit is contained in:
parent
2491bacea1
commit
505e3ea620
89 changed files with 12397 additions and 8435 deletions
2
apps/x/apps/preload/.gitignore
vendored
Normal file
2
apps/x/apps/preload/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
node_modules/
|
||||
dist/
|
||||
16
apps/x/apps/preload/package.json
Normal file
16
apps/x/apps/preload/package.json
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"name": "@x/preload",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "dist/preload.js",
|
||||
"scripts": {
|
||||
"build": "rm -rf dist && tsc && esbuild dist/preload.js --bundle --platform=node --format=cjs --external:electron --outfile=dist/preload.bundle.js && mv dist/preload.bundle.js dist/preload.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@x/shared": "workspace:*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"electron": "^39.2.7",
|
||||
"esbuild": "^0.24.2"
|
||||
}
|
||||
}
|
||||
54
apps/x/apps/preload/src/preload.ts
Normal file
54
apps/x/apps/preload/src/preload.ts
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import { contextBridge, ipcRenderer } from 'electron';
|
||||
import { ipc as ipcShared } from '@x/shared';
|
||||
|
||||
type InvokeChannels = ipcShared.InvokeChannels;
|
||||
type IPCChannels = ipcShared.IPCChannels;
|
||||
type SendChannels = ipcShared.SendChannels;
|
||||
const { validateRequest } = ipcShared;
|
||||
|
||||
const ipc = {
|
||||
/**
|
||||
* Invoke a channel that expects a response (request/response pattern)
|
||||
* Only channels with non-null responses can be invoked
|
||||
*/
|
||||
invoke<K extends InvokeChannels>(
|
||||
channel: K,
|
||||
args: IPCChannels[K]['req']
|
||||
): Promise<IPCChannels[K]['res']> {
|
||||
// Runtime validation of request payload
|
||||
const validatedArgs = validateRequest(channel, args);
|
||||
return ipcRenderer.invoke(channel, validatedArgs);
|
||||
},
|
||||
|
||||
/**
|
||||
* Send a message to a channel without expecting a response (fire-and-forget)
|
||||
* Only channels with null responses can be sent
|
||||
*/
|
||||
send<K extends SendChannels>(
|
||||
channel: K,
|
||||
args: IPCChannels[K]['req']
|
||||
): void {
|
||||
// Runtime validation of request payload
|
||||
const validatedArgs = validateRequest(channel, args);
|
||||
ipcRenderer.send(channel, validatedArgs);
|
||||
},
|
||||
|
||||
/**
|
||||
* Listen to a send channel event
|
||||
* Returns a cleanup function to remove the listener
|
||||
*/
|
||||
on<K extends SendChannels>(
|
||||
channel: K,
|
||||
handler: (event: IPCChannels[K]['req']) => void
|
||||
): () => void {
|
||||
const listener = (_event: unknown, data: IPCChannels[K]['req']) => {
|
||||
handler(data);
|
||||
};
|
||||
ipcRenderer.on(channel, listener);
|
||||
return () => {
|
||||
ipcRenderer.removeListener(channel, listener);
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
contextBridge.exposeInMainWorld('ipc', ipc);
|
||||
9
apps/x/apps/preload/tsconfig.json
Normal file
9
apps/x/apps/preload/tsconfig.json
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"rootDir": "src",
|
||||
"types": ["electron"]
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue