From 9395e8801e8f3c332269927439fcbf8f2752d36a Mon Sep 17 00:00:00 2001 From: Daniel Ponte Date: Mon, 21 Oct 2024 21:49:43 -0400 Subject: [PATCH] wip --- lib/controller/stillbox.dart | 15 +++++++++++++-- lib/views/login.dart | 5 +++++ protobuf/stillbox.proto | 5 +++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/controller/stillbox.dart b/lib/controller/stillbox.dart index 50c8b4b..fb1e09d 100644 --- a/lib/controller/stillbox.dart +++ b/lib/controller/stillbox.dart @@ -1,6 +1,9 @@ import 'dart:async'; +import 'dart:io'; import 'package:flutter/foundation.dart'; import 'package:http/http.dart' as http; +import 'package:just_audio/just_audio.dart'; +import 'package:web_socket_channel/web_socket_channel.dart'; import '../pb/stillbox.pb.dart'; import 'stillbox_none.dart' if (dart.library.io) 'stillbox_io.dart' @@ -76,8 +79,11 @@ class Stillbox extends ChangeNotifier { if (!kIsWeb && token != null) { storage.setKey('token', token); } - await connect(); - return true; + try { + await connect(); + } on WebSocketChannelException catch(e) { + return false; + } } return false; } @@ -87,6 +93,11 @@ class Stillbox extends ChangeNotifier { return; } channel.connect(_wsUri); + try { + await channel.channel?.ready; + } on WebSocketChannelException catch(e) { + _handleError(e); + } channel.stream.listen((event) => _handleData(event), onDone: () { connected = false; diff --git a/lib/views/login.dart b/lib/views/login.dart index 7495cea..92bee5e 100644 --- a/lib/views/login.dart +++ b/lib/views/login.dart @@ -113,6 +113,11 @@ class _LoginState extends State { const Duration(milliseconds: 0), ), ); + } else if (context.mounted) { + // display a snackbar + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar(content: Text('Login failed.')), + ); } } else { ScaffoldMessenger.of(context).showSnackBar( diff --git a/protobuf/stillbox.proto b/protobuf/stillbox.proto index 8a49ce8..99b2bdb 100644 --- a/protobuf/stillbox.proto +++ b/protobuf/stillbox.proto @@ -39,7 +39,7 @@ message Call { } message Hello { - Version version = 1; + ServerInfo server_info = 1; } message UserPopup { @@ -105,9 +105,10 @@ message Filter { message Search { } -message Version { +message ServerInfo { string server_name = 1; string version = 2; string built = 3; string platform = 4; + string db_size = 5; }