From 8c52d1f31ac6066e178de994fec42a11ce018fde Mon Sep 17 00:00:00 2001 From: sommerfeld Date: Fri, 5 Jul 2024 15:23:53 +0100 Subject: Print QRcode for nostrconnect URI --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + src/main.rs | 8 ++++++++ 3 files changed, 16 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 810b693..4438918 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1134,6 +1134,12 @@ dependencies = [ "hex", ] +[[package]] +name = "qrcode" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23e719ca51966ff9f5a8436edb00d6115b3c606a0bb27c8f8ca74a38ff2b036d" + [[package]] name = "quote" version = "1.0.36" @@ -1760,6 +1766,7 @@ dependencies = [ "nostr-signer", "pretty_env_logger", "procfs", + "qrcode", "serde", "serde_json", "tokio", diff --git a/Cargo.toml b/Cargo.toml index 3ecd886..8b9e8df 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,7 @@ nostr-relay-pool = "0.32.0" nostr-sdk = { version = "0.32.0", default-features = false } nostr-signer = { version = "0.32.1", default-features = false, features = ["nip46"] } pretty_env_logger = "0.5.0" +qrcode = { version = "0.14.0", default-features = false } serde = { version = "1.0.203", features = ["derive"] } serde_json = "1.0.118" tokio = { version = "1.38.0", features = ["rt-multi-thread", "signal", "time"] } diff --git a/src/main.rs b/src/main.rs index dcd28e6..dfbbc25 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,6 +26,7 @@ use nostr_sdk::{ use nostr_signer::{Nip46Signer, NostrSigner}; #[cfg(any(target_os = "linux", target_os = "android"))] use procfs::net::TcpState; +use qrcode::{render::unicode, QrCode}; use serde::{Deserialize, Serialize}; use serde_json::{from_reader, to_string}; #[cfg(unix)] @@ -94,6 +95,13 @@ impl ClientData { println!( "Use your NIP46 signer app (e.g. Amber) to connect by using this URI:\n{uri}" ); + let code = QrCode::new(uri.clone()).unwrap(); + let image = code + .render::() + .dark_color(unicode::Dense1x2::Light) + .light_color(unicode::Dense1x2::Dark) + .build(); + println!("{}", image); uri } }; -- cgit v1.2.3-70-g09d2