diff --git a/.gitignore b/.gitignore index 1b6985c..67c4583 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ # Ignore Gradle build output directory build + +.idea/ diff --git a/LICENSE b/LICENSE index d159169..800fb2f 100644 --- a/LICENSE +++ b/LICENSE @@ -290,8 +290,8 @@ to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. - - Copyright (C) + C-lightning plugin to create a small QR code when lightningd made somethings + Copyright (C) 2020 Vincenzo Palazzo vincenzopalazzodev@gmail.com This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -336,4 +336,4 @@ This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. +Public License instead of this License. \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 8557bde..edccd38 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,34 +1,26 @@ -/* - * This file was generated by the Gradle 'init' task. - * - * This generated file contains a sample Kotlin application project to get you started. - */ - plugins { - // Apply the Kotlin JVM plugin to add support for Kotlin. id("org.jetbrains.kotlin.jvm") version "1.3.71" - // Apply the application plugin to add support for building a CLI application. application } +val mainClass = "io.jlightning.qr.cli.AppKt" repositories { - // Use jcenter for resolving dependencies. - // You can declare any Maven/Ivy/file repository here. jcenter() } dependencies { - // Align versions of all Kotlin components implementation(platform("org.jetbrains.kotlin:kotlin-bom")) - - // Use the Kotlin JDK 8 standard library. implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") + implementation("io.github.material-ui-swing:DarkStackOverflowTheme:0.0.1-rc2") + implementation("io.github.vincenzopalazzo:material-ui-swing:1.1.1") + implementation("io.github.material-ui-swing:LinkLabelUI:0.0.1-rc1") + + api(fileTree("${project.projectDir}/devlib") { include("JQRInterface-0.0.1-rc1-all.jar") }) + api(fileTree("${project.projectDir}/devlib") { include("jrpclightning-0.1.6-SNAPSHOT.jar") }) - // Use the Kotlin test library. - testImplementation("org.jetbrains.kotlin:kotlin-test") - // Use the Kotlin JUnit integration. + testImplementation("org.jetbrains.kotlin:kotlin-test") testImplementation("org.jetbrains.kotlin:kotlin-test-junit") } @@ -36,3 +28,20 @@ application { // Define the main class for the application. mainClassName = "io.jlightning.qr.cli.AppKt" } + + +tasks { + register("fatJar", Jar::class.java) { + archiveClassifier.set("all") + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + manifest { + attributes("Main-Class" to mainClass) + } + from(configurations.runtimeClasspath.get() + .onEach { println("add from dependencies: ${it.name}") } + .map { if (it.isDirectory) it else zipTree(it) }) + val sourcesMain = sourceSets.main.get() + sourcesMain.allSource.forEach { println("add from sources: ${it.name}") } + from(sourcesMain.output) + } +} diff --git a/devlib/JQRInterface-0.0.1-rc1-all.jar b/devlib/JQRInterface-0.0.1-rc1-all.jar new file mode 100644 index 0000000..2807a79 Binary files /dev/null and b/devlib/JQRInterface-0.0.1-rc1-all.jar differ diff --git a/devlib/jrpclightning-0.1.6-SNAPSHOT.jar b/devlib/jrpclightning-0.1.6-SNAPSHOT.jar new file mode 100644 index 0000000..80989c9 Binary files /dev/null and b/devlib/jrpclightning-0.1.6-SNAPSHOT.jar differ diff --git a/qr-cli.sh b/qr-cli.sh new file mode 100755 index 0000000..4ece7d3 --- /dev/null +++ b/qr-cli.sh @@ -0,0 +1,18 @@ +# C-lightning plugin to create a small QR code when lightningd made somethings +# Copyright (C) 2020 Vincenzo Palazzo vincenzopalazzodev@gmail.com + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +/usr/lib/jvm/jdk-13.0.2/bin/java -jar /home/vincent/Github/qr-cli/build/libs/qr-cli-all.jar \ No newline at end of file diff --git a/src/main/kotlin/io/jlightning/qr/cli/App.kt b/src/main/kotlin/io/jlightning/qr/cli/App.kt index adecad1..f2add69 100644 --- a/src/main/kotlin/io/jlightning/qr/cli/App.kt +++ b/src/main/kotlin/io/jlightning/qr/cli/App.kt @@ -1,15 +1,29 @@ -/* - * This Kotlin source file was generated by the Gradle 'init' task. +/** + * C-lightning plugin to create a small QR code when lightningd made somethings + * Copyright (C) 2020 Vincenzo Palazzo vincenzopalazzodev@gmail.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ package io.jlightning.qr.cli -class App { - val greeting: String - get() { - return "Hello world." - } -} +import io.jlightning.qr.cli.plugin.PluginQRCli +/** + * @author https://github.com/vincenzopalazzo + */ fun main(args: Array) { - println(App().greeting) + val qrCli = PluginQRCli() + qrCli.start() } diff --git a/src/main/kotlin/io/jlightning/qr/cli/plugin/PluginQRCli.kt b/src/main/kotlin/io/jlightning/qr/cli/plugin/PluginQRCli.kt new file mode 100644 index 0000000..eae069c --- /dev/null +++ b/src/main/kotlin/io/jlightning/qr/cli/plugin/PluginQRCli.kt @@ -0,0 +1,85 @@ +/** + * C-lightning plugin to create a small QR code when lightningd made somethings + * Copyright (C) 2020 Vincenzo Palazzo vincenzopalazzodev@gmail.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +package io.jlightning.qr.cli.plugin + +import io.jlightning.qr.cli.ui.AfterRunUIAction +import io.jlightning.qr.cli.ui.QRCliUI +import jrpc.clightning.CLightningRPC +import jrpc.clightning.annotation.RPCMethod +import jrpc.clightning.annotation.Subscription +import jrpc.clightning.exceptions.CLightningException +import jrpc.clightning.plugins.CLightningPlugin +import jrpc.clightning.plugins.log.CLightningLevelLog +import jrpc.service.converters.jsonwrapper.CLightningJsonObject +import java.lang.Exception +import javax.swing.SwingUtilities + +/** + * @author https://github.com/vincenzopalazzo + */ +class PluginQRCli: CLightningPlugin() { + + + @RPCMethod(name = "peer-url", description = "generate a per URL with invoice") + fun peerUrl(plugin: CLightningPlugin, request: CLightningJsonObject, response: CLightningJsonObject){ + plugin.log(CLightningLevelLog.DEBUG, "RPC method qrInvoice") + plugin.log(CLightningLevelLog.DEBUG, request) + try{ + val getInfo = CLightningRPC.getInstance().info + val url = "%s@%s:%s".format(getInfo.id, getInfo.binding[0].address, getInfo.binding[0].port) + QRCliUI.instance.qrContent = url + QRCliUI.instance.title = "Node URL" + SwingUtilities.invokeLater{ QRCliUI.instance.initApp() } + response.apply { + add("node_url", url) + } + }catch (e: Exception){ + e.printStackTrace() + response.apply { + add("error", e.localizedMessage) + } + } + + } + + @Subscription(notification = "invoice_creation") + fun invoiceCrated(data: CLightningJsonObject) { + log(CLightningLevelLog.WARNING, data) + val invoiceCreation = data.get("params").asJsonObject + .get("invoice_creation").asJsonObject + log(CLightningLevelLog.WARNING, invoiceCreation) + val label = invoiceCreation.get("label").asString + log(CLightningLevelLog.WARNING, label) + try{ + QRCliUI.instance.title = "Invoice with label $label" + QRCliUI.instance.addEventAfterInitApp(object : AfterRunUIAction(){ + override fun run() { + val invoice = CLightningRPC.getInstance().listInvoices(label) + QRCliUI.instance.qrContent = invoice.listInvoice[0].bolt11 + } + }) + SwingUtilities.invokeLater { + QRCliUI.instance.initApp() + } + }catch (ex: CLightningException){ + ex.printStackTrace() + log(CLightningLevelLog.WARNING, ex.localizedMessage) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/io/jlightning/qr/cli/ui/AfterRunUIAction.kt b/src/main/kotlin/io/jlightning/qr/cli/ui/AfterRunUIAction.kt new file mode 100644 index 0000000..45e46c2 --- /dev/null +++ b/src/main/kotlin/io/jlightning/qr/cli/ui/AfterRunUIAction.kt @@ -0,0 +1,27 @@ +/** + * C-lightning plugin to create a small QR code when lightningd made somethings + * Copyright (C) 2020 Vincenzo Palazzo vincenzopalazzodev@gmail.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +package io.jlightning.qr.cli.ui + +/** + * @author https://github.com/vincenzopalazzo + */ +abstract class AfterRunUIAction { + + abstract fun run() +} \ No newline at end of file diff --git a/src/main/kotlin/io/jlightning/qr/cli/ui/QRCliUI.kt b/src/main/kotlin/io/jlightning/qr/cli/ui/QRCliUI.kt new file mode 100644 index 0000000..0a6971d --- /dev/null +++ b/src/main/kotlin/io/jlightning/qr/cli/ui/QRCliUI.kt @@ -0,0 +1,65 @@ +/** + * C-lightning plugin to create a small QR code when lightningd made somethings + * Copyright (C) 2020 Vincenzo Palazzo vincenzopalazzodev@gmail.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +package io.jlightning.qr.cli.ui + +import io.materialtheme.darkstackoverflow.DarkStackOverflowTheme +import mdlaf.MaterialLookAndFeel +import java.awt.Dimension +import javax.swing.JFrame +import javax.swing.UIManager + +/** + * @author https://github.com/vincenzopalazzo + */ +class QRCliUI: JFrame() { + + init { + UIManager.setLookAndFeel(MaterialLookAndFeel(DarkStackOverflowTheme())) + } + + private object HOLDER { + val SINGLETON = QRCliUI() + } + + companion object{ + val instance: QRCliUI by lazy { HOLDER.SINGLETON } + } + + internal var qrContent: String = "" + private var evetAfterRunApp: AfterRunUIAction? = null + private lateinit var qrUIContainer: QRUIContainer + + fun initApp(){ + if(evetAfterRunApp != null){ + evetAfterRunApp!!.run() + evetAfterRunApp = null + } + + qrUIContainer = QRUIContainer(qrContent) + contentPane = qrUIContainer + size = Dimension(500, 350) + setLocationRelativeTo(null) + defaultCloseOperation = HIDE_ON_CLOSE + isVisible = true + } + + fun addEventAfterInitApp(event: AfterRunUIAction){ + this.evetAfterRunApp = event + } +} \ No newline at end of file diff --git a/src/main/kotlin/io/jlightning/qr/cli/ui/QRUIContainer.kt b/src/main/kotlin/io/jlightning/qr/cli/ui/QRUIContainer.kt new file mode 100644 index 0000000..94ef1a5 --- /dev/null +++ b/src/main/kotlin/io/jlightning/qr/cli/ui/QRUIContainer.kt @@ -0,0 +1,56 @@ +/** + * C-lightning plugin to create a small QR code when lightningd made somethings + * Copyright (C) 2020 Vincenzo Palazzo vincenzopalazzodev@gmail.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +package io.jlightning.qr.cli.ui + +import io.vincenzopalazzo.qr.QRCode +import org.material.component.linklabelui.model.LinkLabel +import java.awt.BorderLayout +import javax.swing.ImageIcon +import javax.swing.JLabel +import javax.swing.JPanel + +/** + * @author https://github.com/vincenzopalazzo + */ +class QRUIContainer(private val qrcontent: String): JPanel(){ + + private lateinit var label: LinkLabel + private lateinit var qrImage: ImageIcon + + init { + initView() + } + + private fun initView(){ + label = LinkLabel(qrcontent) + val imageQr = QRCode.getQrToImage(qrcontent, 300, 300) + qrImage = ImageIcon(imageQr) + + initLayout() + initActions() + isVisible = true + } + + private fun initLayout(){ + layout = BorderLayout() + this.add(JLabel(qrImage), BorderLayout.CENTER) + } + + private fun initActions(){} +} \ No newline at end of file