npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

electron-proxy

v1.0.12

Published

- 本质是把web页面,利用electron提供的webview容器,打包成桌面应用。【此处可能需要electon的node端能力,进行一些文件的读写操作】 # electron-proxy是什么? - electron-proxy是为了解决不同平台,调用相同方法,得到预期结果的一个抽象封装。 # electron-proxy是为了解决什么问题? - 如同一个功能的web页面,期望在浏览器和electron中都可以运行,但是内部都需要调用从本地获取用户信息【例子不一定合适】的方法,electron有el

Downloads

5

Readme

electron跨平台应用的本质是什么?

  • 本质是把web页面,利用electron提供的webview容器,打包成桌面应用。【此处可能需要electon的node端能力,进行一些文件的读写操作】

electron-proxy是什么?

  • electron-proxy是为了解决不同平台,调用相同方法,得到预期结果的一个抽象封装。

electron-proxy是为了解决什么问题?

  • 如同一个功能的web页面,期望在浏览器和electron中都可以运行,但是内部都需要调用从本地获取用户信息【例子不一定合适】的方法,electron有electron的实现,浏览器有浏览器的实现,在代码里如何做呢?
if (electron){
  electron.getUserInfo()
} else {
  window.getUserInfo()
}
  • 上述的代码确实可以解决问题,但是,如果后续还要求在其他平台,有不同的实现,怎么做呢?if (Android), if (IOS)???都9102年了,不能用面向对象吗?electron-proxy就是帮你利用面向对象的设计模式----策略模式,帮你解决不同平台的问题,如何做?

electron-proxy使用?

  • 外部业务层可以定义不用平台,统一实现方法的接口:
interface ICustomBusinessProxy extends IBusinessProxy {
  getUserInfo: () => Promise<IUserInfo>;
}
  • 分别实现electron和web的getUserInfo的方法:
class CustomBusinessElectronProxy extends BusinessElectronProxy implements ICustomBusinessProxy {
  constructor(content: ICustomBusinessProxy = window['electron']) {
    super(content);
  }
  getUserInfo = async (): Promise<IUserInfo> => {
    await this.invoke({
      name: 'getUserInfo',
    })
  }
}

class CustomBusinessWebProxy extends BusinessWebProxy implements ICustomBusinessProxy {
  getUserInfo = async (): Promise<IUserInfo> => {
    return Promise.resolve(new UserInfo());
  }
}
  • 对外导出
import { Platform } from "electron-proxy";

export default new Platform<ICustomBusinessProxy>();

export {
  CustomBusinessElectronProxy,
  CustomBusinessWebProxy
}
  • 在web页面启动的入口文件处,注入
platform
  .init(new CustomBusinessElectronProxy(), new CustomBusinessWebProxy())
  .finally(() => render(App));
  • 在调用的地方,使用
const userInfo = await platform.Proxy.getUserInfo()
  • 如果需要做平台扩展【新增安卓、ios平台】,如何做?继承Platform,添加新增的策略函数即可
import { Platform } from "electron-proxy";
class CustomerPlatform<T extends IBusinessProxy> extends Platform<T> {

}

export default CustomerPlatform;