Skip to content

Commit db10be3

Browse files
authored
Make web compatible calls for locale and skip PackageInfo (#395)
* Make web compatible calls for locale and skip PackageInfo * Also get country code for web locale * Add description of early web support
1 parent 0672d49 commit db10be3

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ It's possible to add other parameters to work with your instance of Parse Server
4949
coreStore: await CoreStoreSharedPrefsImp.getInstance()); // Local data storage method. Will use SharedPreferences instead of Sembast as an internal DB
5050
```
5151

52+
53+
#### Early Web support
54+
Currently this requires adding `X-Parse-Installation-Id` as an allowed header to parse-server.
55+
When running directly via docker, set the env var `PARSE_SERVER_ALLOW_HEADERS=X-Parse-Installation-Id`.
56+
When running via express, set [ParseServerOptions](https://parseplatform.org/parse-server/api/master/ParseServerOptions.html) `allowHeader: ['X-Parse-Installation-Id']`.
57+
58+
Be aware that for web ParseInstallation does include app name, version or package identifier.
59+
60+
5261
## Objects
5362
You can create custom objects by calling:
5463
```dart

lib/parse_server_sdk.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'dart:convert';
55
import 'dart:io';
66
import 'dart:math';
77
import 'dart:typed_data';
8+
import 'dart:ui' as ui;
89

910
import 'package:devicelocale/devicelocale.dart';
1011
import 'package:flutter/foundation.dart' show kIsWeb;

lib/src/objects/parse_installation.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,20 @@ class ParseInstallation extends ParseObject {
8383
}
8484

8585
//Locale
86-
final String locale = await Devicelocale.currentLocale;
86+
final String locale = kIsWeb ? ui.window.locale.toString() : await Devicelocale.currentLocale;
8787
if (locale != null && locale.isNotEmpty) {
8888
set<String>(keyLocaleIdentifier, locale);
8989
}
9090

9191
//Timezone
9292

9393
//App info
94-
final PackageInfo packageInfo = await PackageInfo.fromPlatform();
95-
set<String>(keyAppName, packageInfo.appName);
96-
set<String>(keyAppVersion, packageInfo.version);
97-
set<String>(keyAppIdentifier, packageInfo.packageName);
94+
if (!kIsWeb) {
95+
final PackageInfo packageInfo = await PackageInfo.fromPlatform();
96+
set<String>(keyAppName, packageInfo.appName);
97+
set<String>(keyAppVersion, packageInfo.version);
98+
set<String>(keyAppIdentifier, packageInfo.packageName);
99+
}
98100
set<String>(keyParseVersion, keySdkVersion);
99101
}
100102

0 commit comments

Comments
 (0)