feat(system-tools): 添加任务栏外观设置工具
- 新增 LocalCall 类实现任务栏外观设置功能- 添加 TaskbarAppearanceWindow 界面类 - 在 MainWindow 中集成任务栏主题设置工具 -优化图标路径处理逻辑
This commit is contained in:
@@ -1,4 +0,0 @@
|
||||
package org.tzd.explorer;
|
||||
|
||||
public class DesktopIconRenderer {
|
||||
}
|
||||
150
src/main/java/org/tzd/explorer/LocalCall.java
Normal file
150
src/main/java/org/tzd/explorer/LocalCall.java
Normal file
@@ -0,0 +1,150 @@
|
||||
package org.tzd.explorer;
|
||||
|
||||
import com.axis.innovators.box.tools.FolderCreator;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author tzdwindows 7
|
||||
*/
|
||||
public class LocalCall {
|
||||
private static final String LIBRARY = FolderCreator.getLibraryFolder();
|
||||
private static final String TASKBAR_EXE = "TaskbarTranslucentConsole.exe";
|
||||
|
||||
/**
|
||||
* Enum representing the different taskbar accent modes
|
||||
*/
|
||||
public enum TaskbarAccentMode {
|
||||
/** Disables any accent effect (需要将restartExplorer设置为真)*/
|
||||
@Description("Disables any accent effect")
|
||||
ACCENT_DISABLED(0),
|
||||
|
||||
/** Enables gradient effect (纯色任务栏,设置的alpha无效)*/
|
||||
@Description("Enables gradient effect")
|
||||
ACCENT_ENABLE_GRADIENT(1),
|
||||
|
||||
/** Enables transparent gradient effect (纯色任务栏,设置的alpha有效)*/
|
||||
@Description("Enables transparent gradient effect")
|
||||
ACCENT_ENABLE_TRANSPARENTGRADIENT(2),
|
||||
|
||||
/** Enables blur behind effect (设置alpha为0可实现透明任务栏) */
|
||||
@Description("Enables blur behind effect")
|
||||
ACCENT_ENABLE_BLURBEHIND(3),
|
||||
|
||||
/** Enables acrylic blur behind effect (Windows 10 Fluent Design) (模糊,设置的alpha无效)*/
|
||||
@Description("Enables acrylic blur behind effect (Windows 10 Fluent Design)")
|
||||
ACCENT_ENABLE_ACRYLICBLURBEHIND(4),
|
||||
|
||||
/** Invalid state (需要将restartExplorer设置为真)*/
|
||||
@Description("Invalid state")
|
||||
ACCENT_INVALID_STATE(5);
|
||||
|
||||
private final int value;
|
||||
|
||||
TaskbarAccentMode(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the enum value from an integer
|
||||
* @param value The integer value to convert
|
||||
* @return Corresponding TaskbarAccentMode
|
||||
* @throws IllegalArgumentException if the value is invalid
|
||||
*/
|
||||
public static TaskbarAccentMode fromValue(int value) {
|
||||
for (TaskbarAccentMode mode : values()) {
|
||||
if (mode.value == value) {
|
||||
return mode;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Invalid TaskbarAccentMode value: " + value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the taskbar appearance
|
||||
* @param mode The accent mode to apply
|
||||
* @param color The color in hex format (0xRRGGBB)
|
||||
* @param alpha The alpha value (0-255)
|
||||
* @param restartExplorer Whether to restart explorer.exe
|
||||
* @throws IOException If the process fails to start
|
||||
* @throws InterruptedException If the process is interrupted
|
||||
*/
|
||||
public static void setTaskbarAppearance(TaskbarAccentMode mode, String color, int alpha, boolean restartExplorer)
|
||||
throws IOException, InterruptedException {
|
||||
if (color == null) color = "0x000000";
|
||||
String raw = color.trim();
|
||||
if (raw.startsWith("#")) raw = raw.substring(1);
|
||||
if (raw.startsWith("0x") || raw.startsWith("0X")) raw = raw.substring(2);
|
||||
if (raw.length() > 6) {
|
||||
raw = raw.substring(raw.length() - 6);
|
||||
}
|
||||
while (raw.length() < 6) raw = "0" + raw;
|
||||
|
||||
String colorArg = "0x" + raw.toUpperCase();
|
||||
|
||||
String exePath = LIBRARY + "\\" + TASKBAR_EXE;
|
||||
java.util.List<String> cmd = new java.util.ArrayList<>();
|
||||
cmd.add(exePath);
|
||||
cmd.add("--mode");
|
||||
cmd.add(String.valueOf(mode.getValue()));
|
||||
cmd.add("--color");
|
||||
cmd.add(colorArg);
|
||||
cmd.add("--alpha");
|
||||
cmd.add(String.valueOf(alpha));
|
||||
if (restartExplorer) {
|
||||
cmd.add("--restart");
|
||||
}
|
||||
|
||||
System.out.println("Exec: " + String.join(" ", cmd));
|
||||
|
||||
ProcessBuilder pb = new ProcessBuilder(cmd);
|
||||
pb.redirectErrorStream(true);
|
||||
|
||||
Process process = pb.start();
|
||||
StringBuilder output = new StringBuilder();
|
||||
try (java.io.BufferedReader reader = new java.io.BufferedReader(
|
||||
new java.io.InputStreamReader(process.getInputStream(), java.nio.charset.StandardCharsets.UTF_8))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
output.append(line).append(System.lineSeparator());
|
||||
System.out.println(line);
|
||||
}
|
||||
}
|
||||
|
||||
int exit = process.waitFor();
|
||||
if (exit != 0) {
|
||||
throw new IOException("TaskbarTranslucentConsole exit code: " + exit + "\nOutput:\n" + output.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the help message for TaskbarTranslucentConsole.exe
|
||||
* @throws IOException If the process fails to start
|
||||
* @throws InterruptedException If the process is interrupted
|
||||
*/
|
||||
public static void showTaskbarHelp() throws IOException, InterruptedException {
|
||||
String command = LIBRARY + "\\" + TASKBAR_EXE + " --help";
|
||||
Process process = Runtime.getRuntime().exec(command);
|
||||
process.waitFor();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException, InterruptedException {
|
||||
LocalCall.setTaskbarAppearance(
|
||||
LocalCall.TaskbarAccentMode.ACCENT_ENABLE_BLURBEHIND,
|
||||
"0x000000",
|
||||
0,
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom annotation for enum descriptions
|
||||
*/
|
||||
@interface Description {
|
||||
String value();
|
||||
}
|
||||
Reference in New Issue
Block a user