mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-07 00:24:18 +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',
|
'https://api.$rootAddress/graphql',
|
||||||
httpClient: ioClient,
|
httpClient: ioClient,
|
||||||
parser: ResponseLoggingParser(),
|
parser: ResponseLoggingParser(),
|
||||||
|
defaultHeaders: {'Accept-Language': _locale},
|
||||||
);
|
);
|
||||||
|
|
||||||
final String token = _getApiToken();
|
final String token = _getApiToken();
|
||||||
|
@ -101,7 +102,12 @@ abstract class GraphQLApiMap {
|
||||||
'ws://api.$rootAddress/graphql',
|
'ws://api.$rootAddress/graphql',
|
||||||
config: SocketClientConfig(
|
config: SocketClientConfig(
|
||||||
autoReconnect: true,
|
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 _getApiToken() {
|
||||||
String token = '';
|
String token = '';
|
||||||
final serverDetails = getIt<ApiConfigModel>().serverDetails;
|
final serverDetails = getIt<ApiConfigModel>().serverDetails;
|
||||||
|
|
|
@ -9,6 +9,7 @@ class ApiConfigModel {
|
||||||
final Box _box = Hive.box(BNames.serverInstallationBox);
|
final Box _box = Hive.box(BNames.serverInstallationBox);
|
||||||
|
|
||||||
ServerHostingDetails? get serverDetails => _serverDetails;
|
ServerHostingDetails? get serverDetails => _serverDetails;
|
||||||
|
String? get localeCode => _localeCode;
|
||||||
String? get serverProviderKey => _serverProviderKey;
|
String? get serverProviderKey => _serverProviderKey;
|
||||||
String? get serverLocation => _serverLocation;
|
String? get serverLocation => _serverLocation;
|
||||||
String? get serverType => _serverType;
|
String? get serverType => _serverType;
|
||||||
|
@ -20,6 +21,7 @@ class ApiConfigModel {
|
||||||
ServerDomain? get serverDomain => _serverDomain;
|
ServerDomain? get serverDomain => _serverDomain;
|
||||||
BackblazeBucket? get backblazeBucket => _backblazeBucket;
|
BackblazeBucket? get backblazeBucket => _backblazeBucket;
|
||||||
|
|
||||||
|
String? _localeCode;
|
||||||
String? _serverProviderKey;
|
String? _serverProviderKey;
|
||||||
String? _serverLocation;
|
String? _serverLocation;
|
||||||
String? _dnsProviderKey;
|
String? _dnsProviderKey;
|
||||||
|
@ -31,6 +33,10 @@ class ApiConfigModel {
|
||||||
ServerDomain? _serverDomain;
|
ServerDomain? _serverDomain;
|
||||||
BackblazeBucket? _backblazeBucket;
|
BackblazeBucket? _backblazeBucket;
|
||||||
|
|
||||||
|
Future<void> setLocaleCode(final String value) async {
|
||||||
|
_localeCode = value;
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> storeServerProviderType(final ServerProviderType value) async {
|
Future<void> storeServerProviderType(final ServerProviderType value) async {
|
||||||
await _box.put(BNames.serverProvider, value);
|
await _box.put(BNames.serverProvider, value);
|
||||||
_serverProvider = value;
|
_serverProvider = value;
|
||||||
|
@ -82,6 +88,7 @@ class ApiConfigModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear() {
|
void clear() {
|
||||||
|
_localeCode = null;
|
||||||
_serverProviderKey = null;
|
_serverProviderKey = null;
|
||||||
_dnsProvider = null;
|
_dnsProvider = null;
|
||||||
_serverLocation = null;
|
_serverLocation = null;
|
||||||
|
@ -95,6 +102,7 @@ class ApiConfigModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
void init() {
|
void init() {
|
||||||
|
_localeCode = 'en';
|
||||||
_serverProviderKey = _box.get(BNames.hetznerKey);
|
_serverProviderKey = _box.get(BNames.hetznerKey);
|
||||||
_serverLocation = _box.get(BNames.serverLocation);
|
_serverLocation = _box.get(BNames.serverLocation);
|
||||||
_dnsProviderKey = _box.get(BNames.cloudFlareKey);
|
_dnsProviderKey = _box.get(BNames.cloudFlareKey);
|
||||||
|
|
|
@ -71,34 +71,38 @@ class SelfprivacyApp extends StatelessWidget {
|
||||||
builder: (
|
builder: (
|
||||||
final BuildContext context,
|
final BuildContext context,
|
||||||
final AppSettingsState appSettings,
|
final AppSettingsState appSettings,
|
||||||
) =>
|
) {
|
||||||
MaterialApp.router(
|
getIt.get<ApiConfigModel>().setLocaleCode(
|
||||||
routeInformationParser: _appRouter.defaultRouteParser(),
|
context.locale.languageCode,
|
||||||
routerDelegate: _appRouter.delegate(),
|
);
|
||||||
scaffoldMessengerKey:
|
return MaterialApp.router(
|
||||||
getIt.get<NavigationService>().scaffoldMessengerKey,
|
routeInformationParser: _appRouter.defaultRouteParser(),
|
||||||
localizationsDelegates: context.localizationDelegates,
|
routerDelegate: _appRouter.delegate(),
|
||||||
supportedLocales: context.supportedLocales,
|
scaffoldMessengerKey:
|
||||||
locale: context.locale,
|
getIt.get<NavigationService>().scaffoldMessengerKey,
|
||||||
debugShowCheckedModeBanner: false,
|
localizationsDelegates: context.localizationDelegates,
|
||||||
title: 'SelfPrivacy',
|
supportedLocales: context.supportedLocales,
|
||||||
theme: lightThemeData,
|
locale: context.locale,
|
||||||
darkTheme: darkThemeData,
|
debugShowCheckedModeBanner: false,
|
||||||
themeMode: appSettings.isAutoDarkModeOn
|
title: 'SelfPrivacy',
|
||||||
? ThemeMode.system
|
theme: lightThemeData,
|
||||||
: appSettings.isDarkModeOn
|
darkTheme: darkThemeData,
|
||||||
? ThemeMode.dark
|
themeMode: appSettings.isAutoDarkModeOn
|
||||||
: ThemeMode.light,
|
? ThemeMode.system
|
||||||
builder: (final BuildContext context, final Widget? widget) {
|
: appSettings.isDarkModeOn
|
||||||
Widget error = const Text('...rendering error...');
|
? ThemeMode.dark
|
||||||
if (widget is Scaffold || widget is Navigator) {
|
: ThemeMode.light,
|
||||||
error = Scaffold(body: Center(child: error));
|
builder: (final BuildContext context, final Widget? widget) {
|
||||||
}
|
Widget error = const Text('...rendering error...');
|
||||||
ErrorWidget.builder =
|
if (widget is Scaffold || widget is Navigator) {
|
||||||
(final FlutterErrorDetails errorDetails) => error;
|
error = Scaffold(body: Center(child: error));
|
||||||
return widget!;
|
}
|
||||||
},
|
ErrorWidget.builder =
|
||||||
),
|
(final FlutterErrorDetails errorDetails) => error;
|
||||||
|
return widget!;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue