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 a7d636e
Show file tree
Hide file tree
Showing 31 changed files with 523 additions and 288 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
25 changes: 0 additions & 25 deletions packages/protocol_handler/windows/CMakeLists.txt

This file was deleted.

Loading

0 comments on commit a7d636e

Please sign in to comment.