fix: Récupérer l'opération active depuis la table operations
- Corrige l'erreur SQL 'Unknown column fk_operation in users' - L'opération active est récupérée depuis operations.chk_active = 1 - Jointure avec users pour filtrer par entité de l'admin créateur - Query: SELECT o.id FROM operations o INNER JOIN users u ON u.fk_entite = o.fk_entite WHERE u.id = ? AND o.chk_active = 1
This commit is contained in:
@@ -1 +0,0 @@
|
||||
/home/pierre/.pub-cache/hosted/pub.dev/url_launcher_windows-3.1.4/
|
||||
66
app/windows/flutter/ephemeral/.plugin_symlinks/url_launcher_windows/AUTHORS
Executable file
66
app/windows/flutter/ephemeral/.plugin_symlinks/url_launcher_windows/AUTHORS
Executable file
@@ -0,0 +1,66 @@
|
||||
# Below is a list of people and organizations that have contributed
|
||||
# to the Flutter project. Names should be added to the list like so:
|
||||
#
|
||||
# Name/Organization <email address>
|
||||
|
||||
Google Inc.
|
||||
The Chromium Authors
|
||||
German Saprykin <saprykin.h@gmail.com>
|
||||
Benjamin Sauer <sauer.benjamin@gmail.com>
|
||||
larsenthomasj@gmail.com
|
||||
Ali Bitek <alibitek@protonmail.ch>
|
||||
Pol Batlló <pol.batllo@gmail.com>
|
||||
Anatoly Pulyaevskiy
|
||||
Hayden Flinner <haydenflinner@gmail.com>
|
||||
Stefano Rodriguez <hlsroddy@gmail.com>
|
||||
Salvatore Giordano <salvatoregiordanoo@gmail.com>
|
||||
Brian Armstrong <brian@flutter.institute>
|
||||
Paul DeMarco <paulmdemarco@gmail.com>
|
||||
Fabricio Nogueira <feufeu@gmail.com>
|
||||
Simon Lightfoot <simon@devangels.london>
|
||||
Ashton Thomas <ashton@acrinta.com>
|
||||
Thomas Danner <thmsdnnr@gmail.com>
|
||||
Diego Velásquez <diego.velasquez.lopez@gmail.com>
|
||||
Hajime Nakamura <nkmrhj@gmail.com>
|
||||
Tuyển Vũ Xuân <netsoft1985@gmail.com>
|
||||
Miguel Ruivo <miguel@miguelruivo.com>
|
||||
Sarthak Verma <sarthak@artiosys.com>
|
||||
Mike Diarmid <mike@invertase.io>
|
||||
Invertase <oss@invertase.io>
|
||||
Elliot Hesp <elliot@invertase.io>
|
||||
Vince Varga <vince.varga@smaho.com>
|
||||
Aawaz Gyawali <awazgyawali@gmail.com>
|
||||
EUI Limited <ian.evans3@admiralgroup.co.uk>
|
||||
Katarina Sheremet <katarina@sheremet.ch>
|
||||
Thomas Stockx <thomas@stockxit.com>
|
||||
Sarbagya Dhaubanjar <sarbagyastha@gmail.com>
|
||||
Ozkan Eksi <ozeksi@gmail.com>
|
||||
Rishab Nayak <rishab@bu.edu>
|
||||
ko2ic <ko2ic.dev@gmail.com>
|
||||
Jonathan Younger <jonathan@daikini.com>
|
||||
Jose Sanchez <josesm82@gmail.com>
|
||||
Debkanchan Samadder <debu.samadder@gmail.com>
|
||||
Audrius Karosevicius <audrius.karosevicius@gmail.com>
|
||||
Lukasz Piliszczuk <lukasz@intheloup.io>
|
||||
SoundReply Solutions GmbH <ch@soundreply.com>
|
||||
Rafal Wachol <rwachol@gmail.com>
|
||||
Pau Picas <pau.picas@gmail.com>
|
||||
Christian Weder <chrstian.weder@yapeal.ch>
|
||||
Alexandru Tuca <salexandru.tuca@outlook.com>
|
||||
Christian Weder <chrstian.weder@yapeal.ch>
|
||||
Rhodes Davis Jr. <rody.davis.jr@gmail.com>
|
||||
Luigi Agosti <luigi@tengio.com>
|
||||
Quentin Le Guennec <quentin@tengio.com>
|
||||
Koushik Ravikumar <koushik@tengio.com>
|
||||
Nissim Dsilva <nissim@tengio.com>
|
||||
Giancarlo Rocha <giancarloiff@gmail.com>
|
||||
Ryo Miyake <ryo@miyake.id>
|
||||
Théo Champion <contact.theochampion@gmail.com>
|
||||
Kazuki Yamaguchi <y.kazuki0614n@gmail.com>
|
||||
Eitan Schwartz <eshvartz@gmail.com>
|
||||
Chris Rutkowski <chrisrutkowski89@gmail.com>
|
||||
Juan Alvarez <juan.alvarez@resideo.com>
|
||||
Aleksandr Yurkovskiy <sanekyy@gmail.com>
|
||||
Anton Borries <mail@antonborri.es>
|
||||
Alex Li <google@alexv525.com>
|
||||
Rahul Raj <64.rahulraj@gmail.com>
|
||||
114
app/windows/flutter/ephemeral/.plugin_symlinks/url_launcher_windows/CHANGELOG.md
Executable file
114
app/windows/flutter/ephemeral/.plugin_symlinks/url_launcher_windows/CHANGELOG.md
Executable file
@@ -0,0 +1,114 @@
|
||||
## 3.1.4
|
||||
|
||||
* Updates minimum supported SDK version to Flutter 3.22/Dart 3.4.
|
||||
* Fixes an issue where the URL logged would not be unescaped on failure.
|
||||
|
||||
## 3.1.3
|
||||
|
||||
* Updates minimum supported SDK version to Flutter 3.19/Dart 3.3.
|
||||
* Fixes handling of `file:` URLs that contain UTF-8 encoded paths.
|
||||
|
||||
## 3.1.2
|
||||
|
||||
* Updates to pigeon 21.
|
||||
* Updates minimum supported SDK version to Flutter 3.16/Dart 3.2.
|
||||
|
||||
## 3.1.1
|
||||
|
||||
* Updates `launchUrl` to return false instead of throwing when there is no handler.
|
||||
* Updates minimum supported SDK version to Flutter 3.10/Dart 3.0.
|
||||
|
||||
## 3.1.0
|
||||
|
||||
* Implements `supportsMode` and `supportsCloseForMode`.
|
||||
|
||||
## 3.0.8
|
||||
|
||||
* Adds pub topics to package metadata.
|
||||
* Updates minimum supported SDK version to Flutter 3.7/Dart 2.19.
|
||||
|
||||
## 3.0.7
|
||||
|
||||
* Updates pigeon dependency for url_launcher_windows to "^10.1.2".
|
||||
* Updates minimum supported SDK version to Flutter 3.3/Dart 2.18.
|
||||
|
||||
## 3.0.6
|
||||
|
||||
* Sets a cmake_policy compatibility version to fix build warnings.
|
||||
|
||||
## 3.0.5
|
||||
|
||||
* Clarifies explanation of endorsement in README.
|
||||
* Aligns Dart and Flutter SDK constraints.
|
||||
|
||||
## 3.0.4
|
||||
|
||||
* Updates links for the merge of flutter/plugins into flutter/packages.
|
||||
|
||||
## 3.0.3
|
||||
|
||||
* Converts internal implentation to Pigeon.
|
||||
* Updates minimum Flutter version to 3.0.
|
||||
|
||||
## 3.0.2
|
||||
|
||||
* Updates code for stricter lint checks.
|
||||
* Updates minimum Flutter version to 2.10.
|
||||
|
||||
## 3.0.1
|
||||
|
||||
* Fixes library_private_types_in_public_api, sort_child_properties_last and use_key_in_widget_constructors
|
||||
lint warnings.
|
||||
|
||||
## 3.0.0
|
||||
|
||||
* Changes the major version since, due to a typo in `default_package` in
|
||||
existing versions of `url_launcher`, requiring Dart registration in this
|
||||
package is in practice a breaking change.
|
||||
* Does not include any API changes; clients can allow both 2.x or 3.x.
|
||||
|
||||
## 2.0.3
|
||||
|
||||
**\[Retracted\]**
|
||||
|
||||
* Switches to an in-package method channel implementation.
|
||||
* Adds unit tests.
|
||||
* Updates code for new analysis options.
|
||||
|
||||
## 2.0.2
|
||||
|
||||
* Replaced reference to `shared_preferences` plugin with the `url_launcher` in the README.
|
||||
|
||||
## 2.0.1
|
||||
|
||||
* Updated installation instructions in README.
|
||||
|
||||
## 2.0.0
|
||||
|
||||
* Migrate to null-safety.
|
||||
* Update the example app: remove the deprecated `RaisedButton` and `FlatButton` widgets.
|
||||
* Set `implementation` in pubspec.yaml
|
||||
|
||||
## 0.0.2+1
|
||||
|
||||
* Update Flutter SDK constraint.
|
||||
|
||||
## 0.0.2
|
||||
|
||||
* Update integration test examples to use `testWidgets` instead of `test`.
|
||||
|
||||
## 0.0.1+3
|
||||
|
||||
* Update Dart SDK constraint in example.
|
||||
|
||||
## 0.0.1+2
|
||||
|
||||
* Check in windows/ directory for example/
|
||||
|
||||
## 0.0.1+1
|
||||
|
||||
* Update README to reflect endorsement.
|
||||
|
||||
## 0.0.1
|
||||
|
||||
* Initial Windows implementation of `url_launcher`.
|
||||
25
app/windows/flutter/ephemeral/.plugin_symlinks/url_launcher_windows/LICENSE
Executable file
25
app/windows/flutter/ephemeral/.plugin_symlinks/url_launcher_windows/LICENSE
Executable file
@@ -0,0 +1,25 @@
|
||||
Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer in the documentation and/or other materials provided
|
||||
with the distribution.
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
@@ -0,0 +1,15 @@
|
||||
# url\_launcher\_windows
|
||||
|
||||
The Windows implementation of [`url_launcher`][1].
|
||||
|
||||
## Usage
|
||||
|
||||
This package is [endorsed][2], which means you can simply use `url_launcher`
|
||||
normally. This package will be automatically included in your app when you do,
|
||||
so you do not need to add it to your `pubspec.yaml`.
|
||||
|
||||
However, if you `import` this package to use any of its APIs directly, you
|
||||
should add it to your `pubspec.yaml` as usual.
|
||||
|
||||
[1]: https://pub.dev/packages/url_launcher
|
||||
[2]: https://flutter.dev/to/endorsed-federated-plugin
|
||||
@@ -0,0 +1,9 @@
|
||||
# Platform Implementation Test App
|
||||
|
||||
This is a test app for manual testing and automated integration testing
|
||||
of this platform implementation. It is not intended to demonstrate actual use of
|
||||
this package, since the intent is that plugin clients use the app-facing
|
||||
package.
|
||||
|
||||
Unless you are making changes to this implementation package, this example is
|
||||
very unlikely to be relevant.
|
||||
@@ -0,0 +1,20 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:integration_test/integration_test.dart';
|
||||
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart';
|
||||
|
||||
void main() {
|
||||
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
testWidgets('canLaunch', (WidgetTester _) async {
|
||||
final UrlLauncherPlatform launcher = UrlLauncherPlatform.instance;
|
||||
|
||||
expect(await launcher.canLaunch('randomstring'), false);
|
||||
|
||||
// Generally all devices should have some default browser.
|
||||
expect(await launcher.canLaunch('http://flutter.dev'), true);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// ignore_for_file: public_member_api_docs
|
||||
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart';
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'URL Launcher',
|
||||
theme: ThemeData(
|
||||
primarySwatch: Colors.blue,
|
||||
),
|
||||
home: const MyHomePage(title: 'URL Launcher'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyHomePage extends StatefulWidget {
|
||||
const MyHomePage({super.key, required this.title});
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
Future<void>? _launched;
|
||||
|
||||
Future<void> _launchInBrowser(String url) async {
|
||||
if (await UrlLauncherPlatform.instance.canLaunch(url)) {
|
||||
await UrlLauncherPlatform.instance.launch(
|
||||
url,
|
||||
useSafariVC: false,
|
||||
useWebView: false,
|
||||
enableJavaScript: false,
|
||||
enableDomStorage: false,
|
||||
universalLinksOnly: false,
|
||||
headers: <String, String>{},
|
||||
);
|
||||
} else {
|
||||
throw Exception('Could not launch $url');
|
||||
}
|
||||
}
|
||||
|
||||
Widget _launchStatus(BuildContext context, AsyncSnapshot<void> snapshot) {
|
||||
if (snapshot.hasError) {
|
||||
return Text('Error: ${snapshot.error}');
|
||||
} else {
|
||||
return const Text('');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
const String toLaunch = 'https://www.cylog.org/headers/';
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(widget.title),
|
||||
),
|
||||
body: ListView(
|
||||
children: <Widget>[
|
||||
Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
const Padding(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
child: Text(toLaunch),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () => setState(() {
|
||||
_launched = _launchInBrowser(toLaunch);
|
||||
}),
|
||||
child: const Text('Launch in browser'),
|
||||
),
|
||||
const Padding(padding: EdgeInsets.all(16.0)),
|
||||
FutureBuilder<void>(future: _launched, builder: _launchStatus),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
name: url_launcher_example
|
||||
description: Demonstrates the Windows implementation of the url_launcher plugin.
|
||||
publish_to: none
|
||||
|
||||
environment:
|
||||
sdk: ^3.4.0
|
||||
flutter: ">=3.22.0"
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
url_launcher_platform_interface: ^2.2.0
|
||||
url_launcher_windows:
|
||||
# When depending on this package from a real application you should use:
|
||||
# url_launcher_windows: ^x.y.z
|
||||
# See https://dart.dev/tools/pub/dependencies#version-constraints
|
||||
# The example app is bundled with the plugin so we use a path dependency on
|
||||
# the parent directory to use the current plugin's version.
|
||||
path: ../
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
integration_test:
|
||||
sdk: flutter
|
||||
|
||||
flutter:
|
||||
uses-material-design: true
|
||||
@@ -0,0 +1,7 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:integration_test/integration_test_driver.dart';
|
||||
|
||||
Future<void> main() => integrationDriver();
|
||||
@@ -0,0 +1,100 @@
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
project(example LANGUAGES CXX)
|
||||
|
||||
set(BINARY_NAME "example")
|
||||
|
||||
cmake_policy(SET CMP0063 NEW)
|
||||
|
||||
set(CMAKE_INSTALL_RPATH "$ORIGIN/lib")
|
||||
|
||||
# Configure build options.
|
||||
get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
|
||||
if(IS_MULTICONFIG)
|
||||
set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release"
|
||||
CACHE STRING "" FORCE)
|
||||
else()
|
||||
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
||||
set(CMAKE_BUILD_TYPE "Debug" CACHE
|
||||
STRING "Flutter build mode" FORCE)
|
||||
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
|
||||
"Debug" "Profile" "Release")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
|
||||
set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}")
|
||||
set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}")
|
||||
|
||||
# Use Unicode for all projects.
|
||||
add_definitions(-DUNICODE -D_UNICODE)
|
||||
|
||||
# Compilation settings that should be applied to most targets.
|
||||
function(APPLY_STANDARD_SETTINGS TARGET)
|
||||
target_compile_features(${TARGET} PUBLIC cxx_std_17)
|
||||
target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100")
|
||||
target_compile_options(${TARGET} PRIVATE /EHsc)
|
||||
target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0")
|
||||
target_compile_definitions(${TARGET} PRIVATE "$<$<CONFIG:Debug>:_DEBUG>")
|
||||
endfunction()
|
||||
|
||||
set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
|
||||
|
||||
# Flutter library and tool build rules.
|
||||
add_subdirectory(${FLUTTER_MANAGED_DIR})
|
||||
|
||||
# Application build
|
||||
add_subdirectory("runner")
|
||||
|
||||
# Enable the test target.
|
||||
set(include_url_launcher_windows_tests TRUE)
|
||||
# Provide an alias for the test target using the name expected by repo tooling.
|
||||
add_custom_target(unit_tests DEPENDS url_launcher_windows_test)
|
||||
|
||||
# Generated plugin build rules, which manage building the plugins and adding
|
||||
# them to the application.
|
||||
include(flutter/generated_plugins.cmake)
|
||||
|
||||
|
||||
# === Installation ===
|
||||
# Support files are copied into place next to the executable, so that it can
|
||||
# run in place. This is done instead of making a separate bundle (as on Linux)
|
||||
# so that building and running from within Visual Studio will work.
|
||||
set(BUILD_BUNDLE_DIR "$<TARGET_FILE_DIR:${BINARY_NAME}>")
|
||||
# Make the "install" step default, as it's required to run.
|
||||
set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1)
|
||||
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
|
||||
set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
|
||||
endif()
|
||||
|
||||
set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
|
||||
set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}")
|
||||
|
||||
install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
|
||||
COMPONENT Runtime)
|
||||
|
||||
install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
|
||||
COMPONENT Runtime)
|
||||
|
||||
install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
|
||||
COMPONENT Runtime)
|
||||
|
||||
if(PLUGIN_BUNDLED_LIBRARIES)
|
||||
install(FILES "${PLUGIN_BUNDLED_LIBRARIES}"
|
||||
DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
|
||||
COMPONENT Runtime)
|
||||
endif()
|
||||
|
||||
# Fully re-copy the assets directory on each build to avoid having stale files
|
||||
# from a previous install.
|
||||
set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
|
||||
install(CODE "
|
||||
file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")
|
||||
" COMPONENT Runtime)
|
||||
install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
|
||||
DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime)
|
||||
|
||||
# Install the AOT library on non-Debug builds only.
|
||||
install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
|
||||
CONFIGURATIONS Profile;Release
|
||||
COMPONENT Runtime)
|
||||
@@ -0,0 +1,107 @@
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral")
|
||||
|
||||
# Configuration provided via flutter tool.
|
||||
include(${EPHEMERAL_DIR}/generated_config.cmake)
|
||||
|
||||
# TODO: Move the rest of this into files in ephemeral. See
|
||||
# https://github.com/flutter/flutter/issues/57146.
|
||||
set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper")
|
||||
|
||||
# Set fallback configurations for older versions of the flutter tool.
|
||||
if (NOT DEFINED FLUTTER_TARGET_PLATFORM)
|
||||
set(FLUTTER_TARGET_PLATFORM "windows-x64")
|
||||
endif()
|
||||
|
||||
# === Flutter Library ===
|
||||
set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll")
|
||||
|
||||
# Published to parent scope for install step.
|
||||
set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE)
|
||||
set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE)
|
||||
set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE)
|
||||
set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE)
|
||||
|
||||
list(APPEND FLUTTER_LIBRARY_HEADERS
|
||||
"flutter_export.h"
|
||||
"flutter_windows.h"
|
||||
"flutter_messenger.h"
|
||||
"flutter_plugin_registrar.h"
|
||||
)
|
||||
list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/")
|
||||
add_library(flutter INTERFACE)
|
||||
target_include_directories(flutter INTERFACE
|
||||
"${EPHEMERAL_DIR}"
|
||||
)
|
||||
target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib")
|
||||
add_dependencies(flutter flutter_assemble)
|
||||
|
||||
# === Wrapper ===
|
||||
list(APPEND CPP_WRAPPER_SOURCES_CORE
|
||||
"core_implementations.cc"
|
||||
"standard_codec.cc"
|
||||
)
|
||||
list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/")
|
||||
list(APPEND CPP_WRAPPER_SOURCES_PLUGIN
|
||||
"plugin_registrar.cc"
|
||||
)
|
||||
list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/")
|
||||
list(APPEND CPP_WRAPPER_SOURCES_APP
|
||||
"flutter_engine.cc"
|
||||
"flutter_view_controller.cc"
|
||||
)
|
||||
list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/")
|
||||
|
||||
# Wrapper sources needed for a plugin.
|
||||
add_library(flutter_wrapper_plugin STATIC
|
||||
${CPP_WRAPPER_SOURCES_CORE}
|
||||
${CPP_WRAPPER_SOURCES_PLUGIN}
|
||||
)
|
||||
apply_standard_settings(flutter_wrapper_plugin)
|
||||
set_target_properties(flutter_wrapper_plugin PROPERTIES
|
||||
POSITION_INDEPENDENT_CODE ON)
|
||||
set_target_properties(flutter_wrapper_plugin PROPERTIES
|
||||
CXX_VISIBILITY_PRESET hidden)
|
||||
target_link_libraries(flutter_wrapper_plugin PUBLIC flutter)
|
||||
target_include_directories(flutter_wrapper_plugin PUBLIC
|
||||
"${WRAPPER_ROOT}/include"
|
||||
)
|
||||
add_dependencies(flutter_wrapper_plugin flutter_assemble)
|
||||
|
||||
# Wrapper sources needed for the runner.
|
||||
add_library(flutter_wrapper_app STATIC
|
||||
${CPP_WRAPPER_SOURCES_CORE}
|
||||
${CPP_WRAPPER_SOURCES_APP}
|
||||
)
|
||||
apply_standard_settings(flutter_wrapper_app)
|
||||
target_link_libraries(flutter_wrapper_app PUBLIC flutter)
|
||||
target_include_directories(flutter_wrapper_app PUBLIC
|
||||
"${WRAPPER_ROOT}/include"
|
||||
)
|
||||
add_dependencies(flutter_wrapper_app flutter_assemble)
|
||||
|
||||
# === Flutter tool backend ===
|
||||
# _phony_ is a non-existent file to force this command to run every time,
|
||||
# since currently there's no way to get a full input/output list from the
|
||||
# flutter tool.
|
||||
set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_")
|
||||
set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE)
|
||||
add_custom_command(
|
||||
OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}
|
||||
${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN}
|
||||
${CPP_WRAPPER_SOURCES_APP}
|
||||
${PHONY_OUTPUT}
|
||||
COMMAND ${CMAKE_COMMAND} -E env
|
||||
${FLUTTER_TOOL_ENVIRONMENT}
|
||||
"${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat"
|
||||
${FLUTTER_TARGET_PLATFORM} $<CONFIG>
|
||||
VERBATIM
|
||||
)
|
||||
add_custom_target(flutter_assemble DEPENDS
|
||||
"${FLUTTER_LIBRARY}"
|
||||
${FLUTTER_LIBRARY_HEADERS}
|
||||
${CPP_WRAPPER_SOURCES_CORE}
|
||||
${CPP_WRAPPER_SOURCES_PLUGIN}
|
||||
${CPP_WRAPPER_SOURCES_APP}
|
||||
)
|
||||
@@ -0,0 +1,24 @@
|
||||
#
|
||||
# Generated file, do not edit.
|
||||
#
|
||||
|
||||
list(APPEND FLUTTER_PLUGIN_LIST
|
||||
url_launcher_windows
|
||||
)
|
||||
|
||||
list(APPEND FLUTTER_FFI_PLUGIN_LIST
|
||||
)
|
||||
|
||||
set(PLUGIN_BUNDLED_LIBRARIES)
|
||||
|
||||
foreach(plugin ${FLUTTER_PLUGIN_LIST})
|
||||
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin})
|
||||
target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin)
|
||||
list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>)
|
||||
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
|
||||
endforeach(plugin)
|
||||
|
||||
foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
|
||||
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin})
|
||||
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
|
||||
endforeach(ffi_plugin)
|
||||
@@ -0,0 +1,18 @@
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
project(runner LANGUAGES CXX)
|
||||
|
||||
add_executable(${BINARY_NAME} WIN32
|
||||
"flutter_window.cpp"
|
||||
"main.cpp"
|
||||
"run_loop.cpp"
|
||||
"utils.cpp"
|
||||
"win32_window.cpp"
|
||||
"${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
|
||||
"Runner.rc"
|
||||
"runner.exe.manifest"
|
||||
)
|
||||
apply_standard_settings(${BINARY_NAME})
|
||||
target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX")
|
||||
target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app)
|
||||
target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}")
|
||||
add_dependencies(${BINARY_NAME} flutter_assemble)
|
||||
@@ -0,0 +1,121 @@
|
||||
// Microsoft Visual C++ generated resource script.
|
||||
//
|
||||
#pragma code_page(65001)
|
||||
#include "resource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "winres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// English (United States) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE
|
||||
BEGIN
|
||||
"resource.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE
|
||||
BEGIN
|
||||
"#include ""winres.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE
|
||||
BEGIN
|
||||
"\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Icon
|
||||
//
|
||||
|
||||
// Icon with lowest ID value placed first to ensure application icon
|
||||
// remains consistent on all systems.
|
||||
IDI_APP_ICON ICON "resources\\app_icon.ico"
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Version
|
||||
//
|
||||
|
||||
#if defined(FLUTTER_VERSION_MAJOR) && defined(FLUTTER_VERSION_MINOR) && defined(FLUTTER_VERSION_PATCH) && defined(FLUTTER_VERSION_BUILD)
|
||||
#define VERSION_AS_NUMBER FLUTTER_VERSION_MAJOR,FLUTTER_VERSION_MINOR,FLUTTER_VERSION_PATCH,FLUTTER_VERSION_BUILD
|
||||
#else
|
||||
#define VERSION_AS_NUMBER 1,0,0,0
|
||||
#endif
|
||||
|
||||
#if defined(FLUTTER_VERSION)
|
||||
#define VERSION_AS_STRING FLUTTER_VERSION
|
||||
#else
|
||||
#define VERSION_AS_STRING "1.0.0"
|
||||
#endif
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION VERSION_AS_NUMBER
|
||||
PRODUCTVERSION VERSION_AS_NUMBER
|
||||
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS VS_FF_DEBUG
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS VOS__WINDOWS32
|
||||
FILETYPE VFT_APP
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904e4"
|
||||
BEGIN
|
||||
VALUE "CompanyName", "com.example" "\0"
|
||||
VALUE "FileDescription", "A new Flutter project." "\0"
|
||||
VALUE "FileVersion", VERSION_AS_STRING "\0"
|
||||
VALUE "InternalName", "example" "\0"
|
||||
VALUE "LegalCopyright", "Copyright (C) 2020 com.example. All rights reserved." "\0"
|
||||
VALUE "OriginalFilename", "example.exe" "\0"
|
||||
VALUE "ProductName", "example" "\0"
|
||||
VALUE "ProductVersion", VERSION_AS_STRING "\0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x409, 1252
|
||||
END
|
||||
END
|
||||
|
||||
#endif // English (United States) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
||||
@@ -0,0 +1,68 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "flutter_window.h"
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include "flutter/generated_plugin_registrant.h"
|
||||
|
||||
FlutterWindow::FlutterWindow(RunLoop* run_loop,
|
||||
const flutter::DartProject& project)
|
||||
: run_loop_(run_loop), project_(project) {}
|
||||
|
||||
FlutterWindow::~FlutterWindow() {}
|
||||
|
||||
bool FlutterWindow::OnCreate() {
|
||||
if (!Win32Window::OnCreate()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
RECT frame = GetClientArea();
|
||||
|
||||
// The size here must match the window dimensions to avoid unnecessary surface
|
||||
// creation / destruction in the startup path.
|
||||
flutter_controller_ = std::make_unique<flutter::FlutterViewController>(
|
||||
frame.right - frame.left, frame.bottom - frame.top, project_);
|
||||
// Ensure that basic setup of the controller was successful.
|
||||
if (!flutter_controller_->engine() || !flutter_controller_->view()) {
|
||||
return false;
|
||||
}
|
||||
RegisterPlugins(flutter_controller_->engine());
|
||||
run_loop_->RegisterFlutterInstance(flutter_controller_->engine());
|
||||
SetChildContent(flutter_controller_->view()->GetNativeWindow());
|
||||
return true;
|
||||
}
|
||||
|
||||
void FlutterWindow::OnDestroy() {
|
||||
if (flutter_controller_) {
|
||||
run_loop_->UnregisterFlutterInstance(flutter_controller_->engine());
|
||||
flutter_controller_ = nullptr;
|
||||
}
|
||||
|
||||
Win32Window::OnDestroy();
|
||||
}
|
||||
|
||||
LRESULT
|
||||
FlutterWindow::MessageHandler(HWND hwnd, UINT const message,
|
||||
WPARAM const wparam,
|
||||
LPARAM const lparam) noexcept {
|
||||
// Give Flutter, including plugins, an opporutunity to handle window messages.
|
||||
if (flutter_controller_) {
|
||||
std::optional<LRESULT> result =
|
||||
flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam,
|
||||
lparam);
|
||||
if (result) {
|
||||
return *result;
|
||||
}
|
||||
}
|
||||
|
||||
switch (message) {
|
||||
case WM_FONTCHANGE:
|
||||
flutter_controller_->engine()->ReloadSystemFonts();
|
||||
break;
|
||||
}
|
||||
|
||||
return Win32Window::MessageHandler(hwnd, message, wparam, lparam);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef RUNNER_FLUTTER_WINDOW_H_
|
||||
#define RUNNER_FLUTTER_WINDOW_H_
|
||||
|
||||
#include <flutter/dart_project.h>
|
||||
#include <flutter/flutter_view_controller.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "run_loop.h"
|
||||
#include "win32_window.h"
|
||||
|
||||
// A window that does nothing but host a Flutter view.
|
||||
class FlutterWindow : public Win32Window {
|
||||
public:
|
||||
// Creates a new FlutterWindow driven by the |run_loop|, hosting a
|
||||
// Flutter view running |project|.
|
||||
explicit FlutterWindow(RunLoop* run_loop,
|
||||
const flutter::DartProject& project);
|
||||
virtual ~FlutterWindow();
|
||||
|
||||
protected:
|
||||
// Win32Window:
|
||||
bool OnCreate() override;
|
||||
void OnDestroy() override;
|
||||
LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam,
|
||||
LPARAM const lparam) noexcept override;
|
||||
|
||||
private:
|
||||
// The run loop driving events for this window.
|
||||
RunLoop* run_loop_;
|
||||
|
||||
// The project to run.
|
||||
flutter::DartProject project_;
|
||||
|
||||
// The Flutter instance hosted by this window.
|
||||
std::unique_ptr<flutter::FlutterViewController> flutter_controller_;
|
||||
};
|
||||
|
||||
#endif // RUNNER_FLUTTER_WINDOW_H_
|
||||
@@ -0,0 +1,40 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include <flutter/dart_project.h>
|
||||
#include <flutter/flutter_view_controller.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include "flutter_window.h"
|
||||
#include "run_loop.h"
|
||||
#include "utils.h"
|
||||
|
||||
int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
|
||||
_In_ wchar_t* command_line, _In_ int show_command) {
|
||||
// Attach to console when present (e.g., 'flutter run') or create a
|
||||
// new console when running with a debugger.
|
||||
if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) {
|
||||
CreateAndAttachConsole();
|
||||
}
|
||||
|
||||
// Initialize COM, so that it is available for use in the library and/or
|
||||
// plugins.
|
||||
::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
|
||||
|
||||
RunLoop run_loop;
|
||||
|
||||
flutter::DartProject project(L"data");
|
||||
FlutterWindow window(&run_loop, project);
|
||||
Win32Window::Point origin(10, 10);
|
||||
Win32Window::Size size(1280, 720);
|
||||
if (!window.CreateAndShow(L"example", origin, size)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
window.SetQuitOnClose(true);
|
||||
|
||||
run_loop.Run();
|
||||
|
||||
::CoUninitialize();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Visual C++ generated include file.
|
||||
// Used by Runner.rc
|
||||
//
|
||||
#define IDI_APP_ICON 101
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 102
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 1001
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 33 KiB |
@@ -0,0 +1,70 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "run_loop.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
RunLoop::RunLoop() {}
|
||||
|
||||
RunLoop::~RunLoop() {}
|
||||
|
||||
void RunLoop::Run() {
|
||||
bool keep_running = true;
|
||||
TimePoint next_flutter_event_time = TimePoint::clock::now();
|
||||
while (keep_running) {
|
||||
std::chrono::nanoseconds wait_duration =
|
||||
std::max(std::chrono::nanoseconds(0),
|
||||
next_flutter_event_time - TimePoint::clock::now());
|
||||
::MsgWaitForMultipleObjects(
|
||||
0, nullptr, FALSE, static_cast<DWORD>(wait_duration.count() / 1000),
|
||||
QS_ALLINPUT);
|
||||
bool processed_events = false;
|
||||
MSG message;
|
||||
// All pending Windows messages must be processed; MsgWaitForMultipleObjects
|
||||
// won't return again for items left in the queue after PeekMessage.
|
||||
while (::PeekMessage(&message, nullptr, 0, 0, PM_REMOVE)) {
|
||||
processed_events = true;
|
||||
if (message.message == WM_QUIT) {
|
||||
keep_running = false;
|
||||
break;
|
||||
}
|
||||
::TranslateMessage(&message);
|
||||
::DispatchMessage(&message);
|
||||
// Allow Flutter to process messages each time a Windows message is
|
||||
// processed, to prevent starvation.
|
||||
next_flutter_event_time =
|
||||
std::min(next_flutter_event_time, ProcessFlutterMessages());
|
||||
}
|
||||
// If the PeekMessage loop didn't run, process Flutter messages.
|
||||
if (!processed_events) {
|
||||
next_flutter_event_time =
|
||||
std::min(next_flutter_event_time, ProcessFlutterMessages());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RunLoop::RegisterFlutterInstance(
|
||||
flutter::FlutterEngine* flutter_instance) {
|
||||
flutter_instances_.insert(flutter_instance);
|
||||
}
|
||||
|
||||
void RunLoop::UnregisterFlutterInstance(
|
||||
flutter::FlutterEngine* flutter_instance) {
|
||||
flutter_instances_.erase(flutter_instance);
|
||||
}
|
||||
|
||||
RunLoop::TimePoint RunLoop::ProcessFlutterMessages() {
|
||||
TimePoint next_event_time = TimePoint::max();
|
||||
for (auto instance : flutter_instances_) {
|
||||
std::chrono::nanoseconds wait_duration = instance->ProcessMessages();
|
||||
if (wait_duration != std::chrono::nanoseconds::max()) {
|
||||
next_event_time =
|
||||
std::min(next_event_time, TimePoint::clock::now() + wait_duration);
|
||||
}
|
||||
}
|
||||
return next_event_time;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef RUNNER_RUN_LOOP_H_
|
||||
#define RUNNER_RUN_LOOP_H_
|
||||
|
||||
#include <flutter/flutter_engine.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <set>
|
||||
|
||||
// A runloop that will service events for Flutter instances as well
|
||||
// as native messages.
|
||||
class RunLoop {
|
||||
public:
|
||||
RunLoop();
|
||||
~RunLoop();
|
||||
|
||||
// Prevent copying
|
||||
RunLoop(RunLoop const&) = delete;
|
||||
RunLoop& operator=(RunLoop const&) = delete;
|
||||
|
||||
// Runs the run loop until the application quits.
|
||||
void Run();
|
||||
|
||||
// Registers the given Flutter instance for event servicing.
|
||||
void RegisterFlutterInstance(flutter::FlutterEngine* flutter_instance);
|
||||
|
||||
// Unregisters the given Flutter instance from event servicing.
|
||||
void UnregisterFlutterInstance(flutter::FlutterEngine* flutter_instance);
|
||||
|
||||
private:
|
||||
using TimePoint = std::chrono::steady_clock::time_point;
|
||||
|
||||
// Processes all currently pending messages for registered Flutter instances.
|
||||
TimePoint ProcessFlutterMessages();
|
||||
|
||||
std::set<flutter::FlutterEngine*> flutter_instances_;
|
||||
};
|
||||
|
||||
#endif // RUNNER_RUN_LOOP_H_
|
||||
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
||||
<application xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||
<windowsSettings>
|
||||
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
|
||||
</windowsSettings>
|
||||
</application>
|
||||
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||
<application>
|
||||
<!-- Windows 10 -->
|
||||
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
|
||||
<!-- Windows 8.1 -->
|
||||
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
|
||||
<!-- Windows 8 -->
|
||||
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
|
||||
<!-- Windows 7 -->
|
||||
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
|
||||
</application>
|
||||
</compatibility>
|
||||
</assembly>
|
||||
@@ -0,0 +1,26 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#include <flutter_windows.h>
|
||||
#include <io.h>
|
||||
#include <stdio.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
void CreateAndAttachConsole() {
|
||||
if (::AllocConsole()) {
|
||||
FILE* unused;
|
||||
if (freopen_s(&unused, "CONOUT$", "w", stdout)) {
|
||||
_dup2(_fileno(stdout), 1);
|
||||
}
|
||||
if (freopen_s(&unused, "CONOUT$", "w", stderr)) {
|
||||
_dup2(_fileno(stdout), 2);
|
||||
}
|
||||
std::ios::sync_with_stdio();
|
||||
FlutterDesktopResyncOutputStreams();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef RUNNER_UTILS_H_
|
||||
#define RUNNER_UTILS_H_
|
||||
|
||||
// Creates a console for the process, and redirects stdout and stderr to
|
||||
// it for both the runner and the Flutter library.
|
||||
void CreateAndAttachConsole();
|
||||
|
||||
#endif // RUNNER_UTILS_H_
|
||||
@@ -0,0 +1,240 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "win32_window.h"
|
||||
|
||||
#include <flutter_windows.h>
|
||||
|
||||
#include "resource.h"
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr const wchar_t kWindowClassName[] = L"FLUTTER_RUNNER_WIN32_WINDOW";
|
||||
|
||||
// The number of Win32Window objects that currently exist.
|
||||
static int g_active_window_count = 0;
|
||||
|
||||
using EnableNonClientDpiScaling = BOOL __stdcall(HWND hwnd);
|
||||
|
||||
// Scale helper to convert logical scaler values to physical using passed in
|
||||
// scale factor
|
||||
int Scale(int source, double scale_factor) {
|
||||
return static_cast<int>(source * scale_factor);
|
||||
}
|
||||
|
||||
// Dynamically loads the |EnableNonClientDpiScaling| from the User32 module.
|
||||
// This API is only needed for PerMonitor V1 awareness mode.
|
||||
void EnableFullDpiSupportIfAvailable(HWND hwnd) {
|
||||
HMODULE user32_module = LoadLibraryA("User32.dll");
|
||||
if (!user32_module) {
|
||||
return;
|
||||
}
|
||||
auto enable_non_client_dpi_scaling =
|
||||
reinterpret_cast<EnableNonClientDpiScaling*>(
|
||||
GetProcAddress(user32_module, "EnableNonClientDpiScaling"));
|
||||
if (enable_non_client_dpi_scaling != nullptr) {
|
||||
enable_non_client_dpi_scaling(hwnd);
|
||||
FreeLibrary(user32_module);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// Manages the Win32Window's window class registration.
|
||||
class WindowClassRegistrar {
|
||||
public:
|
||||
~WindowClassRegistrar() = default;
|
||||
|
||||
// Returns the singleton registar instance.
|
||||
static WindowClassRegistrar* GetInstance() {
|
||||
if (!instance_) {
|
||||
instance_ = new WindowClassRegistrar();
|
||||
}
|
||||
return instance_;
|
||||
}
|
||||
|
||||
// Returns the name of the window class, registering the class if it hasn't
|
||||
// previously been registered.
|
||||
const wchar_t* GetWindowClass();
|
||||
|
||||
// Unregisters the window class. Should only be called if there are no
|
||||
// instances of the window.
|
||||
void UnregisterWindowClass();
|
||||
|
||||
private:
|
||||
WindowClassRegistrar() = default;
|
||||
|
||||
static WindowClassRegistrar* instance_;
|
||||
|
||||
bool class_registered_ = false;
|
||||
};
|
||||
|
||||
WindowClassRegistrar* WindowClassRegistrar::instance_ = nullptr;
|
||||
|
||||
const wchar_t* WindowClassRegistrar::GetWindowClass() {
|
||||
if (!class_registered_) {
|
||||
WNDCLASS window_class{};
|
||||
window_class.hCursor = LoadCursor(nullptr, IDC_ARROW);
|
||||
window_class.lpszClassName = kWindowClassName;
|
||||
window_class.style = CS_HREDRAW | CS_VREDRAW;
|
||||
window_class.cbClsExtra = 0;
|
||||
window_class.cbWndExtra = 0;
|
||||
window_class.hInstance = GetModuleHandle(nullptr);
|
||||
window_class.hIcon =
|
||||
LoadIcon(window_class.hInstance, MAKEINTRESOURCE(IDI_APP_ICON));
|
||||
window_class.hbrBackground = 0;
|
||||
window_class.lpszMenuName = nullptr;
|
||||
window_class.lpfnWndProc = Win32Window::WndProc;
|
||||
RegisterClass(&window_class);
|
||||
class_registered_ = true;
|
||||
}
|
||||
return kWindowClassName;
|
||||
}
|
||||
|
||||
void WindowClassRegistrar::UnregisterWindowClass() {
|
||||
UnregisterClass(kWindowClassName, nullptr);
|
||||
class_registered_ = false;
|
||||
}
|
||||
|
||||
Win32Window::Win32Window() { ++g_active_window_count; }
|
||||
|
||||
Win32Window::~Win32Window() {
|
||||
--g_active_window_count;
|
||||
Destroy();
|
||||
}
|
||||
|
||||
bool Win32Window::CreateAndShow(const std::wstring& title, const Point& origin,
|
||||
const Size& size) {
|
||||
Destroy();
|
||||
|
||||
const wchar_t* window_class =
|
||||
WindowClassRegistrar::GetInstance()->GetWindowClass();
|
||||
|
||||
const POINT target_point = {static_cast<LONG>(origin.x),
|
||||
static_cast<LONG>(origin.y)};
|
||||
HMONITOR monitor = MonitorFromPoint(target_point, MONITOR_DEFAULTTONEAREST);
|
||||
UINT dpi = FlutterDesktopGetDpiForMonitor(monitor);
|
||||
double scale_factor = dpi / 96.0;
|
||||
|
||||
HWND window = CreateWindow(
|
||||
window_class, title.c_str(), WS_OVERLAPPEDWINDOW | WS_VISIBLE,
|
||||
Scale(origin.x, scale_factor), Scale(origin.y, scale_factor),
|
||||
Scale(size.width, scale_factor), Scale(size.height, scale_factor),
|
||||
nullptr, nullptr, GetModuleHandle(nullptr), this);
|
||||
|
||||
if (!window) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return OnCreate();
|
||||
}
|
||||
|
||||
// static
|
||||
LRESULT CALLBACK Win32Window::WndProc(HWND const window, UINT const message,
|
||||
WPARAM const wparam,
|
||||
LPARAM const lparam) noexcept {
|
||||
if (message == WM_NCCREATE) {
|
||||
auto window_struct = reinterpret_cast<CREATESTRUCT*>(lparam);
|
||||
SetWindowLongPtr(window, GWLP_USERDATA,
|
||||
reinterpret_cast<LONG_PTR>(window_struct->lpCreateParams));
|
||||
|
||||
auto that = static_cast<Win32Window*>(window_struct->lpCreateParams);
|
||||
EnableFullDpiSupportIfAvailable(window);
|
||||
that->window_handle_ = window;
|
||||
} else if (Win32Window* that = GetThisFromHandle(window)) {
|
||||
return that->MessageHandler(window, message, wparam, lparam);
|
||||
}
|
||||
|
||||
return DefWindowProc(window, message, wparam, lparam);
|
||||
}
|
||||
|
||||
LRESULT
|
||||
Win32Window::MessageHandler(HWND hwnd, UINT const message, WPARAM const wparam,
|
||||
LPARAM const lparam) noexcept {
|
||||
switch (message) {
|
||||
case WM_DESTROY:
|
||||
window_handle_ = nullptr;
|
||||
Destroy();
|
||||
if (quit_on_close_) {
|
||||
PostQuitMessage(0);
|
||||
}
|
||||
return 0;
|
||||
|
||||
case WM_DPICHANGED: {
|
||||
auto newRectSize = reinterpret_cast<RECT*>(lparam);
|
||||
LONG newWidth = newRectSize->right - newRectSize->left;
|
||||
LONG newHeight = newRectSize->bottom - newRectSize->top;
|
||||
|
||||
SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth,
|
||||
newHeight, SWP_NOZORDER | SWP_NOACTIVATE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
case WM_SIZE:
|
||||
RECT rect = GetClientArea();
|
||||
if (child_content_ != nullptr) {
|
||||
// Size and position the child window.
|
||||
MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left,
|
||||
rect.bottom - rect.top, TRUE);
|
||||
}
|
||||
return 0;
|
||||
|
||||
case WM_ACTIVATE:
|
||||
if (child_content_ != nullptr) {
|
||||
SetFocus(child_content_);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
return DefWindowProc(window_handle_, message, wparam, lparam);
|
||||
}
|
||||
|
||||
void Win32Window::Destroy() {
|
||||
OnDestroy();
|
||||
|
||||
if (window_handle_) {
|
||||
DestroyWindow(window_handle_);
|
||||
window_handle_ = nullptr;
|
||||
}
|
||||
if (g_active_window_count == 0) {
|
||||
WindowClassRegistrar::GetInstance()->UnregisterWindowClass();
|
||||
}
|
||||
}
|
||||
|
||||
Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept {
|
||||
return reinterpret_cast<Win32Window*>(
|
||||
GetWindowLongPtr(window, GWLP_USERDATA));
|
||||
}
|
||||
|
||||
void Win32Window::SetChildContent(HWND content) {
|
||||
child_content_ = content;
|
||||
SetParent(content, window_handle_);
|
||||
RECT frame = GetClientArea();
|
||||
|
||||
MoveWindow(content, frame.left, frame.top, frame.right - frame.left,
|
||||
frame.bottom - frame.top, true);
|
||||
|
||||
SetFocus(child_content_);
|
||||
}
|
||||
|
||||
RECT Win32Window::GetClientArea() {
|
||||
RECT frame;
|
||||
GetClientRect(window_handle_, &frame);
|
||||
return frame;
|
||||
}
|
||||
|
||||
HWND Win32Window::GetHandle() { return window_handle_; }
|
||||
|
||||
void Win32Window::SetQuitOnClose(bool quit_on_close) {
|
||||
quit_on_close_ = quit_on_close;
|
||||
}
|
||||
|
||||
bool Win32Window::OnCreate() {
|
||||
// No-op; provided for subclasses.
|
||||
return true;
|
||||
}
|
||||
|
||||
void Win32Window::OnDestroy() {
|
||||
// No-op; provided for subclasses.
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef RUNNER_WIN32_WINDOW_H_
|
||||
#define RUNNER_WIN32_WINDOW_H_
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
// A class abstraction for a high DPI-aware Win32 Window. Intended to be
|
||||
// inherited from by classes that wish to specialize with custom
|
||||
// rendering and input handling
|
||||
class Win32Window {
|
||||
public:
|
||||
struct Point {
|
||||
unsigned int x;
|
||||
unsigned int y;
|
||||
Point(unsigned int x, unsigned int y) : x(x), y(y) {}
|
||||
};
|
||||
|
||||
struct Size {
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
Size(unsigned int width, unsigned int height)
|
||||
: width(width), height(height) {}
|
||||
};
|
||||
|
||||
Win32Window();
|
||||
virtual ~Win32Window();
|
||||
|
||||
// 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
|
||||
// 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
|
||||
// as logical pixels and scale to appropriate for the default monitor. Returns
|
||||
// true if the window was created successfully.
|
||||
bool CreateAndShow(const std::wstring& title, const Point& origin,
|
||||
const Size& size);
|
||||
|
||||
// Release OS resources associated with window.
|
||||
void Destroy();
|
||||
|
||||
// Inserts |content| into the window tree.
|
||||
void SetChildContent(HWND content);
|
||||
|
||||
// Returns the backing Window handle to enable clients to set icon and other
|
||||
// window properties. Returns nullptr if the window has been destroyed.
|
||||
HWND GetHandle();
|
||||
|
||||
// If true, closing this window will quit the application.
|
||||
void SetQuitOnClose(bool quit_on_close);
|
||||
|
||||
// Return a RECT representing the bounds of the current client area.
|
||||
RECT GetClientArea();
|
||||
|
||||
protected:
|
||||
// Processes and route salient window messages for mouse handling,
|
||||
// size change and DPI. Delegates handling of these to member overloads that
|
||||
// inheriting classes can handle.
|
||||
virtual LRESULT MessageHandler(HWND window, UINT const message,
|
||||
WPARAM const wparam,
|
||||
LPARAM const lparam) noexcept;
|
||||
|
||||
// Called when CreateAndShow is called, allowing subclass window-related
|
||||
// setup. Subclasses should return false if setup fails.
|
||||
virtual bool OnCreate();
|
||||
|
||||
// Called when Destroy is called.
|
||||
virtual void OnDestroy();
|
||||
|
||||
private:
|
||||
friend class WindowClassRegistrar;
|
||||
|
||||
// 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
|
||||
// non-client DPI scaling so that the non-client area automatically
|
||||
// responsponds to changes in DPI. All other messages are handled by
|
||||
// MessageHandler.
|
||||
static LRESULT CALLBACK WndProc(HWND const window, UINT const message,
|
||||
WPARAM const wparam,
|
||||
LPARAM const lparam) noexcept;
|
||||
|
||||
// Retrieves a class instance pointer for |window|
|
||||
static Win32Window* GetThisFromHandle(HWND const window) noexcept;
|
||||
|
||||
bool quit_on_close_ = false;
|
||||
|
||||
// window handle for top level window.
|
||||
HWND window_handle_ = nullptr;
|
||||
|
||||
// window handle for hosted content.
|
||||
HWND child_content_ = nullptr;
|
||||
};
|
||||
|
||||
#endif // RUNNER_WIN32_WINDOW_H_
|
||||
@@ -0,0 +1,58 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:url_launcher_platform_interface/link.dart';
|
||||
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart';
|
||||
|
||||
import 'src/messages.g.dart';
|
||||
|
||||
/// An implementation of [UrlLauncherPlatform] for Windows.
|
||||
class UrlLauncherWindows extends UrlLauncherPlatform {
|
||||
/// Creates a new plugin implementation instance.
|
||||
UrlLauncherWindows({
|
||||
@visibleForTesting UrlLauncherApi? api,
|
||||
}) : _hostApi = api ?? UrlLauncherApi();
|
||||
|
||||
final UrlLauncherApi _hostApi;
|
||||
|
||||
/// Registers this class as the default instance of [UrlLauncherPlatform].
|
||||
static void registerWith() {
|
||||
UrlLauncherPlatform.instance = UrlLauncherWindows();
|
||||
}
|
||||
|
||||
@override
|
||||
final LinkDelegate? linkDelegate = null;
|
||||
|
||||
@override
|
||||
Future<bool> canLaunch(String url) {
|
||||
return _hostApi.canLaunchUrl(url);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> launch(
|
||||
String url, {
|
||||
required bool useSafariVC,
|
||||
required bool useWebView,
|
||||
required bool enableJavaScript,
|
||||
required bool enableDomStorage,
|
||||
required bool universalLinksOnly,
|
||||
required Map<String, String> headers,
|
||||
String? webOnlyWindowName,
|
||||
}) async {
|
||||
return _hostApi.launchUrl(url);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> supportsMode(PreferredLaunchMode mode) async {
|
||||
return mode == PreferredLaunchMode.platformDefault ||
|
||||
mode == PreferredLaunchMode.externalApplication;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> supportsCloseForMode(PreferredLaunchMode mode) async {
|
||||
// No supported mode is closeable.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
Use of this source code is governed by a BSD-style license that can be
|
||||
found in the LICENSE file.
|
||||
@@ -0,0 +1,18 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:pigeon/pigeon.dart';
|
||||
|
||||
@ConfigurePigeon(PigeonOptions(
|
||||
dartOut: 'lib/src/messages.g.dart',
|
||||
cppOptions: CppOptions(namespace: 'url_launcher_windows'),
|
||||
cppHeaderOut: 'windows/messages.g.h',
|
||||
cppSourceOut: 'windows/messages.g.cpp',
|
||||
copyrightHeader: 'pigeons/copyright.txt',
|
||||
))
|
||||
@HostApi(dartHostTestHandler: 'TestUrlLauncherApi')
|
||||
abstract class UrlLauncherApi {
|
||||
bool canLaunchUrl(String url);
|
||||
bool launchUrl(String url);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
name: url_launcher_windows
|
||||
description: Windows implementation of the url_launcher plugin.
|
||||
repository: https://github.com/flutter/packages/tree/main/packages/url_launcher/url_launcher_windows
|
||||
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+url_launcher%22
|
||||
version: 3.1.4
|
||||
|
||||
environment:
|
||||
sdk: ^3.4.0
|
||||
flutter: ">=3.22.0"
|
||||
|
||||
flutter:
|
||||
plugin:
|
||||
implements: url_launcher
|
||||
platforms:
|
||||
windows:
|
||||
pluginClass: UrlLauncherWindows
|
||||
dartPluginClass: UrlLauncherWindows
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
url_launcher_platform_interface: ^2.2.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
pigeon: ^21.0.0
|
||||
test: ^1.16.3
|
||||
|
||||
topics:
|
||||
- links
|
||||
- os-integration
|
||||
- url-launcher
|
||||
- urls
|
||||
@@ -0,0 +1,165 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart';
|
||||
import 'package:url_launcher_windows/src/messages.g.dart';
|
||||
import 'package:url_launcher_windows/url_launcher_windows.dart';
|
||||
|
||||
void main() {
|
||||
late _FakeUrlLauncherApi api;
|
||||
late UrlLauncherWindows plugin;
|
||||
|
||||
setUp(() {
|
||||
api = _FakeUrlLauncherApi();
|
||||
plugin = UrlLauncherWindows(api: api);
|
||||
});
|
||||
|
||||
test('registers instance', () {
|
||||
UrlLauncherWindows.registerWith();
|
||||
expect(UrlLauncherPlatform.instance, isA<UrlLauncherWindows>());
|
||||
});
|
||||
|
||||
group('canLaunch', () {
|
||||
test('handles true', () async {
|
||||
api.canLaunch = true;
|
||||
|
||||
final bool result = await plugin.canLaunch('http://example.com/');
|
||||
|
||||
expect(result, isTrue);
|
||||
expect(api.argument, 'http://example.com/');
|
||||
});
|
||||
|
||||
test('handles false', () async {
|
||||
api.canLaunch = false;
|
||||
|
||||
final bool result = await plugin.canLaunch('http://example.com/');
|
||||
|
||||
expect(result, isFalse);
|
||||
expect(api.argument, 'http://example.com/');
|
||||
});
|
||||
});
|
||||
|
||||
group('launch', () {
|
||||
test('handles success', () async {
|
||||
api.canLaunch = true;
|
||||
|
||||
expect(
|
||||
await plugin.launch(
|
||||
'http://example.com/',
|
||||
useSafariVC: true,
|
||||
useWebView: false,
|
||||
enableJavaScript: false,
|
||||
enableDomStorage: false,
|
||||
universalLinksOnly: false,
|
||||
headers: const <String, String>{},
|
||||
),
|
||||
true);
|
||||
expect(api.argument, 'http://example.com/');
|
||||
});
|
||||
|
||||
test('handles failure', () async {
|
||||
api.canLaunch = false;
|
||||
|
||||
expect(
|
||||
await plugin.launch(
|
||||
'http://example.com/',
|
||||
useSafariVC: true,
|
||||
useWebView: false,
|
||||
enableJavaScript: false,
|
||||
enableDomStorage: false,
|
||||
universalLinksOnly: false,
|
||||
headers: const <String, String>{},
|
||||
),
|
||||
false);
|
||||
expect(api.argument, 'http://example.com/');
|
||||
});
|
||||
|
||||
test('handles errors', () async {
|
||||
api.throwError = true;
|
||||
|
||||
await expectLater(
|
||||
plugin.launch(
|
||||
'http://example.com/',
|
||||
useSafariVC: true,
|
||||
useWebView: false,
|
||||
enableJavaScript: false,
|
||||
enableDomStorage: false,
|
||||
universalLinksOnly: false,
|
||||
headers: const <String, String>{},
|
||||
),
|
||||
throwsA(isA<PlatformException>()));
|
||||
expect(api.argument, 'http://example.com/');
|
||||
});
|
||||
});
|
||||
|
||||
group('supportsMode', () {
|
||||
test('returns true for platformDefault', () async {
|
||||
final UrlLauncherWindows launcher = UrlLauncherWindows(api: api);
|
||||
expect(await launcher.supportsMode(PreferredLaunchMode.platformDefault),
|
||||
true);
|
||||
});
|
||||
|
||||
test('returns true for external application', () async {
|
||||
final UrlLauncherWindows launcher = UrlLauncherWindows(api: api);
|
||||
expect(
|
||||
await launcher.supportsMode(PreferredLaunchMode.externalApplication),
|
||||
true);
|
||||
});
|
||||
|
||||
test('returns false for other modes', () async {
|
||||
final UrlLauncherWindows launcher = UrlLauncherWindows(api: api);
|
||||
expect(
|
||||
await launcher
|
||||
.supportsMode(PreferredLaunchMode.externalNonBrowserApplication),
|
||||
false);
|
||||
expect(await launcher.supportsMode(PreferredLaunchMode.inAppBrowserView),
|
||||
false);
|
||||
expect(
|
||||
await launcher.supportsMode(PreferredLaunchMode.inAppWebView), false);
|
||||
});
|
||||
});
|
||||
|
||||
test('supportsCloseForMode returns false', () async {
|
||||
final UrlLauncherWindows launcher = UrlLauncherWindows(api: api);
|
||||
expect(
|
||||
await launcher
|
||||
.supportsCloseForMode(PreferredLaunchMode.platformDefault),
|
||||
false);
|
||||
expect(
|
||||
await launcher
|
||||
.supportsCloseForMode(PreferredLaunchMode.externalApplication),
|
||||
false);
|
||||
});
|
||||
}
|
||||
|
||||
class _FakeUrlLauncherApi implements UrlLauncherApi {
|
||||
/// The argument that was passed to an API call.
|
||||
String? argument;
|
||||
|
||||
/// Controls the behavior of the fake canLaunch implementations.
|
||||
///
|
||||
/// - [canLaunchUrl] returns this value.
|
||||
/// - [launchUrl] returns this value if [throwError] is false.
|
||||
bool canLaunch = false;
|
||||
|
||||
/// Whether to throw a platform exception.
|
||||
bool throwError = false;
|
||||
|
||||
@override
|
||||
Future<bool> canLaunchUrl(String url) async {
|
||||
argument = url;
|
||||
return canLaunch;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> launchUrl(String url) async {
|
||||
argument = url;
|
||||
if (throwError) {
|
||||
throw PlatformException(code: 'Failed');
|
||||
}
|
||||
return canLaunch;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
set(PROJECT_NAME "url_launcher_windows")
|
||||
project(${PROJECT_NAME} LANGUAGES CXX)
|
||||
|
||||
cmake_policy(VERSION 3.10...3.24)
|
||||
|
||||
set(PLUGIN_NAME "${PROJECT_NAME}_plugin")
|
||||
|
||||
list(APPEND PLUGIN_SOURCES
|
||||
"messages.g.cpp"
|
||||
"messages.g.h"
|
||||
"system_apis.cpp"
|
||||
"system_apis.h"
|
||||
"url_launcher_plugin.cpp"
|
||||
"url_launcher_plugin.h"
|
||||
)
|
||||
|
||||
add_library(${PLUGIN_NAME} SHARED
|
||||
"include/url_launcher_windows/url_launcher_windows.h"
|
||||
"url_launcher_windows.cpp"
|
||||
${PLUGIN_SOURCES}
|
||||
)
|
||||
apply_standard_settings(${PLUGIN_NAME})
|
||||
set_target_properties(${PLUGIN_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden)
|
||||
target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)
|
||||
target_include_directories(${PLUGIN_NAME} INTERFACE
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||
target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin shlwapi.lib)
|
||||
|
||||
# List of absolute paths to libraries that should be bundled with the plugin
|
||||
set(file_chooser_bundled_libraries
|
||||
""
|
||||
PARENT_SCOPE
|
||||
)
|
||||
|
||||
|
||||
# === Tests ===
|
||||
|
||||
if (${include_${PROJECT_NAME}_tests})
|
||||
set(TEST_RUNNER "${PROJECT_NAME}_test")
|
||||
enable_testing()
|
||||
# TODO(stuartmorgan): Consider using a single shared, pre-checked-in googletest
|
||||
# instance rather than downloading for each plugin. This approach makes sense
|
||||
# for a template, but not for a monorepo with many plugins.
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
googletest
|
||||
URL https://github.com/google/googletest/archive/release-1.11.0.zip
|
||||
)
|
||||
# Prevent overriding the parent project's compiler/linker settings
|
||||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||
# Disable install commands for gtest so it doesn't end up in the bundle.
|
||||
set(INSTALL_GTEST OFF CACHE BOOL "Disable installation of googletest" FORCE)
|
||||
|
||||
FetchContent_MakeAvailable(googletest)
|
||||
|
||||
# The plugin's C API is not very useful for unit testing, so build the sources
|
||||
# directly into the test binary rather than using the DLL.
|
||||
add_executable(${TEST_RUNNER}
|
||||
test/url_launcher_windows_test.cpp
|
||||
${PLUGIN_SOURCES}
|
||||
)
|
||||
apply_standard_settings(${TEST_RUNNER})
|
||||
target_include_directories(${TEST_RUNNER} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
target_link_libraries(${TEST_RUNNER} PRIVATE flutter_wrapper_plugin shlwapi.lib)
|
||||
target_link_libraries(${TEST_RUNNER} PRIVATE gtest_main gmock)
|
||||
# flutter_wrapper_plugin has link dependencies on the Flutter DLL.
|
||||
add_custom_command(TARGET ${TEST_RUNNER} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
"${FLUTTER_LIBRARY}" $<TARGET_FILE_DIR:${TEST_RUNNER}>
|
||||
)
|
||||
|
||||
include(GoogleTest)
|
||||
gtest_discover_tests(${TEST_RUNNER})
|
||||
endif()
|
||||
@@ -0,0 +1,26 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
#ifndef PACKAGES_URL_LAUNCHER_URL_LAUNCHER_WINDOWS_WINDOWS_INCLUDE_URL_LAUNCHER_WINDOWS_URL_LAUNCHER_PLUGIN_H_
|
||||
#define PACKAGES_URL_LAUNCHER_URL_LAUNCHER_WINDOWS_WINDOWS_INCLUDE_URL_LAUNCHER_WINDOWS_URL_LAUNCHER_PLUGIN_H_
|
||||
|
||||
#include <flutter_plugin_registrar.h>
|
||||
|
||||
#ifdef FLUTTER_PLUGIN_IMPL
|
||||
#define FLUTTER_PLUGIN_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define FLUTTER_PLUGIN_EXPORT __declspec(dllimport)
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void UrlLauncherWindowsRegisterWithRegistrar(
|
||||
FlutterDesktopPluginRegistrarRef registrar);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // PACKAGES_URL_LAUNCHER_URL_LAUNCHER_WINDOWS_WINDOWS_INCLUDE_URL_LAUNCHER_WINDOWS_URL_LAUNCHER_PLUGIN_H_
|
||||
@@ -0,0 +1,148 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
// Autogenerated from Pigeon (v21.0.0), do not edit directly.
|
||||
// See also: https://pub.dev/packages/pigeon
|
||||
|
||||
#undef _HAS_EXCEPTIONS
|
||||
|
||||
#include "messages.g.h"
|
||||
|
||||
#include <flutter/basic_message_channel.h>
|
||||
#include <flutter/binary_messenger.h>
|
||||
#include <flutter/encodable_value.h>
|
||||
#include <flutter/standard_message_codec.h>
|
||||
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace url_launcher_windows {
|
||||
using flutter::BasicMessageChannel;
|
||||
using flutter::CustomEncodableValue;
|
||||
using flutter::EncodableList;
|
||||
using flutter::EncodableMap;
|
||||
using flutter::EncodableValue;
|
||||
|
||||
FlutterError CreateConnectionError(const std::string channel_name) {
|
||||
return FlutterError(
|
||||
"channel-error",
|
||||
"Unable to establish connection on channel: '" + channel_name + "'.",
|
||||
EncodableValue(""));
|
||||
}
|
||||
|
||||
PigeonCodecSerializer::PigeonCodecSerializer() {}
|
||||
|
||||
EncodableValue PigeonCodecSerializer::ReadValueOfType(
|
||||
uint8_t type, flutter::ByteStreamReader* stream) const {
|
||||
return flutter::StandardCodecSerializer::ReadValueOfType(type, stream);
|
||||
}
|
||||
|
||||
void PigeonCodecSerializer::WriteValue(
|
||||
const EncodableValue& value, flutter::ByteStreamWriter* stream) const {
|
||||
flutter::StandardCodecSerializer::WriteValue(value, stream);
|
||||
}
|
||||
|
||||
/// The codec used by UrlLauncherApi.
|
||||
const flutter::StandardMessageCodec& UrlLauncherApi::GetCodec() {
|
||||
return flutter::StandardMessageCodec::GetInstance(
|
||||
&PigeonCodecSerializer::GetInstance());
|
||||
}
|
||||
|
||||
// Sets up an instance of `UrlLauncherApi` to handle messages through the
|
||||
// `binary_messenger`.
|
||||
void UrlLauncherApi::SetUp(flutter::BinaryMessenger* binary_messenger,
|
||||
UrlLauncherApi* api) {
|
||||
UrlLauncherApi::SetUp(binary_messenger, api, "");
|
||||
}
|
||||
|
||||
void UrlLauncherApi::SetUp(flutter::BinaryMessenger* binary_messenger,
|
||||
UrlLauncherApi* api,
|
||||
const std::string& message_channel_suffix) {
|
||||
const std::string prepended_suffix =
|
||||
message_channel_suffix.length() > 0
|
||||
? std::string(".") + message_channel_suffix
|
||||
: "";
|
||||
{
|
||||
BasicMessageChannel<> channel(
|
||||
binary_messenger,
|
||||
"dev.flutter.pigeon.url_launcher_windows.UrlLauncherApi.canLaunchUrl" +
|
||||
prepended_suffix,
|
||||
&GetCodec());
|
||||
if (api != nullptr) {
|
||||
channel.SetMessageHandler(
|
||||
[api](const EncodableValue& message,
|
||||
const flutter::MessageReply<EncodableValue>& reply) {
|
||||
try {
|
||||
const auto& args = std::get<EncodableList>(message);
|
||||
const auto& encodable_url_arg = args.at(0);
|
||||
if (encodable_url_arg.IsNull()) {
|
||||
reply(WrapError("url_arg unexpectedly null."));
|
||||
return;
|
||||
}
|
||||
const auto& url_arg = std::get<std::string>(encodable_url_arg);
|
||||
ErrorOr<bool> output = api->CanLaunchUrl(url_arg);
|
||||
if (output.has_error()) {
|
||||
reply(WrapError(output.error()));
|
||||
return;
|
||||
}
|
||||
EncodableList wrapped;
|
||||
wrapped.push_back(EncodableValue(std::move(output).TakeValue()));
|
||||
reply(EncodableValue(std::move(wrapped)));
|
||||
} catch (const std::exception& exception) {
|
||||
reply(WrapError(exception.what()));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
channel.SetMessageHandler(nullptr);
|
||||
}
|
||||
}
|
||||
{
|
||||
BasicMessageChannel<> channel(
|
||||
binary_messenger,
|
||||
"dev.flutter.pigeon.url_launcher_windows.UrlLauncherApi.launchUrl" +
|
||||
prepended_suffix,
|
||||
&GetCodec());
|
||||
if (api != nullptr) {
|
||||
channel.SetMessageHandler(
|
||||
[api](const EncodableValue& message,
|
||||
const flutter::MessageReply<EncodableValue>& reply) {
|
||||
try {
|
||||
const auto& args = std::get<EncodableList>(message);
|
||||
const auto& encodable_url_arg = args.at(0);
|
||||
if (encodable_url_arg.IsNull()) {
|
||||
reply(WrapError("url_arg unexpectedly null."));
|
||||
return;
|
||||
}
|
||||
const auto& url_arg = std::get<std::string>(encodable_url_arg);
|
||||
ErrorOr<bool> output = api->LaunchUrl(url_arg);
|
||||
if (output.has_error()) {
|
||||
reply(WrapError(output.error()));
|
||||
return;
|
||||
}
|
||||
EncodableList wrapped;
|
||||
wrapped.push_back(EncodableValue(std::move(output).TakeValue()));
|
||||
reply(EncodableValue(std::move(wrapped)));
|
||||
} catch (const std::exception& exception) {
|
||||
reply(WrapError(exception.what()));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
channel.SetMessageHandler(nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EncodableValue UrlLauncherApi::WrapError(std::string_view error_message) {
|
||||
return EncodableValue(
|
||||
EncodableList{EncodableValue(std::string(error_message)),
|
||||
EncodableValue("Error"), EncodableValue()});
|
||||
}
|
||||
|
||||
EncodableValue UrlLauncherApi::WrapError(const FlutterError& error) {
|
||||
return EncodableValue(EncodableList{EncodableValue(error.code()),
|
||||
EncodableValue(error.message()),
|
||||
error.details()});
|
||||
}
|
||||
|
||||
} // namespace url_launcher_windows
|
||||
@@ -0,0 +1,103 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
// Autogenerated from Pigeon (v21.0.0), do not edit directly.
|
||||
// See also: https://pub.dev/packages/pigeon
|
||||
|
||||
#ifndef PIGEON_MESSAGES_G_H_
|
||||
#define PIGEON_MESSAGES_G_H_
|
||||
#include <flutter/basic_message_channel.h>
|
||||
#include <flutter/binary_messenger.h>
|
||||
#include <flutter/encodable_value.h>
|
||||
#include <flutter/standard_message_codec.h>
|
||||
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace url_launcher_windows {
|
||||
|
||||
// Generated class from Pigeon.
|
||||
|
||||
class FlutterError {
|
||||
public:
|
||||
explicit FlutterError(const std::string& code) : code_(code) {}
|
||||
explicit FlutterError(const std::string& code, const std::string& message)
|
||||
: code_(code), message_(message) {}
|
||||
explicit FlutterError(const std::string& code, const std::string& message,
|
||||
const flutter::EncodableValue& details)
|
||||
: code_(code), message_(message), details_(details) {}
|
||||
|
||||
const std::string& code() const { return code_; }
|
||||
const std::string& message() const { return message_; }
|
||||
const flutter::EncodableValue& details() const { return details_; }
|
||||
|
||||
private:
|
||||
std::string code_;
|
||||
std::string message_;
|
||||
flutter::EncodableValue details_;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class ErrorOr {
|
||||
public:
|
||||
ErrorOr(const T& rhs) : v_(rhs) {}
|
||||
ErrorOr(const T&& rhs) : v_(std::move(rhs)) {}
|
||||
ErrorOr(const FlutterError& rhs) : v_(rhs) {}
|
||||
ErrorOr(const FlutterError&& rhs) : v_(std::move(rhs)) {}
|
||||
|
||||
bool has_error() const { return std::holds_alternative<FlutterError>(v_); }
|
||||
const T& value() const { return std::get<T>(v_); };
|
||||
const FlutterError& error() const { return std::get<FlutterError>(v_); };
|
||||
|
||||
private:
|
||||
friend class UrlLauncherApi;
|
||||
ErrorOr() = default;
|
||||
T TakeValue() && { return std::get<T>(std::move(v_)); }
|
||||
|
||||
std::variant<T, FlutterError> v_;
|
||||
};
|
||||
|
||||
class PigeonCodecSerializer : public flutter::StandardCodecSerializer {
|
||||
public:
|
||||
PigeonCodecSerializer();
|
||||
inline static PigeonCodecSerializer& GetInstance() {
|
||||
static PigeonCodecSerializer sInstance;
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
void WriteValue(const flutter::EncodableValue& value,
|
||||
flutter::ByteStreamWriter* stream) const override;
|
||||
|
||||
protected:
|
||||
flutter::EncodableValue ReadValueOfType(
|
||||
uint8_t type, flutter::ByteStreamReader* stream) const override;
|
||||
};
|
||||
|
||||
// Generated interface from Pigeon that represents a handler of messages from
|
||||
// Flutter.
|
||||
class UrlLauncherApi {
|
||||
public:
|
||||
UrlLauncherApi(const UrlLauncherApi&) = delete;
|
||||
UrlLauncherApi& operator=(const UrlLauncherApi&) = delete;
|
||||
virtual ~UrlLauncherApi() {}
|
||||
virtual ErrorOr<bool> CanLaunchUrl(const std::string& url) = 0;
|
||||
virtual ErrorOr<bool> LaunchUrl(const std::string& url) = 0;
|
||||
|
||||
// The codec used by UrlLauncherApi.
|
||||
static const flutter::StandardMessageCodec& GetCodec();
|
||||
// Sets up an instance of `UrlLauncherApi` to handle messages through the
|
||||
// `binary_messenger`.
|
||||
static void SetUp(flutter::BinaryMessenger* binary_messenger,
|
||||
UrlLauncherApi* api);
|
||||
static void SetUp(flutter::BinaryMessenger* binary_messenger,
|
||||
UrlLauncherApi* api,
|
||||
const std::string& message_channel_suffix);
|
||||
static flutter::EncodableValue WrapError(std::string_view error_message);
|
||||
static flutter::EncodableValue WrapError(const FlutterError& error);
|
||||
|
||||
protected:
|
||||
UrlLauncherApi() = default;
|
||||
};
|
||||
} // namespace url_launcher_windows
|
||||
#endif // PIGEON_MESSAGES_G_H_
|
||||
@@ -0,0 +1,38 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
#include "system_apis.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
namespace url_launcher_windows {
|
||||
|
||||
SystemApis::SystemApis() {}
|
||||
|
||||
SystemApis::~SystemApis() {}
|
||||
|
||||
SystemApisImpl::SystemApisImpl() {}
|
||||
|
||||
SystemApisImpl::~SystemApisImpl() {}
|
||||
|
||||
LSTATUS SystemApisImpl::RegCloseKey(HKEY key) { return ::RegCloseKey(key); }
|
||||
|
||||
LSTATUS SystemApisImpl::RegOpenKeyExW(HKEY key, LPCWSTR sub_key, DWORD options,
|
||||
REGSAM desired, PHKEY result) {
|
||||
return ::RegOpenKeyExW(key, sub_key, options, desired, result);
|
||||
}
|
||||
|
||||
LSTATUS SystemApisImpl::RegQueryValueExW(HKEY key, LPCWSTR value_name,
|
||||
LPDWORD type, LPBYTE data,
|
||||
LPDWORD data_size) {
|
||||
return ::RegQueryValueExW(key, value_name, nullptr, type, data, data_size);
|
||||
}
|
||||
|
||||
HINSTANCE SystemApisImpl::ShellExecuteW(HWND hwnd, LPCWSTR operation,
|
||||
LPCWSTR file, LPCWSTR parameters,
|
||||
LPCWSTR directory, int show_flags) {
|
||||
return ::ShellExecuteW(hwnd, operation, file, parameters, directory,
|
||||
show_flags);
|
||||
}
|
||||
|
||||
} // namespace url_launcher_windows
|
||||
@@ -0,0 +1,56 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
#include <windows.h>
|
||||
|
||||
namespace url_launcher_windows {
|
||||
|
||||
// An interface wrapping system APIs used by the plugin, for mocking.
|
||||
class SystemApis {
|
||||
public:
|
||||
SystemApis();
|
||||
virtual ~SystemApis();
|
||||
|
||||
// Disallow copy and move.
|
||||
SystemApis(const SystemApis&) = delete;
|
||||
SystemApis& operator=(const SystemApis&) = delete;
|
||||
|
||||
// Wrapper for RegCloseKey.
|
||||
virtual LSTATUS RegCloseKey(HKEY key) = 0;
|
||||
|
||||
// Wrapper for RegQueryValueEx.
|
||||
virtual LSTATUS RegQueryValueExW(HKEY key, LPCWSTR value_name, LPDWORD type,
|
||||
LPBYTE data, LPDWORD data_size) = 0;
|
||||
|
||||
// Wrapper for RegOpenKeyEx.
|
||||
virtual LSTATUS RegOpenKeyExW(HKEY key, LPCWSTR sub_key, DWORD options,
|
||||
REGSAM desired, PHKEY result) = 0;
|
||||
|
||||
// Wrapper for ShellExecute.
|
||||
virtual HINSTANCE ShellExecuteW(HWND hwnd, LPCWSTR operation, LPCWSTR file,
|
||||
LPCWSTR parameters, LPCWSTR directory,
|
||||
int show_flags) = 0;
|
||||
};
|
||||
|
||||
// Implementation of SystemApis using the Win32 APIs.
|
||||
class SystemApisImpl : public SystemApis {
|
||||
public:
|
||||
SystemApisImpl();
|
||||
virtual ~SystemApisImpl();
|
||||
|
||||
// Disallow copy and move.
|
||||
SystemApisImpl(const SystemApisImpl&) = delete;
|
||||
SystemApisImpl& operator=(const SystemApisImpl&) = delete;
|
||||
|
||||
// SystemApis Implementation:
|
||||
virtual LSTATUS RegCloseKey(HKEY key);
|
||||
virtual LSTATUS RegOpenKeyExW(HKEY key, LPCWSTR sub_key, DWORD options,
|
||||
REGSAM desired, PHKEY result);
|
||||
virtual LSTATUS RegQueryValueExW(HKEY key, LPCWSTR value_name, LPDWORD type,
|
||||
LPBYTE data, LPDWORD data_size);
|
||||
virtual HINSTANCE ShellExecuteW(HWND hwnd, LPCWSTR operation, LPCWSTR file,
|
||||
LPCWSTR parameters, LPCWSTR directory,
|
||||
int show_flags);
|
||||
};
|
||||
|
||||
} // namespace url_launcher_windows
|
||||
@@ -0,0 +1,188 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
#include <flutter/method_call.h>
|
||||
#include <flutter/method_result_functions.h>
|
||||
#include <flutter/standard_method_codec.h>
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#include "messages.g.h"
|
||||
#include "url_launcher_plugin.h"
|
||||
|
||||
namespace url_launcher_windows {
|
||||
namespace test {
|
||||
|
||||
namespace {
|
||||
|
||||
using flutter::EncodableMap;
|
||||
using flutter::EncodableValue;
|
||||
using ::testing::_;
|
||||
using ::testing::DoAll;
|
||||
using ::testing::HasSubstr;
|
||||
using ::testing::Pointee;
|
||||
using ::testing::Return;
|
||||
using ::testing::SetArgPointee;
|
||||
using ::testing::StrEq;
|
||||
|
||||
class MockSystemApis : public SystemApis {
|
||||
public:
|
||||
MOCK_METHOD(LSTATUS, RegCloseKey, (HKEY key), (override));
|
||||
MOCK_METHOD(LSTATUS, RegQueryValueExW,
|
||||
(HKEY key, LPCWSTR value_name, LPDWORD type, LPBYTE data,
|
||||
LPDWORD data_size),
|
||||
(override));
|
||||
MOCK_METHOD(LSTATUS, RegOpenKeyExW,
|
||||
(HKEY key, LPCWSTR sub_key, DWORD options, REGSAM desired,
|
||||
PHKEY result),
|
||||
(override));
|
||||
MOCK_METHOD(HINSTANCE, ShellExecuteW,
|
||||
(HWND hwnd, LPCWSTR operation, LPCWSTR file, LPCWSTR parameters,
|
||||
LPCWSTR directory, int show_flags),
|
||||
(override));
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(UrlLauncherPlugin, CanLaunchSuccessTrue) {
|
||||
std::unique_ptr<MockSystemApis> system = std::make_unique<MockSystemApis>();
|
||||
|
||||
// Return success values from the registery commands.
|
||||
HKEY fake_key = reinterpret_cast<HKEY>(1);
|
||||
EXPECT_CALL(*system, RegOpenKeyExW)
|
||||
.WillOnce(DoAll(SetArgPointee<4>(fake_key), Return(ERROR_SUCCESS)));
|
||||
EXPECT_CALL(*system, RegQueryValueExW).WillOnce(Return(ERROR_SUCCESS));
|
||||
EXPECT_CALL(*system, RegCloseKey(fake_key)).WillOnce(Return(ERROR_SUCCESS));
|
||||
|
||||
UrlLauncherPlugin plugin(std::move(system));
|
||||
ErrorOr<bool> result = plugin.CanLaunchUrl("https://some.url.com");
|
||||
|
||||
ASSERT_FALSE(result.has_error());
|
||||
EXPECT_TRUE(result.value());
|
||||
}
|
||||
|
||||
TEST(UrlLauncherPlugin, CanLaunchQueryFailure) {
|
||||
std::unique_ptr<MockSystemApis> system = std::make_unique<MockSystemApis>();
|
||||
|
||||
// Return success values from the registery commands, except for the query,
|
||||
// to simulate a scheme that is in the registry, but has no URL handler.
|
||||
HKEY fake_key = reinterpret_cast<HKEY>(1);
|
||||
EXPECT_CALL(*system, RegOpenKeyExW)
|
||||
.WillOnce(DoAll(SetArgPointee<4>(fake_key), Return(ERROR_SUCCESS)));
|
||||
EXPECT_CALL(*system, RegQueryValueExW).WillOnce(Return(ERROR_FILE_NOT_FOUND));
|
||||
EXPECT_CALL(*system, RegCloseKey(fake_key)).WillOnce(Return(ERROR_SUCCESS));
|
||||
|
||||
UrlLauncherPlugin plugin(std::move(system));
|
||||
ErrorOr<bool> result = plugin.CanLaunchUrl("https://some.url.com");
|
||||
|
||||
ASSERT_FALSE(result.has_error());
|
||||
EXPECT_FALSE(result.value());
|
||||
}
|
||||
|
||||
TEST(UrlLauncherPlugin, CanLaunchHandlesOpenFailure) {
|
||||
std::unique_ptr<MockSystemApis> system = std::make_unique<MockSystemApis>();
|
||||
|
||||
// Return failure for opening.
|
||||
EXPECT_CALL(*system, RegOpenKeyExW).WillOnce(Return(ERROR_BAD_PATHNAME));
|
||||
|
||||
UrlLauncherPlugin plugin(std::move(system));
|
||||
ErrorOr<bool> result = plugin.CanLaunchUrl("https://some.url.com");
|
||||
|
||||
ASSERT_FALSE(result.has_error());
|
||||
EXPECT_FALSE(result.value());
|
||||
}
|
||||
|
||||
TEST(UrlLauncherPlugin, LaunchReportsSuccess) {
|
||||
std::unique_ptr<MockSystemApis> system = std::make_unique<MockSystemApis>();
|
||||
|
||||
// Return a success value (>32) from launching.
|
||||
EXPECT_CALL(*system, ShellExecuteW)
|
||||
.WillOnce(Return(reinterpret_cast<HINSTANCE>(33)));
|
||||
|
||||
UrlLauncherPlugin plugin(std::move(system));
|
||||
ErrorOr<bool> result = plugin.LaunchUrl("https://some.url.com");
|
||||
|
||||
ASSERT_FALSE(result.has_error());
|
||||
EXPECT_TRUE(result.value());
|
||||
}
|
||||
|
||||
TEST(UrlLauncherPlugin, LaunchReportsFailure) {
|
||||
std::unique_ptr<MockSystemApis> system = std::make_unique<MockSystemApis>();
|
||||
|
||||
// Return error 31 from launching, indicating no handler.
|
||||
EXPECT_CALL(*system, ShellExecuteW)
|
||||
.WillOnce(Return(reinterpret_cast<HINSTANCE>(SE_ERR_NOASSOC)));
|
||||
|
||||
UrlLauncherPlugin plugin(std::move(system));
|
||||
ErrorOr<bool> result = plugin.LaunchUrl("https://some.url.com");
|
||||
|
||||
ASSERT_FALSE(result.has_error());
|
||||
EXPECT_FALSE(result.value());
|
||||
}
|
||||
|
||||
TEST(UrlLauncherPlugin, LaunchReportsError) {
|
||||
std::unique_ptr<MockSystemApis> system = std::make_unique<MockSystemApis>();
|
||||
|
||||
// Return a failure value (<=32) from launching.
|
||||
EXPECT_CALL(*system, ShellExecuteW)
|
||||
.WillOnce(Return(reinterpret_cast<HINSTANCE>(32)));
|
||||
|
||||
UrlLauncherPlugin plugin(std::move(system));
|
||||
ErrorOr<bool> result = plugin.LaunchUrl("https://some.url.com");
|
||||
|
||||
EXPECT_TRUE(result.has_error());
|
||||
}
|
||||
|
||||
TEST(UrlLauncherPlugin, LaunchUTF8EncodedFileURLSuccess) {
|
||||
std::unique_ptr<MockSystemApis> system = std::make_unique<MockSystemApis>();
|
||||
|
||||
// Return a success value (>32) from launching.
|
||||
EXPECT_CALL(
|
||||
*system,
|
||||
ShellExecuteW(
|
||||
_, StrEq(L"open"),
|
||||
// 家の管理/スキャナ"),
|
||||
StrEq(
|
||||
L"file:///G:/\x5bb6\x306e\x7ba1\x7406/\x30b9\x30ad\x30e3\x30ca"),
|
||||
_, _, _))
|
||||
.WillOnce(Return(reinterpret_cast<HINSTANCE>(33)));
|
||||
|
||||
UrlLauncherPlugin plugin(std::move(system));
|
||||
ErrorOr<bool> result = plugin.LaunchUrl(
|
||||
"file:///G:/%E5%AE%B6%E3%81%AE%E7%AE%A1%E7%90%86/"
|
||||
"%E3%82%B9%E3%82%AD%E3%83%A3%E3%83%8A");
|
||||
|
||||
ASSERT_FALSE(result.has_error());
|
||||
EXPECT_TRUE(result.value());
|
||||
}
|
||||
|
||||
TEST(UrlLauncherPlugin, LaunchUTF8LogsUnescapedOnFail) {
|
||||
std::unique_ptr<MockSystemApis> system = std::make_unique<MockSystemApis>();
|
||||
|
||||
// Return a failure value (<32) from launching.
|
||||
EXPECT_CALL(
|
||||
*system,
|
||||
ShellExecuteW(
|
||||
_, StrEq(L"open"),
|
||||
// 家の管理/スキャナ"),
|
||||
StrEq(
|
||||
L"file:///G:/\x5bb6\x306e\x7ba1\x7406/\x30b9\x30ad\x30e3\x30ca"),
|
||||
_, _, _))
|
||||
.WillOnce(Return(reinterpret_cast<HINSTANCE>(0)));
|
||||
|
||||
UrlLauncherPlugin plugin(std::move(system));
|
||||
ErrorOr<bool> result = plugin.LaunchUrl(
|
||||
"file:///G:/%E5%AE%B6%E3%81%AE%E7%AE%A1%E7%90%86/"
|
||||
"%E3%82%B9%E3%82%AD%E3%83%A3%E3%83%8A");
|
||||
|
||||
ASSERT_TRUE(result.has_error());
|
||||
EXPECT_THAT(result.error().message(), HasSubstr("家の管理/スキャナ"));
|
||||
}
|
||||
|
||||
} // namespace test
|
||||
} // namespace url_launcher_windows
|
||||
@@ -0,0 +1,137 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
#include "url_launcher_plugin.h"
|
||||
|
||||
#include <flutter/method_channel.h>
|
||||
#include <flutter/plugin_registrar_windows.h>
|
||||
#include <flutter/standard_method_codec.h>
|
||||
#include <shlwapi.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "messages.g.h"
|
||||
|
||||
namespace url_launcher_windows {
|
||||
|
||||
namespace {
|
||||
|
||||
using flutter::EncodableMap;
|
||||
using flutter::EncodableValue;
|
||||
|
||||
// Converts the given UTF-8 string to UTF-16.
|
||||
std::wstring Utf16FromUtf8(const std::string& utf8_string) {
|
||||
if (utf8_string.empty()) {
|
||||
return std::wstring();
|
||||
}
|
||||
int target_length =
|
||||
::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, utf8_string.data(),
|
||||
static_cast<int>(utf8_string.length()), nullptr, 0);
|
||||
if (target_length == 0) {
|
||||
return std::wstring();
|
||||
}
|
||||
std::wstring utf16_string;
|
||||
utf16_string.resize(target_length);
|
||||
int converted_length =
|
||||
::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, utf8_string.data(),
|
||||
static_cast<int>(utf8_string.length()),
|
||||
utf16_string.data(), target_length);
|
||||
if (converted_length == 0) {
|
||||
return std::wstring();
|
||||
}
|
||||
return utf16_string;
|
||||
}
|
||||
|
||||
// Returns the URL argument from |method_call| if it is present, otherwise
|
||||
// returns an empty string.
|
||||
std::string GetUrlArgument(const flutter::MethodCall<>& method_call) {
|
||||
std::string url;
|
||||
const auto* arguments = std::get_if<EncodableMap>(method_call.arguments());
|
||||
if (arguments) {
|
||||
auto url_it = arguments->find(EncodableValue("url"));
|
||||
if (url_it != arguments->end()) {
|
||||
url = std::get<std::string>(url_it->second);
|
||||
}
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// static
|
||||
void UrlLauncherPlugin::RegisterWithRegistrar(
|
||||
flutter::PluginRegistrar* registrar) {
|
||||
std::unique_ptr<UrlLauncherPlugin> plugin =
|
||||
std::make_unique<UrlLauncherPlugin>();
|
||||
UrlLauncherApi::SetUp(registrar->messenger(), plugin.get());
|
||||
registrar->AddPlugin(std::move(plugin));
|
||||
}
|
||||
|
||||
UrlLauncherPlugin::UrlLauncherPlugin()
|
||||
: system_apis_(std::make_unique<SystemApisImpl>()) {}
|
||||
|
||||
UrlLauncherPlugin::UrlLauncherPlugin(std::unique_ptr<SystemApis> system_apis)
|
||||
: system_apis_(std::move(system_apis)) {}
|
||||
|
||||
UrlLauncherPlugin::~UrlLauncherPlugin() = default;
|
||||
|
||||
ErrorOr<bool> UrlLauncherPlugin::CanLaunchUrl(const std::string& url) {
|
||||
size_t separator_location = url.find(":");
|
||||
if (separator_location == std::string::npos) {
|
||||
return false;
|
||||
}
|
||||
std::wstring scheme = Utf16FromUtf8(url.substr(0, separator_location));
|
||||
|
||||
HKEY key = nullptr;
|
||||
if (system_apis_->RegOpenKeyExW(HKEY_CLASSES_ROOT, scheme.c_str(), 0,
|
||||
KEY_QUERY_VALUE, &key) != ERROR_SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
bool has_handler =
|
||||
system_apis_->RegQueryValueExW(key, L"URL Protocol", nullptr, nullptr,
|
||||
nullptr) == ERROR_SUCCESS;
|
||||
system_apis_->RegCloseKey(key);
|
||||
return has_handler;
|
||||
}
|
||||
|
||||
ErrorOr<bool> UrlLauncherPlugin::LaunchUrl(const std::string& url) {
|
||||
std::string url_to_open;
|
||||
if (url.find("file:") == 0) {
|
||||
// ShellExecuteW does not process %-encoded UTF8 strings in file URLs.
|
||||
DWORD unescaped_len = 0;
|
||||
std::string unescaped_url = url;
|
||||
if (FAILED(::UrlUnescapeA(unescaped_url.data(), /*pszUnescaped=*/nullptr,
|
||||
&unescaped_len, URL_UNESCAPE_INPLACE))) {
|
||||
return FlutterError("open_error", "Failed to unescape file URL");
|
||||
}
|
||||
url_to_open = unescaped_url;
|
||||
} else {
|
||||
url_to_open = url;
|
||||
}
|
||||
|
||||
int status =
|
||||
static_cast<int>(reinterpret_cast<INT_PTR>(system_apis_->ShellExecuteW(
|
||||
nullptr, TEXT("open"), Utf16FromUtf8(url_to_open).c_str(), nullptr,
|
||||
nullptr, SW_SHOWNORMAL)));
|
||||
|
||||
// Per ::ShellExecuteW documentation, anything >32 indicates success.
|
||||
if (status <= 32) {
|
||||
if (status == SE_ERR_NOASSOC) {
|
||||
// NOASSOC just means there's nothing registered to handle launching;
|
||||
// return false rather than an error for better consistency with other
|
||||
// platforms.
|
||||
return false;
|
||||
}
|
||||
std::ostringstream error_message;
|
||||
error_message << "Failed to open " << url_to_open
|
||||
<< ": ShellExecute error code " << status;
|
||||
return FlutterError("open_error", error_message.str());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace url_launcher_windows
|
||||
@@ -0,0 +1,43 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
#include <flutter/method_channel.h>
|
||||
#include <flutter/plugin_registrar_windows.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "messages.g.h"
|
||||
#include "system_apis.h"
|
||||
|
||||
namespace url_launcher_windows {
|
||||
|
||||
class UrlLauncherPlugin : public flutter::Plugin, public UrlLauncherApi {
|
||||
public:
|
||||
static void RegisterWithRegistrar(flutter::PluginRegistrar* registrar);
|
||||
|
||||
UrlLauncherPlugin();
|
||||
|
||||
// Creates a plugin instance with the given SystemApi instance.
|
||||
//
|
||||
// Exists for unit testing with mock implementations.
|
||||
UrlLauncherPlugin(std::unique_ptr<SystemApis> system_apis);
|
||||
|
||||
virtual ~UrlLauncherPlugin();
|
||||
|
||||
// Disallow copy and move.
|
||||
UrlLauncherPlugin(const UrlLauncherPlugin&) = delete;
|
||||
UrlLauncherPlugin& operator=(const UrlLauncherPlugin&) = delete;
|
||||
|
||||
// UrlLauncherApi:
|
||||
ErrorOr<bool> CanLaunchUrl(const std::string& url) override;
|
||||
ErrorOr<bool> LaunchUrl(const std::string& url) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<SystemApis> system_apis_;
|
||||
};
|
||||
|
||||
} // namespace url_launcher_windows
|
||||
@@ -0,0 +1,15 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
#include "include/url_launcher_windows/url_launcher_windows.h"
|
||||
|
||||
#include <flutter/plugin_registrar_windows.h>
|
||||
|
||||
#include "url_launcher_plugin.h"
|
||||
|
||||
void UrlLauncherWindowsRegisterWithRegistrar(
|
||||
FlutterDesktopPluginRegistrarRef registrar) {
|
||||
url_launcher_windows::UrlLauncherPlugin::RegisterWithRegistrar(
|
||||
flutter::PluginRegistrarManager::GetInstance()
|
||||
->GetRegistrar<flutter::PluginRegistrarWindows>(registrar));
|
||||
}
|
||||
Reference in New Issue
Block a user