Skip to content

Commit

Permalink
Update :D
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobbvfx committed Aug 5, 2022
1 parent 94c51c4 commit b04f485
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# ResolveRPC
Very very very simple ~~(and probably not memory efficient)~~ Discord Rich Presence Client for [DaVinci Resolve](https://www.blackmagicdesign.com/products/davinciresolve/).
Very very very simple ~~(and probably not memory efficient)~~ Discord Rich Presence Client for [DaVinci Resolve](https://www.blackmagicdesign.com/products/davinciresolve/). Thanks for little help [nadder](https://github.com/nadderus) :D.

## Screenshot
![alt text](https://i.imgur.com/Dv6jfNT.png "Rich Presence in Action")
![alt text](https://i.imgur.com/KXniQP7.png "Rich Presence in Action")

## Requirements
- Windows
Expand Down
23 changes: 15 additions & 8 deletions src/net/jacobb/resolverpc/DiscordRpc.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,28 @@
import com.jagrosh.discordipc.entities.RichPresence;
import com.jagrosh.discordipc.exceptions.NoDiscordClientException;

import java.io.IOException;
import java.time.OffsetDateTime;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;

public class DiscordRpc {
import static net.jacobb.resolverpc.WindowNameFunc.WindowName;

public class DiscordRpc {
public static IPCClient client = new IPCClient(1004088618857549844L);
public static RichPresence.Builder builder = new RichPresence.Builder();
public static void DiscordIntegration() {

client.setListener(new IPCListener(){
@Override
public void onReady(IPCClient client)
{
RichPresence.Builder builder = new RichPresence.Builder();
builder.setState("Editing...")
.setStartTimestamp(OffsetDateTime.now())
.setLargeImage("resolve", "DaVinci Resolve");
public void onReady(IPCClient client) {
try {
builder.setState(WindowName().toString())
.setStartTimestamp(OffsetDateTime.now())
.setLargeImage("resolve", "DaVinci Resolve");
} catch (InterruptedException | IOException e) {
throw new RuntimeException(e);
}
client.sendRichPresence(builder.build());
}
});
Expand Down
37 changes: 33 additions & 4 deletions src/net/jacobb/resolverpc/Main.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
package net.jacobb.resolverpc;

import com.jagrosh.discordipc.exceptions.NoDiscordClientException;
import com.jagrosh.discordipc.IPCClient;
import com.jagrosh.discordipc.entities.RichPresence;

import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;

import static net.jacobb.resolverpc.ProcessListFunc.ProcessList;
import static net.jacobb.resolverpc.WindowNameFunc.WindowName;

public class Main extends DiscordRpc {

public static void main(String[] args) throws IOException, InterruptedException, NoDiscordClientException {
public static void main(String[] args) throws IOException, InterruptedException {

do {
Thread.sleep(5000);
while(ProcessList() == true) {
while(ProcessList()) {
Thread.sleep(5000);
if(!client.getStatus().toString().equals("CONNECTED")) {
DiscordIntegration();
System.out.println("Discord RPC Started");

runTask(client, builder);

Thread.sleep(5000);
}

if(ProcessList() == false){
if(!ProcessList()){
client.close();
System.out.println("Discord RPC Stopped");
Thread.sleep(10000);
Expand All @@ -33,4 +40,26 @@ public static void main(String[] args) throws IOException, InterruptedException,

}

private static void runTask(IPCClient ipcClient, RichPresence.Builder builder) {
Timer timer = new Timer();
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
try {
if (!ProcessList()) {
timer.cancel();
return;
}

builder.setState(WindowName().toString());

ipcClient.sendRichPresence(builder.build());
} catch (InterruptedException | IOException e) {
throw new RuntimeException(e);
}
}
};
timer.schedule(timerTask, 0, 10000);
}

}
38 changes: 38 additions & 0 deletions src/net/jacobb/resolverpc/WindowNameFunc.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package net.jacobb.resolverpc;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.atomic.AtomicReference;

public class WindowNameFunc {

public static AtomicReference<String> WindowName() throws InterruptedException, IOException {

AtomicReference<String> current = new AtomicReference<>("");

Process process = new ProcessBuilder("tasklist", "/v", "/fo", "csv").start();
new Thread(() -> {
Scanner sc = new Scanner(process.getInputStream());
if (sc.hasNextLine()) sc.nextLine();
while (sc.hasNextLine()) {
String line = sc.nextLine();
String[] parts = line.split(",");
String unq = parts[8].substring(1).replaceFirst(".$", "");
unq = unq.replace("N/A", "");
// System.out.println(unq);

if (unq.contains("Project Manager")) {
current.set("Inside: Project Manager");
}
else if (unq.contains("DaVinci Resolve - ")){
unq = unq.replace("DaVinci Resolve - ", "");
current.set("Editing: " + unq);
}

}
}).start();
process.waitFor();

return current;
}
}

0 comments on commit b04f485

Please sign in to comment.