@@ -104,7 +104,10 @@ export * from '{{url}}'
104104
105105 Bridge::Bridge (
106106 const Options& options
107- ) : window::IBridge(options.dispatcher, options.context, options.client, options.userConfig)
107+ ) : window::IBridge(options.dispatcher, options.context, options.client, options.userConfig),
108+ schemeHandlers (*this ),
109+ navigator(*this ),
110+ router(*this )
108111 {
109112 // '-1' may mean the bridge is running as a WebKit web process extension
110113 if (options.client .index >= 0 ) {
@@ -137,13 +140,15 @@ export * from '{{url}}'
137140 }
138141
139142 Bridge::~Bridge () {
140- auto & runtime = static_cast <runtime::Runtime&>(this ->context );
141- // remove observers
142- runtime.services .geolocation .removePermissionChangeObserver (this ->geolocationPermissionChangeObserver );
143- runtime.services .networkStatus .removeObserver (this ->networkStatusObserver );
144- runtime.services .notifications .removePermissionChangeObserver (this ->notificationsPermissionChangeObserver );
145- runtime.services .notifications .removeNotificationResponseObserver (this ->notificationResponseObserver );
146- runtime.services .notifications .removeNotificationPresentedObserver (this ->notificationPresentedObserver );
143+ auto app = App::sharedApplication ();
144+ if (app && !app->shouldExit ) {
145+ // remove observers
146+ app->runtime .services .geolocation .removePermissionChangeObserver (this ->geolocationPermissionChangeObserver );
147+ app->runtime .services .networkStatus .removeObserver (this ->networkStatusObserver );
148+ app->runtime .services .notifications .removePermissionChangeObserver (this ->notificationsPermissionChangeObserver );
149+ app->runtime .services .notifications .removeNotificationResponseObserver (this ->notificationResponseObserver );
150+ app->runtime .services .notifications .removeNotificationPresentedObserver (this ->notificationPresentedObserver );
151+ }
147152 }
148153
149154 void Bridge::init () {
@@ -292,7 +297,7 @@ export * from '{{url}}'
292297 this ->schemeHandlers .configure (configuration);
293298 this ->schemeHandlers .registerSchemeHandler (" ipc" , [this ](
294299 const auto request,
295- const auto bridge,
300+ const auto & bridge,
296301 auto callbacks,
297302 auto callback
298303 ) {
@@ -407,7 +412,7 @@ export * from '{{url}}'
407412
408413 this ->schemeHandlers .registerSchemeHandler (" socket" , [this ](
409414 const auto request,
410- const auto bridge,
415+ const auto & bridge,
411416 auto callbacks,
412417 auto callback
413418 ) {
@@ -416,9 +421,7 @@ export * from '{{url}}'
416421 auto userConfig = this ->userConfig ;
417422 auto bundleIdentifier = userConfig[" meta_bundle_identifier" ];
418423 auto globalBundleIdentifier = globalConfig[" meta_bundle_identifier" ];
419- auto window = app->runtime .windowManager .getWindowForBridge (
420- reinterpret_cast <const window::IBridge*>(bridge)
421- );
424+ auto window = app->runtime .windowManager .getWindowForBridge (&bridge);
422425
423426 // if there was no window, then this is a bad request as scheme
424427 // handlers should only be handled directly in a window with
@@ -832,7 +835,7 @@ export * from '{{url}}'
832835
833836 this ->schemeHandlers .registerSchemeHandler (" node" , [this ](
834837 const auto request,
835- const auto router ,
838+ const auto & bridge ,
836839 auto callbacks,
837840 auto callback
838841 ) {
@@ -1001,8 +1004,7 @@ export * from '{{url}}'
10011004 if (
10021005 globalUserConfig[" meta_bundle_identifier" ] == this ->userConfig [" meta_bundle_identifier" ] ||
10031006 !globalProtocolHandlers.contains (scheme)
1004- ) {
1005-
1007+ ) {
10061008 auto scriptURL = trim (entry.second );
10071009
10081010 if (scriptURL.size () == 0 ) {
@@ -1084,14 +1086,12 @@ export * from '{{url}}'
10841086
10851087 this ->schemeHandlers .registerSchemeHandler (scheme, [this ](
10861088 auto request,
1087- auto bridge,
1089+ const auto & bridge,
10881090 auto callbacks,
10891091 auto callback
10901092 ) {
10911093 auto app = App::sharedApplication ();
1092- auto window = app->runtime .windowManager .getWindowForBridge (
1093- reinterpret_cast <const window::IBridge*>(bridge)
1094- );
1094+ auto window = app->runtime .windowManager .getWindowForBridge (&bridge);
10951095
10961096 auto fetch = serviceworker::Request ();
10971097 SharedPointer<serviceworker::Server> serviceWorkerServer = nullptr ;
0 commit comments