diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 3e84979..0cfc0d3 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -2,6 +2,7 @@ name: Checks on: push: + tags-ignore: '*' paths: - 'src/**' - 'tsconfig.json' diff --git a/README.md b/README.md index e5dcac0..13799da 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,8 @@ interface BadgeAPI { syncConnection() assertConnected() - hasConnectedBadge + set onConnectionLost + get hasConnectedBadge transaction(cmd, payload, timeout) diff --git a/package.json b/package.json index 822ffc5..faeed42 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@badge.team/badge-webusb", - "version": "1.0.1", + "version": "1.0.2", "description": "Web API for the Badge.team MCH2022 badge", "keywords": [ "USB", "WebUSB", diff --git a/src/badge-api.ts b/src/badge-api.ts index 77736a9..cb5bd2e 100644 --- a/src/badge-api.ts +++ b/src/badge-api.ts @@ -19,6 +19,8 @@ export class BadgeAPI { async connect() { this.badge = await BadgeUSB.connect(); this.badge.onConnectionLost = () => delete this.badge; + + if (this._onConnectionLost) this._onConnectionLost(); } async disconnect(reset = false) { @@ -38,6 +40,12 @@ export class BadgeAPI { badge.assertConnected(); } + set onConnectionLost(callback: () => void) { + this._onConnectionLost = callback; + } + + private _onConnectionLost?: () => void; + async syncConnection(): Promise { try { this.assertConnected(this.badge);