mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-15 23:06:07 -04:00
feat: process priority
This commit is contained in:
parent
5edd7a7b72
commit
e9061ebc8b
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Hello Minecraft! Launcher
|
* 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
|
* 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
|
* 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 String preLaunchCommand;
|
||||||
private NativesDirectoryType nativesDirType;
|
private NativesDirectoryType nativesDirType;
|
||||||
private String nativesDir;
|
private String nativesDir;
|
||||||
|
private ProcessPriority processPriority;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The game directory
|
* The game directory
|
||||||
@ -217,6 +218,13 @@ public class LaunchOptions implements Serializable {
|
|||||||
return nativesDir;
|
return nativesDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process priority
|
||||||
|
*/
|
||||||
|
public ProcessPriority getProcessPriority() {
|
||||||
|
return processPriority;
|
||||||
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
|
|
||||||
private final LaunchOptions options = new LaunchOptions();
|
private final LaunchOptions options = new LaunchOptions();
|
||||||
@ -489,5 +497,10 @@ public class LaunchOptions implements Serializable {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Builder setProcessPriority(ProcessPriority processPriority) {
|
||||||
|
options.processPriority = processPriority;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
}
|
@ -71,9 +71,43 @@ public class DefaultLauncher extends Launcher {
|
|||||||
private CommandBuilder generateCommandLine(File nativeFolder) throws IOException {
|
private CommandBuilder generateCommandLine(File nativeFolder) throws IOException {
|
||||||
CommandBuilder res = new CommandBuilder();
|
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
|
// Executable
|
||||||
if (StringUtils.isNotBlank(options.getWrapper()))
|
if (StringUtils.isNotBlank(options.getWrapper()))
|
||||||
res.add(options.getWrapper());
|
res.addAllWithoutParsing(StringUtils.tokenize(options.getWrapper()));
|
||||||
|
|
||||||
res.add(options.getJava().getBinary().toString());
|
res.add(options.getJava().getBinary().toString());
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user