Skip to content

Commit b04f485

Browse files
committed
Update :D
1 parent 94c51c4 commit b04f485

File tree

4 files changed

+88
-14
lines changed

4 files changed

+88
-14
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# ResolveRPC
2-
Very very very simple ~~(and probably not memory efficient)~~ Discord Rich Presence Client for [DaVinci Resolve](https://www.blackmagicdesign.com/products/davinciresolve/).
2+
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.
33

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

77
## Requirements
88
- Windows

src/net/jacobb/resolverpc/DiscordRpc.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,28 @@
55
import com.jagrosh.discordipc.entities.RichPresence;
66
import com.jagrosh.discordipc.exceptions.NoDiscordClientException;
77

8+
import java.io.IOException;
89
import java.time.OffsetDateTime;
10+
import java.util.Timer;
11+
import java.util.TimerTask;
12+
import java.util.concurrent.TimeUnit;
913

10-
public class DiscordRpc {
14+
import static net.jacobb.resolverpc.WindowNameFunc.WindowName;
1115

16+
public class DiscordRpc {
1217
public static IPCClient client = new IPCClient(1004088618857549844L);
18+
public static RichPresence.Builder builder = new RichPresence.Builder();
1319
public static void DiscordIntegration() {
14-
1520
client.setListener(new IPCListener(){
1621
@Override
17-
public void onReady(IPCClient client)
18-
{
19-
RichPresence.Builder builder = new RichPresence.Builder();
20-
builder.setState("Editing...")
21-
.setStartTimestamp(OffsetDateTime.now())
22-
.setLargeImage("resolve", "DaVinci Resolve");
22+
public void onReady(IPCClient client) {
23+
try {
24+
builder.setState(WindowName().toString())
25+
.setStartTimestamp(OffsetDateTime.now())
26+
.setLargeImage("resolve", "DaVinci Resolve");
27+
} catch (InterruptedException | IOException e) {
28+
throw new RuntimeException(e);
29+
}
2330
client.sendRichPresence(builder.build());
2431
}
2532
});

src/net/jacobb/resolverpc/Main.java

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
11
package net.jacobb.resolverpc;
22

3-
import com.jagrosh.discordipc.exceptions.NoDiscordClientException;
3+
import com.jagrosh.discordipc.IPCClient;
4+
import com.jagrosh.discordipc.entities.RichPresence;
45

56
import java.io.IOException;
7+
import java.util.Timer;
8+
import java.util.TimerTask;
69

710
import static net.jacobb.resolverpc.ProcessListFunc.ProcessList;
11+
import static net.jacobb.resolverpc.WindowNameFunc.WindowName;
812

913
public class Main extends DiscordRpc {
1014

11-
public static void main(String[] args) throws IOException, InterruptedException, NoDiscordClientException {
15+
public static void main(String[] args) throws IOException, InterruptedException {
1216

1317
do {
1418
Thread.sleep(5000);
15-
while(ProcessList() == true) {
19+
while(ProcessList()) {
1620
Thread.sleep(5000);
1721
if(!client.getStatus().toString().equals("CONNECTED")) {
1822
DiscordIntegration();
1923
System.out.println("Discord RPC Started");
24+
25+
runTask(client, builder);
26+
2027
Thread.sleep(5000);
2128
}
2229

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

3441
}
3542

43+
private static void runTask(IPCClient ipcClient, RichPresence.Builder builder) {
44+
Timer timer = new Timer();
45+
TimerTask timerTask = new TimerTask() {
46+
@Override
47+
public void run() {
48+
try {
49+
if (!ProcessList()) {
50+
timer.cancel();
51+
return;
52+
}
53+
54+
builder.setState(WindowName().toString());
55+
56+
ipcClient.sendRichPresence(builder.build());
57+
} catch (InterruptedException | IOException e) {
58+
throw new RuntimeException(e);
59+
}
60+
}
61+
};
62+
timer.schedule(timerTask, 0, 10000);
63+
}
64+
3665
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package net.jacobb.resolverpc;
2+
3+
import java.io.IOException;
4+
import java.util.Scanner;
5+
import java.util.concurrent.atomic.AtomicReference;
6+
7+
public class WindowNameFunc {
8+
9+
public static AtomicReference<String> WindowName() throws InterruptedException, IOException {
10+
11+
AtomicReference<String> current = new AtomicReference<>("");
12+
13+
Process process = new ProcessBuilder("tasklist", "/v", "/fo", "csv").start();
14+
new Thread(() -> {
15+
Scanner sc = new Scanner(process.getInputStream());
16+
if (sc.hasNextLine()) sc.nextLine();
17+
while (sc.hasNextLine()) {
18+
String line = sc.nextLine();
19+
String[] parts = line.split(",");
20+
String unq = parts[8].substring(1).replaceFirst(".$", "");
21+
unq = unq.replace("N/A", "");
22+
// System.out.println(unq);
23+
24+
if (unq.contains("Project Manager")) {
25+
current.set("Inside: Project Manager");
26+
}
27+
else if (unq.contains("DaVinci Resolve - ")){
28+
unq = unq.replace("DaVinci Resolve - ", "");
29+
current.set("Editing: " + unq);
30+
}
31+
32+
}
33+
}).start();
34+
process.waitFor();
35+
36+
return current;
37+
}
38+
}

0 commit comments

Comments
 (0)