Skip to content

Commit

Permalink
Merge pull request zenon-network#33 from alienc0der/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
alienc0der authored Apr 21, 2023
2 parents 50840e3 + aec25d6 commit d0763b3
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 4 deletions.
8 changes: 5 additions & 3 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,15 +106,16 @@ main() async {
}
});

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

runApp(
const MyApp(),
);
}

Future<void> _setupTrayManager() async {
if (!Platform.isWindows) {
await trayManager.setTitle('s y r i u s');
}
await trayManager.setIcon(
Platform.isWindows
? 'assets/images/tray_app_icon.ico'
Expand Down
43 changes: 43 additions & 0 deletions lib/widgets/main_app_container.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
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:logging/logging.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 @@ -56,6 +59,7 @@ class _MainAppContainerState extends State<MainAppContainer>
final NodeSyncStatusBloc _netSyncStatusBloc = NodeSyncStatusBloc();

late StreamSubscription _lockBlockStreamSubscription;
late StreamSubscription _incomingLinkSubscription;

Timer? _navigateToLockTimer;

Expand All @@ -70,6 +74,8 @@ class _MainAppContainerState extends State<MainAppContainer>
canRequestFocus: false,
);

bool _initialUriIsHandled = false;

@override
void initState() {
_netSyncStatusBloc.getDataPeriodically();
Expand All @@ -87,6 +93,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 @@ -467,6 +475,7 @@ class _MainAppContainerState extends State<MainAppContainer>
_netSyncStatusBloc.dispose();
_navigateToLockTimer?.cancel();
_lockBlockStreamSubscription.cancel();
_incomingLinkSubscription.cancel();
_tabController?.dispose();
super.dispose();
}
Expand Down Expand Up @@ -630,4 +639,38 @@ class _MainAppContainerState extends State<MainAppContainer>
_lockBloc.addEvent(LockEvent.countDown);
}
}

void _handleIncomingLinks() {
if (!kIsWeb) {
_incomingLinkSubscription = uriLinkStream.listen((Uri? uri) {
Logger('MainAppContainer')
.log(Level.INFO, '_handleIncomingLinks ${uri!.toString()}');
if (!mounted) return;
}, onError: (Object err) {
Logger('MainAppContainer')
.log(Level.WARNING, '_handleIncomingLinks', err);
if (!mounted) return;
});
}
}

Future<void> _handleInitialUri() async {
if (!_initialUriIsHandled) {
_initialUriIsHandled = true;
try {
final uri = await getInitialUri();
if (uri != null) {
Logger('MainAppContainer').log(Level.INFO, '_handleInitialUri $uri');
}
if (!mounted) return;
} on PlatformException catch (e, stackTrace) {
Logger('MainAppContainer').log(Level.WARNING,
'_handleInitialUri PlatformException', e, stackTrace);
} on FormatException catch (e, stackTrace) {
Logger('MainAppContainer').log(
Level.WARNING, '_handleInitialUri FormatException', e, stackTrace);
if (!mounted) return;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class _CardScaffoldState<T> extends State<CardScaffold<T>> {
Expanded(
child: Text(
title,
style: Theme.of(context).textTheme.bodyText1!.copyWith(
style: Theme.of(context).textTheme.bodyLarge!.copyWith(
fontSize: widget.titleFontSize,
height: 1.0,
),
Expand Down
13 changes: 13 additions & 0 deletions macos/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@
<string>$(PRODUCT_COPYRIGHT)</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>CFBundleURLTypes</key>
<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
32 changes: 32 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,38 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.3.1"
uni_links:
dependency: "direct main"
description:
name: uni_links
sha256: "051098acfc9e26a9fde03b487bef5d3d228ca8f67693480c6f33fd4fbb8e2b6e"
url: "https://pub.dev"
source: hosted
version: "0.5.1"
uni_links_desktop:
dependency: "direct main"
description:
name: uni_links_desktop
sha256: "205484c01890259b56d9271bcf299adf9889e881616c976f13061e29e94bb9f0"
url: "https://pub.dev"
source: hosted
version: "0.1.4"
uni_links_platform_interface:
dependency: transitive
description:
name: uni_links_platform_interface
sha256: "929cf1a71b59e3b7c2d8a2605a9cf7e0b125b13bc858e55083d88c62722d4507"
url: "https://pub.dev"
source: hosted
version: "1.0.0"
uni_links_web:
dependency: transitive
description:
name: uni_links_web
sha256: "7539db908e25f67de2438e33cc1020b30ab94e66720b5677ba6763b25f6394df"
url: "https://pub.dev"
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
3 changes: 3 additions & 0 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <screen_retriever/screen_retriever_plugin.h>
#include <share_plus/share_plus_windows_plugin_c_api.h>
#include <tray_manager/tray_manager_plugin.h>
#include <uni_links_desktop/uni_links_desktop_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>
#include <window_manager/window_manager_plugin.h>

Expand All @@ -28,6 +29,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
registry->GetRegistrarForPlugin("SharePlusWindowsPluginCApi"));
TrayManagerPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("TrayManagerPlugin"));
UniLinksDesktopPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UniLinksDesktopPlugin"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
WindowManagerPluginRegisterWithRegistrar(
Expand Down
1 change: 1 addition & 0 deletions windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
screen_retriever
share_plus
tray_manager
uni_links_desktop
url_launcher_windows
window_manager
)
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 d0763b3

Please sign in to comment.