Skip to content

Commit

Permalink
Version 1.0.2 is out
Browse files Browse the repository at this point in the history
Signed-off-by: TheRockYT <[email protected]>
  • Loading branch information
TheRockYT committed Oct 12, 2022
1 parent 78b7555 commit 35ae6db
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 5 deletions.
12 changes: 9 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<artifactId>ShutUpPC</artifactId>
<groupId>therockyt</groupId>
<version>1.0-SNAPSHOT</version>
<version>1.0</version>
<packaging>jar</packaging>

<name>consoleApp</name>
Expand Down Expand Up @@ -61,8 +61,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>6</source>
<target>6</target>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
Expand All @@ -75,6 +75,12 @@
<version>1.7.20</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
Expand Down
81 changes: 79 additions & 2 deletions src/main/kotlin/therockyt/shutuppc/GuiInterface.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package therockyt.shutuppc

import com.azul.crs.client.models.Network
import com.google.gson.JsonParser
import sendPacket
import java.awt.Dimension
import java.awt.GridLayout
Expand All @@ -9,18 +9,31 @@ import java.awt.event.ActionEvent
import java.awt.event.ActionListener
import java.awt.event.KeyAdapter
import java.awt.event.KeyEvent
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader
import java.net.URL
import java.net.URLConnection
import java.util.stream.Collectors
import javax.swing.*
import javax.swing.event.ListSelectionListener
import javax.swing.table.DefaultTableModel
import kotlin.system.exitProcess


class GuiInterface : ActionListener, KeyAdapter() {
val version = "1.0.1"
val version = "1.0.0"
private var frame = JFrame("ShutUpPC by TheRockYT")
private var jtable: JTable? = null
private var pctable: PcConfigTable? = null
var tablemodel: DefaultTableModel? = null
fun setAction(s: String?){
if(s == null){
frame.title = "ShutUpPC by TheRockYT"
}else{
frame.title = "$s - ShutUpPC by TheRockYT"
}
}
fun create(){
frame.defaultCloseOperation = JFrame.EXIT_ON_CLOSE
frame.isResizable = false
Expand All @@ -46,10 +59,13 @@ class GuiInterface : ActionListener, KeyAdapter() {
val process = JMenu("Process")
val about = JMenuItem("About")
val quit = JMenuItem("Quit")
val updates = JMenuItem("Check for Updates (API)")
about.addActionListener(this)
quit.addActionListener(this)
updates.addActionListener(this)
process.add(about)
process.add(quit)
process.add(updates)
menuBar.add(process)
val strArr = ArrayList<String>()
strArr.add("STATE")
Expand Down Expand Up @@ -114,6 +130,64 @@ class GuiInterface : ActionListener, KeyAdapter() {
JOptionPane.showMessageDialog(frame, "Delete failed!\nNo PC selected!", "ShutUpPC - Error", JOptionPane.ERROR_MESSAGE)
}
}
fun checkForUpdates(){
setAction("Checking for updates...")
try {
val content = getURLContent(URL("https://www.therockyt.com/api/shutuppc/versions.json"))
val jsonElement = JsonParser().parse(content)
val jsonObject = jsonElement.asJsonObject
val latest = jsonObject["latest-release"].asString
val latest_development = jsonObject["latest-development"].asString
val current = jsonObject["version"].asJsonObject[version].asJsonObject
var msg = "You are using ShutUpPC v$version"
var warn = false
if(version.equals(latest, true)){
msg += "\nThe latest release"
}else
if(version.equals(latest_development, true)){
msg += "\nThe latest development version"
}else{

if(current["development"].asBoolean){
msg += "\nAn outdated development version."
warn = true
}else{
msg += "\nAn outdated release."
}
msg += "\n(latest release: v$latest/latest development: $latest_development)"
if(current["update"].asBoolean){
msg += "\nAn update is recommended."
warn = true
}
msg += "\nUpdate at https://www.therockyt.com/shutuppc."
}
if(warn){

JOptionPane.showMessageDialog(frame, msg, "ShutUpPC - Update", JOptionPane.WARNING_MESSAGE)
}else{
JOptionPane.showMessageDialog(frame, msg, "ShutUpPC - Update", JOptionPane.INFORMATION_MESSAGE)

}
} catch (e: Exception) {
JOptionPane.showMessageDialog(frame, "ShutUpPC failed to load updates.\n${e.message}", "ShutUpPC - Update failed", JOptionPane.ERROR_MESSAGE)
}
setAction(null)
}

@Throws(Exception::class)
fun getURLContent(url: URL): String? {
val connection = url.openConnection()
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2");
val `is` = connection.getInputStream()
val reader = BufferedReader(InputStreamReader(`is`))
var lines: String? = ""
var line: String? = null
while (reader.readLine().also { line = it } != null) {
lines += line
}
reader.close()
return lines
}
fun wakeCurrentPC(){
val row = jtable!!.selectedRow
if(row > -1){
Expand Down Expand Up @@ -156,6 +230,9 @@ class GuiInterface : ActionListener, KeyAdapter() {
JOptionPane.showMessageDialog(frame, "Edit failed!\nNo PC selected!", "ShutUpPC - Error", JOptionPane.ERROR_MESSAGE)
}
}
if(src.text.equals("Check for Updates (API)")){
checkForUpdates()
}
}
}
}
Expand Down

0 comments on commit 35ae6db

Please sign in to comment.