🐛 Bug fixes and optimization

This commit is contained in:
2024-06-08 21:35:50 +08:00
parent e88a0ddb22
commit 6acbd1ee9e
34 changed files with 481 additions and 392 deletions

View File

@ -2,7 +2,6 @@ import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_background/flutter_background.dart';
import 'package:flutter_webrtc/flutter_webrtc.dart';
import 'package:get/get.dart';
import 'package:livekit_client/livekit_client.dart';
@ -171,35 +170,6 @@ class _ControlsWidgetState extends State<ControlsWidget> {
}
return;
}
if (lkPlatformIs(PlatformType.android)) {
requestBackgroundPermission([bool isRetry = false]) async {
try {
bool hasPermissions = await FlutterBackground.hasPermissions;
if (!isRetry) {
const androidConfig = FlutterBackgroundAndroidConfig(
notificationTitle: 'Screen Sharing',
notificationText: 'Solar Messager is sharing your screen',
notificationImportance: AndroidNotificationImportance.Default,
notificationIcon:
AndroidResource(name: 'launcher_icon', defType: 'mipmap'),
);
hasPermissions = await FlutterBackground.initialize(
androidConfig: androidConfig);
}
if (hasPermissions &&
!FlutterBackground.isBackgroundExecutionEnabled) {
await FlutterBackground.enableBackgroundExecution();
}
} catch (e) {
if (!isRetry) {
return await Future<void>.delayed(const Duration(seconds: 1),
() => requestBackgroundPermission(true));
}
}
}
await requestBackgroundPermission();
}
if (lkPlatformIs(PlatformType.iOS)) {
var track = await LocalVideoTrack.createScreenShareTrack(
const ScreenShareCaptureOptions(
@ -223,12 +193,6 @@ class _ControlsWidgetState extends State<ControlsWidget> {
void disableScreenShare() async {
await participant.setScreenShareEnabled(false);
if (lkPlatformIs(PlatformType.android)) {
// Android specific
try {
await FlutterBackground.disableBackgroundExecution();
} catch (_) {}
}
}
@override

View File

@ -56,7 +56,7 @@ class _ChatMessageInputState extends State<ChatMessageInput> {
Map<String, dynamic> encodeMessage(String content) {
return {
'value': content,
'value': content.trim(),
'keypair_id': null,
'algorithm': 'plain',
};
@ -103,9 +103,11 @@ class _ChatMessageInputState extends State<ChatMessageInput> {
senderId: sender.id,
);
message.isSending = true;
if (_editTo == null) {
message.isSending = true;
widget.onSent(message);
}
if (widget.edit == null) widget.onSent(message);
resetInput();
Response resp;
@ -131,6 +133,7 @@ class _ChatMessageInputState extends State<ChatMessageInput> {
_editTo = null;
_replyTo = null;
_textController.clear();
_attachments.clear();
setState(() {});
}
@ -161,70 +164,66 @@ class _ChatMessageInputState extends State<ChatMessageInput> {
)
];
return Material(
color: Theme.of(context).colorScheme.surface,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Divider(thickness: 0.3, height: 1),
if (_replyTo != null)
MaterialBanner(
leading: const FaIcon(FontAwesomeIcons.reply, size: 18),
dividerColor: Colors.transparent,
content: ChatMessage(
item: _replyTo!,
isContentPreviewing: true,
),
actions: notifyBannerActions,
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
if (_replyTo != null)
MaterialBanner(
leading: const FaIcon(FontAwesomeIcons.reply, size: 18),
dividerColor: Colors.transparent,
content: ChatMessage(
item: _replyTo!,
isContentPreviewing: true,
),
if (_editTo != null)
MaterialBanner(
leading: const Icon(Icons.edit),
dividerColor: Colors.transparent,
content: ChatMessage(
item: _editTo!,
isContentPreviewing: true,
),
actions: notifyBannerActions,
),
SizedBox(
height: 56,
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Expanded(
child: TextField(
controller: _textController,
focusNode: _focusNode,
maxLines: null,
autocorrect: true,
keyboardType: TextInputType.text,
decoration: InputDecoration.collapsed(
hintText: widget.placeholder ??
'messageInputPlaceholder'.trParams(
{'channel': '#${widget.channel.alias}'},
),
),
onSubmitted: (_) => sendMessage(),
onTapOutside: (_) =>
FocusManager.instance.primaryFocus?.unfocus(),
),
),
IconButton(
icon: const Icon(Icons.attach_file),
color: Colors.teal,
onPressed: () => showAttachments(),
),
IconButton(
icon: const Icon(Icons.send),
color: Theme.of(context).colorScheme.primary,
onPressed: () => sendMessage(),
)
],
).paddingOnly(left: 20, right: 16),
actions: notifyBannerActions,
),
],
),
if (_editTo != null)
MaterialBanner(
leading: const Icon(Icons.edit),
dividerColor: Colors.transparent,
content: ChatMessage(
item: _editTo!,
isContentPreviewing: true,
),
actions: notifyBannerActions,
),
SizedBox(
height: 56,
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Expanded(
child: TextField(
controller: _textController,
focusNode: _focusNode,
maxLines: null,
autocorrect: true,
keyboardType: TextInputType.text,
decoration: InputDecoration.collapsed(
hintText: widget.placeholder ??
'messageInputPlaceholder'.trParams(
{'channel': '#${widget.channel.alias}'},
),
),
onSubmitted: (_) => sendMessage(),
onTapOutside: (_) =>
FocusManager.instance.primaryFocus?.unfocus(),
),
),
IconButton(
icon: const Icon(Icons.attach_file),
color: Colors.teal,
onPressed: () => showAttachments(),
),
IconButton(
icon: const Icon(Icons.send),
color: Theme.of(context).colorScheme.primary,
onPressed: () => sendMessage(),
)
],
).paddingOnly(left: 20, right: 16),
),
],
);
}
}

