Skip to content

Commit

Permalink
First release of plugin
Browse files Browse the repository at this point in the history
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>

Add license
  • Loading branch information
vincenzopalazzo committed Sep 2, 2020
1 parent 93819a6 commit 457b49e
Show file tree
Hide file tree
Showing 11 changed files with 304 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@

# Ignore Gradle build output directory
build

.idea/
6 changes: 3 additions & 3 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
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
Expand Down Expand Up @@ -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.
41 changes: 25 additions & 16 deletions build.gradle.kts
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 added devlib/JQRInterface-0.0.1-rc1-all.jar
Binary file not shown.
Binary file added devlib/jrpclightning-0.1.6-SNAPSHOT.jar
Binary file not shown.
18 changes: 18 additions & 0 deletions qr-cli.sh
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
32 changes: 23 additions & 9 deletions src/main/kotlin/io/jlightning/qr/cli/App.kt
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 src/main/kotlin/io/jlightning/qr/cli/plugin/PluginQRCli.kt
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 src/main/kotlin/io/jlightning/qr/cli/ui/AfterRunUIAction.kt
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()
}
65 changes: 65 additions & 0 deletions src/main/kotlin/io/jlightning/qr/cli/ui/QRCliUI.kt
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
}
}
56 changes: 56 additions & 0 deletions src/main/kotlin/io/jlightning/qr/cli/ui/QRUIContainer.kt
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(){}
}

0 comments on commit 457b49e

Please sign in to comment.