3
3
// This must be included before many other Windows headers.
4
4
#include < windows.h>
5
5
6
- // For getPlatformVersion; remove unless needed for your plugin implementation.
7
- #include < VersionHelpers.h>
8
-
9
6
#include < flutter/method_channel.h>
10
7
#include < flutter/plugin_registrar_windows.h>
11
8
#include < flutter/standard_method_codec.h>
@@ -29,6 +26,8 @@ class ProtocolHandlerPlugin : public flutter::Plugin {
29
26
return channel_.get ();
30
27
}
31
28
29
+ std::string ProtocolHandlerPlugin::GetInitialUrl ();
30
+
32
31
virtual ~ProtocolHandlerPlugin ();
33
32
34
33
private:
@@ -102,20 +101,25 @@ std::optional<LRESULT> ProtocolHandlerPlugin::HandleWindowProc(HWND hwnd,
102
101
return std::nullopt;
103
102
}
104
103
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
+
105
117
void ProtocolHandlerPlugin::HandleMethodCall (
106
118
const flutter::MethodCall<flutter::EncodableValue>& method_call,
107
119
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 ()));
119
123
} else {
120
124
result->NotImplemented ();
121
125
}
0 commit comments