From d578dc1e70201b1d8da1a06d288d838baabdcdb6 Mon Sep 17 00:00:00 2001 From: Lyze <11274700+lyze237@users.noreply.github.com> Date: Thu, 15 Aug 2024 00:10:15 +0200 Subject: [PATCH 1/2] Implement looking for manually installed idea on windows --- .../ui/panels/CompleteButtonsPanel.java | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/main/java/gdx/liftoff/ui/panels/CompleteButtonsPanel.java b/src/main/java/gdx/liftoff/ui/panels/CompleteButtonsPanel.java index 8d302289..f7025849 100644 --- a/src/main/java/gdx/liftoff/ui/panels/CompleteButtonsPanel.java +++ b/src/main/java/gdx/liftoff/ui/panels/CompleteButtonsPanel.java @@ -9,11 +9,11 @@ import gdx.liftoff.ui.UserData; import gdx.liftoff.ui.dialogs.FullscreenDialog; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; +import java.io.*; import java.util.Arrays; +import java.util.Comparator; import java.util.List; +import java.util.stream.Stream; import static gdx.liftoff.Main.*; @@ -66,15 +66,32 @@ public void populate(boolean fullscreen) { table.add(ideaButton); addHandListener(ideaButton); try { - List findIntellij = (UIUtils.isWindows) ? Arrays.asList("where.exe", "idea") : Arrays.asList("which", "idea"); - - Process process = new ProcessBuilder(findIntellij).start(); - if (process.waitFor() != 0) { - throw new Exception("IntelliJ not found"); + List findIntellijExecutable = (UIUtils.isWindows) ? Arrays.asList("where.exe", "idea") : Arrays.asList("which", "idea"); + + Process process = new ProcessBuilder(findIntellijExecutable).start(); + if (process.waitFor() == 0) { + intellijPath = new BufferedReader(new InputStreamReader(process.getInputStream())).readLine(); + ideaButton.setDisabled(false); + } else { + if (!UIUtils.isWindows) { + throw new Exception("IntelliJ not found"); + } + + String programFilesFolder = System.getenv("PROGRAMFILES"); + File jetbrainsFolder = new File(programFilesFolder, "JetBrains"); + File[] ideaFolders = jetbrainsFolder.listFiles((dir, name) -> name.contains("IDEA")); + if (ideaFolders == null) { + throw new Exception("IntelliJ not found"); + } + + File intellijFolder = Stream.of(ideaFolders) + .max(Comparator.comparingLong(File::lastModified)) + .orElseThrow(() -> new Exception("IntelliJ not found")); + + intellijPath = new File(intellijFolder, "bin/idea64.exe").getAbsolutePath(); + ideaButton.setDisabled(false); } - intellijPath = new BufferedReader(new InputStreamReader(process.getInputStream())).readLine(); - ideaButton.setDisabled(false); } catch (Exception e) { addTooltip(ideaButton, Align.top, TOOLTIP_WIDTH, prop.getProperty("ideaNotFoundTip")); ideaButton.setDisabled(true); From 915d4292447c4283433d42b85df6e1231698dbd8 Mon Sep 17 00:00:00 2001 From: Lyze <11274700+lyze237@users.noreply.github.com> Date: Thu, 15 Aug 2024 00:30:20 +0200 Subject: [PATCH 2/2] Re-implemented flatpak support from #159 --- .../ui/panels/CompleteButtonsPanel.java | 75 ++++++++++++++----- 1 file changed, 55 insertions(+), 20 deletions(-) diff --git a/src/main/java/gdx/liftoff/ui/panels/CompleteButtonsPanel.java b/src/main/java/gdx/liftoff/ui/panels/CompleteButtonsPanel.java index f7025849..b6ddc283 100644 --- a/src/main/java/gdx/liftoff/ui/panels/CompleteButtonsPanel.java +++ b/src/main/java/gdx/liftoff/ui/panels/CompleteButtonsPanel.java @@ -8,6 +8,7 @@ import com.ray3k.stripe.PopTable; import gdx.liftoff.ui.UserData; import gdx.liftoff.ui.dialogs.FullscreenDialog; +import org.jetbrains.annotations.NotNull; import java.io.*; import java.util.Arrays; @@ -28,6 +29,7 @@ public class CompleteButtonsPanel extends Table implements Panel { PopTable popTable; String intellijPath = null; + boolean intellijIsFlatpak = false; public CompleteButtonsPanel(boolean fullscreen) { this(null, fullscreen); @@ -68,37 +70,34 @@ public void populate(boolean fullscreen) { try { List findIntellijExecutable = (UIUtils.isWindows) ? Arrays.asList("where.exe", "idea") : Arrays.asList("which", "idea"); - Process process = new ProcessBuilder(findIntellijExecutable).start(); - if (process.waitFor() == 0) { - intellijPath = new BufferedReader(new InputStreamReader(process.getInputStream())).readLine(); + Process whereProcess = new ProcessBuilder(findIntellijExecutable).start(); + if (whereProcess.waitFor() == 0) { + intellijPath = new BufferedReader(new InputStreamReader(whereProcess.getInputStream())).readLine(); ideaButton.setDisabled(false); } else { - if (!UIUtils.isWindows) { + if (UIUtils.isLinux) { + intellijPath = findFlatpakIntellij(); + intellijIsFlatpak = true; + ideaButton.setDisabled(false); + } else if (UIUtils.isWindows) { + intellijPath = findManuallyInstalledIntellijOnWindows(); + ideaButton.setDisabled(false); + } else { throw new Exception("IntelliJ not found"); } - - String programFilesFolder = System.getenv("PROGRAMFILES"); - File jetbrainsFolder = new File(programFilesFolder, "JetBrains"); - File[] ideaFolders = jetbrainsFolder.listFiles((dir, name) -> name.contains("IDEA")); - if (ideaFolders == null) { - throw new Exception("IntelliJ not found"); - } - - File intellijFolder = Stream.of(ideaFolders) - .max(Comparator.comparingLong(File::lastModified)) - .orElseThrow(() -> new Exception("IntelliJ not found")); - - intellijPath = new File(intellijFolder, "bin/idea64.exe").getAbsolutePath(); - ideaButton.setDisabled(false); } - } catch (Exception e) { addTooltip(ideaButton, Align.top, TOOLTIP_WIDTH, prop.getProperty("ideaNotFoundTip")); ideaButton.setDisabled(true); } + onChange(ideaButton, () -> { try { - new ProcessBuilder(intellijPath, ".").directory(Gdx.files.absolute(UserData.projectPath).file()).start(); + if (intellijIsFlatpak) { + new ProcessBuilder("flatpak", "run", intellijPath, ".").directory(Gdx.files.absolute(UserData.projectPath).file()).start(); + } else { + new ProcessBuilder(intellijPath, ".").directory(Gdx.files.absolute(UserData.projectPath).file()).start(); + } } catch (IOException e) { ideaButton.setText("WHOOPS"); } @@ -112,6 +111,42 @@ public void populate(boolean fullscreen) { onChange(textButton, () -> Gdx.app.exit()); } + private static String findManuallyInstalledIntellijOnWindows() throws Exception { + String programFilesFolder = System.getenv("PROGRAMFILES"); + File jetbrainsFolder = new File(programFilesFolder, "JetBrains"); + File[] ideaFolders = jetbrainsFolder.listFiles((dir, name) -> name.contains("IDEA")); + if (ideaFolders == null) { + throw new Exception("IntelliJ not found"); + } + + File intellijFolder = Stream.of(ideaFolders) + .max(Comparator.comparingLong(File::lastModified)) + .orElseThrow(() -> new Exception("IntelliJ not found")); + + return new File(intellijFolder, "bin/idea64.exe").getAbsolutePath(); + } + + @NotNull + private static String findFlatpakIntellij() throws Exception { + List findFlatpakIntelliJ = Arrays.asList("flatpak", "list", "--app", "--columns=application"); + + Process flatpakProcess = new ProcessBuilder(findFlatpakIntelliJ).start(); + if (flatpakProcess.waitFor() != 0) { + throw new Exception("Flatpak not found"); + } + + List intellijIds = Arrays.asList("com.jetbrains.IntelliJ-IDEA-Ultimate", "com.jetbrains.IntelliJ-IDEA-Community"); + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(flatpakProcess.getInputStream())); + + String line; + while ((line = bufferedReader.readLine()) != null) { + if (intellijIds.contains(line)) { + return line; + } + } + throw new Exception("Flatpak IntelliJ not installed"); + } + @Override public void captureKeyboardFocus() {