Skip to content

Mrminfive/electron-screenshoter

Repository files navigation

electron-screenshoter

electron 截图插件

types electron platform download

Usage

安装

yarn add electron-screenshoter

使用方式

主进程

const { initMain, close } = require('electron-screenshoter');

app.on('ready', () => {
  const win = new BrowserWindow();
  initMain(win.webContents);

  // 新增快捷键取消截图
  Menu.setApplicationMenu(
    Menu.buildFromTemplate([
      {
        label: '编辑',
        submenu: [
          {
            accelerator: 'Esc',
            label: '取消截图',
            click: close
          }
        ]
      }
    ])
  );
});

注:传入 intMain 方法的参数为实际调用截图功能的渲染进程

渲染进程

const { screenshot } = require('electron-screenshoter');

screenshot().then(({ base64 }) => {
  console.log('截图 base64 地址: ', base64);
});

Notice

windows 系统下使用 nircmd 程序捕捉桌面帧,为保证一致性,插件已将该可执行文件集成至项目中,打包时需要在 package.json 中增加以下配置:

{
  ...
  "build": {
    ...
    "asarUnpack": [
      "*.exe"
    ],
    ...
  }
  ...
}

详细参见:electron-builder-doc: Overridable per Platform Options

About

📷 a electron screenshot util

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published