Skip to content

Commit

Permalink
only call method cahnnel on native platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
denrase committed Dec 19, 2022
1 parent a1335fd commit f181dc0
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 16 deletions.
5 changes: 5 additions & 0 deletions flutter/ios/Classes/SentryFlutterPluginApple.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ public class SentryFlutterPluginApple: NSObject, FlutterPlugin {
let value = arguments?["value"] as? Any
setContexts(key: key, value: value, result: result)

case "removeContexts":
let arguments = call.arguments as? [String: Any?]
let key = arguments?["key"] as? String
removeContexts(key: key, result: result)

case "setUser":
let arguments = call.arguments as? [String: Any?]
let user = arguments?["user"] as? [String: Any?]
Expand Down
6 changes: 4 additions & 2 deletions flutter/lib/src/sentry_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ mixin SentryFlutter {
}

final nativeChannel = SentryNativeChannel(channel, flutterOptions);
final native = SentryNative();
native.setNativeChannel(nativeChannel);
if (flutterOptions.platformChecker.hasNativeIntegration) {
final native = SentryNative();
native.nativeChannel = nativeChannel;
}

final platformDispatcher = PlatformDispatcher.instance;
final wrapper = PlatformDispatcherWrapper(platformDispatcher);
Expand Down
4 changes: 3 additions & 1 deletion flutter/lib/src/sentry_native.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ class SentryNative {
return _instance;
}

SentryNativeChannel? get nativeChannel => _instance._nativeChannel;

/// Provide [nativeChannel] for native communication.
void setNativeChannel(SentryNativeChannel nativeChannel) {
set nativeChannel(SentryNativeChannel? nativeChannel) {
_instance._nativeChannel = nativeChannel;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class Fixture {
late final native = SentryNative();

Fixture() {
native.setNativeChannel(wrapper);
native.nativeChannel = wrapper;
native.reset();
when(hub.options).thenReturn(options);
}
Expand Down
26 changes: 17 additions & 9 deletions flutter/test/mocks.mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,14 @@ class MockSentryTracer extends _i1.Mock implements _i8.SentryTracer {
),
returnValueForMissingStub: null,
);
@override
void scheduleFinish() => super.noSuchMethod(
Invocation.method(
#scheduleFinish,
[],
),
returnValueForMissingStub: null,
);
}

/// A class which mocks [MethodChannel].
Expand Down Expand Up @@ -496,20 +504,20 @@ class MockSentryNative extends _i1.Mock implements _i10.SentryNative {
returnValueForMissingStub: null,
);
@override
bool get didFetchAppStart => (super.noSuchMethod(
Invocation.getter(#didFetchAppStart),
returnValue: false,
) as bool);
@override
void setNativeChannel(_i11.SentryNativeChannel? nativeChannel) =>
set nativeChannel(_i11.SentryNativeChannel? nativeChannel) =>
super.noSuchMethod(
Invocation.method(
#setNativeChannel,
[nativeChannel],
Invocation.setter(
#nativeChannel,
nativeChannel,
),
returnValueForMissingStub: null,
);
@override
bool get didFetchAppStart => (super.noSuchMethod(
Invocation.getter(#didFetchAppStart),
returnValue: false,
) as bool);
@override
_i6.Future<_i11.NativeAppStart?> fetchNativeAppStart() => (super.noSuchMethod(
Invocation.method(
#fetchNativeAppStart,
Expand Down
16 changes: 16 additions & 0 deletions flutter/test/sentry_flutter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:sentry_flutter/src/integrations/integrations.dart';
import 'package:sentry_flutter/src/integrations/screenshot_integration.dart';
import 'package:sentry_flutter/src/renderer/renderer.dart';
import 'package:sentry_flutter/src/sentry_native.dart';
import 'package:sentry_flutter/src/version.dart';
import 'mocks.dart';
import 'mocks.mocks.dart';
Expand Down Expand Up @@ -46,6 +47,9 @@ void main() {
group('Test platform integrations', () {
setUp(() async {
await Sentry.close();
final sentryNative = SentryNative();
sentryNative.nativeChannel = null;
sentryNative.reset();
});

test('Android', () async {
Expand Down Expand Up @@ -86,6 +90,8 @@ void main() {
beforeIntegration: WidgetsFlutterBindingIntegration,
afterIntegration: OnErrorIntegration);

expect(SentryNative().nativeChannel, isNotNull);

await Sentry.close();
}, testOn: 'vm');

Expand Down Expand Up @@ -125,6 +131,8 @@ void main() {
beforeIntegration: WidgetsFlutterBindingIntegration,
afterIntegration: OnErrorIntegration);

expect(SentryNative().nativeChannel, isNotNull);

await Sentry.close();
}, testOn: 'vm');

Expand Down Expand Up @@ -164,6 +172,8 @@ void main() {
beforeIntegration: WidgetsFlutterBindingIntegration,
afterIntegration: OnErrorIntegration);

expect(SentryNative().nativeChannel, isNotNull);

await Sentry.close();
}, testOn: 'vm');

Expand Down Expand Up @@ -205,6 +215,8 @@ void main() {
beforeIntegration: WidgetsFlutterBindingIntegration,
afterIntegration: OnErrorIntegration);

expect(SentryNative().nativeChannel, isNull);

await Sentry.close();
}, testOn: 'vm');

Expand Down Expand Up @@ -246,6 +258,8 @@ void main() {
beforeIntegration: WidgetsFlutterBindingIntegration,
afterIntegration: OnErrorIntegration);

expect(SentryNative().nativeChannel, isNull);

await Sentry.close();
}, testOn: 'vm');

Expand Down Expand Up @@ -288,6 +302,8 @@ void main() {
beforeIntegration: RunZonedGuardedIntegration,
afterIntegration: WidgetsFlutterBindingIntegration);

expect(SentryNative().nativeChannel, isNull);

await Sentry.close();
});

Expand Down
2 changes: 1 addition & 1 deletion flutter/test/sentry_native_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class Fixture {

SentryNative getSut() {
final sut = SentryNative();
sut.setNativeChannel(channel);
sut.nativeChannel = channel;
return sut;
}
}
4 changes: 2 additions & 2 deletions flutter/test/sentry_navigator_observer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void main() {
final mockHub = _MockHub();
final native = SentryNative();
final mockNativeChannel = MockNativeChannel();
native.setNativeChannel(mockNativeChannel);
native.nativeChannel = mockNativeChannel;

final tracer = getMockSentryTracer();
_whenAnyStart(mockHub, tracer);
Expand All @@ -75,7 +75,7 @@ void main() {
mockNativeChannel.nativeFrames = nativeFrames;

final mockNative = SentryNative();
mockNative.setNativeChannel(mockNativeChannel);
mockNative.nativeChannel = mockNativeChannel;

final sut = fixture.getSut(
hub: hub,
Expand Down

0 comments on commit f181dc0

Please sign in to comment.