-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com> Add license
- Loading branch information
1 parent
93819a6
commit 457b49e
Showing
11 changed files
with
304 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ | |
|
||
# Ignore Gradle build output directory | ||
build | ||
|
||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,47 @@ | ||
/* | ||
* 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") | ||
} | ||
|
||
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) | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String>) { | ||
println(App().greeting) | ||
val qrCli = PluginQRCli() | ||
qrCli.start() | ||
} |
85 changes: 85 additions & 0 deletions
85
src/main/kotlin/io/jlightning/qr/cli/plugin/PluginQRCli.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/kotlin/io/jlightning/qr/cli/ui/AfterRunUIAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(){} | ||
} |