Skip to content

Commit 443b6cb

Browse files
committed
Add registerProtocol method
1 parent 15c4cad commit 443b6cb

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

example/lib/main.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ bool _initialUriIsHandled = false;
1212
void main() {
1313
if (Platform.isMacOS || Platform.isWindows) {
1414
enableUniLinksDesktop();
15+
if (Platform.isWindows) {
16+
registerProtocol('unilinks');
17+
}
1518
}
1619
runApp(MaterialApp(home: MyApp()));
1720
}
@@ -266,6 +269,8 @@ List<String>? getCmds() {
266269
cmdSuffix = "'";
267270
} else if (Platform.isMacOS) {
268271
cmd = 'open';
272+
} else if (Platform.isWindows) {
273+
cmd = 'start';
269274
} else {
270275
return null;
271276
}

example/windows/runner/main.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,19 @@
55
#include "flutter_window.h"
66
#include "utils.h"
77

8+
#include <protocol_handler/protocol_handler_plugin.h>
9+
810
int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
911
_In_ wchar_t *command_line, _In_ int show_command) {
12+
HWND hwnd = ::FindWindow(L"FLUTTER_RUNNER_WIN32_WINDOW", L"uni_links_desktop_example");
13+
if (hwnd != NULL) {
14+
DispatchToProtocolHandler(hwnd);
15+
16+
::ShowWindow(hwnd, SW_NORMAL);
17+
::SetForegroundWindow(hwnd);
18+
return EXIT_FAILURE;
19+
}
20+
1021
// Attach to console when present (e.g., 'flutter run') or create a
1122
// new console when running with a debugger.
1223
if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) {

lib/src/uni_links_desktop.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ void enableUniLinksDesktop() {
99
UniLinksPlatform.instance = UniLinksDesktop();
1010
}
1111

12+
void registerProtocol(String scheme) {
13+
protocolHandler.register(scheme);
14+
}
15+
1216
class UniLinksDesktop extends UniLinksPlatform with ProtocolListener {
1317
/// Registers this class as the default instance of [UniLinksDesktop].
1418
static void registerWith() {

0 commit comments

Comments
 (0)