diff --git a/package.json b/package.json index 63528a9..f009961 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "dependencies": { "@jitsi/robotjs": "^0.6.13", "auto-launch": "^5.0.6", + "async": "^3.2.5", "electron-json-storage": "^4.6.0", "lodash": "^4.17.21", "node-hid": "^3.0.0", @@ -45,6 +46,7 @@ "node-mac-permissions": "^2.3.0" }, "devDependencies": { + "@types/async": "^3.2.24", "@types/auto-launch": "^5.0.5", "@types/electron-json-storage": "^4.5.4", "@types/lodash": "^4.14.202", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 499a2d8..0dfeeb6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,9 @@ dependencies: '@jitsi/robotjs': specifier: ^0.6.13 version: 0.6.13 + async: + specifier: ^3.2.5 + version: 3.2.5 auto-launch: specifier: ^5.0.6 version: 5.0.6 @@ -37,6 +40,9 @@ dependencies: version: 3.11.0 devDependencies: + '@types/async': + specifier: ^3.2.24 + version: 3.2.24 '@types/auto-launch': specifier: ^5.0.5 version: 5.0.5 @@ -226,6 +232,10 @@ packages: engines: {node: '>= 10'} dev: true + /@types/async@3.2.24: + resolution: {integrity: sha512-8iHVLHsCCOBKjCF2KwFe0p9Z3rfM9mL+sSP8btyR5vTjJRAqpBYD28/ZLgXPf0pjG1VxOvtCV/BgXkQbpSe8Hw==} + dev: true + /@types/auto-launch@5.0.5: resolution: {integrity: sha512-/nGvQZSzM/pvCMCh4Gt2kIeiUmOP/cKGJbjlInI+A+5MoV/7XmT56DJ6EU8bqc3+ItxEe4UC2GVspmPzcCc8cg==} dev: true diff --git a/src/PointerEngine.ts b/src/PointerEngine.ts index fc6e365..4359df9 100644 --- a/src/PointerEngine.ts +++ b/src/PointerEngine.ts @@ -37,8 +37,8 @@ export class PointerDevice extends BaseObserver { this.resource.on('error', error_cb); this.resource.on('data', data_cb); this.dispose = () => { - this.resource.off('error', error_cb); - this.resource.off('data', data_cb); + this.resource?.off('error', error_cb); + this.resource?.off('data', data_cb); this.dispose = null; }; } diff --git a/src/main.ts b/src/main.ts index 0d5d441..7a9fbde 100644 --- a/src/main.ts +++ b/src/main.ts @@ -8,6 +8,7 @@ import AutoLaunch from 'auto-launch'; import { createLogger, transports } from 'winston'; import { buildLoadingMenu, buildMenu } from './menu'; import { waitForAllPermissions } from './permissions'; +import {} from 'async'; require('source-map-support').install(); @@ -69,12 +70,7 @@ app.on('ready', async () => { setupMovement(); }; - pointerEngine.registerListener({ - devicesChanged: () => { - buildMenuWrapped(); - setupMovement(); - } - }); + configEngine.init(); // add a startup delay const delay = (configEngine.config.startupDelay || 0) * 1_000; @@ -85,10 +81,16 @@ app.on('ready', async () => { // might want startup delay setTimeout(() => { - configEngine.init(); pointerEngine.init(); displayEngine.init(); + pointerEngine.registerListener({ + devicesChanged: () => { + buildMenuWrapped(); + setupMovement(); + } + }); + buildMenuWrapped(); setupMovement(); }, delay);