improve UI for MyWhoosh Link

This commit is contained in:
Jonas Bark
2025-10-27 17:14:38 +01:00
parent 3718a126ac
commit 23aafcd7bc
3 changed files with 39 additions and 42 deletions

View File

@@ -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(),
],
),
],
),
],
],
),
);
},
);
},
);

View File

@@ -227,7 +227,7 @@ class _DevicePageState extends State<DevicePage> 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<DevicePage> 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(

View File

@@ -202,4 +202,12 @@ class Settings {
return migratedData;
}
bool getMyWhooshLinkEnabled() {
return prefs.getBool('mywhoosh_link_enabled') ?? true;
}
Future<void> setMyWhooshLinkEnabled(bool enabled) async {
await prefs.setBool('mywhoosh_link_enabled', enabled);
}
}