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 🙏

© 2026 – Pkg Stats / Ryan Hefner

usb-electron-det

v1.0.2

Published

USB 设备检测 - Electron + Vue 3 + Vite;适用linxu,windows

Downloads

21

Readme

usb-electron-det

USB 设备检测 - Electron + Vue 3 + Vite 示例应用;同时可打包为本地库供其他 Node.js / Electron 项目引用。

作为本地库使用(仅引入库,不引入整个项目)

其他项目可以只引用 USB 检测库,而不会引入本仓库的 Electron 应用、Vue 前端等。推荐使用打包后的 tgz 安装,这样目标项目的 node_modules 里只会出现库产物(dist-lib),不会包含本仓库源码。

1. 在本仓库中打包“仅库”的 tgz:

cd /path/to/usb-det
npm run pack:lib

会先构建库并生成 usb-detection-1.0.0.tgz(版本号以 package.json 为准)。该 tgz 内仅含 dist-lib/ 与 package.json,不含 electron、src、vite 等。

2. 在其它项目中只安装该库:

cd /path/to/your-project
npm install /path/to/usb-det/usb-detection-1.0.0.tgz
# 或
yarn add /path/to/usb-det/usb-detection-1.0.0.tgz
# 或
pnpm add /path/to/usb-det/usb-detection-1.0.0.tgz

安装后,node_modules/usb-detection 内只有库文件,不会带入整个本仓库。

3. 在代码中引用:

// ESM
import { UsbDetector, type UsbDeviceInfo, type UsbDriveInfo } from 'usb-detection'

const detector = new UsbDetector({ pollInterval: 2000, detectDrives: true })
detector.on('change', (e) => console.log('设备变化', e))
detector.onDriveChange((e) => console.log('U 盘变化', e))
detector.start()

// 一次性获取
const devices = await detector.getDevices()
const drives = await detector.getUsbDrives()

导出 API: UsbDetector、UsbDeviceInfo、UsbDriveInfo、DeviceChangeEvent、UsbDriveChangeEvent、UsbDetectorOptions 等(见 lib/index.ts)。

可选(不推荐): 若使用 npm install file:../usb-det 或 npm link usb-detection,虽然运行时只会加载库入口,但 node_modules 中会包含本仓库完整目录。若希望仅引入库,请按上述步骤使用 npm run pack:lib 生成的 tgz 安装。

软件架构

  • electron/main/usb-detector.ts:USB 检测核心(无 Electron 依赖,可单独作为库)
  • electron/main/usb-handler.ts:Electron IPC 与导出到 U 盘
  • lib/index.ts:库入口,供外部项目引用

安装教程(运行本应用)

  1. 克隆仓库后执行 npm install
  2. 开发:npm run dev
  3. 打包:npm run build 或 npm run build:win / npm run build:linux

使用说明

  1. 运行应用后可在界面查看 USB 设备与 U 盘列表
  2. 支持热插拔检测与导出表格到 U 盘

参与贡献

  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request

特技

  1. 使用 Readme_XXX.md 来支持不同的语言,例如 Readme_en.md, Readme_zh.md
  2. Gitee 官方博客 blog.gitee.com
  3. 你可以 https://gitee.com/explore 这个地址来了解 Gitee 上的优秀开源项目
  4. GVP 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
  5. Gitee 官方提供的使用手册 https://gitee.com/help
  6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 https://gitee.com/gitee-stars/