Commit ae70af1e by songyanzhi

feat:init

parent 9290ecd4
# EditorConfig is awesome:http://EditorConfig.org
# top-most EditorConfig file
root = true
# Don't use tabs for indentation.
[*]
indent_style = space
# (Please don't specify an indent_size here; that has too many unintended consequences.)
# Code files
[*.{cs,csx,vb,vbx}]
indent_size = 4
insert_final_newline = true
charset = utf-8-bom
# Xml project files
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}]
indent_size = 2
# Xml config files
[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}]
indent_size = 2
# JSON files
[*.json]
indent_size = 2
# Dotnet code style settings:
[*.{cs,vb}]
# Sort using and Import directives with System.* appearing first
dotnet_sort_system_directives_first = true
# Avoid "this." and "Me." if not necessary
dotnet_style_qualification_for_field = false:suggestion
dotnet_style_qualification_for_property = false:suggestion
dotnet_style_qualification_for_method = false:suggestion
dotnet_style_qualification_for_event = false:suggestion
# Use language keywords instead of framework type names for type references
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
dotnet_style_predefined_type_for_member_access = true:suggestion
# Suggest more modern language features when available
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion
# CSharp code style settings:
[*.cs]
# Prefer "var" everywhere
csharp_style_var_for_built_in_types = true:suggestion
csharp_style_var_when_type_is_apparent = true:suggestion
csharp_style_var_elsewhere = true:suggestion
# Prefer method-like constructs to have a block body
csharp_style_expression_bodied_methods = false:none
csharp_style_expression_bodied_constructors = false:none
csharp_style_expression_bodied_operators = false:none
# Prefer property-like constructs to have an expression-body
csharp_style_expression_bodied_properties = true:none
csharp_style_expression_bodied_indexers = true:none
csharp_style_expression_bodied_accessors = true:none
# Suggest more modern language features when available
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion
csharp_style_throw_expression = true:suggestion
csharp_style_conditional_delegate_call = true:suggestion
# Newline settings
csharp_new_line_before_open_brace = all
csharp_new_line_before_else = true
csharp_new_line_before_catch = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_members_in_anonymous_types = true
# This file is understood by git 1.7.2+.
# Windows specific files should always be crlf on checkout
*.bat text eol=crlf
*.cmd text eol=crlf
*.ps1 text eol=crlf
# Check out the following as ln always for osx/linux/cygwin
*.sh text eol=lf
# Opt in the following types to always normalize line endings
# on checkin and always use native endings on checkout.
*.config text
*.cs text diff=csharp
*.csproj text
*.md text
*.msbuild text
*.nuspec text
*.pp text
*.ps1 text
*.sln text
*.tt text
*.txt text
*.xaml text
*.xml text
# Binary files
*.bmp binary
*.jpeg binary
*.jpg binary
*.nupkg binary
*.png binary
*.sdf binary
*.java linguist-language=Dart
*.kt linguist-language=Dart
*.swift linguist-language=Dart
*.m linguist-language=Dart
*.h linguist-language=Dart
# Miscellaneous
*.class
*.lock
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.project
.svn/
bin/
migrate_working_dir/
# IntelliJ related
*.iml
*.ipr
*.iws
.idea/
# Android Studio related
android/.classpath
android/.settings/
# Visual Studio Code related
.vscode/
# Flutter repo-specific
/bin/cache/
/bin/mingit/
/dev/benchmarks/mega_gallery/
/dev/bots/.recipe_deps
/dev/bots/android_tools/
/dev/docs/doc/
/dev/docs/lib/
/dev/docs/pubspec.yaml
/packages/flutter/coverage/
version
# Flutter/Dart/Pub related
/pubspec.lock
**/doc/api/
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
build/
flutter_*.png
linked_*.ds
unlinked.ds
unlinked_spec.ds
flutter_export_environment.sh
# Android related
**/android/**/gradle-wrapper.jar
**/android/.gradle
**/android/captures/
**/android/gradlew
**/android/gradlew.bat
**/android/local.properties
**/android/**/GeneratedPluginRegistrant.java
# iOS/XCode related
**/ios/**/*.mode1v3
**/ios/**/*.mode2v3
**/ios/**/*.moved-aside
**/ios/**/*.pbxuser
**/ios/**/*.perspectivev3
**/ios/**/*sync/
**/ios/**/.sconsign.dblite
**/ios/**/.tags*
**/ios/**/.vagrant/
**/ios/**/DerivedData/
**/ios/**/Icon?
**/ios/**/Pods/
**/ios/**/.symlinks/
**/ios/**/profile
**/ios/**/xcuserdata
**/ios/.generated/
**/ios/Flutter/App.framework
**/ios/Flutter/Flutter.framework
**/ios/Flutter/Generated.xcconfig
**/ios/Flutter/app.flx
**/ios/Flutter/app.zip
**/ios/Flutter/flutter_assets/
**/ios/ServiceDefinitions.json
**/ios/Runner/GeneratedPluginRegistrant.*
# Exceptions to above rules.
!**/ios/**/default.mode1v3
!**/ios/**/default.mode2v3
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.
version:
revision: 06b979c4d5e1b499745422269f01a00341257058
channel: master
project_type: plugin
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to participate in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as physical or electronic
address, without explicit permission
* Other conduct that could reasonably be considered inappropriate in a
professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within and in public spaces
when an individual represents the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [hello@baseflow.com](mailto:hello@baseflow.com). All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
You can post more details of specific enforcement policies separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
Faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [http://contributor-covenant.org/version/1/4][version]
[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
# Contributing to the Flutter Permission handler plugin
## What you will need
* A Linux, Mac OS X, or Windows machine (note: to run and compile iOS-specific parts you'll need access to a Mac OS X machine);
* git (used for source version control, installation instructions can be found [here](https://git-scm.com/));
* The Flutter SDK (installation instructions can be found [here](https://flutter.io/get-started/install/));
* A personal GitHub account (if you don't have one, you can sign up for free [here](https://github.com/))
## Setting up your development environment
* Fork `https://github.com/Baseflow/flutter-permission-handler` into your own GitHub account. If you already have a fork and moving to a new computer, make sure you update your fork.
* If you haven't configured your machine with an SSH key that's known to GitHub, then
follow [GitHub's directions](https://help.github.com/articles/generating-ssh-keys/)
to generate an SSH key.
* Clone your forked repo on your local development machine: `git clone git@github.com:<your_name_here>/flutter-permission-handler.git`
* Change into the `flutter-permission-handler` directory: `cd flutter-permission-handler`
* Add an upstream to the original repo, so that fetches from the master repository and not your clone: `git remote add upstream git@github.com:Baseflow/flutter-permission-handler.git`
## Running the example project
* Change into the example directory: `cd example`
* Run the App: `flutter run`
## Contribute
We really appreciate contributions via GitHub pull requests. To contribute take the following steps:
* Make sure you are up to date with the latest code on the master:
* `git fetch upstream`
* `git checkout upstream/develop -b <name_of_your_branch>`
* Apply your changes
* Verify your changes and fix potential warnings/ errors:
* Check formatting: `flutter format .`
* Run static analyses: `flutter analyze`
* Run unit-tests: `flutter test`
* Commit your changes: `git commit -am "<your informative commit message>"`
* Push changes to your fork: `git push origin <name_of_your_branch>`
Send us your pull request:
* Go to `https://github.com/Baseflow/flutter-permission-handler` and click the "Compare & pull request" button.
Please make sure you solved all warnings and errors reported by the static code analyses and that you fill in the full pull request template. Failing to do so will result in us asking you to fix it.
MIT License MIT License
Copyright (c) 2020 Baseflow Copyright (c) 2018 Baseflow
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
......
include: package:flutter_lints/flutter.yaml
linter:
rules:
- public_member_api_docs
flutter/ephemeral/ flutter/ephemeral/
# Visual Studio user-specific files. # Visual Studio user-specific files.
*.suo *.suo
*.user *.user
*.userosscache *.userosscache
*.sln.docstates *.sln.docstates
# Visual Studio build-related files. # Visual Studio build-related files.
x64/ x64/
x86/ x86/
# Visual Studio cache files # Visual Studio cache files
# files ending in .cache can be ignored # files ending in .cache can be ignored
*.[Cc]ache *.[Cc]ache
# but keep track of directories ending in .cache # but keep track of directories ending in .cache
!*.[Cc]ache/ !*.[Cc]ache/
// Microsoft Visual C++ generated resource script. // Microsoft Visual C++ generated resource script.
// //
#pragma code_page(65001) #pragma code_page(65001)
#include "resource.h" #include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS #define APSTUDIO_READONLY_SYMBOLS
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// //
// Generated from the TEXTINCLUDE 2 resource. // Generated from the TEXTINCLUDE 2 resource.
// //
#include "winres.h" #include "winres.h"
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS #undef APSTUDIO_READONLY_SYMBOLS
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// English (United States) resources // English (United States) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#ifdef APSTUDIO_INVOKED #ifdef APSTUDIO_INVOKED
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// //
// TEXTINCLUDE // TEXTINCLUDE
// //
1 TEXTINCLUDE 1 TEXTINCLUDE
BEGIN BEGIN
"resource.h\0" "resource.h\0"
END END
2 TEXTINCLUDE 2 TEXTINCLUDE
BEGIN BEGIN
"#include ""winres.h""\r\n" "#include ""winres.h""\r\n"
"\0" "\0"
END END
3 TEXTINCLUDE 3 TEXTINCLUDE
BEGIN BEGIN
"\r\n" "\r\n"
"\0" "\0"
END END
#endif // APSTUDIO_INVOKED #endif // APSTUDIO_INVOKED
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// //
// Icon // Icon
// //
// Icon with lowest ID value placed first to ensure application icon // Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems. // remains consistent on all systems.
IDI_APP_ICON ICON "resources\\app_icon.ico" IDI_APP_ICON ICON "resources\\app_icon.ico"
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// //
// Version // Version
// //
#ifdef FLUTTER_BUILD_NUMBER #ifdef FLUTTER_BUILD_NUMBER
#define VERSION_AS_NUMBER FLUTTER_BUILD_NUMBER #define VERSION_AS_NUMBER FLUTTER_BUILD_NUMBER
#else #else
#define VERSION_AS_NUMBER 1,0,0 #define VERSION_AS_NUMBER 1,0,0
#endif #endif
#ifdef FLUTTER_BUILD_NAME #ifdef FLUTTER_BUILD_NAME
#define VERSION_AS_STRING #FLUTTER_BUILD_NAME #define VERSION_AS_STRING #FLUTTER_BUILD_NAME
#else #else
#define VERSION_AS_STRING "1.0.0" #define VERSION_AS_STRING "1.0.0"
#endif #endif
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION VERSION_AS_NUMBER FILEVERSION VERSION_AS_NUMBER
PRODUCTVERSION VERSION_AS_NUMBER PRODUCTVERSION VERSION_AS_NUMBER
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS VS_FF_DEBUG FILEFLAGS VS_FF_DEBUG
#else #else
FILEFLAGS 0x0L FILEFLAGS 0x0L
#endif #endif
FILEOS VOS__WINDOWS32 FILEOS VOS__WINDOWS32
FILETYPE VFT_APP FILETYPE VFT_APP
FILESUBTYPE 0x0L FILESUBTYPE 0x0L
BEGIN BEGIN
BLOCK "StringFileInfo" BLOCK "StringFileInfo"
BEGIN BEGIN
BLOCK "040904e4" BLOCK "040904e4"
BEGIN BEGIN
VALUE "CompanyName", "com.baseflow.permissionhandler" "\0" VALUE "CompanyName", "com.baseflow.permissionhandler" "\0"
VALUE "FileDescription", "example" "\0" VALUE "FileDescription", "example" "\0"
VALUE "FileVersion", VERSION_AS_STRING "\0" VALUE "FileVersion", VERSION_AS_STRING "\0"
VALUE "InternalName", "example" "\0" VALUE "InternalName", "example" "\0"
VALUE "LegalCopyright", "Copyright (C) 2022 com.baseflow.permissionhandler. All rights reserved." "\0" VALUE "LegalCopyright", "Copyright (C) 2022 com.baseflow.permissionhandler. All rights reserved." "\0"
VALUE "OriginalFilename", "example.exe" "\0" VALUE "OriginalFilename", "example.exe" "\0"
VALUE "ProductName", "example" "\0" VALUE "ProductName", "example" "\0"
VALUE "ProductVersion", VERSION_AS_STRING "\0" VALUE "ProductVersion", VERSION_AS_STRING "\0"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"
BEGIN BEGIN
VALUE "Translation", 0x409, 1252 VALUE "Translation", 0x409, 1252
END END
END END
#endif // English (United States) resources #endif // English (United States) resources
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED #ifndef APSTUDIO_INVOKED
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// //
// Generated from the TEXTINCLUDE 3 resource. // Generated from the TEXTINCLUDE 3 resource.
// //
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED #endif // not APSTUDIO_INVOKED
#include "flutter_window.h" #include "flutter_window.h"
#include <optional> #include <optional>
#include "flutter/generated_plugin_registrant.h" #include "flutter/generated_plugin_registrant.h"
FlutterWindow::FlutterWindow(const flutter::DartProject& project) FlutterWindow::FlutterWindow(const flutter::DartProject& project)
: project_(project) {} : project_(project) {}
FlutterWindow::~FlutterWindow() {} FlutterWindow::~FlutterWindow() {}
bool FlutterWindow::OnCreate() { bool FlutterWindow::OnCreate() {
if (!Win32Window::OnCreate()) { if (!Win32Window::OnCreate()) {
return false; return false;
} }
RECT frame = GetClientArea(); RECT frame = GetClientArea();
// The size here must match the window dimensions to avoid unnecessary surface // The size here must match the window dimensions to avoid unnecessary surface
// creation / destruction in the startup path. // creation / destruction in the startup path.
flutter_controller_ = std::make_unique<flutter::FlutterViewController>( flutter_controller_ = std::make_unique<flutter::FlutterViewController>(
frame.right - frame.left, frame.bottom - frame.top, project_); frame.right - frame.left, frame.bottom - frame.top, project_);
// Ensure that basic setup of the controller was successful. // Ensure that basic setup of the controller was successful.
if (!flutter_controller_->engine() || !flutter_controller_->view()) { if (!flutter_controller_->engine() || !flutter_controller_->view()) {
return false; return false;
} }
RegisterPlugins(flutter_controller_->engine()); RegisterPlugins(flutter_controller_->engine());
SetChildContent(flutter_controller_->view()->GetNativeWindow()); SetChildContent(flutter_controller_->view()->GetNativeWindow());
return true; return true;
} }
void FlutterWindow::OnDestroy() { void FlutterWindow::OnDestroy() {
if (flutter_controller_) { if (flutter_controller_) {
flutter_controller_ = nullptr; flutter_controller_ = nullptr;
} }
Win32Window::OnDestroy(); Win32Window::OnDestroy();
} }
LRESULT LRESULT
FlutterWindow::MessageHandler(HWND hwnd, UINT const message, FlutterWindow::MessageHandler(HWND hwnd, UINT const message,
WPARAM const wparam, WPARAM const wparam,
LPARAM const lparam) noexcept { LPARAM const lparam) noexcept {
// Give Flutter, including plugins, an opportunity to handle window messages. // Give Flutter, including plugins, an opportunity to handle window messages.
if (flutter_controller_) { if (flutter_controller_) {
std::optional<LRESULT> result = std::optional<LRESULT> result =
flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam, flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam,
lparam); lparam);
if (result) { if (result) {
return *result; return *result;
} }
} }
switch (message) { switch (message) {
case WM_FONTCHANGE: case WM_FONTCHANGE:
flutter_controller_->engine()->ReloadSystemFonts(); flutter_controller_->engine()->ReloadSystemFonts();
break; break;
} }
return Win32Window::MessageHandler(hwnd, message, wparam, lparam); return Win32Window::MessageHandler(hwnd, message, wparam, lparam);
} }
#ifndef RUNNER_FLUTTER_WINDOW_H_ #ifndef RUNNER_FLUTTER_WINDOW_H_
#define RUNNER_FLUTTER_WINDOW_H_ #define RUNNER_FLUTTER_WINDOW_H_
#include <flutter/dart_project.h> #include <flutter/dart_project.h>
#include <flutter/flutter_view_controller.h> #include <flutter/flutter_view_controller.h>
#include <memory> #include <memory>
#include "win32_window.h" #include "win32_window.h"
// A window that does nothing but host a Flutter view. // A window that does nothing but host a Flutter view.
class FlutterWindow : public Win32Window { class FlutterWindow : public Win32Window {
public: public:
// Creates a new FlutterWindow hosting a Flutter view running |project|. // Creates a new FlutterWindow hosting a Flutter view running |project|.
explicit FlutterWindow(const flutter::DartProject& project); explicit FlutterWindow(const flutter::DartProject& project);
virtual ~FlutterWindow(); virtual ~FlutterWindow();
protected: protected:
// Win32Window: // Win32Window:
bool OnCreate() override; bool OnCreate() override;
void OnDestroy() override; void OnDestroy() override;
LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam,
LPARAM const lparam) noexcept override; LPARAM const lparam) noexcept override;
private: private:
// The project to run. // The project to run.
flutter::DartProject project_; flutter::DartProject project_;
// The Flutter instance hosted by this window. // The Flutter instance hosted by this window.
std::unique_ptr<flutter::FlutterViewController> flutter_controller_; std::unique_ptr<flutter::FlutterViewController> flutter_controller_;
}; };
#endif // RUNNER_FLUTTER_WINDOW_H_ #endif // RUNNER_FLUTTER_WINDOW_H_
#include <flutter/dart_project.h> #include <flutter/dart_project.h>
#include <flutter/flutter_view_controller.h> #include <flutter/flutter_view_controller.h>
#include <windows.h> #include <windows.h>
#include "flutter_window.h" #include "flutter_window.h"
#include "utils.h" #include "utils.h"
int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
_In_ wchar_t *command_line, _In_ int show_command) { _In_ wchar_t *command_line, _In_ int show_command) {
// Attach to console when present (e.g., 'flutter run') or create a // Attach to console when present (e.g., 'flutter run') or create a
// new console when running with a debugger. // new console when running with a debugger.
if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) { if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) {
CreateAndAttachConsole(); CreateAndAttachConsole();
} }
// Initialize COM, so that it is available for use in the library and/or // Initialize COM, so that it is available for use in the library and/or
// plugins. // plugins.
::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
flutter::DartProject project(L"data"); flutter::DartProject project(L"data");
std::vector<std::string> command_line_arguments = std::vector<std::string> command_line_arguments =
GetCommandLineArguments(); GetCommandLineArguments();
project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); project.set_dart_entrypoint_arguments(std::move(command_line_arguments));
FlutterWindow window(project); FlutterWindow window(project);
Win32Window::Point origin(10, 10); Win32Window::Point origin(10, 10);
Win32Window::Size size(1280, 720); Win32Window::Size size(1280, 720);
if (!window.CreateAndShow(L"example", origin, size)) { if (!window.CreateAndShow(L"example", origin, size)) {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
window.SetQuitOnClose(true); window.SetQuitOnClose(true);
::MSG msg; ::MSG msg;
while (::GetMessage(&msg, nullptr, 0, 0)) { while (::GetMessage(&msg, nullptr, 0, 0)) {
::TranslateMessage(&msg); ::TranslateMessage(&msg);
::DispatchMessage(&msg); ::DispatchMessage(&msg);
} }
::CoUninitialize(); ::CoUninitialize();
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
//{{NO_DEPENDENCIES}} //{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file. // Microsoft Visual C++ generated include file.
// Used by Runner.rc // Used by Runner.rc
// //
#define IDI_APP_ICON 101 #define IDI_APP_ICON 101
// Next default values for new objects // Next default values for new objects
// //
#ifdef APSTUDIO_INVOKED #ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS #ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 102 #define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40001 #define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001 #define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101 #define _APS_NEXT_SYMED_VALUE 101
#endif #endif
#endif #endif
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<application xmlns="urn:schemas-microsoft-com:asm.v3"> <application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings> <windowsSettings>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness> <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
</windowsSettings> </windowsSettings>
</application> </application>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application> <application>
<!-- Windows 10 --> <!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/> <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
<!-- Windows 8.1 --> <!-- Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/> <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<!-- Windows 8 --> <!-- Windows 8 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/> <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
<!-- Windows 7 --> <!-- Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/> <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
</application> </application>
</compatibility> </compatibility>
</assembly> </assembly>
#include "utils.h" #include "utils.h"
#include <flutter_windows.h> #include <flutter_windows.h>
#include <io.h> #include <io.h>
#include <stdio.h> #include <stdio.h>
#include <windows.h> #include <windows.h>
#include <iostream> #include <iostream>
void CreateAndAttachConsole() { void CreateAndAttachConsole() {
if (::AllocConsole()) { if (::AllocConsole()) {
FILE *unused; FILE *unused;
if (freopen_s(&unused, "CONOUT$", "w", stdout)) { if (freopen_s(&unused, "CONOUT$", "w", stdout)) {
_dup2(_fileno(stdout), 1); _dup2(_fileno(stdout), 1);
} }
if (freopen_s(&unused, "CONOUT$", "w", stderr)) { if (freopen_s(&unused, "CONOUT$", "w", stderr)) {
_dup2(_fileno(stdout), 2); _dup2(_fileno(stdout), 2);
} }
std::ios::sync_with_stdio(); std::ios::sync_with_stdio();
FlutterDesktopResyncOutputStreams(); FlutterDesktopResyncOutputStreams();
} }
} }
std::vector<std::string> GetCommandLineArguments() { std::vector<std::string> GetCommandLineArguments() {
// Convert the UTF-16 command line arguments to UTF-8 for the Engine to use. // Convert the UTF-16 command line arguments to UTF-8 for the Engine to use.
int argc; int argc;
wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc);
if (argv == nullptr) { if (argv == nullptr) {
return std::vector<std::string>(); return std::vector<std::string>();
} }
std::vector<std::string> command_line_arguments; std::vector<std::string> command_line_arguments;
// Skip the first argument as it's the binary name. // Skip the first argument as it's the binary name.
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {
command_line_arguments.push_back(Utf8FromUtf16(argv[i])); command_line_arguments.push_back(Utf8FromUtf16(argv[i]));
} }
::LocalFree(argv); ::LocalFree(argv);
return command_line_arguments; return command_line_arguments;
} }
std::string Utf8FromUtf16(const wchar_t* utf16_string) { std::string Utf8FromUtf16(const wchar_t* utf16_string) {
if (utf16_string == nullptr) { if (utf16_string == nullptr) {
return std::string(); return std::string();
} }
int target_length = ::WideCharToMultiByte( int target_length = ::WideCharToMultiByte(
CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string,
-1, nullptr, 0, nullptr, nullptr); -1, nullptr, 0, nullptr, nullptr);
if (target_length == 0) { if (target_length == 0) {
return std::string(); return std::string();
} }
std::string utf8_string; std::string utf8_string;
utf8_string.resize(target_length); utf8_string.resize(target_length);
int converted_length = ::WideCharToMultiByte( int converted_length = ::WideCharToMultiByte(
CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string,
-1, utf8_string.data(), -1, utf8_string.data(),
target_length, nullptr, nullptr); target_length, nullptr, nullptr);
if (converted_length == 0) { if (converted_length == 0) {
return std::string(); return std::string();
} }
return utf8_string; return utf8_string;
} }
#ifndef RUNNER_UTILS_H_ #ifndef RUNNER_UTILS_H_
#define RUNNER_UTILS_H_ #define RUNNER_UTILS_H_
#include <string> #include <string>
#include <vector> #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 // 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. // encoded in UTF-8. Returns an empty std::string on failure.
std::string Utf8FromUtf16(const wchar_t* utf16_string); std::string Utf8FromUtf16(const wchar_t* utf16_string);
// Gets the command line arguments passed in as a std::vector<std::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. // encoded in UTF-8. Returns an empty std::vector<std::string> on failure.
std::vector<std::string> GetCommandLineArguments(); std::vector<std::string> GetCommandLineArguments();
#endif // RUNNER_UTILS_H_ #endif // RUNNER_UTILS_H_
#ifndef RUNNER_WIN32_WINDOW_H_ #ifndef RUNNER_WIN32_WINDOW_H_
#define RUNNER_WIN32_WINDOW_H_ #define RUNNER_WIN32_WINDOW_H_
#include <windows.h> #include <windows.h>
#include <functional> #include <functional>
#include <memory> #include <memory>
#include <string> #include <string>
// A class abstraction for a high DPI-aware Win32 Window. Intended to be // A class abstraction for a high DPI-aware Win32 Window. Intended to be
// inherited from by classes that wish to specialize with custom // inherited from by classes that wish to specialize with custom
// rendering and input handling // rendering and input handling
class Win32Window { class Win32Window {
public: public:
struct Point { struct Point {
unsigned int x; unsigned int x;
unsigned int y; unsigned int y;
Point(unsigned int x, unsigned int y) : x(x), y(y) {} Point(unsigned int x, unsigned int y) : x(x), y(y) {}
}; };
struct Size { struct Size {
unsigned int width; unsigned int width;
unsigned int height; unsigned int height;
Size(unsigned int width, unsigned int height) Size(unsigned int width, unsigned int height)
: width(width), height(height) {} : width(width), height(height) {}
}; };
Win32Window(); Win32Window();
virtual ~Win32Window(); virtual ~Win32Window();
// Creates and shows a win32 window with |title| and position and size using // Creates and shows a win32 window with |title| and position and size using
// |origin| and |size|. New windows are created on the default monitor. Window // |origin| and |size|. New windows are created on the default monitor. Window
// sizes are specified to the OS in physical pixels, hence to ensure a // sizes are specified to the OS in physical pixels, hence to ensure a
// consistent size to will treat the width height passed in to this function // consistent size to will treat the width height passed in to this function
// as logical pixels and scale to appropriate for the default monitor. Returns // as logical pixels and scale to appropriate for the default monitor. Returns
// true if the window was created successfully. // true if the window was created successfully.
bool CreateAndShow(const std::wstring& title, bool CreateAndShow(const std::wstring& title,
const Point& origin, const Point& origin,
const Size& size); const Size& size);
// Release OS resources associated with window. // Release OS resources associated with window.
void Destroy(); void Destroy();
// Inserts |content| into the window tree. // Inserts |content| into the window tree.
void SetChildContent(HWND content); void SetChildContent(HWND content);
// Returns the backing Window handle to enable clients to set icon and other // Returns the backing Window handle to enable clients to set icon and other
// window properties. Returns nullptr if the window has been destroyed. // window properties. Returns nullptr if the window has been destroyed.
HWND GetHandle(); HWND GetHandle();
// If true, closing this window will quit the application. // If true, closing this window will quit the application.
void SetQuitOnClose(bool quit_on_close); void SetQuitOnClose(bool quit_on_close);
// Return a RECT representing the bounds of the current client area. // Return a RECT representing the bounds of the current client area.
RECT GetClientArea(); RECT GetClientArea();
protected: protected:
// Processes and route salient window messages for mouse handling, // Processes and route salient window messages for mouse handling,
// size change and DPI. Delegates handling of these to member overloads that // size change and DPI. Delegates handling of these to member overloads that
// inheriting classes can handle. // inheriting classes can handle.
virtual LRESULT MessageHandler(HWND window, virtual LRESULT MessageHandler(HWND window,
UINT const message, UINT const message,
WPARAM const wparam, WPARAM const wparam,
LPARAM const lparam) noexcept; LPARAM const lparam) noexcept;
// Called when CreateAndShow is called, allowing subclass window-related // Called when CreateAndShow is called, allowing subclass window-related
// setup. Subclasses should return false if setup fails. // setup. Subclasses should return false if setup fails.
virtual bool OnCreate(); virtual bool OnCreate();
// Called when Destroy is called. // Called when Destroy is called.
virtual void OnDestroy(); virtual void OnDestroy();
private: private:
friend class WindowClassRegistrar; friend class WindowClassRegistrar;
// OS callback called by message pump. Handles the WM_NCCREATE message which // OS callback called by message pump. Handles the WM_NCCREATE message which
// is passed when the non-client area is being created and enables automatic // is passed when the non-client area is being created and enables automatic
// non-client DPI scaling so that the non-client area automatically // non-client DPI scaling so that the non-client area automatically
// responsponds to changes in DPI. All other messages are handled by // responsponds to changes in DPI. All other messages are handled by
// MessageHandler. // MessageHandler.
static LRESULT CALLBACK WndProc(HWND const window, static LRESULT CALLBACK WndProc(HWND const window,
UINT const message, UINT const message,
WPARAM const wparam, WPARAM const wparam,
LPARAM const lparam) noexcept; LPARAM const lparam) noexcept;
// Retrieves a class instance pointer for |window| // Retrieves a class instance pointer for |window|
static Win32Window* GetThisFromHandle(HWND const window) noexcept; static Win32Window* GetThisFromHandle(HWND const window) noexcept;
bool quit_on_close_ = false; bool quit_on_close_ = false;
// window handle for top level window. // window handle for top level window.
HWND window_handle_ = nullptr; HWND window_handle_ = nullptr;
// window handle for hosted content. // window handle for hosted content.
HWND child_content_ = nullptr; HWND child_content_ = nullptr;
}; };
#endif // RUNNER_WIN32_WINDOW_H_ #endif // RUNNER_WIN32_WINDOW_H_
MIT License
Copyright (c) 2018 Baseflow
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment