Skip to content

Commit

Permalink
Merge pull request #64 from Presence-Man/development
Browse files Browse the repository at this point in the history
development -> main
  • Loading branch information
xxAROX authored Jul 17, 2024
2 parents e46ce16 + 074a187 commit 16d1f87
Show file tree
Hide file tree
Showing 44 changed files with 1,639 additions and 576 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/alpha-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: "Release alpha"

on:
push:
branches: [ "alpha*" ]

jobs:
build:
if: "!contains(github.event.head_commit.message, 'ci ignore')"
runs-on: "ubuntu-latest"

steps:
- uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: maven

- name: "Get version"
id: metadata
run: |
javac -d . src/main/java/xxAROX/PresenceMan/Application/AppInfo.java
echo "VERSION=$(java xxAROX.PresenceMan.Application.AppInfo development alpha)" >> $GITHUB_OUTPUT
echo ${{ steps.metadata.outputs.VERSION }}
- name: Build with Maven
run: |
mvn install:install-file -Dfile=./lib/discord-game-sdk4j-0.5.5.jar -DgroupId=discord-game-sdk4j -DartifactId=discord-game-sdk -Dversion=0.5.5 -Dpackaging=jar
mvn -B package --file pom.xml
- name: Rename JAR
run: |
cd target/
cp Application-1.0-SNAPSHOT.jar Presence-Man-App-v${{ steps.metadata.outputs.VERSION }}-dev.jar
cp Application-1.0-SNAPSHOT.jar Presence-Man-App-alpha.jar
cd ../
- name: "Create Release"
uses: "marvinpinto/action-automatic-releases@latest"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
draft: true
automatic_release_tag: "v${{ steps.metadata.outputs.VERSION }}"
prerelease: false
title: "Development Release v${{ steps.metadata.outputs.VERSION }}"
files: "target/Presence-Man-App-alpha.jar"

- name: "Create latest_version-alpha.txt"
run: "echo \"${{ steps.metadata.outputs.VERSION }}\" > latest_version-alpha.txt"

