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

Commit

Permalink
Different Color Schemes in MyColors.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
J-MR-T committed Apr 11, 2021
1 parent 8df04f9 commit 50f839c
Show file tree
Hide file tree
Showing 13 changed files with 320 additions and 199 deletions.
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ jar {
}
}

task shipJar(dependsOn: ['copyCSS', 'copyRsc', 'copyREADME', 'jar']) {
task shipJar(dependsOn: ['copyCSS', 'copyRes', 'copyREADME', 'jar']) {
}

task copyRsc(type: Copy) {
from("$projectDir/rsc")
into("$projectDir/build/libs/rsc")
task copyRes(type: Copy) {
from("$projectDir/res")
into("$projectDir/build/libs/res")
}

task copyCSS(type: Copy) {
Expand Down
2 changes: 1 addition & 1 deletion res/blacklisted.json
Original file line number Diff line number Diff line change
@@ -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"]
["C:\\Program Files (x86)\\Epic Games\\Launcher\\Portal\\Binaries\\Win64\\EpicGamesLauncher.exe"]
2 changes: 1 addition & 1 deletion res/hidden.json
Original file line number Diff line number Diff line change
@@ -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"]
["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"]
1 change: 1 addition & 0 deletions res/testSave.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"handle":{"pid":18368,"startTime":1618128320807,"STARTTIME_ANY":0,"STARTTIME_PROCESS_UNKNOWN":-1},"stringRepresentation":"Discord"}
32 changes: 28 additions & 4 deletions src/main/java/io/PersistenceHelper.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package io;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.InstanceCreator;
import javafx.scene.control.Slider;
import processes.Process;
import processes.ProcessHandler;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Type;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
Expand Down Expand Up @@ -38,7 +42,7 @@ public static void writeBlacklistSet(Set<String> set) throws IOException {
}

public static void writeVolume(double volume, Path path) throws IOException {
Files.writeString(path, String.valueOf(volume*100));
Files.writeString(path, String.valueOf(volume * 100));
}

public static void writeVolume(double volume) throws IOException {
Expand Down Expand Up @@ -75,13 +79,33 @@ public static void startApp(Slider volumeSlider) throws IOException {
final List<String> hiddenProcesses = readHiddenProcesses();
ProcessHandler.hiddenProcesses =
hiddenProcesses != null ? hiddenProcesses : new ArrayList<>(ProcessHandler.DEFAULT_HIDDEN_PROCESSES);
readVolume(volumeSlider);
if (volumeSlider != null) {
readVolume(volumeSlider);
}
ProcessHandler.computeReducedProcessList(true);
}

public static void stopApp(double volume) throws IOException {
public static void stopApp(Double volume) throws IOException {
writeBlacklistSet(ProcessHandler.blacklisted);
writeVolume(volume);
if (volume != null) {
writeVolume(volume);
}
writeHiddenProcesses(ProcessHandler.hiddenProcesses);
}

public static void startApp() throws IOException {
startApp(null);
}

public static void stopApp() throws IOException {
stopApp(null);
}

public static <T> void saveObjectToFile(T object, Path path) throws IOException {
Files.writeString(path, gson.toJson(object));
}

public static <T> T readObjectFromFile(Class<T> tClass, Path path) throws IOException {
return gson.fromJson(Files.readString(path), tClass);
}
}
17 changes: 15 additions & 2 deletions src/main/java/mainpack/Main.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
package mainpack;

import com.sun.javafx.application.LauncherImpl;
import gui.KotlinGUI;
import io.PersistenceHelper;

import java.io.IOException;
import java.util.Arrays;

public class Main {

public static void main(String[] args) {
LauncherImpl.launchApplication(App.class, args);
public static void main(String[] args) throws IOException {
if (Arrays.stream(args).anyMatch(str ->
str.contains("javafx")
|| str.contains("old")
|| str.contains("-old"))) {
LauncherImpl.launchApplication(App.class, args);
} else {
PersistenceHelper.startApp();
new KotlinGUI().getWindow();
}
}

}
124 changes: 17 additions & 107 deletions src/main/java/processes/Process.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package processes;

import org.jetbrains.annotations.NotNull;

import java.time.Duration;
import java.time.Instant;
import java.util.Locale;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
Expand All @@ -10,122 +13,26 @@

public class Process {
private final ProcessHandle handle;
private final String stringRepresentation;
@NotNull
private String stringRepresentation;

public Process(ProcessHandle handle) {
this.handle = handle;
this.stringRepresentation = determineStringRepresentation();
}

public Process(ProcessHandle handle, String stringRepresentation) {
this.handle = handle;
this.stringRepresentation = stringRepresentation;
}

/**
* Process from Command String, which is always disallowed.
*
* @param command The System command which started the process
*/
public Process(String command) {
this(new ProcessHandle() {
@Override
public long pid() {
return 0;
}

@Override
public Optional<ProcessHandle> parent() {
return Optional.empty();
}

@Override
public Stream<ProcessHandle> children() {
return null;
}

@Override
public Stream<ProcessHandle> descendants() {
return null;
}

@Override
public Info info() {
return new Info() {
@Override
public Optional<String> command() {
return Optional.of(command);
}

@Override
public Optional<String> commandLine() {
return Optional.empty();
}

@Override
public Optional<String[]> arguments() {
return Optional.empty();
}

@Override
public Optional<Instant> startInstant() {
return Optional.empty();
}

@Override
public Optional<Duration> totalCpuDuration() {
return Optional.empty();
}

@Override
public Optional<String> user() {
return Optional.of("apoc");
}
};
}

@Override
public CompletableFuture<ProcessHandle> onExit() {
return null;
}

@Override
public boolean supportsNormalTermination() {
return false;
}

@Override
public boolean destroy() {
return false;
}

@Override
public boolean destroyForcibly() {
return false;
}

@Override
public boolean isAlive() {
return true;
}

@Override
public int hashCode() {
return Objects.hash(info().command(), info().user());
}

@Override
public boolean equals(Object other) {
if (this == other) return true;
if (!(other instanceof ProcessHandle)) return false;
ProcessHandle process = (ProcessHandle) other;
return info().command().orElse("").equals(process.info().command().orElse("")) &&
info().user().orElse("").equals(process.info().user().orElse(""));
}

@Override
public int compareTo(ProcessHandle other) {
int dontLetItBeEqual = this.info().command().orElse("").compareTo(other.info().command().orElse(""))
+ this.info().user().orElse("").compareTo(other.info().user().orElse(""));
if(dontLetItBeEqual==0&&!this.equals(other)) return -1;
return dontLetItBeEqual;
}
});
this(new ProcessHandleFromString(command));
}

public String command() {
Expand All @@ -136,15 +43,15 @@ public String user() {
return handle.info().user().orElse("");
}

public boolean kill(){
public boolean kill() {
return handle.destroy();
}

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

Expand All @@ -166,4 +73,7 @@ public String toString() {
return stringRepresentation;
}

public void setStringRepresentation(@NotNull String stringRepresentation) {
this.stringRepresentation = stringRepresentation;
}
}
Loading

0 comments on commit 50f839c

Please sign in to comment.