|
4 | 4 |
|
5 | 5 | part of engine; |
6 | 6 |
|
| 7 | +typedef _HandleMessageCallBack = Future<bool> Function(); |
| 8 | + |
7 | 9 | /// When set to true, all platform messages will be printed to the console. |
8 | 10 | const bool /*!*/ _debugPrintPlatformMessages = false; |
9 | 11 |
|
@@ -112,32 +114,50 @@ class EngineFlutterWindow extends ui.SingletonFlutterWindow { |
112 | 114 | _customUrlStrategy = null; |
113 | 115 | } |
114 | 116 |
|
115 | | - Future<bool> handleNavigationMessage(ByteData? data) async { |
116 | | - final MethodCall decoded = JSONMethodCodec().decodeMethodCall(data); |
117 | | - final Map<String, dynamic>? arguments = decoded.arguments; |
118 | | - switch (decoded.method) { |
119 | | - case 'selectMultiEntryHistory': |
120 | | - await _useMultiEntryBrowserHistory(); |
121 | | - return true; |
122 | | - case 'selectSingleEntryHistory': |
123 | | - await _useSingleEntryBrowserHistory(); |
124 | | - return true; |
125 | | - // the following cases assert that arguments are not null |
126 | | - case 'routeUpdated': // deprecated |
127 | | - assert(arguments != null); |
128 | | - await _useSingleEntryBrowserHistory(); |
129 | | - browserHistory.setRouteName(arguments!['routeName']); |
130 | | - return true; |
131 | | - case 'routeInformationUpdated': |
132 | | - assert(arguments != null); |
133 | | - browserHistory.setRouteName( |
134 | | - arguments!['location'], |
135 | | - state: arguments['state'], |
136 | | - replace: arguments['replace'] ?? false, |
137 | | - ); |
138 | | - return true; |
| 117 | + Future<void> _endOfTheLine = Future<void>.value(null); |
| 118 | + |
| 119 | + Future<bool> _waitInTheLine(_HandleMessageCallBack callback) async { |
| 120 | + final Future<void> currentPosition = _endOfTheLine; |
| 121 | + final Completer<void> completer = Completer<void>(); |
| 122 | + _endOfTheLine = completer.future; |
| 123 | + await currentPosition; |
| 124 | + bool result = false; |
| 125 | + try { |
| 126 | + result = await callback(); |
| 127 | + } finally { |
| 128 | + completer.complete(); |
139 | 129 | } |
140 | | - return false; |
| 130 | + return result; |
| 131 | + } |
| 132 | + |
| 133 | + Future<bool> handleNavigationMessage(ByteData? data) async { |
| 134 | + return _waitInTheLine(() async { |
| 135 | + final MethodCall decoded = JSONMethodCodec().decodeMethodCall(data); |
| 136 | + final Map<String, dynamic>? arguments = decoded.arguments; |
| 137 | + switch (decoded.method) { |
| 138 | + case 'selectMultiEntryHistory': |
| 139 | + await _useMultiEntryBrowserHistory(); |
| 140 | + return true; |
| 141 | + case 'selectSingleEntryHistory': |
| 142 | + await _useSingleEntryBrowserHistory(); |
| 143 | + return true; |
| 144 | + // the following cases assert that arguments are not null |
| 145 | + case 'routeUpdated': // deprecated |
| 146 | + assert(arguments != null); |
| 147 | + await _useSingleEntryBrowserHistory(); |
| 148 | + browserHistory.setRouteName(arguments!['routeName']); |
| 149 | + return true; |
| 150 | + case 'routeInformationUpdated': |
| 151 | + assert(arguments != null); |
| 152 | + browserHistory.setRouteName( |
| 153 | + arguments!['location'], |
| 154 | + state: arguments['state'], |
| 155 | + replace: arguments['replace'] ?? false, |
| 156 | + ); |
| 157 | + return true; |
| 158 | + } |
| 159 | + return false; |
| 160 | + }); |
141 | 161 | } |
142 | 162 |
|
143 | 163 | @override |
|
0 commit comments