Skip to content

Commit

Permalink
bindings/dart: Do not set NativeChannels.session implicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
madadam committed Feb 7, 2024
1 parent 7dc9b45 commit f1d5f08
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 19 deletions.
14 changes: 3 additions & 11 deletions bindings/dart/lib/native_channels.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,12 @@ class NativeChannels {
// Cache of open files.
static final _files = FileCache();

/// Provides the Session instance, to be used in file operations.
/// [session] is the instance used in the OuiSync app for accessing the repository.
///
/// This methoid also sets the method handler for the calls
/// to and from native implementations.
/// Initializes the native channels.
///
/// Important: This method needs to be called when the app starts
/// to guarantee the callbacks to the native methods works as expected.
static void init({Repository? repository}) {
static void init() {
_channel.setMethodCallHandler(_methodHandler);

if (repository != null) {
_repository = repository;
}
}

/// Replaces the current [repository] instance with a new one.
Expand All @@ -76,7 +68,7 @@ class NativeChannels {
/// required operation.
///
/// [repository] is the current repository in the app.
static void setRepository(Repository? repository) {
static set repository(Repository? repository) {
for (var file in _files.removeAll()) {
file.close();
}
Expand Down
9 changes: 1 addition & 8 deletions bindings/dart/lib/ouisync_plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export 'bindings.dart'
PeerSource,
PeerStateKind,
SessionKind;
export 'native_channels.dart' show NativeChannels;

const bool debugTrace = false;

Expand All @@ -35,9 +34,7 @@ class Session {
String? _mountPoint;

Session._(this._client)
: _networkSubscription = Subscription(_client, "network", null) {
NativeChannels.session = this;
}
: _networkSubscription = Subscription(_client, "network", null);

/// Creates a new session in this process.
/// [configPath] is a path to a directory where configuration files shall be stored. If it
Expand Down Expand Up @@ -238,10 +235,6 @@ class Session {
return 0;
}

if (NativeChannels.session?._client.isClosed ?? false) {
NativeChannels.session = null;
}

return handle;
}
}
Expand Down

0 comments on commit f1d5f08

Please sign in to comment.