
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
electron-ipc-decorator
Advanced tools
A TypeScript-first decorator library that simplifies Electron IPC communication with type safety and automatic proxy generation
A TypeScript-first decorator library that simplifies Electron IPC communication with type safety and automatic proxy generation.
npm install electron-ipc-decorator
# or
pnpm add electron-ipc-decorator
# or
yarn add electron-ipc-decorator
import { app } from 'electron'
import { IpcService, IpcMethod, IpcContext } from 'electron-ipc-decorator'
export class AppService extends IpcService {
static readonly groupName = 'app' // Define static group name
@IpcMethod()
getAppVersion(): string {
return app.getVersion()
}
@IpcMethod()
switchAppLocale(context: IpcContext, locale: string): void {
// The first parameter is always IpcContext
// Additional parameters follow after context
i18n.changeLanguage(locale)
app.commandLine.appendSwitch('lang', locale)
}
@IpcMethod()
async search(
context: IpcContext,
input: SearchInput,
): Promise<Electron.Result | null> {
const { sender: webContents } = context
const { promise, resolve } = Promise.withResolvers<Electron.Result | null>()
let requestId = -1
webContents.once('found-in-page', (_, result) => {
resolve(result.requestId === requestId ? result : null)
})
requestId = webContents.findInPage(input.text, input.options)
return promise
}
}
import { createServices, MergeIpcService } from 'electron-ipc-decorator'
import { AppService } from './app-service'
// Create services with automatic type inference
export const services = createServices([AppService])
// Generate type definition for all services
export type IpcServices = MergeIpcService<typeof services>
import { createIpcProxy } from 'electron-ipc-decorator/client'
import type { IpcServices } from './main/services' // Import from main process
// ipcRenderer should be exposed through electron's context bridge
export const ipcServices = createIpcProxy<IpcServices>(ipcRenderer)
// Synchronous methods
const version = await ipcServices.app.getAppVersion()
// Methods with parameters (context is automatically handled)
await ipcServices.app.switchAppLocale('en')
// Async methods
const searchResult = await ipcServices.app.search({
text: 'search term',
options: {
findNext: false,
forward: true,
},
})
@IpcMethod()
Marks a method as an IPC endpoint.
@IpcMethod()
someMethod() { }
IpcService
Base class for creating IPC service groups.
abstract class IpcService {
static readonly groupName: string // Must be defined by subclasses
}
IpcContext
Context object passed as the first parameter to all IPC methods.
interface IpcContext {
sender: WebContents // The WebContents that sent the request
event: IpcMainInvokeEvent // The original IPC event
}
createServices<T>(serviceConstructors: T): ServicesResult<T>
Creates services from an array of service constructors with automatic type inference. Each service class must define a static groupName
property.
// Define services
class AppService extends IpcService {
static readonly groupName = 'app'
// methods...
}
class UserService extends IpcService {
static readonly groupName = 'user'
// methods...
}
// Create services with type safety
const services = createServices([AppService, UserService])
// Type is: { app: AppService, user: UserService }
createIpcProxy<T>(ipcRenderer: IpcRenderer): T
Creates a type-safe proxy for calling IPC methods from the renderer process.
MergeIpcService<T>
Merges multiple service instances into a single type definition.
ExtractServiceMethods<T>
Extracts and transforms service methods for client-side usage, automatically:
IpcContext
parameterPromise<T>
IpcContext
Promise<T>
on the client side, even if they're synchronous on the server// Main process method signature
@IpcMethod()
someMethod(context: IpcContext, param1: string, param2: number): string {
// Implementation
}
// Renderer process usage (auto-generated type)
ipcServices.group.someMethod(param1: string, param2: number): Promise<string>
If you're upgrading from a version that used constructor-based group names, here's how to migrate:
Old way:
export class AppService extends IpcService {
constructor() {
super('app') // Group name in constructor
}
}
// Manual service object creation
export const services = {
app: new AppService(),
}
New way (recommended):
export class AppService extends IpcService {
static readonly groupName = 'app' // Static group name
}
// Automatic service creation with type safety
export const services = createServices([AppService])
Benefits of the new approach:
groupName
is missingErrors thrown in main process methods are automatically caught and re-thrown in the renderer process:
@IpcMethod()
riskyOperation(context: IpcContext): string {
throw new Error("Something went wrong")
}
// In renderer
try {
await ipcServices.app.riskyOperation()
} catch (error) {
console.error("IPC Error:", error.message) // "Something went wrong"
}
@IpcMethod()
sendNotification(context: IpcContext, message: string): void {
const { sender } = context
// Send data back to the specific renderer
sender.send('notification', { message, timestamp: Date.now() })
}
Ensure your tsconfig.json
has decorator support enabled:
{
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}
}
2025 © Innei, Released under the MIT License.
Personal Website · GitHub @Innei
FAQs
A TypeScript-first decorator library that simplifies Electron IPC communication with type safety and automatic proxy generation
We found that electron-ipc-decorator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.