- name: "Update version-alpha.txt"
uses: "test-room-7/action-update-file@v1"
with:
file-path: latest_version-alpha.txt
commit-msg: "Updated alpha version to ${{ steps.metadata.outputs.VERSION }} - ci ignore"
github-token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .idea/copyright/Jan_Michael_Sohn___xxAROX.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/runConfigurations/Run__Alpha.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@
<version>1.6.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.github.JnCrMx</groupId>
<artifactId>discord-game-sdk4j</artifactId>
<version>v0.5.5</version>
</dependency>
<dependency>
<groupId>com.github.xxAROX</groupId>
<artifactId>WebRequester</artifactId>
<version>latest</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
Expand Down
99 changes: 63 additions & 36 deletions src/main/java/xxAROX/PresenceMan/Application/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import xxAROX.PresenceMan.Application.entity.APIActivity;
import xxAROX.PresenceMan.Application.entity.DiscordInfo;
import xxAROX.PresenceMan.Application.entity.XboxUserInfo;
import xxAROX.PresenceMan.Application.entity.Gateway;
import xxAROX.PresenceMan.Application.entity.infos.DiscordInfo;
import xxAROX.PresenceMan.Application.entity.infos.NetworkInfo;
import xxAROX.PresenceMan.Application.entity.infos.XboxUserInfo;
import xxAROX.PresenceMan.Application.events.IBaseListener;
import xxAROX.PresenceMan.Application.scheduler.WaterdogScheduler;
import xxAROX.PresenceMan.Application.sockets.SocketThread;
Expand All @@ -35,11 +37,14 @@
import xxAROX.PresenceMan.Application.ui.AppUI;
import xxAROX.PresenceMan.Application.utils.CacheManager;
import xxAROX.PresenceMan.Application.utils.ThreadFactoryBuilder;
import xxAROX.PresenceMan.Application.utils.Tray;
import xxAROX.PresenceMan.Application.utils.Utils;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.io.IOException;
import java.net.URL;
import java.time.Instant;
import java.util.Objects;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
Expand All @@ -48,33 +53,34 @@
@Getter
@ToString
public final class App {
@Getter static final long created = Instant.now().toEpochMilli();
public static Long network_session_created = null;
public static Long server_session_created = null;
public static String head_url = null;

@Getter private DiscordInfo discord_info = new DiscordInfo();

private static App instance;
@Getter private static App.Events events;
public SocketThread socket = null;
public String network = null;
public String server = null;

public static App getInstance() {
return instance;
}
public static String head_url = null;

@Getter private static App.Events events;
@Getter static final long created = Instant.now().toEpochMilli();
private Logger logger;
public static AppUI ui;
public SocketThread socket = null;
private WaterdogScheduler scheduler;
private ScheduledExecutorService tickExecutor;
private ScheduledFuture<?> tickFuture;
private volatile boolean shutdown = false;
private int currentTick = 0;
public APIActivity api_activity = null;
private volatile boolean shutdown = false;

public NetworkInfo network_info = new NetworkInfo();
public DiscordInfo discord_info = new DiscordInfo();
public XboxUserInfo xboxUserInfo = null;

private ImageIcon transparent_banner = null; // Cache

public boolean isConnectedViaMCBE() {
return App.getInstance().network_info.network_id != null;
}

@SneakyThrows
public App(Logger logger) {
if (instance != null) {
Expand All @@ -89,27 +95,29 @@ public App(Logger logger) {
initDiscord();

ThreadFactoryBuilder builder = ThreadFactoryBuilder.builder().format("Tick Executor - #%d").build();
tickExecutor = Executors.newScheduledThreadPool(1, builder);
tickExecutor = Executors.newScheduledThreadPool(10, builder);

scheduler = new WaterdogScheduler();
tickFuture = tickExecutor.scheduleAtFixedRate(this::processTick, 50, 50, TimeUnit.MILLISECONDS);

SwingUtilities.invokeLater(() -> ui = new AppUI());
if (CacheManager.Settings.ENABLE_AUTO_UPDATE) scheduler.scheduleAsync(new UpdateCheckTask());
if (!AppInfo.development && CacheManager.Settings.ENABLE_AUTO_UPDATE) scheduler.scheduleAsync(new UpdateCheckTask());
App.getInstance().getScheduler().scheduleAsync(new FetchGatewayInformationTask());

SwingUtilities.invokeLater(() -> ui = new AppUI());
xboxUserInfo = CacheManager.loadXboxUserInfo();
logger.info("App is in " + (AppInfo.development ? "development" : "production") + " mode");

while (ui == null) {Thread.sleep(1000);}
logger.info("App is in " + (AppInfo.alpha ? "Alpha" : (AppInfo.development ? "development" : "production")) + " mode");

while (ui == null) {
Thread.sleep(1000);
}
ui.setReady();
new Tray();
}

private void tick(int currentTick) {
scheduler.scheduleAsync(DiscordRPC::discordRunCallbacks);
if (socket != null) socket.tick(currentTick);
if (App.ui != null) App.ui.general_tab.tick();
if (App.ui != null) App.ui.tabs.forEach(t -> t.tick(currentTick));
scheduler.onTick(currentTick);
}

Expand All @@ -120,15 +128,20 @@ private void shutdownServices() {
}

public void updateServer(String new_network, String new_server) {
String before_network = network;
if (before_network == null || !before_network.equalsIgnoreCase(new_network)) {
network_session_created = new_network == null ? null : Instant.now().toEpochMilli();
network = new_network;
String before_network = network_info.network;
if (!Objects.equals(before_network, new_network)) {
network_info.network = new_network;
network_info.network_session_created = new_network == null ? null : Instant.now().toEpochMilli();
network_info.server = null;
network_info.server_session_created = network_info.network_session_created;
events.onNetworkChange(before_network, new_network);
return;
}
String before_server = server;
if (before_server == null || !before_server.equalsIgnoreCase(new_server)) {
server_session_created = new_server == null ? null : Instant.now().toEpochMilli();
server = new_server;
String before_server = network_info.server;
if (!Objects.equals(before_server, new_server)) {
network_info.server_session_created = new_server == null ? null : Instant.now().toEpochMilli();
network_info.server = new_server;
events.onNetworkServerChange(network_info.network, before_server, new_server);
}
}

Expand Down Expand Up @@ -179,8 +192,9 @@ public synchronized void initDiscord(String application_id) {
})
.build()
;
DiscordRPC.discordInitialize(discord_info.getCurrent_application_id(), handlers, false);
DiscordRPC.discordRegister(discord_info.getCurrent_application_id(), "");

DiscordRPC.discordInitialize(application_id, handlers, true);
DiscordRPC.discordRegister(application_id, null);
}

public static void setActivity(APIActivity api_activity) {
Expand All @@ -189,8 +203,8 @@ public static void setActivity(APIActivity api_activity) {
public static void setActivity(APIActivity api_activity, boolean queue) {
App app = App.getInstance();
if (api_activity == null) api_activity = APIActivity.none();
if (api_activity.equals(app.api_activity)) return;
app.api_activity = api_activity;
if (api_activity.equals(app.discord_info.api_activity)) return;
app.discord_info.api_activity = api_activity;
if (app.xboxUserInfo != null) {
if (api_activity.getState() != null) api_activity.setState(Utils.replaceParams(api_activity.getState()));
if (api_activity.getDetails() != null) api_activity.setDetails(Utils.replaceParams(api_activity.getDetails()));
Expand All @@ -209,6 +223,8 @@ public static void setActivity(APIActivity api_activity, boolean queue) {
DiscordRPC.discordUpdatePresence(finalApi_activity1.toDiscord());
} else if (queue) app.discord_info.registerHandler(() -> setActivity(finalApi_activity1, false));
});

if(ui != null) ui.general_tab.update(api_activity);
}

public static Logger getLogger(){
Expand All @@ -224,6 +240,17 @@ private void processTick() {
}
}

public ImageIcon getTransparentBanner() {
if (transparent_banner != null) return transparent_banner;
try {
//transparent_banner = new ImageIcon(ImageIO.read(new URL(Gateway.getUrl() + "/images/empty-banner.png")).getScaledInstance(500,1, 4));
transparent_banner = new ImageIcon(ImageIO.read(new URL(Gateway.getUrl() + "/images/transparent-banner.png")).getScaledInstance(500,1, 4));
return transparent_banner;
} catch (IOException ignore) {
return null;
}
}

public final class Events implements IBaseListener {
@Override
public void onLogin(XboxUserInfo info) {
Expand All @@ -241,7 +268,7 @@ public void onLogout() {

@Override
public void onDiscordReady(DiscordInfo info) {
logger.info("Welcome @" + info.getUsername() + ", discord is ready!");
logger.debug("Welcome @" + info.getUsername() + ", discord-rpc is ready!");
setActivity(APIActivity.none());
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/xxAROX/PresenceMan/Application/AppInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
import java.util.StringJoiner;

public final class AppInfo {
public final static int[] version = new int[]{ 1,2,11 };
public final static int[] version = new int[]{ 1,3,0 };
public final static String name = "Presence-Man";
public static String icon = "icon.png";
public static long discord_application_id = 1133823892486623344L;
public static boolean development = false;
public static boolean alpha = false;

public static String getVersion(){
return getVersion(".");
Expand All @@ -33,7 +34,7 @@ public static String getVersion(){
public static String getVersion(CharSequence delimiter){
StringJoiner joiner = new StringJoiner(delimiter);
for (int part : version) joiner.add(String.valueOf(part));
return joiner.toString() + (development ? "-dev" : "");
return joiner + (alpha ? "-alpha" : development ? "-dev" : "");
}

public static void main(String[] args) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/xxAROX/PresenceMan/Application/Bootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
public class Bootstrap {
@SneakyThrows
public static void main(String[] _args) {
//LOCK();
List<String> args = Arrays.stream(_args).toList();
List<String> lowArgs = args.stream().map(String::toLowerCase).toList();

AppInfo.development = lowArgs.contains("dev") || lowArgs.contains("development");
AppInfo.development = lowArgs.contains("dev") || lowArgs.contains("development") || lowArgs.contains("alpha");
AppInfo.alpha = lowArgs.contains("alpha");

Logger logger = initializeLogger();
if (Utils.SingleInstanceUtils.lockInstance(logger)) new App(logger);
Expand All @@ -45,7 +45,7 @@ public static void main(String[] _args) {
protected static Logger initializeLogger(){
//PropertyConfigurator.configure(ClassLoader.getSystemResource("log4j.properties"));
var logger = LogManager.getLogger(App.class);
//logger.setLevel(AppInfo.development ? Level.DEBUG : Level.INFO);
//logger.setLevel(AppInfo.development ? Level.DEBUG : Level.INFO); // TODO @KeksDev fix meee
return logger;
}
}
Loading

0 comments on commit 16d1f87

Please sign in to comment.