Skip to content

Commit

Permalink
chore: Windows implements migration to protocol_handler_windows package
Browse files Browse the repository at this point in the history
  • Loading branch information
lijy91 committed Jan 28, 2024
1 parent 0d9d80e commit 466cce5
Show file tree
Hide file tree
Showing 30 changed files with 568 additions and 106 deletions.
5 changes: 3 additions & 2 deletions README-ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

- [protocol_handler](#protocol_handler)
- [protocol\_handler](#protocol_handler)
- [平台支持](#平台支持)
- [截图](#截图)
- [快速开始](#快速开始)
Expand Down Expand Up @@ -252,10 +252,11 @@ dependencies:
#include "flutter_window.h"
#include "utils.h"
+#include <protocol_handler/protocol_handler_plugin.h>
+#include <protocol_handler_windows/protocol_handler_windows_plugin_c_api.h>
int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
_In_ wchar_t *command_line, _In_ int show_command) {
+ // Replace protocol_handler_example with your_window_title.
+ HWND hwnd = ::FindWindow(L"FLUTTER_RUNNER_WIN32_WINDOW", L"protocol_handler_example");
+ if (hwnd != NULL) {
+ DispatchToProtocolHandler(hwnd);
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ English | [简体中文](./README-ZH.md)
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

- [protocol_handler](#protocol_handler)
- [protocol\_handler](#protocol_handler)
- [Platform Support](#platform-support)
- [Screenshots](#screenshots)
- [Quick Start](#quick-start)
Expand Down Expand Up @@ -253,10 +253,11 @@ Change the file `windows/runner/main.cpp` as follows:
#include "flutter_window.h"
#include "utils.h"
+#include <protocol_handler/protocol_handler_plugin.h>
+#include <protocol_handler_windows/protocol_handler_windows_plugin_c_api.h>
int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
_In_ wchar_t *command_line, _In_ int show_command) {
+ // Replace protocol_handler_example with your_window_title.
+ HWND hwnd = ::FindWindow(L"FLUTTER_RUNNER_WIN32_WINDOW", L"protocol_handler_example");
+ if (hwnd != NULL) {
+ DispatchToProtocolHandler(hwnd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import FlutterMacOS
import Foundation

import protocol_handler_macos
import screen_retriever
import window_manager

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
ProtocolHandlerMacosPlugin.register(with: registry.registrar(forPlugin: "ProtocolHandlerMacosPlugin"))
ScreenRetrieverPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverPlugin"))
WindowManagerPlugin.register(with: registry.registrar(forPlugin: "WindowManagerPlugin"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@

#include "generated_plugin_registrant.h"

#include <protocol_handler/protocol_handler_plugin.h>
#include <protocol_handler_windows/protocol_handler_windows_plugin_c_api.h>
#include <screen_retriever/screen_retriever_plugin.h>
#include <window_manager/window_manager_plugin.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
ProtocolHandlerPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ProtocolHandlerPlugin"));
ProtocolHandlerWindowsPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ProtocolHandlerWindowsPluginCApi"));
ScreenRetrieverPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ScreenRetrieverPlugin"));
WindowManagerPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("WindowManagerPlugin"));
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
protocol_handler
protocol_handler_windows
screen_retriever
window_manager
)

Expand Down
3 changes: 2 additions & 1 deletion packages/protocol_handler/example/windows/runner/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
#include "flutter_window.h"
#include "utils.h"

#include <protocol_handler/protocol_handler_plugin.h>
#include <protocol_handler_windows/protocol_handler_windows_plugin_c_api.h>

int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
_In_ wchar_t *command_line, _In_ int show_command) {
// Replace protocol_handler_example with your_window_title.
HWND hwnd = ::FindWindow(L"FLUTTER_RUNNER_WIN32_WINDOW", L"protocol_handler_example");
if (hwnd != NULL) {
DispatchToProtocolHandler(hwnd);
Expand Down
9 changes: 4 additions & 5 deletions packages/protocol_handler/lib/src/protocol_handler.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:protocol_handler/src/protocol_registrar.dart';
import 'package:protocol_handler_platform_interface/protocol_handler_platform_interface.dart';

class ProtocolHandler {
Expand Down Expand Up @@ -61,16 +60,16 @@ class ProtocolHandler {
}
}

/// A broadcast stream of incoming protocol urls.
Stream<String?> get onUrlReceived => _platform.onUrlReceived;

/// Register a custom protocol
///
/// [scheme] is the custom protocol scheme, e.g. `myapp`
Future<void> register(String scheme) {
return protocolRegistrar.register(scheme);
return _platform.register(scheme);
}

/// A broadcast stream of incoming protocol urls.
Stream<String?> get onUrlReceived => _platform.onUrlReceived;

/// If the app launch was triggered by an protocol, it will give the link url,
/// otherwise it will give null.
Future<String?> getInitialUrl() {
Expand Down
30 changes: 0 additions & 30 deletions packages/protocol_handler/lib/src/protocol_registrar.dart

This file was deleted.

This file was deleted.

13 changes: 0 additions & 13 deletions packages/protocol_handler/lib/src/protocol_registrar_impl_ios.dart

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 2 additions & 2 deletions packages/protocol_handler/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies:
protocol_handler_ios: ^0.2.0
protocol_handler_macos: ^0.2.0
protocol_handler_platform_interface: ^0.2.0
win32_registry: ^1.0.2
protocol_handler_windows: ^0.2.0

dev_dependencies:
dependency_validator: ^3.0.0
Expand All @@ -38,4 +38,4 @@ flutter:
macos:
default_package: protocol_handler_macos
windows:
pluginClass: ProtocolHandlerPlugin
default_package: protocol_handler_windows
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// This must be included before many other Windows headers.
#include <windows.h>

#include <flutter/event_channel.h>
#include <flutter/event_stream_handler_functions.h>
#include <flutter/method_channel.h>
#include <flutter/plugin_registrar_windows.h>
#include <flutter/standard_method_codec.h>
Expand All @@ -14,7 +16,8 @@

namespace {

class ProtocolHandlerPlugin : public flutter::Plugin {
class ProtocolHandlerPlugin : public flutter::Plugin,
flutter::StreamHandler<flutter::EncodableValue> {
public:
static void RegisterWithRegistrar(flutter::PluginRegistrarWindows* registrar);

Expand Down
29 changes: 29 additions & 0 deletions packages/protocol_handler_windows/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
/pubspec.lock
**/doc/api/
.dart_tool/
build/
30 changes: 30 additions & 0 deletions packages/protocol_handler_windows/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: "67457e669f79e9f8d13d7a68fe09775fefbb79f4"
channel: "stable"

project_type: plugin

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: 67457e669f79e9f8d13d7a68fe09775fefbb79f4
base_revision: 67457e669f79e9f8d13d7a68fe09775fefbb79f4
- platform: windows
create_revision: 67457e669f79e9f8d13d7a68fe09775fefbb79f4
base_revision: 67457e669f79e9f8d13d7a68fe09775fefbb79f4

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'
3 changes: 3 additions & 0 deletions packages/protocol_handler_windows/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.2.0

* First release.
21 changes: 21 additions & 0 deletions packages/protocol_handler_windows/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022-2024 LiJianying <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
12 changes: 12 additions & 0 deletions packages/protocol_handler_windows/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# protocol_handler_windows

[![pub version][pub-image]][pub-url]

[pub-image]: https://img.shields.io/pub/v/protocol_handler_windows.svg
[pub-url]: https://pub.dev/packages/protocol_handler_windows

The Windows implementation of [protocol_handler](https://pub.dev/packages/protocol_handler).

## License

[MIT](./LICENSE)
1 change: 1 addition & 0 deletions packages/protocol_handler_windows/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:mostly_reasonable_lints/flutter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
library protocol_handler_windows;

export 'src/protocol_handler_windows.dart';
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import 'dart:io';

import 'package:protocol_handler/src/protocol_registrar.dart';
import 'package:protocol_handler_platform_interface/protocol_handler_platform_interface.dart';
import 'package:win32_registry/win32_registry.dart';

class ProtocolRegistrarImplWindows extends ProtocolRegistrar {
ProtocolRegistrarImplWindows._();
class ProtocolHandlerWindows extends MethodChannelProtocolHandler {
/// The [ProtocolHandlerWindows] constructor.
ProtocolHandlerWindows() : super();

/// The shared instance of [ProtocolRegistrarImplWindows].
static final ProtocolRegistrarImplWindows instance =
ProtocolRegistrarImplWindows._();
/// Registers this class as the default instance of [ProtocolHandlerWindows].
static void registerWith() {
ProtocolHandlerPlatform.instance = ProtocolHandlerWindows();
}

@override
Future<void> register(String scheme) async {
Expand Down
Loading

0 comments on commit 466cce5

Please sign in to comment.