Skip to content

Commit

Permalink
Fix crash when disabling lighthouse control for users without bluetoo…
Browse files Browse the repository at this point in the history
…th adapters
  • Loading branch information
Raphiiko committed Dec 23, 2023
1 parent 383a096 commit f62783b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed
- Crash for some users without bluetooth adapters when disabling lighthouse control.

## [1.11.2]

### Added
Expand Down
17 changes: 12 additions & 5 deletions src-core/src/lighthouse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@ pub async fn init() {
pub async fn start_scan(duration: Duration) {
// Get the adapter
let adapter_guard = ADAPTER.lock().await;
let adapter = adapter_guard.as_ref().unwrap();
let adapter = match adapter_guard.as_ref() {
Some(adapter) => adapter,
None => {
// No bluetooth adapter was found, we stop here
return;
}
};
// Wait until the adapter is available
if let Err(e) = adapter.wait_available().await {
warn!(
Expand Down Expand Up @@ -381,10 +387,11 @@ async fn reset() {
// Disconnect all devices
{
let adapter_guard = ADAPTER.lock().await;
let adapter = adapter_guard.as_ref().unwrap();
let devices_guard = LIGHTHOUSE_DEVICES.lock().await;
for device in devices_guard.iter() {
let _ = adapter.disconnect_device(&device).await;
if let Some(adapter) = adapter_guard.as_ref() {
let devices_guard = LIGHTHOUSE_DEVICES.lock().await;
for device in devices_guard.iter() {
let _ = adapter.disconnect_device(&device).await;
}
}
}
// Clear all known devices
Expand Down
12 changes: 6 additions & 6 deletions src-ui/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { routeAnimations } from './app-routing.module';
import { TranslateService } from '@ngx-translate/core';
import { AppSettingsService } from './services/app-settings.service';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { distinctUntilChanged, map, skip } from 'rxjs';
import { debounceTime, distinctUntilChanged, map, skip, tap } from 'rxjs';
import { fade } from './utils/animations';
import { TelemetryService } from './services/telemetry.service';

Expand All @@ -27,12 +27,12 @@ export class AppComponent implements OnInit {
.pipe(
takeUntilDestroyed(),
map((settings) => settings.userLanguage),
distinctUntilChanged()
distinctUntilChanged(),
tap((userLanguage) => translate.use(userLanguage)),
debounceTime(10000),
tap((userLanguage) => this.telemetry.trackEvent('use_language', { language: userLanguage }))
)
.subscribe((userLanguage) => {
translate.use(userLanguage);
this.telemetry.trackEvent('use_language', { language: userLanguage });
});
.subscribe();
// Snowverlay
this.settings.settings
.pipe(
Expand Down

0 comments on commit f62783b

Please sign in to comment.