Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4118,7 +4118,7 @@ declare module "socket:window/hotkey" {
* @ignore
* @param {import('../internal/events.js').HotKeyEvent} event
*/
onHotKey(event: import('../internal/events.js').HotKeyEvent): void;
onHotKey(event: import('../internal/events.js').HotKeyEvent): boolean;
/**
* The number of `Binding` instances in the mapping.
* @type {number}
Expand Down
17 changes: 14 additions & 3 deletions api/window/hotkey.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global Event, EventTarget, ErrorEvent, reportError */
/* global Event, EventTarget, ErrorEvent */
import { HotKeyEvent } from '../internal/events.js'
import hooks from '../hooks.js'
import ipc from '../ipc.js'
Expand Down Expand Up @@ -57,6 +57,8 @@ export class Bindings extends EventTarget {
*/
#onhotkey = null

#clock = globalThis.performance.now()

/**
* `Bindings` class constructor.
* @ignore
Expand All @@ -74,12 +76,15 @@ export class Bindings extends EventTarget {
if (!/android|ios/.test(os.platform())) {
sourceEventTarget.addEventListener('hotkey', this.onHotKey)
sourceEventTarget.addEventListener('hotkey', (event) => {
this.#channel.postMessage(event.data)
const { id } = event.data ?? {}
if (!this.has(id)) {
this.#channel.postMessage(event.data)
}
})
}

gc.ref(this)
this.init().catch(reportError)
this.init()
}

/**
Expand Down Expand Up @@ -162,6 +167,12 @@ export class Bindings extends EventTarget {
const { id } = event.data ?? {}
const binding = this.get(id)

if (event.timeStamp < this.#clock) {
return false
}

this.#clock = event.timeStamp

if (binding) {
binding.dispatchEvent(new HotKeyEvent('hotkey', event.data))
}
Expand Down