33// This must be included before many other Windows headers.
44#include < windows.h>
55
6- // For getPlatformVersion; remove unless needed for your plugin implementation.
7- #include < VersionHelpers.h>
8-
96#include < flutter/method_channel.h>
107#include < flutter/plugin_registrar_windows.h>
118#include < flutter/standard_method_codec.h>
@@ -29,6 +26,8 @@ class ProtocolHandlerPlugin : public flutter::Plugin {
2926 return channel_.get ();
3027 }
3128
29+ std::string ProtocolHandlerPlugin::GetInitialUrl ();
30+
3231 virtual ~ProtocolHandlerPlugin ();
3332
3433 private:
@@ -102,20 +101,25 @@ std::optional<LRESULT> ProtocolHandlerPlugin::HandleWindowProc(HWND hwnd,
102101 return std::nullopt ;
103102}
104103
104+ std::string ProtocolHandlerPlugin::GetInitialUrl () {
105+ int argc;
106+ wchar_t ** argv = ::CommandLineToArgvW (::GetCommandLineW (), &argc);
107+ if (argv == nullptr || argc < 2 ) {
108+ return " " ;
109+ }
110+
111+ std::wstring_convert<std::codecvt_utf8_utf16<wchar_t >> converter;
112+ std::string url = converter.to_bytes (argv[1 ]);
113+ ::LocalFree (argv);
114+ return url;
115+ }
116+
105117void ProtocolHandlerPlugin::HandleMethodCall (
106118 const flutter::MethodCall<flutter::EncodableValue>& method_call,
107119 std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
108- if (method_call.method_name ().compare (" getPlatformVersion" ) == 0 ) {
109- std::ostringstream version_stream;
110- version_stream << " Windows " ;
111- if (IsWindows10OrGreater ()) {
112- version_stream << " 10+" ;
113- } else if (IsWindows8OrGreater ()) {
114- version_stream << " 8" ;
115- } else if (IsWindows7OrGreater ()) {
116- version_stream << " 7" ;
117- }
118- result->Success (flutter::EncodableValue (version_stream.str ()));
120+ if (method_call.method_name ().compare (" getInitialUrl" ) == 0 ) {
121+ std::string value = GetInitialUrl ();
122+ result->Success (flutter::EncodableValue (value.c_str ()));
119123 } else {
120124 result->NotImplemented ();
121125 }
0 commit comments