mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-07 00:24:18 +00:00
Merge pull request 'feat(graphql): Implement Accept-Language header for GraphQL API map' (#243) from graphql-locale into master
Reviewed-on: https://git.selfprivacy.org/SelfPrivacy/selfprivacy.org.app/pulls/243 Reviewed-by: Inex Code <inex.code@selfprivacy.org>
This commit is contained in:
commit
ac6a4c192e
|
@ -71,15 +71,14 @@ abstract class GraphQLApiMap {
|
|||
'https://api.$rootAddress/graphql',
|
||||
httpClient: ioClient,
|
||||
parser: ResponseLoggingParser(),
|
||||
defaultHeaders: {'Accept-Language': _locale},
|
||||
);
|
||||
|
||||
final String token = _getApiToken();
|
||||
|
||||
final Link graphQLLink = RequestLoggingLink().concat(
|
||||
isWithToken
|
||||
? AuthLink(
|
||||
getToken: () async =>
|
||||
customToken == '' ? 'Bearer $token' : customToken,
|
||||
customToken == '' ? 'Bearer $_token' : customToken,
|
||||
).concat(httpLink)
|
||||
: httpLink,
|
||||
);
|
||||
|
@ -95,13 +94,16 @@ abstract class GraphQLApiMap {
|
|||
}
|
||||
|
||||
Future<GraphQLClient> getSubscriptionClient() async {
|
||||
final String token = _getApiToken();
|
||||
|
||||
final WebSocketLink webSocketLink = WebSocketLink(
|
||||
'ws://api.$rootAddress/graphql',
|
||||
config: SocketClientConfig(
|
||||
autoReconnect: true,
|
||||
headers: token.isEmpty ? null : {'Authorization': 'Bearer $token'},
|
||||
headers: _token.isEmpty
|
||||
? null
|
||||
: {
|
||||
'Authorization': 'Bearer $_token',
|
||||
'Accept-Language': _locale,
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
|
@ -111,7 +113,9 @@ abstract class GraphQLApiMap {
|
|||
);
|
||||
}
|
||||
|
||||
String _getApiToken() {
|
||||
String get _locale => getIt.get<ApiConfigModel>().localeCode ?? 'en';
|
||||
|
||||
String get _token {
|
||||
String token = '';
|
||||
final serverDetails = getIt<ApiConfigModel>().serverDetails;
|
||||
if (serverDetails != null) {
|
||||
|
|
|
@ -9,6 +9,7 @@ class ApiConfigModel {
|
|||
final Box _box = Hive.box(BNames.serverInstallationBox);
|
||||
|
||||
ServerHostingDetails? get serverDetails => _serverDetails;
|
||||
String? get localeCode => _localeCode;
|
||||
String? get serverProviderKey => _serverProviderKey;
|
||||
String? get serverLocation => _serverLocation;
|
||||
String? get serverType => _serverType;
|
||||
|
@ -20,6 +21,7 @@ class ApiConfigModel {
|
|||
ServerDomain? get serverDomain => _serverDomain;
|
||||
BackblazeBucket? get backblazeBucket => _backblazeBucket;
|
||||
|
||||
String? _localeCode;
|
||||
String? _serverProviderKey;
|
||||
String? _serverLocation;
|
||||
String? _dnsProviderKey;
|
||||
|
@ -31,6 +33,10 @@ class ApiConfigModel {
|
|||
ServerDomain? _serverDomain;
|
||||
BackblazeBucket? _backblazeBucket;
|
||||
|
||||
Future<void> setLocaleCode(final String value) async {
|
||||
_localeCode = value;
|
||||
}
|
||||
|
||||
Future<void> storeServerProviderType(final ServerProviderType value) async {
|
||||
await _box.put(BNames.serverProvider, value);
|
||||
_serverProvider = value;
|
||||
|
@ -82,6 +88,7 @@ class ApiConfigModel {
|
|||
}
|
||||
|
||||
void clear() {
|
||||
_localeCode = null;
|
||||
_serverProviderKey = null;
|
||||
_dnsProvider = null;
|
||||
_serverLocation = null;
|
||||
|
@ -95,6 +102,7 @@ class ApiConfigModel {
|
|||
}
|
||||
|
||||
void init() {
|
||||
_localeCode = 'en';
|
||||
_serverProviderKey = _box.get(BNames.hetznerKey);
|
||||
_serverLocation = _box.get(BNames.serverLocation);
|
||||
_dnsProviderKey = _box.get(BNames.cloudFlareKey);
|
||||
|
|
|
@ -71,34 +71,38 @@ class SelfprivacyApp extends StatelessWidget {
|
|||
builder: (
|
||||
final BuildContext context,
|
||||
final AppSettingsState appSettings,
|
||||
) =>
|
||||
MaterialApp.router(
|
||||
routeInformationParser: _appRouter.defaultRouteParser(),
|
||||
routerDelegate: _appRouter.delegate(),
|
||||
scaffoldMessengerKey:
|
||||
getIt.get<NavigationService>().scaffoldMessengerKey,
|
||||
localizationsDelegates: context.localizationDelegates,
|
||||
supportedLocales: context.supportedLocales,
|
||||
locale: context.locale,
|
||||
debugShowCheckedModeBanner: false,
|
||||
title: 'SelfPrivacy',
|
||||
theme: lightThemeData,
|
||||
darkTheme: darkThemeData,
|
||||
themeMode: appSettings.isAutoDarkModeOn
|
||||
? ThemeMode.system
|
||||
: appSettings.isDarkModeOn
|
||||
? ThemeMode.dark
|
||||
: ThemeMode.light,
|
||||
builder: (final BuildContext context, final Widget? widget) {
|
||||
Widget error = const Text('...rendering error...');
|
||||
if (widget is Scaffold || widget is Navigator) {
|
||||
error = Scaffold(body: Center(child: error));
|
||||
}
|
||||
ErrorWidget.builder =
|
||||
(final FlutterErrorDetails errorDetails) => error;
|
||||
return widget!;
|
||||
},
|
||||
),
|
||||
) {
|
||||
getIt.get<ApiConfigModel>().setLocaleCode(
|
||||
context.locale.languageCode,
|
||||
);
|
||||
return MaterialApp.router(
|
||||
routeInformationParser: _appRouter.defaultRouteParser(),
|
||||
routerDelegate: _appRouter.delegate(),
|
||||
scaffoldMessengerKey:
|
||||
getIt.get<NavigationService>().scaffoldMessengerKey,
|
||||
localizationsDelegates: context.localizationDelegates,
|
||||
supportedLocales: context.supportedLocales,
|
||||
locale: context.locale,
|
||||
debugShowCheckedModeBanner: false,
|
||||
title: 'SelfPrivacy',
|
||||
theme: lightThemeData,
|
||||
darkTheme: darkThemeData,
|
||||
themeMode: appSettings.isAutoDarkModeOn
|
||||
? ThemeMode.system
|
||||
: appSettings.isDarkModeOn
|
||||
? ThemeMode.dark
|
||||
: ThemeMode.light,
|
||||
builder: (final BuildContext context, final Widget? widget) {
|
||||
Widget error = const Text('...rendering error...');
|
||||
if (widget is Scaffold || widget is Navigator) {
|
||||
error = Scaffold(body: Center(child: error));
|
||||
}
|
||||
ErrorWidget.builder =
|
||||
(final FlutterErrorDetails errorDetails) => error;
|
||||
return widget!;
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue