Skip to content

Commit

Permalink
Fix: the BackgroundIsolateBinaryMessenger initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Maksimka101 committed Aug 24, 2023
1 parent c213c16 commit 5511ef6
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 28 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 5.5

- Fix the `BackgroundIsolateBinaryMessenger` initialization.

## 0.5.4
- Upgrade to the flutter 3.13.0.

Expand Down
2 changes: 1 addition & 1 deletion example/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>9.0</string>
<string>11.0</string>
</dict>
</plist>
13 changes: 8 additions & 5 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -127,7 +127,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1430;
ORGANIZATIONNAME = "";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
Expand Down Expand Up @@ -171,10 +171,12 @@
/* Begin PBXShellScriptBuildPhase section */
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${TARGET_BUILD_DIR}/${INFOPLIST_PATH}",
);
name = "Thin Binary";
outputPaths = (
Expand All @@ -185,6 +187,7 @@
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down Expand Up @@ -272,7 +275,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down Expand Up @@ -350,7 +353,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -399,7 +402,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
4 changes: 4 additions & 0 deletions example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,9 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
4 changes: 2 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class _MyHomePageState extends State<MyHomePage> {
}

Future<void> _createAssetsIsolate() async {
final isolate = await Combine().spawn<String>(
final isolate = await Combine().spawn(
(context) {
final messenger = context.messenger;

Expand Down Expand Up @@ -170,7 +170,7 @@ class _MyHomePageState extends State<MyHomePage> {
title: const Text("Error from calculate fibonacci worker"),
subtitle: Text(_calculateFibonacciError.toString()),
),
]
],
],
),
);
Expand Down
2 changes: 1 addition & 1 deletion example/macos/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1430;
ORGANIZATIONNAME = "";
TargetAttributes = {
33CC10EC2044A3C60003C045 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.5.4"
version: "0.5.5"
cupertino_icons:
dependency: "direct main"
description:
Expand Down
2 changes: 0 additions & 2 deletions lib/src/bindings/isolate_bindings/isolate_binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'package:flutter/services.dart';

part 'absent_scheduler_binding.dart';
part 'mock_binary_messenger_service_binding.dart';
part 'mock_restoration_manager.dart';

class IsolateBinding extends BindingBase
with
Expand All @@ -20,5 +19,4 @@ class IsolateBinding extends BindingBase
ui.PlatformDispatcher get platformDispatcher {
throw UnimplementedError();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ mixin _MockBinaryMessengerServiceBinding on ServicesBinding {

@override
RestorationManager createRestorationManager() {
return _MockRestorationManager();
throw IsolateBindingInitializationFinished();
}
}

class IsolateBindingInitializationFinished {}

This file was deleted.

12 changes: 6 additions & 6 deletions lib/src/isolate_factory/native_isolate_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,20 @@ class NativeIsolateFactory extends IsolateFactory {
}

static void _runInIsolate<T>(_IsolateSetup<T> setup) {
final receivePort = ReceivePort();
final isolateMessenger = NativeInternalIsolateMessenger(
setup.sendPort,
receivePort.asBroadcastStream().cast<Object?>(),
);
final isolateToken = setup.isolateToken;
if (isolateToken != null) {
_lastUsedIsolateToken = isolateToken;
BackgroundIsolateBinaryMessenger.ensureInitialized(isolateToken);
}
final receivePort = ReceivePort();
final isolateMessenger = NativeInternalIsolateMessenger(
setup.sendPort,
receivePort.asBroadcastStream().cast<Object?>(),
);
IsolatedBinaryMessengerMiddleware(isolateMessenger).initialize();
try {
IsolateBinding();
} catch (_) {} // Isolate binding should throw exception to skip unnecessary initialization.
} on IsolateBindingInitializationFinished catch (_) {} // Isolate binding will throw an exception to skip unnecessary initialization.

final isolateContext = IsolateContext(
argument: setup.argument,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: combine
description: A Flutter package which allows you to work with
MethodChannels in Isolate and provides simplified Isolate and Thread Pool API.
version: 0.5.4
version: 0.5.5
homepage: https://github.com/Maksimka101/combine
repository: https://github.com/Maksimka101/combine

Expand Down

0 comments on commit 5511ef6

Please sign in to comment.