Skip to content

Commit

Permalink
Add registerProtocol method
Browse files Browse the repository at this point in the history
  • Loading branch information
lijy91 committed Mar 20, 2022
1 parent 15c4cad commit 443b6cb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ bool _initialUriIsHandled = false;
void main() {
if (Platform.isMacOS || Platform.isWindows) {
enableUniLinksDesktop();
if (Platform.isWindows) {
registerProtocol('unilinks');
}
}
runApp(MaterialApp(home: MyApp()));
}
Expand Down Expand Up @@ -266,6 +269,8 @@ List<String>? getCmds() {
cmdSuffix = "'";
} else if (Platform.isMacOS) {
cmd = 'open';
} else if (Platform.isWindows) {
cmd = 'start';
} else {
return null;
}
Expand Down
11 changes: 11 additions & 0 deletions example/windows/runner/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,19 @@
#include "flutter_window.h"
#include "utils.h"

#include <protocol_handler/protocol_handler_plugin.h>

int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
_In_ wchar_t *command_line, _In_ int show_command) {
HWND hwnd = ::FindWindow(L"FLUTTER_RUNNER_WIN32_WINDOW", L"uni_links_desktop_example");
if (hwnd != NULL) {
DispatchToProtocolHandler(hwnd);

::ShowWindow(hwnd, SW_NORMAL);
::SetForegroundWindow(hwnd);
return EXIT_FAILURE;
}

// 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()) {
Expand Down
4 changes: 4 additions & 0 deletions lib/src/uni_links_desktop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ void enableUniLinksDesktop() {
UniLinksPlatform.instance = UniLinksDesktop();
}

void registerProtocol(String scheme) {
protocolHandler.register(scheme);
}

class UniLinksDesktop extends UniLinksPlatform with ProtocolListener {
/// Registers this class as the default instance of [UniLinksDesktop].
static void registerWith() {
Expand Down

0 comments on commit 443b6cb

Please sign in to comment.