<commit_before><commit_msg>feat(app): add manager service to access backend<commit_after>import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs';
import { DPICapabilities } from 'src/lib/ts/devices/dpi';
import {
  Color,
  LEDCapabilities,
  LEDModes,
  LEDZones,
} from 'src/lib/ts/devices/led';

import { HIDDeviceConfigurator } from 'src/lib/ts/devices/configurator';
import manager from 'src/lib/ts/manager';

@Injectable({
  providedIn: 'root',
})
export class ManagerService {
  deviceSubject = new BehaviorSubject<HIDDeviceConfigurator | undefined>(
    undefined,
  );

  async connectToDevice(): Promise<void> {
    try {
      const device = await manager.connect();
      this.deviceSubject.next(device);
    } catch (error) {
      console.error(`Error connecting to device:`, error);
    }
  }

  get device$(): Observable<HIDDeviceConfigurator | undefined> {
    return this.deviceSubject.asObservable();
  }

  get device(): HIDDeviceConfigurator | undefined {
    return this.deviceSubject.getValue();
  }

  get ledCapabilities(): LEDCapabilities | undefined {
    return this.device?.ledCapabilities?.();
  }

  setLed(color: Color, zone: LEDZones, mode?: LEDModes): void {
    this.device?.setLed?.(color, zone, mode);
  }

  get dpiCapabilities(): DPICapabilities | undefined {
    return this.device?.dpiCapabilities?.();
  }

  setDpiLevel(level: number, cpi: number): void {
    this.device?.setDPILevel?.(level, cpi);
  }
}
{'fraction_non_alphanumeric': 0.13449899125756556, 'fraction_numerical': 0.0, 'mean_word_length': 4.2027972027972025, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2330524', 'n_tokens_mistral': 474, 'n_tokens_neox': 464, 'n_words': 102}