Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
e48446af
Unverified
Commit
e48446af
authored
Oct 30, 2020
by
George Wright
Committed by
GitHub
Oct 30, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Send command line arguments through to the Flutter Engine on Windows (#68931)
parent
678f3cb4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
0 deletions
+59
-0
main.cpp.tmpl
...ter_tools/templates/app/windows.tmpl/runner/main.cpp.tmpl
+6
-0
utils.cpp
...flutter_tools/templates/app/windows.tmpl/runner/utils.cpp
+42
-0
utils.h
...s/flutter_tools/templates/app/windows.tmpl/runner/utils.h
+11
-0
No files found.
packages/flutter_tools/templates/app/windows.tmpl/runner/main.cpp.tmpl
View file @
e48446af
...
@@ -21,6 +21,12 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
...
@@ -21,6 +21,12 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
RunLoop run_loop;
RunLoop run_loop;
flutter::DartProject project(L"data");
flutter::DartProject project(L"data");
std::vector<std::string> command_line_arguments =
GetCommandLineArguments();
project.set_dart_entrypoint_arguments(std::move(command_line_arguments));
FlutterWindow window(&run_loop, project);
FlutterWindow window(&run_loop, project);
Win32Window::Point origin(10, 10);
Win32Window::Point origin(10, 10);
Win32Window::Size size(1280, 720);
Win32Window::Size size(1280, 720);
...
...
packages/flutter_tools/templates/app/windows.tmpl/runner/utils.cpp
View file @
e48446af
...
@@ -20,3 +20,45 @@ void CreateAndAttachConsole() {
...
@@ -20,3 +20,45 @@ void CreateAndAttachConsole() {
FlutterDesktopResyncOutputStreams
();
FlutterDesktopResyncOutputStreams
();
}
}
}
}
std
::
vector
<
std
::
string
>
GetCommandLineArguments
()
{
// Convert the UTF-16 command line arguments to UTF-8 for the Engine to use.
int
argc
;
wchar_t
**
argv
=
::
CommandLineToArgvW
(
::
GetCommandLineW
(),
&
argc
);
if
(
argv
==
nullptr
)
{
return
std
::
vector
<
std
::
string
>
();
}
std
::
vector
<
std
::
string
>
command_line_arguments
;
// Skip the first argument as it's the binary name.
for
(
int
i
=
1
;
i
<
argc
;
i
++
)
{
command_line_arguments
.
push_back
(
Utf8FromUtf16
(
argv
[
i
]));
}
::
LocalFree
(
argv
);
return
command_line_arguments
;
}
std
::
string
Utf8FromUtf16
(
const
wchar_t
*
utf16_string
)
{
if
(
utf16_string
==
nullptr
)
{
return
std
::
string
();
}
int
target_length
=
::
WideCharToMultiByte
(
CP_UTF8
,
WC_ERR_INVALID_CHARS
,
utf16_string
,
-
1
,
nullptr
,
0
,
nullptr
,
nullptr
);
if
(
target_length
==
0
)
{
return
std
::
string
();
}
std
::
string
utf8_string
;
utf8_string
.
resize
(
target_length
);
int
converted_length
=
::
WideCharToMultiByte
(
CP_UTF8
,
WC_ERR_INVALID_CHARS
,
utf16_string
,
-
1
,
utf8_string
.
data
(),
target_length
,
nullptr
,
nullptr
);
if
(
converted_length
==
0
)
{
return
std
::
string
();
}
return
utf8_string
;
}
packages/flutter_tools/templates/app/windows.tmpl/runner/utils.h
View file @
e48446af
#ifndef RUNNER_UTILS_H_
#ifndef RUNNER_UTILS_H_
#define RUNNER_UTILS_H_
#define RUNNER_UTILS_H_
#include <string>
#include <vector>
// Creates a console for the process, and redirects stdout and stderr to
// Creates a console for the process, and redirects stdout and stderr to
// it for both the runner and the Flutter library.
// it for both the runner and the Flutter library.
void
CreateAndAttachConsole
();
void
CreateAndAttachConsole
();
// Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string
// encoded in UTF-8. Returns an empty std::string on failure.
std
::
string
Utf8FromUtf16
(
const
wchar_t
*
utf16_string
);
// Gets the command line arguments passed in as a std::vector<std::string>,
// encoded in UTF-8. Returns an empty std::vector<std::string> on failure.
std
::
vector
<
std
::
string
>
GetCommandLineArguments
();
#endif // RUNNER_UTILS_H_
#endif // RUNNER_UTILS_H_
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment