Skip to content

Commit

Permalink
Merge branch 'main' into ni/sync-timeout-options
Browse files Browse the repository at this point in the history
  • Loading branch information
nirinchev authored Aug 2, 2024
2 parents ceb3aba + 25deb78 commit 367f5a4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Fixed
* Fixed an issue where creating a flexible sync configuration with an embedded object not referenced by any top-level object would throw a "No such table" exception with no meaningful information about the issue. Now a `RealmException` will be thrown that includes the offending object name, as well as more precise text for what the root cause of the error is. (PR [#1748](https://github.com/realm/realm-dart/pull/1748))
* `AppConfiguration.maxConnectionTimeout` never had any effect and has been deprecated in favor of `SyncTimeoutOptions.connectTimeout`. (PR [#1764](https://github.com/realm/realm-dart/pull/1764))
* Pure dart apps, when compiled to an exe and run from outside the project directory would fail to load the native shared library. (Issue [#1765](https://github.com/realm/realm-dart/issues/1765))

### Compatibility
* Realm Studio: 15.0.0 or later.
Expand Down
28 changes: 15 additions & 13 deletions packages/realm_dart/lib/src/handles/native/init.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ String _getLibPathDart(Package realmDartPackage) {
_platformNotSupported();
}


String _getLibName(String stem) => switch (targetOsType) {
TargetOsType.android => 'lib$stem.so',
TargetOsType.ios => stem, // xcframeworks are a directory
Expand All @@ -69,13 +68,13 @@ String? _getNearestProjectRoot(String dir) {
return null;
}

File _getPackageConfigJson(Directory d) {
File? _getPackageConfigJson(Directory d) {
final root = _getNearestProjectRoot(d.path);
if (root != null) {
final file = File(p.join(root, '.dart_tool', 'package_config.json'));
if (file.existsSync()) return file;
}
throw StateError('Could not find package_config.json');
return null;
}

Never _platformNotSupported() => throw UnsupportedError('Platform ${Platform.operatingSystem} is not supported');
Expand Down Expand Up @@ -107,25 +106,28 @@ DynamicLibrary _openRealmLib() {

final isFlutterTest = Platform.environment.containsKey('FLUTTER_TEST');
if (isFlutterPlatform && !isFlutterTest) {
return open(_getLibPathFlutter());
return open(_getLibPathFlutter()); // flutter app
}

// NOTE: This needs to be sync, so we cannot use findPackageConfig
final packageConfigFile = _getPackageConfigJson(Directory.current);
final packageConfig = PackageConfig.parseBytes(packageConfigFile.readAsBytesSync(), packageConfigFile.uri);

if (isFlutterTest) {
final realmPackage = packageConfig['realm']!;
return open(_getLibPathFlutterTest(realmPackage));
if (packageConfigFile != null) {
// inside a project
final packageConfig = PackageConfig.parseBytes(packageConfigFile.readAsBytesSync(), packageConfigFile.uri);
if (isFlutterTest) {
// running flutter test (not flutter test integration_test or flutter drive)
final realmPackage = packageConfig['realm']!;
return open(_getLibPathFlutterTest(realmPackage));
}
// plain dart
final realmDartPackage = packageConfig['realm_dart']!;
return open(_getLibPathDart(realmDartPackage));
}

final realmDartPackage = packageConfig['realm_dart']!;

// else plain dart
// plain dart (compiled or interpreted)
final candidatePaths = [
nativeLibraryName, // just ask OS..
p.join(_exeDirName, nativeLibraryName), // try finding it next to the executable
_getLibPathDart(realmDartPackage), // try finding it in the package
];
DynamicLibrary? lib;
for (final path in candidatePaths) {
Expand Down

0 comments on commit 367f5a4

Please sign in to comment.