@alwith/module-gamepad

中文文档
0.6.1发布于 2026/11/09SEE LICENSE IN LICENSETypeScriptES Module构建来源已验证近 30 天下载 1748

Reusable controller mapping engine and React interface. This is a private release candidate.

原始使用文档

Gamepad module

Reusable controller mapping engine and React interface. This is a private release candidate.

Exports: core client, React panel/provider, Tauri host and transport, generated plugin commands (./commands), generated native contract, locales and assets. The Tauri plugin is alwith-gamepad on crates.io; this package carries the native libraries. Import styles.css once and explicitly register gamepadResources in the host i18n instance. Wrap GamepadPanel in GamepadProvider with native transport, permissions, capture lifecycle, and error reporting.

Cargo consumers depend on alwith-gamepad by version; the application's stager takes the native library from this package.

The native service owns profiles, revisions, startup/shutdown, and input injection. Selecting a controller automatically activates its saved profile. All controllers retain the shared mapping policy. System injection ownership is exclusive among hosts that implement the shared lock. An unmodified Desktop does not yet participate in this lock.

Build and tests use Bun and Cargo. Run bun run build, bun run test, and bun run test:rust from this directory. Native smoke tests marked ignored require explicit execution. Physical device coverage and Windows validation remain required before a stable release. This package has not been published.

Host integration

import { createGamepadClient } from "@alwith/module-gamepad"
import { createTauriGamepadHost } from "@alwith/module-gamepad/tauri"
import { GamepadPanel, GamepadProvider } from "@alwith/module-gamepad/react"
import { gamepadResources } from "@alwith/module-gamepad/locales"
import "@alwith/module-gamepad/styles.css"

The root entry has no React, DOM or Tauri imports and does not start native services. createTauriGamepadHost({ platform, onError, applications, generateConfig }) builds a complete host from the plugin commands; supply applications from @alwith/module-installed-apps with createInstalledApplications(onError) from @alwith/module-gamepad/installed-apps (that package is an optional peer, needed only for this entry):

import { createTauriGamepadHost } from "@alwith/module-gamepad/tauri"
import { createInstalledApplications } from "@alwith/module-gamepad/installed-apps"

const host = createTauriGamepadHost({ platform, onError, applications: createInstalledApplications(onError) })

A headless consumer can provide GamepadTransport directly. Register the desired entries from gamepadResources under the gamepad namespace (13 languages). The panel uses the host's semantic color variables. Portals carry their own style scope.

[dependencies]
alwith-gamepad = "0.6"
.plugin(alwith_gamepad::init(Config { development_directory, ..Default::default() }))
// in the application's ordered shutdown
alwith_gamepad::shutdown(app)?;

Config takes the debug-build development_directory of the native libraries and overrides the profile path (default gamepad/profiles.json in app data) and the shared per-user injection-lock path. legacy_profile_path names ALwith Desktop's gamepad-devices.json ({ "<device name>": Config }, grip color inside each config): when the profile store does not exist yet, every device is imported as the profile of that name at revision 1 with its color, none active; the legacy file is left untouched and an invalid entry fails the start with its device name. Rust hosts outside init use GamepadService::with_legacy_profiles. ALwith U always stored profiles at the default path in this format, so it passes no legacy path. The default permission set alwith-gamepad:default covers the panel; grant it only to trusted application windows in the app's capabilities. Profile saves require the expected revision. savedRevision and appliedRevision are distinct: persistence while stopped does not imply injection is active. Selecting a device automatically loads and activates its profile; subsequent edits are saved and applied immediately. Controllers share that mapping but own separate layer, axis, held-action and repeat states.

The plugin owns key-capture policy: it suspends injection, removes the application menu where needed, and restores both on stop, failure, focus loss, window destruction and shutdown. Pending starts are cancelled on focus loss. Engine events and captured keys reach only the webviews that subscribed through their channels. A destroyed window's virtual controller is detached natively; stopping application-owned AI tasks stays with the host. Native global capture is implemented for macOS and Windows; other hosts use DOM capture with injection suspended. AI generation is optional, receives an AbortSignal, and never imports a model provider. The ./ai entry provides prompt construction and validated full/incremental JSON parsing.

The panel retains a 320px device column and fixed-size controller diagram. Use a dedicated window at least 1250 by 750 pixels. Semantic host colors theme the interface and its portals.

Validation and release status

macOS arm64 verification includes unit tests, profile persistence/conflict tests, client subscription races, a React stale-save test, and explicit native virtual-controller tests with system output disabled. Physical controllers, rumble hardware, permission UI, global key interception, and Windows execution still require manual validation. The package remains private and must not be published as a stable release on this evidence.

版本与发布记录

@alwith/module-gamepad 共发布 9 个版本,首次发布于 2026/10/22;过去 12 个月发布了 9 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.6.1latest2026/11/091 天前
0.6.02026/11/036 天前
0.5.22026/11/037 天前
0.5.02026/10/3010 天前
0.1.0-rc.8next2026/10/2911 天前
0.1.0-rc.72026/10/2515 天前

关于 @alwith/module-gamepad 的常见问题

@alwith/module-gamepad 是什么?

Reusable controller mapping engine and React interface. This is a private release candidate.

如何安装 @alwith/module-gamepad?

在项目目录运行 npm install @alwith/module-gamepad,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react-i18next(^18.0.0)、@tauri-apps/api(^3.0.0-alpha.3)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@alwith/module-gamepad 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@alwith/module-gamepad 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@alwith/module-gamepad 可以商用吗?

@alwith/module-gamepad 使用 SEE LICENSE IN LICENSE 许可。许可条款写在包内的独立文件中,请阅读该文件确认可否商用。以上为概括,不构成法律意见,请以许可原文为准。

@alwith/module-gamepad 的下载量有多少?

根据 npm 官方下载统计,@alwith/module-gamepad 在 2026/10/06 – 2026/11/04 这 30 天内被下载 1,748 次,日均约 58 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@alwith/module-gamepad 还在维护吗?

最新版本 0.6.1 发布于 2026/11/09(1 天前);至今共发布 9 个版本,其中过去 12 个月发布了 9 个;首次发布于 2026/10/22。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。