diff --git a/l10n.yaml b/l10n.yaml index b49b5df..3dee198 100644 --- a/l10n.yaml +++ b/l10n.yaml @@ -1,4 +1,5 @@ arb-dir: lib/l10n template-arb-file: app_en.arb +preferred-supported-locales: en output-localization-file: app_localizations.dart untranslated-messages-file: untranslated_messages.json diff --git a/lib/main.dart b/lib/main.dart index 6d34343..bbcf489 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1261,79 +1261,44 @@ class _MainAppState extends State { ], ), imageBuilder: (uri, title, alt) { + Widget errorImage = InkWell( + onTap: () { + selectionHaptic(); + ScaffoldMessenger.of(context) + .showSnackBar(SnackBar( + content: Text( + AppLocalizations.of( + context)! + .notAValidImage), + showCloseIcon: true)); + }, + child: Container( + decoration: BoxDecoration( + borderRadius: + BorderRadius + .circular(8), + color: Theme.of(context) + .brightness == + Brightness.light + ? Colors.white + : Colors.black), + padding: + const EdgeInsets.only( + left: 100, + right: 100, + top: 32), + child: const Image( + image: AssetImage( + "assets/logo512error.png")))); if (uri.isAbsolute) { return Image.network( uri.toString(), errorBuilder: (context, error, stackTrace) { - return InkWell( - onTap: () { - selectionHaptic(); - ScaffoldMessenger.of( - context) - .showSnackBar(SnackBar( - content: Text( - AppLocalizations.of( - context)! - .notAValidImage), - showCloseIcon: - true)); - }, - child: Container( - decoration: BoxDecoration( - borderRadius: - BorderRadius - .circular( - 8), - color: Theme.of(context) - .brightness == - Brightness - .light - ? Colors.white - : Colors.black), - padding: - const EdgeInsets - .only( - left: 100, - right: 100, - top: 32), - child: const Image( - image: AssetImage( - "assets/logo512error.png")))); + return errorImage; }); } else { - return InkWell( - onTap: () { - selectionHaptic(); - ScaffoldMessenger.of( - context) - .showSnackBar(SnackBar( - content: Text( - AppLocalizations.of( - context)! - .notAValidImage), - showCloseIcon: - true)); - }, - child: Container( - decoration: BoxDecoration( - borderRadius: - BorderRadius - .circular(8), - color: Theme.of(context) - .brightness == - Brightness - .light - ? Colors.white - : Colors.black), - padding: - const EdgeInsets.only( - left: 100, - right: 100, - top: 32), - child: const Image( - image: AssetImage( - "assets/logo512error.png")))); + return errorImage; } }, styleSheet: (p0.author == user) diff --git a/lib/settings/voice.dart b/lib/settings/voice.dart index 0af758a..0de3fe3 100644 --- a/lib/settings/voice.dart +++ b/lib/settings/voice.dart @@ -95,14 +95,10 @@ class _ScreenSettingsVoiceState extends State { : !(permissionBluetooth && permissionRecord) ? AppLocalizations.of(context)! .settingsVoicePermissionNot - : !(prefs!.getBool( - "voiceModeEnabled") ?? - false) - ? AppLocalizations.of(context)! - .settingsVoiceNotEnabled - : AppLocalizations.of(context)! - .settingsVoiceNotSupported, + : AppLocalizations.of(context)! + .settingsVoiceNotSupported, Icons.info_rounded, () { + selectionHaptic(); if (permissionLoading) return; if (!(permissionBluetooth && permissionRecord)) { void load() async { @@ -139,7 +135,6 @@ class _ScreenSettingsVoiceState extends State { } else if (!voiceLanguageOptions.contains( (prefs!.getString("voiceLanguage") ?? "en_US"))) { - selectionHaptic(); ScaffoldMessenger.of(context).showSnackBar(SnackBar( content: Text(AppLocalizations.of(context)! .settingsVoiceTtsNotSupportedDescription), diff --git a/lib/worker/sender.dart b/lib/worker/sender.dart index d6711df..4759c14 100644 --- a/lib/worker/sender.dart +++ b/lib/worker/sender.dart @@ -79,6 +79,9 @@ Future getTitleAi(List history) async { .replaceAll("_", "") .replaceAll("\n", " ") .trim(); + while (title.contains(" ")) { + title = title.replaceAll(" ", " "); + } return title; } @@ -169,58 +172,58 @@ Future send(String value, BuildContext context, Function setState, baseUrl: "$host/api"); try { - if ((prefs!.getString("requestType") ?? "stream") == "stream") { - final stream = client - .generateChatCompletionStream( - request: llama.GenerateChatCompletionRequest( - model: model!, - messages: history, - keepAlive: int.parse(prefs!.getString("keepAlive") ?? "300")), - ) - .timeout(const Duration(seconds: 30)); + if ((prefs!.getString("requestType") ?? "stream") == "stream") { + final stream = client + .generateChatCompletionStream( + request: llama.GenerateChatCompletionRequest( + model: model!, + messages: history, + keepAlive: int.parse(prefs!.getString("keepAlive") ?? "300")), + ) + .timeout(const Duration(seconds: 30)); - await for (final res in stream) { - text += (res.message?.content ?? ""); - for (var i = 0; i < messages.length; i++) { - if (messages[i].id == newId) { - messages.removeAt(i); - break; + await for (final res in stream) { + text += (res.message?.content ?? ""); + for (var i = 0; i < messages.length; i++) { + if (messages[i].id == newId) { + messages.removeAt(i); + break; + } } + if (chatAllowed) return ""; + // if (text.trim() == "") { + // throw Exception(); + // } + messages.insert( + 0, types.TextMessage(author: assistant, id: newId, text: text)); + if (onStream != null) { + onStream(text, false); + } + setState(() {}); + heavyHaptic(); } + } else { + llama.GenerateChatCompletionResponse request; + request = await client + .generateChatCompletion( + request: llama.GenerateChatCompletionRequest( + model: model!, + messages: history, + keepAlive: int.parse(prefs!.getString("keepAlive") ?? "300")), + ) + .timeout(const Duration(seconds: 30)); if (chatAllowed) return ""; - // if (text.trim() == "") { + // if (request.message!.content.trim() == "") { // throw Exception(); // } messages.insert( - 0, types.TextMessage(author: assistant, id: newId, text: text)); - if (onStream != null) { - onStream(text, false); - } + 0, + types.TextMessage( + author: assistant, id: newId, text: request.message!.content)); + text = request.message!.content; setState(() {}); heavyHaptic(); } - } else { - llama.GenerateChatCompletionResponse request; - request = await client - .generateChatCompletion( - request: llama.GenerateChatCompletionRequest( - model: model!, - messages: history, - keepAlive: int.parse(prefs!.getString("keepAlive") ?? "300")), - ) - .timeout(const Duration(seconds: 30)); - if (chatAllowed) return ""; - // if (request.message!.content.trim() == "") { - // throw Exception(); - // } - messages.insert( - 0, - types.TextMessage( - author: assistant, id: newId, text: request.message!.content)); - text = request.message!.content; - setState(() {}); - heavyHaptic(); - } } catch (e) { for (var i = 0; i < messages.length; i++) { if (messages[i].id == newId) { diff --git a/pubspec.yaml b/pubspec.yaml index bfec6db..f78b8c8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -42,6 +42,7 @@ dependencies: dynamic_color: ^1.7.0 volume_controller: ^2.0.7 universal_html: ^2.2.4 + dev_dependencies: flutter_test: sdk: flutter