Skip to content
This repository was archived by the owner on May 14, 2022. It is now read-only.

Commit 50f839c

Browse files
committed
Different Color Schemes in MyColors.kt
1 parent 8df04f9 commit 50f839c

File tree

13 files changed

+320
-199
lines changed

13 files changed

+320
-199
lines changed

build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ jar {
3333
}
3434
}
3535

36-
task shipJar(dependsOn: ['copyCSS', 'copyRsc', 'copyREADME', 'jar']) {
36+
task shipJar(dependsOn: ['copyCSS', 'copyRes', 'copyREADME', 'jar']) {
3737
}
3838

39-
task copyRsc(type: Copy) {
40-
from("$projectDir/rsc")
41-
into("$projectDir/build/libs/rsc")
39+
task copyRes(type: Copy) {
40+
from("$projectDir/res")
41+
into("$projectDir/build/libs/res")
4242
}
4343

4444
task copyCSS(type: Copy) {

res/blacklisted.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
["C:\\Users\\Apoc\\AppData\\Local\\JetBrains\\IntelliJ IDEA 2020.3\\bin\\idea64.exe","C:\\Users\\Apoc\\AppData\\Local\\JetBrains\\IntelliJ IDEA 2020.3\\jbr\\bin\\jcef_helper.exe","C:\\Program Files\\WindowsApps\\Microsoft.WindowsStore_12101.1001.14.0_x64__8wekyb3d8bbwe\\WinStore.App.exe","C:\\Users\\Apoc\\scoop\\apps\\spotify-latest\\1.1.56.595.g2d2da0de\\Spotify.exe","C:\\Program Files\\WindowsApps\\Microsoft.ZuneMusic_10.20122.11121.0_x64__8wekyb3d8bbwe\\Music.UI.exe"]
1+
["C:\\Program Files (x86)\\Epic Games\\Launcher\\Portal\\Binaries\\Win64\\EpicGamesLauncher.exe"]

res/hidden.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
["System32","Nvidia","SystemApps","wallpaper","Razer","Native Instruments","xboxGam","Microsoft.ZuneVideo","Settings","GWSL","Keyboard Chattering Fix","YourPhone","webhelper","Driver","Gaomon","Git","fsnotifier","C:\\Program Files (x86)\\Origin\\QtWebEngineProcess.exe"]
1+
["System32","Nvidia","SystemApps","wallpaper","Razer","Native Instruments","xboxGam","Microsoft.ZuneVideo","Settings","GWSL","Keyboard Chattering Fix","YourPhone","webhelper","Driver","Gaomon","Git","fsnotifier","C:\\Program Files (x86)\\Origin\\QtWebEngineProcess.exe","C:\\Users\\Apoc\\AppData\\Local\\JetBrains\\IntelliJ IDEA 2020.3\\jbr\\bin\\jcef_helper.exe","C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\pwahelper.exe","C:\\Program Files\\Microsoft Office\\root\\Office16\\ONENOTEM.EXE","C:\\Users\\Apoc\\AppData\\Local\\JetBrains\\IntelliJ IDEA 2020.3\\lib\\pty4j-native\\win\\x86-64\\winpty-agent.exe","C:\\Users\\Apoc\\AppData\\Roaming\\SuperF4\\SuperF4.exe","C:\\Users\\Apoc\\AppData\\Local\\FluxSoftware\\Flux\\flux.exe","C:\\Windows\\explorer.exe","C:\\Program Files\\WindowsApps\\Microsoft.WindowsStore_12101.1001.14.0_x64__8wekyb3d8bbwe\\WinStore.App.exe","C:\\Program Files\\WindowsApps\\Microsoft.ZuneMusic_10.20122.11121.0_x64__8wekyb3d8bbwe\\Music.UI.exe","C:\\Riot Games\\Riot Client\\RiotClientServices.exe","C:\\Riot Games\\Riot Client\\RiotClientCrashHandler.exe","C:\\Riot Games\\League of Legends\\LeagueClientUx.exe","C:\\Riot Games\\League of Legends\\LeagueCrashHandler.exe","C:\\Riot Games\\League of Legends\\LeagueClientUxRender.exe","C:\\Users\\Apoc\\AppData\\Local\\JetBrains\\IntelliJ IDEA 2020.3\\jbr\\bin\\java.exe"]

res/testSave.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"handle":{"pid":18368,"startTime":1618128320807,"STARTTIME_ANY":0,"STARTTIME_PROCESS_UNKNOWN":-1},"stringRepresentation":"Discord"}

src/main/java/io/PersistenceHelper.java

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
package io;
22

33
import com.google.gson.Gson;
4+
import com.google.gson.GsonBuilder;
5+
import com.google.gson.InstanceCreator;
46
import javafx.scene.control.Slider;
7+
import processes.Process;
58
import processes.ProcessHandler;
69

710
import java.io.FileInputStream;
811
import java.io.FileNotFoundException;
912
import java.io.IOException;
1013
import java.io.InputStreamReader;
14+
import java.lang.reflect.Type;
1115
import java.nio.file.Files;
1216
import java.nio.file.Path;
1317
import java.util.ArrayList;
@@ -38,7 +42,7 @@ public static void writeBlacklistSet(Set<String> set) throws IOException {
3842
}
3943

4044
public static void writeVolume(double volume, Path path) throws IOException {
41-
Files.writeString(path, String.valueOf(volume*100));
45+
Files.writeString(path, String.valueOf(volume * 100));
4246
}
4347

4448
public static void writeVolume(double volume) throws IOException {
@@ -75,13 +79,33 @@ public static void startApp(Slider volumeSlider) throws IOException {
7579
final List<String> hiddenProcesses = readHiddenProcesses();
7680
ProcessHandler.hiddenProcesses =
7781
hiddenProcesses != null ? hiddenProcesses : new ArrayList<>(ProcessHandler.DEFAULT_HIDDEN_PROCESSES);
78-
readVolume(volumeSlider);
82+
if (volumeSlider != null) {
83+
readVolume(volumeSlider);
84+
}
7985
ProcessHandler.computeReducedProcessList(true);
8086
}
8187

82-
public static void stopApp(double volume) throws IOException {
88+
public static void stopApp(Double volume) throws IOException {
8389
writeBlacklistSet(ProcessHandler.blacklisted);
84-
writeVolume(volume);
90+
if (volume != null) {
91+
writeVolume(volume);
92+
}
8593
writeHiddenProcesses(ProcessHandler.hiddenProcesses);
8694
}
95+
96+
public static void startApp() throws IOException {
97+
startApp(null);
98+
}
99+
100+
public static void stopApp() throws IOException {
101+
stopApp(null);
102+
}
103+
104+
public static <T> void saveObjectToFile(T object, Path path) throws IOException {
105+
Files.writeString(path, gson.toJson(object));
106+
}
107+
108+
public static <T> T readObjectFromFile(Class<T> tClass, Path path) throws IOException {
109+
return gson.fromJson(Files.readString(path), tClass);
110+
}
87111
}

src/main/java/mainpack/Main.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
package mainpack;
22

33
import com.sun.javafx.application.LauncherImpl;
4+
import gui.KotlinGUI;
5+
import io.PersistenceHelper;
6+
7+
import java.io.IOException;
8+
import java.util.Arrays;
49

510
public class Main {
611

7-
public static void main(String[] args) {
8-
LauncherImpl.launchApplication(App.class, args);
12+
public static void main(String[] args) throws IOException {
13+
if (Arrays.stream(args).anyMatch(str ->
14+
str.contains("javafx")
15+
|| str.contains("old")
16+
|| str.contains("-old"))) {
17+
LauncherImpl.launchApplication(App.class, args);
18+
} else {
19+
PersistenceHelper.startApp();
20+
new KotlinGUI().getWindow();
21+
}
922
}
1023

1124
}

src/main/java/processes/Process.java

Lines changed: 17 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package processes;
22

3+
import org.jetbrains.annotations.NotNull;
4+
35
import java.time.Duration;
46
import java.time.Instant;
7+
import java.util.Locale;
58
import java.util.Objects;
69
import java.util.Optional;
710
import java.util.concurrent.CompletableFuture;
@@ -10,122 +13,26 @@
1013

1114
public class Process {
1215
private final ProcessHandle handle;
13-
private final String stringRepresentation;
16+
@NotNull
17+
private String stringRepresentation;
1418

1519
public Process(ProcessHandle handle) {
1620
this.handle = handle;
1721
this.stringRepresentation = determineStringRepresentation();
1822
}
1923

24+
public Process(ProcessHandle handle, String stringRepresentation) {
25+
this.handle = handle;
26+
this.stringRepresentation = stringRepresentation;
27+
}
28+
2029
/**
2130
* Process from Command String, which is always disallowed.
2231
*
2332
* @param command The System command which started the process
2433
*/
2534
public Process(String command) {
26-
this(new ProcessHandle() {
27-
@Override
28-
public long pid() {
29-
return 0;
30-
}
31-
32-
@Override
33-
public Optional<ProcessHandle> parent() {
34-
return Optional.empty();
35-
}
36-
37-
@Override
38-
public Stream<ProcessHandle> children() {
39-
return null;
40-
}
41-
42-
@Override
43-
public Stream<ProcessHandle> descendants() {
44-
return null;
45-
}
46-
47-
@Override
48-
public Info info() {
49-
return new Info() {
50-
@Override
51-
public Optional<String> command() {
52-
return Optional.of(command);
53-
}
54-
55-
@Override
56-
public Optional<String> commandLine() {
57-
return Optional.empty();
58-
}
59-
60-
@Override
61-
public Optional<String[]> arguments() {
62-
return Optional.empty();
63-
}
64-
65-
@Override
66-
public Optional<Instant> startInstant() {
67-
return Optional.empty();
68-
}
69-
70-
@Override
71-
public Optional<Duration> totalCpuDuration() {
72-
return Optional.empty();
73-
}
74-
75-
@Override
76-
public Optional<String> user() {
77-
return Optional.of("apoc");
78-
}
79-
};
80-
}
81-
82-
@Override
83-
public CompletableFuture<ProcessHandle> onExit() {
84-
return null;
85-
}
86-
87-
@Override
88-
public boolean supportsNormalTermination() {
89-
return false;
90-
}
91-
92-
@Override
93-
public boolean destroy() {
94-
return false;
95-
}
96-
97-
@Override
98-
public boolean destroyForcibly() {
99-
return false;
100-
}
101-
102-
@Override
103-
public boolean isAlive() {
104-
return true;
105-
}
106-
107-
@Override
108-
public int hashCode() {
109-
return Objects.hash(info().command(), info().user());
110-
}
111-
112-
@Override
113-
public boolean equals(Object other) {
114-
if (this == other) return true;
115-
if (!(other instanceof ProcessHandle)) return false;
116-
ProcessHandle process = (ProcessHandle) other;
117-
return info().command().orElse("").equals(process.info().command().orElse("")) &&
118-
info().user().orElse("").equals(process.info().user().orElse(""));
119-
}
120-
121-
@Override
122-
public int compareTo(ProcessHandle other) {
123-
int dontLetItBeEqual = this.info().command().orElse("").compareTo(other.info().command().orElse(""))
124-
+ this.info().user().orElse("").compareTo(other.info().user().orElse(""));
125-
if(dontLetItBeEqual==0&&!this.equals(other)) return -1;
126-
return dontLetItBeEqual;
127-
}
128-
});
35+
this(new ProcessHandleFromString(command));
12936
}
13037

13138
public String command() {
@@ -136,15 +43,15 @@ public String user() {
13643
return handle.info().user().orElse("");
13744
}
13845

139-
public boolean kill(){
46+
public boolean kill() {
14047
return handle.destroy();
14148
}
14249

14350
private String determineStringRepresentation() {
14451
String[] pathParts = command().split(Pattern.quote("\\"));
14552
if (pathParts.length == 0) return "";
146-
String returnString = pathParts[pathParts.length - 1].replaceAll(".exe|64|32", "");
147-
if ("".equals(returnString)) return "";
53+
String returnString = pathParts[pathParts.length - 1].toLowerCase().replaceAll(".exe|64|32", "");
54+
if (returnString.isBlank()) return "";
14855
return Character.toUpperCase(returnString.charAt(0)) + returnString.substring(1);
14956
}
15057

@@ -166,4 +73,7 @@ public String toString() {
16673
return stringRepresentation;
16774
}
16875

76+
public void setStringRepresentation(@NotNull String stringRepresentation) {
77+
this.stringRepresentation = stringRepresentation;
78+
}
16979
}

0 commit comments

Comments
 (0)