在未知桌面环境禁用 moveToTrash (#2885)

* 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 <zjx001202@gmail.com>
This commit is contained in:
ShulkerSakura 2024-03-09 20:38:48 +08:00 committed by GitHub
parent eadfff349a
commit 2249f4ee0e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 3 deletions

View File

@ -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.

View File

@ -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.
* <p>
@ -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;
}