Skip to content

Commit

Permalink
fix: debounce mdns restart
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Aug 9, 2024
1 parent 6b9b4a1 commit c52f8a0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions satellite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"@napi-rs/canvas": "^0.1.53",
"@xencelabs-quick-keys/node": "^1.0.0",
"conf": "^13.0.1",
"debounce-fn": "^6.0.0",
"electron-about-window": "^1.15.2",
"electron-store": "^10.0.0",
"eventemitter3": "^5.0.1",
Expand Down
23 changes: 16 additions & 7 deletions satellite/src/mdnsAnnouncer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type Conf from 'conf'
import type { SatelliteConfig } from './config.js'
import { Bonjour, Service } from '@julusian/bonjour-service'
import os from 'os'
import debounceFn from 'debounce-fn'

export class MdnsAnnouncer {
readonly #appConfig: Conf<SatelliteConfig>
Expand All @@ -12,15 +13,23 @@ export class MdnsAnnouncer {
constructor(appConfig: Conf<SatelliteConfig>) {
this.#appConfig = appConfig

this.#appConfig.onDidChange('mdnsEnabled', () => this.restart())
this.#appConfig.onDidChange('restPort', () => this.restart())
this.#appConfig.onDidChange('restEnabled', () => this.restart())
this.#appConfig.onDidChange('mdnsEnabled', () => this.#restart())
this.#appConfig.onDidChange('installationName', () => this.#restart())
this.#appConfig.onDidChange('restPort', () => this.#restart())
this.#appConfig.onDidChange('restEnabled', () => this.#restart())
}

restart() {
this.stop()
this.start()
}
readonly #restart = debounceFn(
() => {
this.stop()
this.start()
},
{
wait: 50,
before: false,
after: true,
},
)

start() {
if (!this.#appConfig.get('mdnsEnabled')) return
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6426,6 +6426,7 @@ __metadata:
"@xencelabs-quick-keys/node": "npm:^1.0.0"
conf: "npm:^13.0.1"
cross-env: "npm:^7.0.3"
debounce-fn: "npm:^6.0.0"
electron: "npm:31.2.1"
electron-about-window: "npm:^1.15.2"
electron-builder: "npm:^24.13.3"
Expand Down

0 comments on commit c52f8a0

Please sign in to comment.