🎨 Improve code structure

This commit is contained in:
LittleSheep 2024-06-22 22:39:32 +08:00
parent 27e5b4ca6f
commit 09e9a30eef
28 changed files with 69 additions and 44 deletions

View File

@ -164,7 +164,7 @@ class AccountProvider extends GetxController {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) return;
final client = auth.configureClient(service: 'passport');
final client = auth.configureClient('passport');
final resp = await client.get('/api/notifications?skip=0&take=100');
if (resp.statusCode == 200) {
@ -197,7 +197,7 @@ class AccountProvider extends GetxController {
token = await FirebaseMessaging.instance.getToken();
}
final client = auth.configureClient(service: 'passport');
final client = auth.configureClient('passport');
final resp = await client.post('/api/notifications/subscribe', {
'provider': provider,

View File

@ -58,8 +58,8 @@ class AuthProvider extends GetConnect {
return request;
}
GetConnect configureClient({
String? service,
GetConnect configureClient(
String service, {
timeout = const Duration(seconds: 5),
}) {
final client = GetConnect(
@ -68,10 +68,7 @@ class AuthProvider extends GetConnect {
allowAutoSignedCert: true,
);
client.httpClient.addAuthenticator(requestAuthenticator);
if (service != null) {
client.httpClient.baseUrl = ServiceFinder.services[service];
}
client.httpClient.baseUrl = ServiceFinder.services[service];
return client;
}
@ -152,7 +149,7 @@ class AuthProvider extends GetConnect {
return _cachedUserProfileResponse!;
}
final client = configureClient(service: 'passport');
final client = configureClient('passport');
final resp = await client.get('/api/users/me');
if (resp.statusCode != 200) {

View File

@ -97,7 +97,7 @@ class AttachmentProvider extends GetConnect {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
final client = auth.configureClient(service: 'paperclip');
final client = auth.configureClient('paperclip');
var resp = await client.put('/api/attachments/$id', {
'metadata': {
@ -119,7 +119,7 @@ class AttachmentProvider extends GetConnect {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
final client = auth.configureClient(service: 'paperclip');
final client = auth.configureClient('paperclip');
var resp = await client.delete('/api/attachments/$id');
if (resp.statusCode != 200) {

View File

@ -57,7 +57,7 @@ class ChatCallProvider extends GetxController {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
final client = auth.configureClient(service: 'messaging');
final client = auth.configureClient('messaging');
final resp = await client.post(
'/api/channels/global/${channel.value!.alias}/calls/ongoing/token',

View File

@ -9,7 +9,7 @@ class ChannelProvider extends GetxController {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
final client = auth.configureClient(service: 'messaging');
final client = auth.configureClient('messaging');
final resp = await client.get('/api/channels/$realm/$alias');
if (resp.statusCode != 200) {
@ -23,7 +23,7 @@ class ChannelProvider extends GetxController {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
final client = auth.configureClient(service: 'messaging');
final client = auth.configureClient('messaging');
final resp = await client.get('/api/channels/$realm/$alias/me');
if (resp.statusCode != 200) {
@ -38,7 +38,7 @@ class ChannelProvider extends GetxController {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
final client = auth.configureClient(service: 'messaging');
final client = auth.configureClient('messaging');
final resp = await client.get('/api/channels/$realm/$alias/calls/ongoing');
if (resp.statusCode == 404) {
@ -54,7 +54,7 @@ class ChannelProvider extends GetxController {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
final client = auth.configureClient(service: 'messaging');
final client = auth.configureClient('messaging');
final resp = await client.get('/api/channels/$scope');
if (resp.statusCode != 200) {
@ -68,7 +68,7 @@ class ChannelProvider extends GetxController {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
final client = auth.configureClient(service: 'messaging');
final client = auth.configureClient('messaging');
final resp = await client.get('/api/channels/$realm/me/available');
if (resp.statusCode != 200) {
@ -82,7 +82,7 @@ class ChannelProvider extends GetxController {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
final client = auth.configureClient(service: 'messaging');
final client = auth.configureClient('messaging');
final resp = await client.post('/api/channels/$scope', payload);
if (resp.statusCode != 200) {
@ -107,7 +107,7 @@ class ChannelProvider extends GetxController {
if (related == null) return null;
final prof = await auth.getProfile();
final client = auth.configureClient(service: 'messaging');
final client = auth.configureClient('messaging');
final resp = await client.post('/api/channels/$scope/dm', {
'alias': const Uuid().v4().replaceAll('-', '').substring(0, 12),
@ -128,7 +128,7 @@ class ChannelProvider extends GetxController {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
final client = auth.configureClient(service: 'messaging');
final client = auth.configureClient('messaging');
final resp = await client.put('/api/channels/$scope/$id', payload);
if (resp.statusCode != 200) {

View File

@ -6,7 +6,7 @@ class RealmProvider extends GetxController {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
final client = auth.configureClient(service: 'passport');
final client = auth.configureClient('passport');
final resp = await client.get('/api/realms/$alias');
if (resp.statusCode != 200) {
@ -20,7 +20,7 @@ class RealmProvider extends GetxController {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
final client = auth.configureClient(service: 'passport');
final client = auth.configureClient('passport');
final resp = await client.get('/api/realms/me/available');
if (resp.statusCode != 200) {

View File

@ -32,7 +32,7 @@ class _NotificationScreenState extends State<NotificationScreen> {
}
if (markList.isNotEmpty) {
final client = auth.configureClient(service: 'passport');
final client = auth.configureClient('passport');
await client.put('/api/notifications/batch/read', {'messages': markList});
}
@ -54,7 +54,7 @@ class _NotificationScreenState extends State<NotificationScreen> {
setState(() => _isBusy = true);
final client = auth.configureClient(service: 'passport');
final client = auth.configureClient('passport');
await client.put('/api/notifications/${element.id}/read', {});

View File

@ -98,7 +98,7 @@ class _PersonalizeScreenState extends State<PersonalizeScreen> {
context.showErrorDialog(e);
}
final client = auth.configureClient(service: 'passport');
final client = auth.configureClient('passport');
final resp = await client.put(
'/api/users/me/$position',
@ -120,7 +120,7 @@ class _PersonalizeScreenState extends State<PersonalizeScreen> {
setState(() => _isBusy = true);
final client = auth.configureClient(service: 'passport');
final client = auth.configureClient('passport');
_birthday?.toIso8601String();
final resp = await client.put(

View File

@ -110,7 +110,7 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) return;
final client = auth.configureClient(service: 'messaging');
final client = auth.configureClient('messaging');
final resp = await client.get(
'/api/channels/${widget.realm}/${widget.alias}/messages?take=10&offset=$pageKey');

View File

@ -79,7 +79,7 @@ class _ChannelDetailScreenState extends State<ChannelDetailScreen> {
setState(() => _isBusy = true);
final client = auth.configureClient(service: 'messaging');
final client = auth.configureClient('messaging');
final resp = await client.put(
'/api/channels/${widget.realm}/${widget.channel.alias}/members/me', {

View File

@ -64,7 +64,7 @@ class _PostPublishingScreenState extends State<PostPublishingScreen> {
setState(() => _isBusy = true);
final client = auth.configureClient(service: 'interactive');
final client = auth.configureClient('interactive');
final payload = {
'content': _contentController.value.text,

View File

@ -41,7 +41,7 @@ class _RealmOrganizeScreenState extends State<RealmOrganizeScreen> {
setState(() => _isBusy = true);
final client = auth.configureClient(service: 'passport');
final client = auth.configureClient('passport');
final payload = {
'alias': _aliasController.value.text.toLowerCase(),

View File

@ -29,7 +29,7 @@ class _ChannelDeletionDialogState extends State<ChannelDeletionDialog> {
setState(() => _isBusy = true);
final client = auth.configureClient(service: 'messaging');
final client = auth.configureClient('messaging');
final resp = await client
.delete('/api/channels/${widget.realm}/${widget.channel.id}');
@ -48,7 +48,7 @@ class _ChannelDeletionDialogState extends State<ChannelDeletionDialog> {
setState(() => _isBusy = true);
final client = auth.configureClient(service: 'messaging');
final client = auth.configureClient('messaging');
final resp = await client.delete(
'/api/channels/${widget.realm}/${widget.channel.alias}/members/me',

View File

@ -75,7 +75,7 @@ class _ChannelMemberListPopupState extends State<ChannelMemberListPopup> {
setState(() => _isBusy = true);
final client = auth.configureClient(service: 'messaging');
final client = auth.configureClient('messaging');
final resp = await client.post(
'/api/channels/${widget.realm}/${widget.channel.alias}/members',
@ -96,7 +96,7 @@ class _ChannelMemberListPopupState extends State<ChannelMemberListPopup> {
setState(() => _isBusy = true);
final client = auth.configureClient(service: 'messaging');
final client = auth.configureClient('messaging');
final resp = await client.request(
'/api/channels/${widget.realm}/${widget.channel.alias}/members',

View File

@ -33,7 +33,7 @@ class _ChatCallButtonState extends State<ChatCallButton> {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) return;
final client = auth.configureClient(service: 'messaging');
final client = auth.configureClient('messaging');
setState(() => _isBusy = true);
@ -57,7 +57,7 @@ class _ChatCallButtonState extends State<ChatCallButton> {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) return;
final client = auth.configureClient(service: 'messaging');
final client = auth.configureClient('messaging');
setState(() => _isBusy = true);

View File

@ -30,7 +30,7 @@ class _ChatMessageDeletionDialogState extends State<ChatMessageDeletionDialog> {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) return;
final client = auth.configureClient(service: 'messaging');
final client = auth.configureClient('messaging');
setState(() => _isBusy = true);

View File

@ -69,7 +69,7 @@ class _ChatMessageInputState extends State<ChatMessageInput> {
final prof = await auth.getProfile();
if (!await auth.isAuthorized) return;
final client = auth.configureClient(service: 'messaging');
final client = auth.configureClient('messaging');
final payload = {
'uuid': const Uuid().v4(),

View File

@ -153,7 +153,7 @@ class _PostDeletionDialogState extends State<PostDeletionDialog> {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) return;
final client = auth.configureClient(service: 'interactive');
final client = auth.configureClient('interactive');
setState(() => _isBusy = true);
final resp = await client.delete('/api/posts/${widget.item.id}');

View File

@ -50,7 +50,7 @@ class _PostQuickActionState extends State<PostQuickAction> {
if (_isSubmitting) return;
if (!await auth.isAuthorized) return;
final client = auth.configureClient(service: 'interactive');
final client = auth.configureClient('interactive');
setState(() => _isSubmitting = true);

View File

@ -27,7 +27,7 @@ class _RealmDeletionDialogState extends State<RealmDeletionDialog> {
setState(() => _isBusy = true);
final client = auth.configureClient(service: 'passport');
final client = auth.configureClient('passport');
final resp = await client.delete('/api/realms/${widget.realm.id}');
if (resp.statusCode != 200) {
@ -45,7 +45,7 @@ class _RealmDeletionDialogState extends State<RealmDeletionDialog> {
setState(() => _isBusy = true);
final client = auth.configureClient(service: 'passport');
final client = auth.configureClient('passport');
final resp =
await client.delete('/api/realms/${widget.realm.id}/members/me');

View File

@ -72,7 +72,7 @@ class _RealmMemberListPopupState extends State<RealmMemberListPopup> {
setState(() => _isBusy = true);
final client = auth.configureClient(service: 'passport');
final client = auth.configureClient('passport');
final resp = await client.post(
'/api/realms/${widget.realm.alias}/members',
@ -93,7 +93,7 @@ class _RealmMemberListPopupState extends State<RealmMemberListPopup> {
setState(() => _isBusy = true);
final client = auth.configureClient(service: 'passport');
final client = auth.configureClient('passport');
final resp = await client.request(
'/api/realms/${widget.realm.alias}/members',

View File

@ -7,6 +7,7 @@
#include "generated_plugin_registrant.h"
#include <file_selector_linux/file_selector_plugin.h>
#include <flutter_acrylic/flutter_acrylic_plugin.h>
#include <flutter_secure_storage_linux/flutter_secure_storage_linux_plugin.h>
#include <flutter_webrtc/flutter_web_r_t_c_plugin.h>
#include <sentry_flutter/sentry_flutter_plugin.h>
@ -16,6 +17,9 @@ void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) file_selector_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin");
file_selector_plugin_register_with_registrar(file_selector_linux_registrar);
g_autoptr(FlPluginRegistrar) flutter_acrylic_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterAcrylicPlugin");
flutter_acrylic_plugin_register_with_registrar(flutter_acrylic_registrar);
g_autoptr(FlPluginRegistrar) flutter_secure_storage_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterSecureStorageLinuxPlugin");
flutter_secure_storage_linux_plugin_register_with_registrar(flutter_secure_storage_linux_registrar);

View File

@ -4,6 +4,7 @@
list(APPEND FLUTTER_PLUGIN_LIST
file_selector_linux
flutter_acrylic
flutter_secure_storage_linux
flutter_webrtc
sentry_flutter

View File

@ -14,6 +14,7 @@ import flutter_local_notifications
import flutter_secure_storage_macos
import flutter_webrtc
import livekit_client
import macos_window_utils
import package_info_plus
import path_provider_foundation
import sentry_flutter
@ -33,6 +34,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FlutterSecureStoragePlugin.register(with: registry.registrar(forPlugin: "FlutterSecureStoragePlugin"))
FlutterWebRTCPlugin.register(with: registry.registrar(forPlugin: "FlutterWebRTCPlugin"))
LiveKitPlugin.register(with: registry.registrar(forPlugin: "LiveKitPlugin"))
MacOSWindowUtilsPlugin.register(with: registry.registrar(forPlugin: "MacOSWindowUtilsPlugin"))
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SentryFlutterPlugin.register(with: registry.registrar(forPlugin: "SentryFlutterPlugin"))

View File

@ -334,6 +334,14 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_acrylic:
dependency: "direct main"
description:
name: flutter_acrylic
sha256: b3996dbde5abf5823cc9ead4cf2e5267c3181f15585fe47ce4dc4472e7ec827a
url: "https://pub.dev"
source: hosted
version: "1.1.4"
flutter_animate:
dependency: "direct main"
description:
@ -688,6 +696,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.2.0"
macos_window_utils:
dependency: transitive
description:
name: macos_window_utils
sha256: "230be594d26f6dee92c5a1544f4242d25138a5bfb9f185b27f14de3949ef0be8"
url: "https://pub.dev"
source: hosted
version: "1.5.0"
markdown:
dependency: transitive
description:

View File

@ -69,6 +69,7 @@ dependencies:
package_info_plus: ^8.0.0
device_info_plus: ^10.1.0
shared_preferences: ^2.2.3
flutter_acrylic: ^1.1.4
dev_dependencies:
flutter_test:

View File

@ -9,6 +9,7 @@
#include <connectivity_plus/connectivity_plus_windows_plugin.h>
#include <file_selector_windows/file_selector_windows.h>
#include <firebase_core/firebase_core_plugin_c_api.h>
#include <flutter_acrylic/flutter_acrylic_plugin.h>
#include <flutter_secure_storage_windows/flutter_secure_storage_windows_plugin.h>
#include <flutter_webrtc/flutter_web_r_t_c_plugin.h>
#include <livekit_client/live_kit_plugin.h>
@ -24,6 +25,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
registry->GetRegistrarForPlugin("FileSelectorWindows"));
FirebaseCorePluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FirebaseCorePluginCApi"));
FlutterAcrylicPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FlutterAcrylicPlugin"));
FlutterSecureStorageWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FlutterSecureStorageWindowsPlugin"));
FlutterWebRTCPluginRegisterWithRegistrar(

View File

@ -6,6 +6,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
connectivity_plus
file_selector_windows
firebase_core
flutter_acrylic
flutter_secure_storage_windows
flutter_webrtc
livekit_client