From 2249f4ee0e6b54260b1c30aae649e0148699d703 Mon Sep 17 00:00:00 2001 From: ShulkerSakura <50770360+ShulkerSakura@users.noreply.github.com> Date: Sat, 9 Mar 2024 20:38:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E6=9C=AA=E7=9F=A5=E6=A1=8C=E9=9D=A2?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E7=A6=81=E7=94=A8=20moveToTrash=20(#2885)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added Optifine Icon * Updated Optifine Icons * Updated Optifine Icons * Added new HMCL logo * update * Add ChromeOS Detection * ChromeOS Detection * Removed useless import * Style Checked * Add private constructor * Style Check * Simplification * update * update * update * update * update * update --------- Co-authored-by: Glavo --- .../java/org/jackhuang/hmcl/Launcher.java | 4 ++- .../org/jackhuang/hmcl/util/io/FileUtils.java | 31 +++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/Launcher.java b/HMCL/src/main/java/org/jackhuang/hmcl/Launcher.java index bf967fc5a..772a436e1 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/Launcher.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/Launcher.java @@ -284,8 +284,10 @@ public final class Launcher extends Application { .findAny() .map(bean -> bean.getUsage().getUsed() / 1024 / 1024 + "MB") .orElse("Unknown")); - if (OperatingSystem.CURRENT_OS.isLinuxOrBSD()) + if (OperatingSystem.CURRENT_OS.isLinuxOrBSD()) { LOG.info("XDG Session Type: " + System.getenv("XDG_SESSION_TYPE")); + LOG.info("XDG Current Desktop: " + System.getenv("XDG_CURRENT_DESKTOP")); + } launch(Launcher.class, args); } catch (Throwable e) { // Fucking JavaFX will suppress the exception and will break our crash reporter. diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/FileUtils.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/FileUtils.java index 02c833da7..2a3e830c6 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/FileUtils.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/FileUtils.java @@ -32,6 +32,7 @@ import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.List; +import java.util.Locale; import java.util.Objects; import java.util.Optional; import java.util.function.Predicate; @@ -283,6 +284,32 @@ public final class FileUtils { }); } + public static boolean hasKnownDesktop() { + if (!OperatingSystem.CURRENT_OS.isLinuxOrBSD()) + return true; + + String desktops = System.getenv("XDG_CURRENT_DESKTOP"); + if (desktops == null) { + desktops = System.getenv("XDG_SESSION_DESKTOP"); + } + + if (desktops == null) { + return false; + } + for (String desktop : desktops.split(":")) { + switch (desktop.toLowerCase(Locale.ROOT)) { + case "gnome": + case "xfce": + case "kde": + case "mate": + case "deepin": + return true; + } + } + + return false; + } + /** * Move file to trash. *

@@ -299,7 +326,7 @@ public final class FileUtils { * @see FileUtils#isMovingToTrashSupported() */ public static boolean moveToTrash(File file) { - if (OperatingSystem.CURRENT_OS.isLinuxOrBSD()) { + if (OperatingSystem.CURRENT_OS.isLinuxOrBSD() && hasKnownDesktop()) { if (!file.exists()) { return false; } @@ -365,7 +392,7 @@ public final class FileUtils { * @return true if the method exists. */ public static boolean isMovingToTrashSupported() { - if (OperatingSystem.CURRENT_OS.isLinuxOrBSD()) { + if (OperatingSystem.CURRENT_OS.isLinuxOrBSD() && hasKnownDesktop()) { return true; }