Skip to content

Commit

Permalink
Merge pull request zenon-network#23 from mik3mast3rs/wallet-connect
Browse files Browse the repository at this point in the history
Add deep linking
  • Loading branch information
alienc0der authored Feb 10, 2023
2 parents 5db5ce6 + 994c7d6 commit adb0bf3
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:logging/logging.dart';
import 'package:overlay_support/overlay_support.dart';
import 'package:provider/provider.dart';
import 'package:tray_manager/tray_manager.dart';
import 'package:uni_links_desktop/uni_links_desktop.dart';
import 'package:window_manager/window_manager.dart';
import 'package:zenon_syrius_wallet_flutter/blocs/blocs.dart';
import 'package:zenon_syrius_wallet_flutter/model/model.dart';
Expand Down Expand Up @@ -105,6 +106,10 @@ main() async {
}
});

if (Platform.isWindows) {
registerProtocol('syrius');
}

runApp(
const MyApp(),
);
Expand Down
53 changes: 53 additions & 0 deletions lib/widgets/main_app_container.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
import 'package:provider/provider.dart';
import 'package:uni_links/uni_links.dart';
import 'package:zenon_syrius_wallet_flutter/blocs/blocs.dart';
import 'package:zenon_syrius_wallet_flutter/main.dart';
import 'package:zenon_syrius_wallet_flutter/model/model.dart';
Expand Down Expand Up @@ -70,6 +72,11 @@ class _MainAppContainerState extends State<MainAppContainer>
canRequestFocus: false,
);

final _scaffoldKey = GlobalKey();

bool _initialUriIsHandled = false;


@override
void initState() {
_netSyncStatusBloc.getDataPeriodically();
Expand All @@ -87,6 +94,8 @@ class _MainAppContainerState extends State<MainAppContainer>
_animation = Tween(begin: 1.0, end: 3.0).animate(_animationController);
kCurrentPage = kWalletInitCompleted ? Tabs.dashboard : Tabs.lock;
_initLockBlock();
_handleIncomingLinks();
_handleInitialUri();
super.initState();
}

Expand Down Expand Up @@ -630,4 +639,48 @@ class _MainAppContainerState extends State<MainAppContainer>
_lockBloc.addEvent(LockEvent.countDown);
}
}


/// Handle incoming links - the ones that the app will receive from the OS
/// while already started.
void _handleIncomingLinks() {
if (!kIsWeb) {
// It will handle app links while the app is already started - be it in
// the foreground or in the background.
uriLinkStream.listen((Uri? uri) {
if (!mounted) return;
}, onError: (Object err) {
if (!mounted) return;
});
}
}

Future<void> _handleInitialUri() async {
if (!_initialUriIsHandled) {
_initialUriIsHandled = true;
_showSnackBar('_handleInitialUri called');
try {
final uri = await getInitialUri();
if (uri == null) {
} else {
}
if (!mounted) return;
} on PlatformException {
// Platform messages may fail but we ignore the exception
} on FormatException {
if (!mounted) return;
}
}
}

void _showSnackBar(String msg) {
WidgetsBinding.instance.addPostFrameCallback((_) {
final context = _scaffoldKey.currentContext;
if (context != null) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(msg),
));
}
});
}
}
12 changes: 12 additions & 0 deletions macos/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@
<string>$(PRODUCT_COPYRIGHT)</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string></string>
<key>CFBundleURLSchemes</key>
<array>
<string>syrius</string>
</array>
</dict>
</array>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
Expand Down
28 changes: 28 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,34 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.3.1"
uni_links:
dependency: "direct main"
description:
name: uni_links
url: "https://pub.dartlang.org"
source: hosted
version: "0.5.1"
uni_links_desktop:
dependency: "direct main"
description:
name: uni_links_desktop
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4"
uni_links_platform_interface:
dependency: transitive
description:
name: uni_links_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
uni_links_web:
dependency: transitive
description:
name: uni_links_web
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.0"
universal_io:
dependency: transitive
description:
Expand Down
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ dependencies:
tray_manager: ^0.2.0
open_filex: ^4.3.2
launch_at_startup: ^0.2.1
uni_links_desktop: ^0.1.4
uni_links: ^0.5.1
logging: ^1.1.1

dev_dependencies:
Expand Down
10 changes: 10 additions & 0 deletions windows/runner/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,18 @@
#include "flutter_window.h"
#include "utils.h"

#include <uni_links_desktop/uni_links_desktop_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"s y r i u s");
if (hwnd != NULL) {
DispatchToUniLinksDesktop(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

0 comments on commit adb0bf3

Please sign in to comment.