diff --git a/lib/bluetooth/devices/link/link_device.dart b/lib/bluetooth/devices/link/link_device.dart index be3ea4f..173fdd7 100644 --- a/lib/bluetooth/devices/link/link_device.dart +++ b/lib/bluetooth/devices/link/link_device.dart @@ -1,7 +1,6 @@ import 'package:flutter/material.dart'; import 'package:swift_control/bluetooth/devices/base_device.dart'; import 'package:swift_control/main.dart'; -import 'package:swift_control/widgets/loading_widget.dart'; import 'package:swift_control/widgets/small_progress_indicator.dart'; class LinkDevice extends BaseDevice { @@ -26,47 +25,37 @@ class LinkDevice extends BaseDevice { return ValueListenableBuilder( valueListenable: whooshLink.isConnected, builder: (context, isConnected, _) { - return Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text('MyWhoosh Link: ${isConnected ? 'Connected' : 'Not connected'}'), - Row( - children: [ - if (!isConnected) - LoadingWidget( - futureCallback: () => connection.startMyWhooshServer(), - renderChild: (isLoading, tap) => ValueListenableBuilder( - valueListenable: whooshLink.isConnected, - builder: (c, isConnected, _) => TextButton( - onPressed: !isConnected ? tap : null, - child: isLoading || (!isConnected && whooshLink.isStarted.value) - ? SmallProgressIndicator() - : Text('Connect'), - ), + return StatefulBuilder( + builder: (context, setState) { + return SwitchListTile.adaptive( + contentPadding: EdgeInsets.zero, + value: settings.getMyWhooshLinkEnabled(), + onChanged: (value) { + settings.setMyWhooshLinkEnabled(value); + if (!value) { + disconnect(); + connection.disconnect(this, forget: true); + } else if (value) { + connection.startMyWhooshServer(); + } + setState(() {}); + }, + title: Text('Enable MyWhoosh Link'), + subtitle: Row( + spacing: 12, + children: [ + if (!settings.getMyWhooshLinkEnabled()) + Text('Disabled') + else ...[ + Text( + isConnected ? "Connected" : "Looking for connection...", ), - ), - - PopupMenuButton( - itemBuilder: (c) => [ - if (isConnected) - PopupMenuItem( - child: Text('Disconnect'), - onTap: () { - connection.disconnect(this, forget: true); - }, - ) - else - PopupMenuItem( - child: Text('Stop'), - onTap: () { - whooshLink.stopServer(); - }, - ), + if (!isConnected) SmallProgressIndicator(), ], - ), - ], - ), - ], + ], + ), + ); + }, ); }, ); diff --git a/lib/pages/device.dart b/lib/pages/device.dart index e2069f1..3c4ca4b 100644 --- a/lib/pages/device.dart +++ b/lib/pages/device.dart @@ -227,7 +227,7 @@ class _DevicePageState extends State with WidgetsBindingObserver { if (connection.remoteDevices.isNotEmpty || actionHandler is RemoteActions || - whooshLink.isStarted.value) + !whooshLink.isConnected.value) Container( margin: const EdgeInsets.only(bottom: 8.0), width: double.infinity, @@ -250,7 +250,7 @@ class _DevicePageState extends State with WidgetsBindingObserver { (device) => device.showInformation(context), ), - if (whooshLink.isStarted.value) LinkDevice('').showInformation(context), + if (!whooshLink.isConnected.value) LinkDevice('').showInformation(context), if (actionHandler is RemoteActions) Row( diff --git a/lib/utils/settings/settings.dart b/lib/utils/settings/settings.dart index 54afc29..cb7d358 100644 --- a/lib/utils/settings/settings.dart +++ b/lib/utils/settings/settings.dart @@ -202,4 +202,12 @@ class Settings { return migratedData; } + + bool getMyWhooshLinkEnabled() { + return prefs.getBool('mywhoosh_link_enabled') ?? true; + } + + Future setMyWhooshLinkEnabled(bool enabled) async { + await prefs.setBool('mywhoosh_link_enabled', enabled); + } }