<commit_before>import 'dart:async';
import 'package:audio_service/audio_service.dart';
import 'package:flutter/material.dart';
import 'package:polaris/background/entrypoint.dart' as service;
import 'package:polaris/foreground/authentication.dart' as authentication;
import 'package:polaris/foreground/connection.dart' as connection;
import 'package:polaris/shared/host.dart' as host;
import 'package:polaris/shared/token.dart' as token;
import 'package:polaris/foreground/ui/strings.dart';

class Manager extends ChangeNotifier {
  final connection.Manager connectionManager;
  final authentication.Manager authenticationManager;
  final host.Manager hostManager;
  final token.Manager tokenManager;
  final Launcher launcher;
  bool isServiceRunning = false;

  Manager({
    @required this.connectionManager,
    @required this.authenticationManager,
    @required this.hostManager,
    @required this.tokenManager,
    @required this.launcher,
  })  : assert(connectionManager != null),
        assert(authenticationManager != null),
        assert(hostManager != null),
        assert(tokenManager != null),
        assert(launcher != null) {
    connectionManager.addListener(_updateService);
    authenticationManager.addListener(_updateService);
    _updateService();
  }

  Future<void> _updateService() async {
    // TODO this will try to kill service when UI reboots but service is still alive!
    final bool canRunService = connectionManager.state == connection.State.connected &&
        authenticationManager.state == authentication.State.authenticated;
    if (canRunService) {
      await launcher.start();
      isServiceRunning = true;
      notifyListeners();
    } else {
      isServiceRunning = false;<commit_msg>Allow client restarts without interrupting service<commit_after>import 'dart:async';
import 'package:audio_service/audio_service.dart';
import 'package:flutter/material.dart';
import 'package:polaris/background/entrypoint.dart' as service;
import 'package:polaris/foreground/authentication.dart' as authentication;
import 'package:polaris/foreground/connection.dart' as connection;
import 'package:polaris/shared/host.dart' as host;
import 'package:polaris/shared/token.dart' as token;
import 'package:polaris/foreground/ui/strings.dart';

class Manager extends ChangeNotifier {
  final connection.Manager connectionManager;
  final authentication.Manager authenticationManager;
  final host.Manager hostManager;
  final token.Manager tokenManager;
  final Launcher launcher;
  bool isServiceRunning = false;

  Manager({
    @required this.connectionManager,
    @required this.authenticationManager,
    @required this.hostManager,
    @required this.tokenManager,
    @required this.launcher,
  })  : assert(connectionManager != null),
        assert(authenticationManager != null),
        assert(hostManager != null),
        assert(tokenManager != null),
        assert(launcher != null) {
    connectionManager.addListener(_updateService);
    authenticationManager.addListener(_updateService);
    _updateService();
  }

  Future<void> _updateService() async {
    final bool isConnected = connectionManager.state == connection.State.connected &&
        authenticationManager.state == authentication.State.authenticated;
    final bool isDisconnected = connectionManager.state == connection.State.disconnected ||
        authenticationManager.state == authentication.State.unauthenticated;
    final bool isReconnecting = connectionManager.state == connection.State.reconnecting ||
        authenticationManager.state == authentication.State.reauthenticating;
    if (isConnected) {
      await launcher.start();
      isServiceRunning = true;
      notifyListeners();
    } else if (isDisconnected && !isReconnecting) {
      isServiceRunning = false;
{'fraction_non_alphanumeric': 0.09691861996312878, 'fraction_numerical': 0.0, 'mean_word_length': 4.719879518072289, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5366555', 'n_tokens_mistral': 1001, 'n_tokens_neox': 994, 'n_words': 224}