feat: process priority

This commit is contained in:
huanghongxun 2021-08-26 03:52:32 +08:00
parent 5edd7a7b72
commit e9061ebc8b
3 changed files with 75 additions and 2 deletions

View File

@ -1,6 +1,6 @@
/*
* Hello Minecraft! Launcher
* Copyright (C) 2020 huangyuhui <huanghongxun2008@126.com> and contributors
* Copyright (C) 2021 huangyuhui <huanghongxun2008@126.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -55,6 +55,7 @@ public class LaunchOptions implements Serializable {
private String preLaunchCommand;
private NativesDirectoryType nativesDirType;
private String nativesDir;
private ProcessPriority processPriority;
/**
* The game directory
@ -217,6 +218,13 @@ public class LaunchOptions implements Serializable {
return nativesDir;
}
/**
* Process priority
*/
public ProcessPriority getProcessPriority() {
return processPriority;
}
public static class Builder {
private final LaunchOptions options = new LaunchOptions();
@ -489,5 +497,10 @@ public class LaunchOptions implements Serializable {
return this;
}
public Builder setProcessPriority(ProcessPriority processPriority) {
options.processPriority = processPriority;
return this;
}
}
}

View File

@ -0,0 +1,26 @@
/*
* Hello Minecraft! Launcher
* Copyright (C) 2021 huangyuhui <huanghongxun2008@126.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.jackhuang.hmcl.game;
public enum ProcessPriority {
LOW,
BELOW_NORMAL,
NORMAL,
ABOVE_NORMAL,
HIGH
}

View File

@ -71,9 +71,43 @@ public class DefaultLauncher extends Launcher {
private CommandBuilder generateCommandLine(File nativeFolder) throws IOException {
CommandBuilder res = new CommandBuilder();
switch (options.getProcessPriority()) {
case HIGH:
if (OperatingSystem.CURRENT_OS == OperatingSystem.WINDOWS) {
res.add("cmd", "/C", "start", "unused title", "/B", "/high");
} else if (OperatingSystem.CURRENT_OS == OperatingSystem.LINUX) {
res.add("nice", "-n", "-5");
}
break;
case ABOVE_NORMAL:
if (OperatingSystem.CURRENT_OS == OperatingSystem.WINDOWS) {
res.add("cmd", "/C", "start", "unused title", "/B", "/abovenormal");
} else if (OperatingSystem.CURRENT_OS == OperatingSystem.LINUX) {
res.add("nice", "-n", "-1");
}
break;
case NORMAL:
// do nothing
break;
case BELOW_NORMAL:
if (OperatingSystem.CURRENT_OS == OperatingSystem.WINDOWS) {
res.add("cmd", "/C", "start", "unused title", "/B", "/belownormal");
} else if (OperatingSystem.CURRENT_OS == OperatingSystem.LINUX) {
res.add("nice", "-n", "1");
}
break;
case LOW:
if (OperatingSystem.CURRENT_OS == OperatingSystem.WINDOWS) {
res.add("cmd", "/C", "start", "unused title", "/B", "/low");
} else if (OperatingSystem.CURRENT_OS == OperatingSystem.LINUX) {
res.add("nice", "-n", "5");
}
break;
}
// Executable
if (StringUtils.isNotBlank(options.getWrapper()))
res.add(options.getWrapper());
res.addAllWithoutParsing(StringUtils.tokenize(options.getWrapper()));
res.add(options.getJava().getBinary().toString());