@@ -597,13 +597,12 @@ export * from '{{url}}'
597597 });
598598
599599 if (fetched) {
600- // FIXME(@jwerle): revisit timeout
601- // this->core->setTimeout(32000, [request] () mutable {
602- // if (request->isActive()) {
603- // auto response = SchemeHandlers::Response(request, 408);
604- // response.fail("ServiceWorker request timed out.");
605- // }
606- // });
600+ this ->getRuntime ()->services .timers .setTimeout (32000 , [request] () mutable {
601+ if (request->isActive ()) {
602+ auto response = SchemeHandlers::Response (request, 408 );
603+ response.fail (" ServiceWorker request timed out." );
604+ }
605+ });
607606 return ;
608607 }
609608 }
@@ -739,13 +738,12 @@ export * from '{{url}}'
739738 });
740739
741740 if (fetched) {
742- // FIXME(@jwerle): revisit timeout
743- // this->core->setTimeout(32000, [request] () mutable {
744- // if (request->isActive()) {
745- // auto response = SchemeHandlers::Response(request, 408);
746- // response.fail("ServiceWorker request timed out.");
747- // }
748- // });
741+ this ->getRuntime ()->services .timers .setTimeout (32000 , [request] () mutable {
742+ if (request->isActive ()) {
743+ auto response = SchemeHandlers::Response (request, 408 );
744+ response.fail (" ServiceWorker request timed out." );
745+ }
746+ });
749747 return ;
750748 }
751749 }
@@ -779,23 +777,23 @@ export * from '{{url}}'
779777 auto resource = filesystem::Resource (resourcePath, { .cache = true });
780778
781779 if (resource.exists ()) {
782- const auto url = (
783- #if SOCKET_RUNTIME_PLATFORM_ANDROID
784- " https:// " +
785- #else
786- " socket:// " +
787- #endif
788- toLowerCase (bundleIdentifier) +
789- contentLocation +
790- (request-> query . size () > 0 ? " ? " + request->query : " " )
791- );
780+ auto url = URL ();
781+ #if SOCKET_RUNTIME_PLATFORM_ANDROID
782+ url. scheme = " https" ;
783+ #else
784+ url. scheme = " socket" ;
785+ #endif
786+ url. hostname = toLowerCase (bundleIdentifier);
787+ url. pathname = contentLocation;
788+ url. search = request->query ;
789+ debug ( " URL1: %s " , url. str (). c_str () );
792790
793791 const auto moduleImportProxy = tmpl (
794792 String (reinterpret_cast <const char *>(resource.read ())).find (" export default" ) != String::npos
795793 ? ESM_IMPORT_PROXY_TEMPLATE_WITH_DEFAULT_EXPORT
796794 : ESM_IMPORT_PROXY_TEMPLATE_WITHOUT_DEFAULT_EXPORT,
797795 Map<String, String> {
798- {" url" , url},
796+ {" url" , url. str () },
799797 {" commit" , version::VERSION_HASH_STRING},
800798 {" protocol" , " socket" },
801799 {" pathname" , pathname},
@@ -902,22 +900,22 @@ export * from '{{url}}'
902900 }
903901
904902 if (resource.exists ()) {
905- const auto url = (
906- #if SOCKET_RUNTIME_PLATFORM_ANDROID
907- " https:// " +
908- #else
909- " socket:// " +
910- #endif
911- toLowerCase (bundleIdentifier) +
912- " /socket" +
913- pathname
914- );
903+ auto url = URL ();
904+ #if SOCKET_RUNTIME_PLATFORM_ANDROID
905+ url. scheme = " https" ;
906+ #else
907+ url. scheme = " socket" ;
908+ #endif
909+ url. hostname = toLowerCase (bundleIdentifier);
910+ url. pathname = " /socket" + pathname;
911+ url. search = request-> query ;
912+ debug ( " URL2: %s " , url. str (). c_str () );
915913 const auto moduleImportProxy = tmpl (
916914 String (reinterpret_cast <const char *>(resource.read ())).find (" export default" ) != String::npos
917915 ? ESM_IMPORT_PROXY_TEMPLATE_WITH_DEFAULT_EXPORT
918916 : ESM_IMPORT_PROXY_TEMPLATE_WITHOUT_DEFAULT_EXPORT,
919917 Map<String, String> {
920- {" url" , url},
918+ {" url" , url. str () },
921919 {" commit" , version::VERSION_HASH_STRING},
922920 {" protocol" , " node" },
923921 {" pathname" , pathname},
@@ -949,10 +947,29 @@ export * from '{{url}}'
949947 callback (response);
950948 });
951949
950+ Set<String> globalProtocolHandlers = { " npm" };
952951 Map<String, String> protocolHandlers = {};
953952 auto globalUserConfig = getUserConfig ();
954- if (globalUserConfig[" meta_bundle_identifier" ] == this ->userConfig [" meta_bundle_identifier" ]) {
955- protocolHandlers.insert ({" npm" , " /socket/npm/service-worker.js" });
953+ protocolHandlers.insert ({" npm" , " /socket/npm/service-worker.js" });
954+
955+ for (const auto & entry : split (globalUserConfig[" webview_protocol-handlers" ], " " )) {
956+ const auto scheme = replace (trim (entry), " :" , " " );
957+ if (this ->navigator .serviceWorkerServer ->container .protocols .registerHandler (scheme)) {
958+ protocolHandlers.insert_or_assign (scheme, " " );
959+ globalProtocolHandlers.insert (scheme);
960+ }
961+ }
962+
963+ for (const auto & entry : globalUserConfig) {
964+ const auto & key = entry.first ;
965+ if (key.starts_with (" webview_protocol-handlers_" )) {
966+ const auto scheme = replace (replace (trim (key), " webview_protocol-handlers_" , " " ), " :" , " " );;
967+ const auto data = entry.second ;
968+ if (this ->navigator .serviceWorkerServer ->container .protocols .registerHandler (scheme, { data })) {
969+ protocolHandlers.insert_or_assign (scheme, data);
970+ globalProtocolHandlers.insert (scheme);
971+ }
972+ }
956973 }
957974
958975 for (const auto & entry : split (this ->userConfig [" webview_protocol-handlers" ], " " )) {
@@ -968,7 +985,6 @@ export * from '{{url}}'
968985 const auto scheme = replace (replace (trim (key), " webview_protocol-handlers_" , " " ), " :" , " " );;
969986 const auto data = entry.second ;
970987 if (this ->navigator .serviceWorkerServer ->container .protocols .registerHandler (scheme, { data })) {
971- debug (" protocol: %s %s" , scheme.c_str (), data.c_str ());
972988 protocolHandlers.insert_or_assign (scheme, data);
973989 }
974990 }
@@ -978,6 +994,12 @@ export * from '{{url}}'
978994 const auto & scheme = entry.first ;
979995 const auto id = rand64 ();
980996
997+ if (globalUserConfig[" meta_bundle_identifier" ] != this ->userConfig [" meta_bundle_identifier" ]) {
998+ if (globalProtocolHandlers.contains (scheme)) {
999+ continue ;
1000+ }
1001+ }
1002+
9811003 auto scriptURL = trim (entry.second );
9821004
9831005 if (scriptURL.size () == 0 ) {
@@ -1010,6 +1032,8 @@ export * from '{{url}}'
10101032 scriptURL
10111033 );
10121034
1035+ debug (" scriptURL: %s" , scriptURL.c_str ());
1036+
10131037 auto env = JSON::Object::Entries {};
10141038 for (const auto & entry : this ->userConfig ) {
10151039 if (entry.first .starts_with (" env_" )) {
@@ -1023,14 +1047,16 @@ export * from '{{url}}'
10231047 }
10241048
10251049 if (scheme == " npm" ) {
1026- this ->navigator .serviceWorkerServer ->container .registerServiceWorker ({
1027- .type = serviceworker::Registration::Options::Type::Module,
1028- .scriptURL = scriptURL,
1029- .scope = scope,
1030- .scheme = scheme,
1031- .serializedWorkerArgs = " " ,
1032- .id = id
1033- });
1050+ if (globalUserConfig[" meta_bundle_identifier" ] == this ->userConfig [" meta_bundle_identifier" ]) {
1051+ this ->navigator .serviceWorkerServer ->container .registerServiceWorker ({
1052+ .type = serviceworker::Registration::Options::Type::Module,
1053+ .scriptURL = scriptURL,
1054+ .scope = scope,
1055+ .scheme = scheme,
1056+ .serializedWorkerArgs = " " ,
1057+ .id = id
1058+ });
1059+ }
10341060 } else {
10351061 this ->navigator .serviceWorkerServer ->container .registerServiceWorker ({
10361062 .type = serviceworker::Registration::Options::Type::Module,
@@ -1045,9 +1071,9 @@ export * from '{{url}}'
10451071 {" headless" , this ->userConfig [" build_headless" ] == " true" },
10461072 {" config" , this ->userConfig },
10471073 {" conduit" , JSON::Object::Entries {
1048- {" port" , this ->context . getRuntime ()->services .conduit .port },
1049- {" hostname" , this ->context . getRuntime ()->services .conduit .hostname },
1050- {" sharedKey" , this ->context . getRuntime ()->services .conduit .sharedKey }
1074+ {" port" , this ->getRuntime ()->services .conduit .port },
1075+ {" hostname" , this ->getRuntime ()->services .conduit .hostname },
1076+ {" sharedKey" , this ->getRuntime ()->services .conduit .sharedKey }
10511077 }}
10521078 }).str ()),
10531079 .id = id
@@ -1248,7 +1274,7 @@ extern "C" {
12481274 return false ;
12491275 }
12501276
1251- const auto window = app->windowManager .getWindow (index);
1277+ const auto window = app->runtime . windowManager .getWindow (index);
12521278
12531279 if (!window) {
12541280 ANDROID_THROW (env, " Invalid window requested" );
0 commit comments