Add websocket support
This commit is contained in:
16 files changed
+1042
-168
No files matched your search
@@ -1,4 +1,3 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
@@ -14,14 +13,12 @@ class SettingsScreen extends ConsumerStatefulWidget {
|
||||
|
||||
class _SettingsScreenState extends ConsumerState<SettingsScreen> {
|
||||
late TextEditingController _hostController;
|
||||
late double _pollInterval;
|
||||
bool _startWithSession = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_hostController = TextEditingController(text: ref.read(deviceHostProvider));
|
||||
_pollInterval = ref.read(pollIntervalProvider);
|
||||
_loadAutostart();
|
||||
}
|
||||
|
||||
@@ -41,14 +38,11 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
|
||||
if (host.isEmpty) return;
|
||||
|
||||
ref.read(deviceHostProvider.notifier).state = host;
|
||||
ref.read(pollIntervalProvider.notifier).state = _pollInterval;
|
||||
ref.read(pollingProvider.notifier).restart();
|
||||
|
||||
await AutostartService.setEnabled(_startWithSession);
|
||||
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString('busylight_host', host);
|
||||
await prefs.setDouble('busylight_poll_interval', _pollInterval);
|
||||
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
@@ -58,12 +52,6 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
String _intervalLabel(double seconds) {
|
||||
if (seconds == 0.0) return 'Off';
|
||||
if (seconds < 2.0) return '${seconds}s';
|
||||
return '${ (seconds)}s';
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@@ -103,52 +91,6 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
|
||||
// ── Polling interval ────────────────────────────────────────────
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text('Status polling',
|
||||
style: TextStyle(color: Colors.grey.shade300, fontSize: 13, fontWeight: FontWeight.w600)),
|
||||
Text(
|
||||
_intervalLabel(_pollInterval),
|
||||
style: const TextStyle(color: Colors.amber, fontSize: 13, fontWeight: FontWeight.w600),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
SliderTheme(
|
||||
data: SliderTheme.of(context).copyWith(
|
||||
activeTrackColor: Colors.amber,
|
||||
thumbColor: Colors.amber,
|
||||
inactiveTrackColor: Colors.grey.shade800,
|
||||
overlayColor: Colors.amber.withOpacity(0.2),
|
||||
),
|
||||
child: Slider(
|
||||
value: _pollInterval,
|
||||
min: 0.0,
|
||||
max: 2.0,
|
||||
divisions: 4,
|
||||
onChanged: (v) => setState(() => _pollInterval = v),
|
||||
),
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text('Off', style: TextStyle(color: Colors.grey.shade600, fontSize: 11)),
|
||||
Text('0.5s', style: TextStyle(color: Colors.grey.shade600, fontSize: 11)),
|
||||
Text('1s', style: TextStyle(color: Colors.grey.shade600, fontSize: 11)),
|
||||
Text('1.5s', style: TextStyle(color: Colors.grey.shade600, fontSize: 11)),
|
||||
Text('2s', style: TextStyle(color: Colors.grey.shade600, fontSize: 11)),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
_pollInterval == 0
|
||||
? 'Polling is disabled. Status will only refresh manually.'
|
||||
: 'Status is pulled from the device every $_pollInterval seconds.',
|
||||
style: TextStyle(color: Colors.grey.shade600, fontSize: 12),
|
||||
),
|
||||
|
||||
// ── Start with session (macOS + Windows only) ───────────────────
|
||||
if (AutostartService.isSupported) ...[
|
||||
const SizedBox(height: 32),
|
||||
|
||||
Reference in new issue
Block a user