Skip to content

Commit

Permalink
Added version display and API
Browse files Browse the repository at this point in the history
  • Loading branch information
imTigger committed Aug 7, 2024
1 parent 41299bc commit 0283c19
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/main/java/tigerworkshop/webapphardwarebridge/Server.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tigerworkshop.webapphardwarebridge;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fazecast.jSerialComm.SerialPort;
import io.javalin.Javalin;
Expand All @@ -10,10 +11,7 @@
import io.javalin.util.JavalinBindException;
import io.javalin.websocket.WsContext;
import lombok.extern.log4j.Log4j2;
import tigerworkshop.webapphardwarebridge.dtos.Config;
import tigerworkshop.webapphardwarebridge.dtos.NotificationDTO;
import tigerworkshop.webapphardwarebridge.dtos.PrintServiceDTO;
import tigerworkshop.webapphardwarebridge.dtos.SerialPortDTO;
import tigerworkshop.webapphardwarebridge.dtos.*;
import tigerworkshop.webapphardwarebridge.interfaces.WebSocketServerInterface;
import tigerworkshop.webapphardwarebridge.interfaces.WebSocketServiceInterface;
import tigerworkshop.webapphardwarebridge.services.ConfigService;
Expand Down Expand Up @@ -229,6 +227,12 @@ synchronized public void start() throws Exception {
ctx.contentType(ContentType.APPLICATION_JSON).result(objectMapper.writeValueAsString(dtos));
});

javalinServer.get("/system/version.json", ctx -> {
VersionDTO dto = new VersionDTO(Constants.APP_NAME, Constants.APP_ID, Constants.VERSION);

ctx.contentType(ContentType.APPLICATION_JSON).result(objectMapper.writeValueAsString(dto));
});

javalinServer.post("/system/restart.json", ctx -> {
stop();
ThreadUtil.silentSleep(500);
Expand All @@ -239,6 +243,7 @@ synchronized public void start() throws Exception {

try {
javalinServer.start(serverConfig.getBind(), serverConfig.getPort());
log.info("{} {} running on {}", Constants.APP_NAME, Constants.VERSION, serverConfig.getUri());
} catch (JavalinBindException e) {
log.info("Unable to bind port, another instance is already running?");
System.exit(1);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package tigerworkshop.webapphardwarebridge.dtos;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@AllArgsConstructor
public class VersionDTO {
public String appName;
public String appId;
public String version;
}

0 comments on commit 0283c19

Please sign in to comment.