View File

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'package:get/get.dart';
import 'package:solian/providers/account.dart';
import 'package:solian/providers/auth.dart';
import 'package:solian/providers/chat.dart';
class BackgroundStateWidget extends StatelessWidget {
@ -9,6 +10,7 @@ class BackgroundStateWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
final AuthProvider auth = Get.find();
final AccountProvider account = Get.find();
final ChatProvider chat = Get.find();
@ -20,35 +22,51 @@ class BackgroundStateWidget extends StatelessWidget {
return Row(children: [
if (disconnected && !connecting)
IconButton(
tooltip: [
if (account.isConnected.isFalse)
'Lost Connection with Passport Server...',
if (chat.isConnected.isFalse)
'Lost Connection with Messaging Server...',
].join('\n'),
icon: const Icon(Icons.wifi_off)
.animate(onPlay: (c) => c.repeat())
.fadeIn(duration: 800.ms)
.then()
.fadeOut(duration: 800.ms),
onPressed: () {
if (account.isConnected.isFalse) account.connect();
if (chat.isConnected.isFalse) chat.connect();
FutureBuilder(
future: auth.isAuthorized,
builder: (context, snapshot) {
if (!snapshot.hasData || snapshot.data == false) {
return const SizedBox();
}
return IconButton(
tooltip: [
if (account.isConnected.isFalse)
'Lost Connection with Passport Server...',
if (chat.isConnected.isFalse)
'Lost Connection with Messaging Server...',
].join('\n'),
icon: const Icon(Icons.wifi_off)
.animate(onPlay: (c) => c.repeat())
.fadeIn(duration: 800.ms)
.then()
.fadeOut(duration: 800.ms),
onPressed: () {
if (account.isConnected.isFalse) account.connect();
if (chat.isConnected.isFalse) chat.connect();
},
);
},
),
if (connecting)
IconButton(
tooltip: [
if (account.isConnecting.isTrue)
'Waiting Passport Server Response...',
if (chat.isConnecting.isTrue)
'Waiting Messaging Server Response...',
].join('\n'),
icon: const Icon(Icons.sync)
.animate(onPlay: (c) => c.repeat())
.rotate(duration: 1850.ms, begin: 1, end: 0),
onPressed: () {},
FutureBuilder(
future: auth.isAuthorized,
builder: (context, snapshot) {
if (!snapshot.hasData || snapshot.data == false) {
return const SizedBox();
}
return IconButton(
tooltip: [
if (account.isConnecting.isTrue)
'Waiting Passport Server Response...',
if (chat.isConnecting.isTrue)
'Waiting Messaging Server Response...',
].join('\n'),
icon: const Icon(Icons.sync)
.animate(onPlay: (c) => c.repeat())
.rotate(duration: 1850.ms, begin: 1, end: 0),
onPressed: () {},
);
},
),
]);
});