()
| 347 | } |
| 348 | |
| 349 | watchUPnPPortsChange () { |
| 350 | const { systemConfig } = this.configManager |
| 351 | const watchKeys = ['listen-port', 'dht-listen-port'] |
| 352 | |
| 353 | watchKeys.forEach((key) => { |
| 354 | this.configListeners[key] = systemConfig.onDidChange(key, async (newValue, oldValue) => { |
| 355 | logger.info('[Motrix] detected port change event:', key, newValue, oldValue) |
| 356 | const enable = this.configManager.getUserConfig('enable-upnp') |
| 357 | if (!enable) { |
| 358 | return |
| 359 | } |
| 360 | |
| 361 | const promises = [ |
| 362 | this.upnp.unmap(oldValue), |
| 363 | this.upnp.map(newValue) |
| 364 | ] |
| 365 | try { |
| 366 | await Promise.allSettled(promises) |
| 367 | } catch (e) { |
| 368 | logger.info('[Motrix] change UPnP port mapping failed:', e) |
| 369 | } |
| 370 | }) |
| 371 | }) |
| 372 | } |
| 373 | |
| 374 | watchUPnPEnabledChange () { |
| 375 | const { userConfig } = this.configManager |
no test coverage detected