mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 23:39:07 +07:00
IDEA-346478 Collect detailed statistic about Linux configuration
- Added KDE themes detection GitOrigin-RevId: a219eeae9e8a51b6945c4ba6f2a6649df72dfa87
This commit is contained in:
committed by
intellij-monorepo-bot
parent
46a1de2e7b
commit
89ca23e9fd
@@ -14,6 +14,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.VisibleForTesting;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
@@ -45,6 +46,12 @@ public final class LinuxWindowManagerUsageCollector extends ApplicationUsagesCol
|
||||
private static final List<String> GNOME_THEME_FAMILIES = Arrays.asList(
|
||||
"Yaru-"
|
||||
);
|
||||
private static final List<String> KDE_THEME_NAMES = Arrays.asList(
|
||||
"org.kde.breezedark.desktop",
|
||||
"org.kde.breezetwilight.desktop",
|
||||
"org.kde.breeze.desktop"
|
||||
);
|
||||
|
||||
@VisibleForTesting
|
||||
public static final List<String> ALL_THEME_NAMES = new ArrayList<>();
|
||||
|
||||
@@ -98,6 +105,7 @@ public final class LinuxWindowManagerUsageCollector extends ApplicationUsagesCol
|
||||
for (String family : GNOME_THEME_FAMILIES) {
|
||||
ALL_THEME_NAMES.add(family + "*");
|
||||
}
|
||||
ALL_THEME_NAMES.addAll(KDE_THEME_NAMES);
|
||||
}
|
||||
|
||||
private static final EventId1<String> CURRENT_DESKTOP =
|
||||
@@ -141,18 +149,18 @@ public final class LinuxWindowManagerUsageCollector extends ApplicationUsagesCol
|
||||
return EMPTY_THEME;
|
||||
}
|
||||
|
||||
Optional<String> result = GNOME_THEME_NAMES.stream()
|
||||
.filter(s -> s.equalsIgnoreCase(theme))
|
||||
.findFirst();
|
||||
if (result.isPresent()) {
|
||||
return result.get();
|
||||
String result = find(GNOME_THEME_NAMES, s -> s.equalsIgnoreCase(theme));
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
result = GNOME_THEME_FAMILIES.stream()
|
||||
.filter(s -> theme.startsWith(s))
|
||||
.findFirst();
|
||||
result = find(KDE_THEME_NAMES, s -> s.equalsIgnoreCase(theme));
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
return result.map(s -> s + "*").orElse(UNKNOWN_THEME);
|
||||
result = find(GNOME_THEME_FAMILIES, s -> theme.startsWith(s));
|
||||
return result == null ? UNKNOWN_THEME : result + "*";
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -166,6 +174,12 @@ public final class LinuxWindowManagerUsageCollector extends ApplicationUsagesCol
|
||||
return isGnome ? findReportedName(windowManger, GNOME_WINDOW_MANAGERS) : findReportedName(windowManger, WINDOW_MANAGERS);
|
||||
}
|
||||
|
||||
private static @Nullable String find(@NotNull List<String> list, @NotNull Predicate<String> predicate) {
|
||||
return list.stream()
|
||||
.filter(predicate)
|
||||
.findFirst().orElse(null);
|
||||
}
|
||||
|
||||
private static @NotNull String findReportedName(@NotNull String original, @NotNull Map<String, String> keywordToName) {
|
||||
for (Map.Entry<String, String> entry : keywordToName.entrySet()) {
|
||||
if (original.contains(entry.getKey())) {
|
||||
|
||||
@@ -21,12 +21,17 @@ import sun.misc.Unsafe;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.peer.ComponentPeer;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public final class X11UiUtil {
|
||||
private static final Logger LOG = Logger.getInstance(X11UiUtil.class);
|
||||
@@ -44,6 +49,8 @@ public final class X11UiUtil {
|
||||
private static final long NET_WM_STATE_ADD = 1;
|
||||
private static final long NET_WM_STATE_TOGGLE = 2;
|
||||
|
||||
public static final String KDE_LAF_PROPERTY = "LookAndFeelPackage=";
|
||||
|
||||
/**
|
||||
* List of all known tile WM in lower case, can be updated later
|
||||
*/
|
||||
@@ -326,30 +333,29 @@ public final class X11UiUtil {
|
||||
public static @Nullable String getTheme() {
|
||||
ThreadingAssertions.assertBackgroundThread();
|
||||
if (SystemInfo.isGNOME) {
|
||||
try {
|
||||
Process process = new ProcessBuilder("gsettings", "get", "org.gnome.desktop.interface", "gtk-theme").start();
|
||||
if (!process.waitFor(5, TimeUnit.SECONDS)) {
|
||||
LOG.info("Cannot get theme, timeout");
|
||||
process.destroyForcibly();
|
||||
return null;
|
||||
}
|
||||
|
||||
if (process.exitValue() != 0) {
|
||||
LOG.info("Cannot get theme, exit code " + process.exitValue());
|
||||
return null;
|
||||
}
|
||||
|
||||
String result = FileUtil.loadTextAndClose(process.getInputStream()).trim();
|
||||
if (result.startsWith("'") && result.endsWith("'")) {
|
||||
result = result.substring(1, result.length() - 1);
|
||||
}
|
||||
String result = exec("Cannot get gnome theme", "gsettings", "get", "org.gnome.desktop.interface", "gtk-theme");
|
||||
|
||||
if (result == null || !result.startsWith("'") || !result.endsWith("'")) {
|
||||
return result;
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOG.info("Cannot get theme", e);
|
||||
|
||||
return result.substring(1, result.length() - 1);
|
||||
}
|
||||
|
||||
if (SystemInfo.isKDE) {
|
||||
// https://github.com/shalva97/kde-configuration-files
|
||||
Path home = Path.of(System.getenv("HOME"), ".config/kdeglobals");
|
||||
List<String> matches = grepFile("Cannot get KDE theme", home,
|
||||
Pattern.compile("\\s*" + KDE_LAF_PROPERTY + ".*"));
|
||||
if (matches.size() != 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String result = matches.get(0).trim();
|
||||
if (result.startsWith(KDE_LAF_PROPERTY)) {
|
||||
return result.substring(KDE_LAF_PROPERTY.length()).trim();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -442,4 +448,44 @@ public final class X11UiUtil {
|
||||
field.setAccessible(true);
|
||||
return field;
|
||||
}
|
||||
|
||||
private static @Nullable String exec(String errorMessage, String... command) {
|
||||
try {
|
||||
Process process = new ProcessBuilder(command).start();
|
||||
if (!process.waitFor(5, TimeUnit.SECONDS)) {
|
||||
LOG.info(errorMessage + ": timeout");
|
||||
process.destroyForcibly();
|
||||
return null;
|
||||
}
|
||||
|
||||
if (process.exitValue() != 0) {
|
||||
LOG.info(errorMessage + ": exit code " + process.exitValue());
|
||||
return null;
|
||||
}
|
||||
|
||||
return FileUtil.loadTextAndClose(process.getInputStream()).trim();
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOG.info(errorMessage, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static List<String> grepFile(String errorMessage, Path file, Pattern pattern) {
|
||||
List<String> result = new ArrayList<>();
|
||||
try (BufferedReader reader = Files.newBufferedReader(file, StandardCharsets.UTF_8)) {
|
||||
String line;
|
||||
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (pattern.matcher(line).matches()) {
|
||||
result.add(line);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.info(errorMessage, e);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user