()
| 19 | } |
| 20 | |
| 21 | function loadNativeModifiersHelper(): NativeModifiersHelper | undefined { |
| 22 | if (nativeModifiersHelper !== undefined) return nativeModifiersHelper ?? undefined; |
| 23 | nativeModifiersHelper = null; |
| 24 | if (process.platform !== "darwin") return undefined; |
| 25 | const arch = process.arch; |
| 26 | if (arch !== "x64" && arch !== "arm64") return undefined; |
| 27 | |
| 28 | const moduleDir = path.dirname(fileURLToPath(import.meta.url)); |
| 29 | const nativePath = path.join("native", "darwin", "prebuilds", `darwin-${arch}`, "darwin-modifiers.node"); |
| 30 | const candidates = [ |
| 31 | path.join(moduleDir, "..", nativePath), |
| 32 | path.join(moduleDir, nativePath), |
| 33 | path.join(path.dirname(process.execPath), nativePath), |
| 34 | ]; |
| 35 | |
| 36 | for (const modulePath of candidates) { |
| 37 | try { |
| 38 | const helper = cjsRequire(modulePath) as unknown; |
| 39 | if (isNativeModifiersHelper(helper)) { |
| 40 | nativeModifiersHelper = helper; |
| 41 | return helper; |
| 42 | } |
| 43 | } catch { |
| 44 | // Try the next possible packaging location. |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | return undefined; |
| 49 | } |
| 50 | |
| 51 | export function isNativeModifierPressed(key: ModifierKey): boolean { |
| 52 | const helper = loadNativeModifiersHelper(); |
no test coverage detected