mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-05 07:34:23 +00:00
feat(graphql): Implement Accept-Language header for GraphQL API map
This commit is contained in:
parent
51f5bb9f31
commit
08f3258615
|
@ -71,6 +71,7 @@ abstract class GraphQLApiMap {
|
|||
'https://api.$rootAddress/graphql',
|
||||
httpClient: ioClient,
|
||||
parser: ResponseLoggingParser(),
|
||||
defaultHeaders: {'Accept-Language': _locale},
|
||||
);
|
||||
|
||||
final String token = _getApiToken();
|
||||
|
@ -101,7 +102,12 @@ abstract class GraphQLApiMap {
|
|||
'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,6 +117,8 @@ abstract class GraphQLApiMap {
|
|||
);
|
||||
}
|
||||
|
||||
String get _locale => getIt.get<ApiConfigModel>().localeCode ?? 'en';
|
||||
|
||||
String _getApiToken() {
|
||||
String token = '';
|
||||
final serverDetails = getIt<ApiConfigModel>().serverDetails;
|
||||
|
|
|
@ -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