Skip to content

Commit ebd5319

Browse files
authored
Merge pull request #159 from manunite/feature/browserId_inject_script
fix: Modified to manage scripts injected per browser ID
2 parents 16c4b25 + a6607ed commit ebd5319

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/src/webview_manager.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ class WebviewManager extends ValueNotifier<bool> {
1717
final MethodChannel pluginChannel = const MethodChannel("webview_cef");
1818

1919
final Map<int, WebViewController> _webViews = <int, WebViewController>{};
20+
final Map<int, InjectUserScripts?> _injectUserScripts = <int, InjectUserScripts>{};
2021

2122
final Map<int, WebViewController> _tempWebViews = <int, WebViewController>{};
22-
InjectUserScripts? _injectUserScripts = InjectUserScripts();
23+
final Map<int, InjectUserScripts?> _tempInjectUserScripts = <int, InjectUserScripts>{};
2324

2425
int nextIndex = 1;
2526

@@ -33,7 +34,7 @@ class WebviewManager extends ValueNotifier<bool> {
3334
final controller =
3435
WebViewController(pluginChannel, browserIndex, loading: loading);
3536
_tempWebViews[browserIndex] = controller;
36-
_injectUserScripts = injectUserScripts;
37+
_tempInjectUserScripts[browserIndex] = injectUserScripts;
3738

3839
return controller;
3940
}
@@ -74,7 +75,10 @@ class WebviewManager extends ValueNotifier<bool> {
7475

7576
void onBrowserCreated(int browserIndex, int browserId) {
7677
_webViews[browserId] = _tempWebViews[browserIndex]!;
78+
_injectUserScripts[browserId] = _tempInjectUserScripts[browserIndex];
79+
7780
_tempWebViews.remove(browserIndex);
81+
_tempInjectUserScripts.remove(browserIndex);
7882
}
7983

8084
Future<void> methodCallhandler(MethodCall call) async {
@@ -134,7 +138,7 @@ class WebviewManager extends ValueNotifier<bool> {
134138
int browserId = call.arguments["browserId"] as int;
135139
String urlId = call.arguments["urlId"] as String;
136140

137-
await _injectUserScriptIfNeeds(browserId, _injectUserScripts?.retrieveLoadStartInjectScripts() ?? []);
141+
await _injectUserScriptIfNeeds(browserId, _injectUserScripts[browserId]?.retrieveLoadStartInjectScripts() ?? []);
138142

139143
WebViewController controller =
140144
_webViews[browserId] as WebViewController;
@@ -144,7 +148,7 @@ class WebviewManager extends ValueNotifier<bool> {
144148
int browserId = call.arguments["browserId"] as int;
145149
String urlId = call.arguments["urlId"] as String;
146150

147-
await _injectUserScriptIfNeeds(browserId, _injectUserScripts?.retrieveLoadEndInjectScripts() ?? []);
151+
await _injectUserScriptIfNeeds(browserId, _injectUserScripts[browserId]?.retrieveLoadEndInjectScripts() ?? []);
148152

149153
WebViewController controller =
150154
_webViews[browserId] as WebViewController;

0 commit comments

Comments
 (0)