GithubHelp home page GithubHelp logo

miaowing / electron-nest-rpc Goto Github PK

View Code? Open in Web Editor NEW
9.0 3.0 1.0 247 KB

Provides a simple way to invoke nest.js service between the renderer process (web page) and the main process

JavaScript 11.21% TypeScript 88.79%

electron-nest-rpc's Introduction

Description

The electron-nest-rpc module provides a simple way to invoke nest service between the renderer process (web page) and the main process.

Installation

$ npm i --save electron-nest-rpc

Examples

https://github.com/miaowing/electron-nest-rpc-example

https://github.com/miaowing/dolphin

Quick Start

Main Process

import { ApplicationModule } from "./app.module";
import { BrowserWindow } from 'electron';
import { NestFactory } from "@nestjs/core";
import { NestRPC } from 'electron-nest-rpc';
import * as path from 'path';

async function bootstrap() {
    const window = new BrowserWindow({
        show: true,
        width: 966,
        height: 647,
        minWidth: 966,
        minHeight: 647,
        titleBarStyle: 'hidden',
    });
    const nestContext = await NestFactory.createApplicationContext(ApplicationModule);
    NestRPC.register(nestContext);
    
    window.loadURL(formatUrl({
        pathname: path.join(__dirname, 'index.html'),
        protocol: 'file',
        slashes: true
    }));
}

bootstrap();

Renderer Process

import * as React from 'react';
import { nestRPC, RPCException } from 'electron-nest-rpc';
import { UserService } from './services/UserService';

export class TestPage extends React.Component<any> {
    private readonly userService: UserService = nestRPC(UserService);
    private state = {users: []};
    
    constructor(props: any) {
        super(props);
    }
    
    async componentDidMount() {
        try {
            const users = await this.userService.getUsers();
            this.setState({users});
        } catch (e: RPCException) {
            console.log(e.message);
        }
    }
    
    render() {
        const users = this.state.users;
        return <ul>
            {users.map(user => <li key={user.id}>{user.name}</li>)}
        </ul>;
    }
}

Stay in touch

License

Nest is MIT licensed.

electron-nest-rpc's People

Contributors

miaowing avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

veici

electron-nest-rpc's Issues

electron-nest-rpc looks fantastic - any chance of a sample project?

Looking at the code for electron-nest-rpc is very exciting. The code looks very simple, very general-purpose, and very clever.

That said, the main README only explains part of how to set up a working example. I've been trying to set up a basic sample app that uses it and haven't been able to figure out exactly how it's intended to be hosted. I think I'm close, but am unable to actually get it to work. A sample hello-world project would help a lot and be greatly appreciated.

Also, I'll mention there seems to be some kind of typescript & electron compatibility issue currently impacting new electron v7 and electron v8 projects. In case it impacts you when you're putting making a sample app, here is a comment I posted elsewhere on working around the issue: electron/electron#21612 (comment)

DevTools failed to load SourceMap:

Not sure if the warning is related to this project, but it happens as soon as I add this line:

private readonly accountService: AccountService = nestRPC(AccountService)

I can barely read anything in the dev-console because there are thousands of lines like this:

DevTools failed to load SourceMap: Could not load content for http://localhost:8080/User/<id>/<full-path-to-project>/node_modules/rxjs/index.js.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.