package dev.crucifixbeta.mod.gui.clickgui.pages;

import dev.crucifixbeta.api.utils.Wrapper;
import dev.crucifixbeta.api.utils.math.AnimateUtil;
import dev.crucifixbeta.api.utils.render.ColorUtil;
import dev.crucifixbeta.api.utils.render.Render2DUtil;
import dev.crucifixbeta.api.utils.render.TextUtil;
import dev.crucifixbeta.core.impl.ConfigManager;
import dev.crucifixbeta.core.impl.FontManager;
import dev.crucifixbeta.mod.gui.clickgui.ClickGuiFrame;
import dev.crucifixbeta.mod.gui.clickgui.ClickGuiScreen;
import dev.crucifixbeta.mod.gui.items.buttons.StringButton;
import dev.crucifixbeta.mod.modules.impl.client.ClickGui;
import dev.crucifixbeta.mod.modules.impl.client.ClientSetting;
import java.awt.Color;
import java.awt.Desktop;
import java.awt.Desktop.Action;
import java.io.File;
import java.util.ArrayList;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.util.InputUtil;
import net.minecraft.client.util.SelectionManager;
import net.minecraft.util.StringHelper;

@Environment(EnvType.CLIENT)
public final class ClickGuiConfigPage {
   private final ClickGuiScreen host;
   private final ArrayList<String> configNames = new ArrayList<>();
   private float configScroll;
   private String selectedConfigName;
   private String appliedConfigName;
   private String configNameInput = "";
   private boolean configNameListening;
   private String lastSavedConfigName;
   private long lastSavedConfigTime;
   private float configSelectAnimY;
   private boolean configSelectAnimInit;

   public ClickGuiConfigPage(ClickGuiScreen host) {
      this.host = host;
   }

   public void onOpen() {
      this.refreshConfigList();
      this.configScroll = 0.0F;
      this.configNameListening = false;
      this.configSelectAnimInit = false;
      if (this.selectedConfigName != null && !this.configNames.contains(this.selectedConfigName)) {
         this.selectedConfigName = null;
      }

      if (this.selectedConfigName == null && !this.configNames.isEmpty()) {
         this.selectedConfigName = this.configNames.get(0);
      }
   }

   public void stopNameListening() {
      this.configNameListening = false;
   }

   public void mouseScrolled(double verticalAmount, int screenH) {
      if (Wrapper.mc != null && Wrapper.mc.getWindow() != null) {
         this.refreshConfigList();
         int var4 = this.host.getFontHeight() + 6;
         float var5 = (float)(screenH - 44);
         float var6 = (float)this.configNames.size() * (float)var4;
         float var7 = Math.max(0.0F, var6 - var5);
         float var8 = this.configScroll + (float)(-verticalAmount) * 18.0F;
         if (var8 < 0.0F) {
            var8 = 0.0F;
         }

         if (var8 > var7) {
            var8 = var7;
         }

         this.configScroll = var8;
      }
   }

   public boolean keyPressed(int keyCode) {
      if (!this.configNameListening) {
         return false;
      } else {
         switch (keyCode) {
            case 32:
               this.configNameInput = this.configNameInput + " ";
               if (this.configNameInput.length() > 64) {
                  this.configNameInput = this.configNameInput.substring(0, 64);
               }

               return true;
            case 86:
               if (Wrapper.mc != null && Wrapper.mc.getWindow() != null && InputUtil.isKeyPressed(Wrapper.mc.getWindow().getHandle(), 341)) {
                  this.configNameInput = this.configNameInput + SelectionManager.getClipboard(Wrapper.mc);
                  if (this.configNameInput.length() > 64) {
                     this.configNameInput = this.configNameInput.substring(0, 64);
                  }

                  return true;
               }
            default:
               return false;
            case 256:
               this.configNameListening = false;
               return true;
            case 257:
            case 335:
               this.configNameListening = false;
               return true;
            case 259:
               this.configNameInput = StringButton.removeLastChar(this.configNameInput);
               return true;
         }
      }
   }

   public boolean charTyped(char chr) {
      if (this.configNameListening && StringHelper.isValidChar(chr)) {
         this.configNameInput = this.configNameInput + chr;
         if (this.configNameInput.length() > 64) {
            this.configNameInput = this.configNameInput.substring(0, 64);
         }

         return true;
      } else {
         return false;
      }
   }

   public void render(DrawContext context, int mouseX, int mouseY, float delta, ClickGuiFrame frame) {
      ClickGui var6 = ClickGui.getInstance();
      if (var6 != null) {
         this.refreshConfigList();
         if (this.selectedConfigName != null && !this.configNames.contains(this.selectedConfigName)) {
            this.selectedConfigName = null;
         }

         if (this.selectedConfigName == null && !this.configNames.isEmpty()) {
            this.selectedConfigName = this.configNames.get(0);
         }

         float var7 = frame.unitMouseX(mouseX);
         float var8 = frame.unitMouseY(mouseY);
         float var9 = frame.baseX(ClickGuiScreen.Page.Config);
         float var10 = frame.scale == 0.0F ? (float)frame.screenW : (float)frame.screenW / frame.scale;
         float var11 = Math.max(8.0F, (var10 - (float)frame.panelW) / 2.0F);
         float var12 = var9 + var11 + 10.0F;
         float var13 = (float)(frame.panelW - 20);
         float var14 = (float)frame.panelY + 10.0F;
         float var15 = (float)frame.panelY + 28.0F;
         float var16 = 8.0F;
         float var17 = var13 * 0.62F;
         float var18 = var12 + var17 + var16;
         float var19 = var13 - var17 - var16;
         boolean var20 = FontManager.isCustomFontEnabled();
         boolean var21 = FontManager.isShadowEnabled();
         boolean var22 = ClientSetting.INSTANCE != null && ClientSetting.INSTANCE.chinese.getValue();
         String var23 = var22 ? "\u914d\u7f6e\u5217\u8868" : "Configs";
         String var24 = var22 ? "\u9009\u62e9\u914d\u7f6e\u540e\u70b9\u51fb Apply \u624d\u4f1a\u5e94\u7528" : "Select a config, then click Apply";
         String var25 = var22 ? "\u65e0" : "None";
         TextUtil.drawString(context, var23, (double)(var12 + 2.0F), (double)var14, var6.enableTextColor.getValue().getRGB(), var20, var21);
         int var26 = this.host.getFontHeight() + 6;
         float var27 = (float)var26 - 0.5F;
         float var28 = var15 - (float)var26;
         float var29 = (float)frame.screenH - 20.0F;
         int var30 = -1;
         if (this.selectedConfigName != null && !this.selectedConfigName.isEmpty()) {
            for (int var31 = 0; var31 < this.configNames.size(); var31++) {
               String var32 = this.configNames.get(var31);
               if (var32 != null && var32.equalsIgnoreCase(this.selectedConfigName)) {
                  var30 = var31;
                  break;
               }
            }
         }

         float var82 = 0.0F;
         if (var30 >= 0) {
            var82 = var15 + (float)var30 * (float)var26 - this.configScroll;
            float var84 = AnimateUtil.deltaTime();
            if (var84 <= 0.0F) {
               var84 = 0.016F;
            }

            float var33 = var84 * 18.0F;
            if (var33 < 0.0F) {
               var33 = 0.0F;
            }

            if (var33 > 0.35F) {
               var33 = 0.35F;
            }

            if (!this.configSelectAnimInit) {
               this.configSelectAnimY = var82;
               this.configSelectAnimInit = true;
            } else {
               this.configSelectAnimY = this.configSelectAnimY + (var82 - this.configSelectAnimY) * var33;
            }
         }

         for (int var85 = 0; var85 < this.configNames.size(); var85++) {
            float var89 = var15 + (float)var85 * (float)var26 - this.configScroll;
            if (!(var89 + var27 < var28) && !(var89 > var29)) {
               boolean var34 = var7 >= var12 && var7 <= var12 + var17 && var8 >= var89 && var8 <= var89 + var27;
               int var35 = var34 ? var6.hoverColor.getValue().getRGB() : var6.defaultColor.getValue().getRGB();
               Render2DUtil.rect(context.getMatrices(), var12, var89, var12 + var17, var89 + var27, var35);
            }
         }

         if (var30 >= 0) {
            float var86 = this.configSelectAnimY;
            boolean var90 = var7 >= var12 && var7 <= var12 + var17 && var8 >= var86 && var8 <= var86 + var27;
            int var93 = var90 ? var6.hoverAlpha.getValueInt() : var6.alpha.getValueInt();
            if (!(var86 + var27 < var28) && !(var86 > var29)) {
               if (var6.colorMode.getValue() == ClickGui.ColorMode.Spectrum) {
                  Render2DUtil.drawLutRect(context.getMatrices(), var12, var86, var17, var27, var6.getSpectrumLutId(), var6.getSpectrumLutHeight(), var93);
               } else {
                  Color var96 = var6.getActiveColor((double)var86 * 0.25);
                  Render2DUtil.rect(context.getMatrices(), var12, var86, var12 + var17, var86 + var27, ColorUtil.injectAlpha(var96, var93).getRGB());
               }
            }
         }

         for (int var87 = 0; var87 < this.configNames.size(); var87++) {
            String var91 = this.configNames.get(var87);
            float var94 = var15 + (float)var87 * (float)var26 - this.configScroll;
            if (!(var94 + var27 < var28) && !(var94 > var29)) {
               boolean var97 = var7 >= var12 && var7 <= var12 + var17 && var8 >= var94 && var8 <= var94 + var27;
               boolean var36 = this.selectedConfigName != null && var91 != null && var91.equalsIgnoreCase(this.selectedConfigName);
               int var37 = !var97 && !var36 ? var6.defaultTextColor.getValue().getRGB() : var6.enableTextColor.getValue().getRGB();
               float var38 = this.host.getCenteredTextY(var94, var27);
               TextUtil.drawString(context, var91, (double)(var12 + 6.0F), (double)var38, var37, var20, var21);
            }
         }

         String var88 = var22 ? "\u5f53\u524d\u9009\u62e9: " : "Selected: ";
         String var92 = var22 ? "\u5df2\u5e94\u7528: " : "Applied: ";
         String var95 = this.selectedConfigName == null ? var25 : this.selectedConfigName;
         String var98 = this.appliedConfigName == null ? var25 : this.appliedConfigName;
         TextUtil.drawString(context, var88 + var95, (double)var18, (double)var14, var6.defaultTextColor.getValue().getRGB(), var20, var21);
         float var99 = var14 + (float)this.host.getFontHeight() + 4.0F;
         TextUtil.drawString(context, var92 + var98, (double)var18, (double)var99, var6.defaultTextColor.getValue().getRGB(), var20, var21);
         float var100 = var99 + (float)this.host.getFontHeight() + 8.0F;
         String var101 = var22 ? "\u540d\u79f0" : "Name";
         TextUtil.drawString(context, var101, (double)var18, (double)var100, var6.defaultTextColor.getValue().getRGB(), var20, var21);
         float var39 = var100 + (float)this.host.getFontHeight() + 4.0F;
         float var40 = (float)var26 - 0.5F;
         boolean var41 = var7 >= var18 && var7 <= var18 + var19 && var8 >= var39 && var8 <= var39 + var40;
         int var42 = !var41 && !this.configNameListening ? var6.defaultColor.getValue().getRGB() : var6.hoverColor.getValue().getRGB();
         Render2DUtil.rect(context.getMatrices(), var18, var39, var18 + var19, var39 + var40, var42);
         String var43 = var22 ? "\u8bf7\u8f93\u5165\u914d\u7f6e\u540d" : "Please type config name";
         String var44 = this.configNameInput != null && !this.configNameInput.isEmpty() ? this.configNameInput : var43;
         if (this.configNameListening) {
            var44 = var44 + StringButton.getIdleSign();
         }

         float var45 = this.host.getCenteredTextY(var39, var40);
         TextUtil.drawString(context, var44, (double)(var18 + 6.0F), (double)var45, var6.enableTextColor.getValue().getRGB(), var20, var21);
         float var46 = var39 + var40 + 8.0F;
         float var47 = (float)var26 - 0.5F;
         String var48 = var22 ? "\u521b\u5efa\u65b0\u914d\u7f6e" : "Create New Config";
         String var49 = var22 ? "\u5907\u4efd" : "Backup";
         String var50 = var22 ? "\u5220\u9664" : "Delete";
         String var51 = var22 ? "\u4fdd\u5b58" : "Save";
         String var52 = var22 ? "\u5e94\u7528" : "Apply";
         String var53 = var22 ? "\u6253\u5f00\u914d\u7f6e\u6587\u4ef6\u5939" : "Open Folder";
         boolean var54 = !this.sanitizeConfigName(this.configNameInput).isEmpty();
         boolean var55 = this.selectedConfigName != null && !this.selectedConfigName.isEmpty();
         boolean var56 = var55 || var54;
         boolean var60 = var7 >= var18 && var7 <= var18 + var19 && var8 >= var46 && var8 <= var46 + var47;
         int var61 = var54 ? (var60 ? var6.hoverColor.getValue().getRGB() : var6.defaultColor.getValue().getRGB()) : var6.defaultColor.getValue().getRGB();
         Render2DUtil.rect(context.getMatrices(), var18, var46, var18 + var19, var46 + var47, var61);
         TextUtil.drawString(
            context, var48, (double)(var18 + 6.0F), (double)this.host.getCenteredTextY(var46, var47), var6.enableTextColor.getValue().getRGB(), var20, var21
         );
         float var62 = var46 + var47 + 4.0F;
         boolean var63 = var7 >= var18 && var7 <= var18 + var19 && var8 >= var62 && var8 <= var62 + var47;
         int var64 = var55 ? (var63 ? var6.hoverColor.getValue().getRGB() : var6.defaultColor.getValue().getRGB()) : var6.defaultColor.getValue().getRGB();
         Render2DUtil.rect(context.getMatrices(), var18, var62, var18 + var19, var62 + var47, var64);
         TextUtil.drawString(
            context, var49, (double)(var18 + 6.0F), (double)this.host.getCenteredTextY(var62, var47), var6.enableTextColor.getValue().getRGB(), var20, var21
         );
         float var65 = var62 + var47 + 4.0F;
         boolean var66 = var7 >= var18 && var7 <= var18 + var19 && var8 >= var65 && var8 <= var65 + var47;
         int var67 = var55 ? (var66 ? var6.hoverColor.getValue().getRGB() : var6.defaultColor.getValue().getRGB()) : var6.defaultColor.getValue().getRGB();
         Render2DUtil.rect(context.getMatrices(), var18, var65, var18 + var19, var65 + var47, var67);
         TextUtil.drawString(
            context, var50, (double)(var18 + 6.0F), (double)this.host.getCenteredTextY(var65, var47), var6.enableTextColor.getValue().getRGB(), var20, var21
         );
         float var68 = var65 + var47 + 4.0F;
         boolean var69 = var7 >= var18 && var7 <= var18 + var19 && var8 >= var68 && var8 <= var68 + var47;
         int var70 = var56 ? (var69 ? var6.hoverColor.getValue().getRGB() : var6.defaultColor.getValue().getRGB()) : var6.defaultColor.getValue().getRGB();
         Render2DUtil.rect(context.getMatrices(), var18, var68, var18 + var19, var68 + var47, var70);
         TextUtil.drawString(
            context, var51, (double)(var18 + 6.0F), (double)this.host.getCenteredTextY(var68, var47), var6.enableTextColor.getValue().getRGB(), var20, var21
         );
         float var71 = var68 + var47 + 4.0F;
         boolean var72 = var7 >= var18 && var7 <= var18 + var19 && var8 >= var71 && var8 <= var71 + var47;
         int var73 = var55 ? (var72 ? var6.hoverColor.getValue().getRGB() : var6.defaultColor.getValue().getRGB()) : var6.defaultColor.getValue().getRGB();
         Render2DUtil.rect(context.getMatrices(), var18, var71, var18 + var19, var71 + var47, var73);
         TextUtil.drawString(
            context, var52, (double)(var18 + 6.0F), (double)this.host.getCenteredTextY(var71, var47), var6.enableTextColor.getValue().getRGB(), var20, var21
         );
         float var74 = var71 + var47 + 4.0F;
         boolean var75 = var7 >= var18 && var7 <= var18 + var19 && var8 >= var74 && var8 <= var74 + var47;
         int var76 = var75 ? var6.hoverColor.getValue().getRGB() : var6.defaultColor.getValue().getRGB();
         Render2DUtil.rect(context.getMatrices(), var18, var74, var18 + var19, var74 + var47, var76);
         TextUtil.drawString(
            context, var53, (double)(var18 + 6.0F), (double)this.host.getCenteredTextY(var74, var47), var6.enableTextColor.getValue().getRGB(), var20, var21
         );
         float var77 = var74 + var47 + 8.0F;
         TextUtil.drawString(context, var24, (double)(var18 + 2.0F), (double)var77, var6.defaultTextColor.getValue().getRGB(), var20, var21);
         if (this.lastSavedConfigName != null && !this.lastSavedConfigName.isEmpty()) {
            long var78 = System.currentTimeMillis();
            if (var78 - this.lastSavedConfigTime <= 2500L) {
               String var80 = var22 ? "已保存: cfg/" + this.lastSavedConfigName + ".cfg" : "Saved: cfg/" + this.lastSavedConfigName + ".cfg";
               float var81 = var77 + (float)this.host.getFontHeight() + 4.0F;
               TextUtil.drawString(context, var80, (double)(var18 + 2.0F), (double)var81, var6.enableTextColor.getValue().getRGB(), var20, var21);
            }
         }
      }
   }

   public boolean mouseClicked(int mouseX, int mouseY, int mouseButton, ClickGuiFrame frame) {
      if (Wrapper.mc == null || Wrapper.mc.getWindow() == null) {
         return false;
      } else if (mouseButton != 0) {
         this.configNameListening = false;
         return false;
      } else {
         float var5 = frame.unitMouseX(mouseX);
         float var6 = frame.unitMouseY(mouseY);
         float var7 = frame.baseX(ClickGuiScreen.Page.Config);
         float var8 = frame.scale == 0.0F ? (float)frame.screenW : (float)frame.screenW / frame.scale;
         float var9 = Math.max(8.0F, (var8 - (float)frame.panelW) / 2.0F);
         float var10 = var7 + var9 + 10.0F;
         float var11 = (float)(frame.panelW - 20);
         float var12 = (float)frame.panelY + 28.0F;
         float var13 = 8.0F;
         float var14 = var11 * 0.62F;
         float var15 = var10 + var14 + var13;
         float var16 = var11 - var14 - var13;
         int var17 = this.host.getFontHeight() + 6;
         float var18 = (float)var17 - 0.5F;
         this.refreshConfigList();

         for (int var19 = 0; var19 < this.configNames.size(); var19++) {
            String var20 = this.configNames.get(var19);
            float var21 = var12 + (float)var19 * (float)var17 - this.configScroll;
            if (var5 >= var10 && var5 <= var10 + var14 && var6 >= var21 && var6 <= var21 + var18) {
               this.selectedConfigName = var20;
               this.configNameListening = false;
               return true;
            }
         }

         float var36 = (float)frame.panelY + 10.0F + (float)this.host.getFontHeight() + 4.0F + (float)this.host.getFontHeight() + 8.0F;
         float var37 = var36 + (float)this.host.getFontHeight() + 4.0F;
         float var38 = (float)var17 - 0.5F;
         if (var5 >= var15 && var5 <= var15 + var16 && var6 >= var37 && var6 <= var37 + var38) {
            this.configNameListening = true;
            return true;
         } else {
            this.configNameListening = false;
            float var22 = var37 + var38 + 8.0F;
            float var23 = (float)var17 - 0.5F;
            float var24 = var22 + var23 + 4.0F;
            float var25 = var24 + var23 + 4.0F;
            float var26 = var25 + var23 + 4.0F;
            float var27 = var26 + var23 + 4.0F;
            float var28 = var27 + var23 + 4.0F;
            boolean var29 = !this.sanitizeConfigName(this.configNameInput).isEmpty();
            boolean var30 = this.selectedConfigName != null && !this.selectedConfigName.isEmpty();
            boolean var31 = var30 || var29;
            if (var5 >= var15 && var5 <= var15 + var16 && var6 >= var22 && var6 <= var22 + var23 && var29) {
               String var42 = this.createDefaultConfig(this.configNameInput);
               if (var42 != null) {
                  this.selectedConfigName = var42;
               }

               return true;
            } else if (var5 >= var15 && var5 <= var15 + var16 && var6 >= var24 && var6 <= var24 + var23 && var30) {
               String var41 = this.backupConfig(this.selectedConfigName, this.configNameInput);
               if (var41 != null) {
                  this.selectedConfigName = var41;
               }

               return true;
            } else if (var5 >= var15 && var5 <= var15 + var16 && var6 >= var25 && var6 <= var25 + var23 && var30) {
               final String var40 = this.selectedConfigName;
               boolean var44 = ClientSetting.INSTANCE != null && ClientSetting.INSTANCE.chinese.getValue();
               String var45 = var44 ? "\u786e\u8ba4\u5220\u9664" : "Confirm Delete";
               String var46 = var44 ? "确定删除配置: " + var40 + " ?" : "Delete config: " + var40 + " ?";
               this.host
                  .openConfirm(
                     var45,
                     var46,
                     new Runnable() {
                        @Override
                        public void run() {
                           ClickGuiConfigPage.this.deleteConfig(var40);
                           ClickGuiConfigPage.this.selectedConfigName = ClickGuiConfigPage.this.configNames.isEmpty()
                              ? null
                              : ClickGuiConfigPage.this.configNames.get(0);
                           if (var40 != null && var40.equalsIgnoreCase(ClickGuiConfigPage.this.appliedConfigName)) {
                              ClickGuiConfigPage.this.appliedConfigName = null;
                           }
                        }
                     }
                  );
               return true;
            } else if (var5 >= var15 && var5 <= var15 + var16 && var6 >= var26 && var6 <= var26 + var23 && var31) {
               String var39 = var30 ? this.selectedConfigName : this.configNameInput;
               String var43 = this.saveConfig(var39);
               if (var43 != null) {
                  this.lastSavedConfigName = var43;
                  this.lastSavedConfigTime = System.currentTimeMillis();
                  this.selectedConfigName = var43;
               }

               return true;
            } else if (var5 >= var15 && var5 <= var15 + var16 && var6 >= var27 && var6 <= var27 + var23 && var30) {
               final String var32 = this.selectedConfigName;
               boolean var33 = ClientSetting.INSTANCE != null && ClientSetting.INSTANCE.chinese.getValue();
               String var34 = var33 ? "\u786e\u8ba4\u5e94\u7528" : "Confirm Apply";
               String var35 = var33 ? "应用配置: " + var32 : "Apply config: " + var32;
               this.host.openConfirm(var34, var35, new Runnable() {
                  @Override
                  public void run() {
                     ClickGuiConfigPage.this.loadConfig(var32);
                  }
               });
               return true;
            } else if (var5 >= var15 && var5 <= var15 + var16 && var6 >= var28 && var6 <= var28 + var23) {
               this.openConfigFolder();
               return true;
            } else {
               return false;
            }
         }
      }
   }

   private void refreshConfigList() {
      this.configNames.clear();
      this.configNames.addAll(ConfigManager.listCfgNames());
   }

   private String sanitizeConfigName(String name) {
      return ConfigManager.sanitizeCfgName(name);
   }

   private String createDefaultConfig(String nameInput) {
      String var2 = ConfigManager.createDefaultCfg(nameInput);
      this.refreshConfigList();
      return var2;
   }

   private String backupConfig(String fromName, String toNameInput) {
      String var3 = ConfigManager.backupCfg(fromName, toNameInput);
      this.refreshConfigList();
      return var3;
   }

   private void deleteConfig(String name) {
      ConfigManager.deleteCfg(name);
      this.refreshConfigList();
   }

   private String saveConfig(String name) {
      String var2 = ConfigManager.saveCfg(name);
      this.refreshConfigList();
      return var2;
   }

   private void loadConfig(String name) {
      if (ConfigManager.loadCfg(name)) {
         this.appliedConfigName = name;
      }
   }

   private void openConfigFolder() {
      try {
         File var1 = ConfigManager.getCfgFolder();
         if (var1 == null) {
            return;
         }

         if (Desktop.isDesktopSupported()) {
            Desktop var2 = Desktop.getDesktop();
            if (var2 != null && var2.isSupported(Action.OPEN)) {
               var2.open(var1);
               return;
            }
         }

         String var6 = System.getProperty("os.name");
         String var3 = var1.getAbsolutePath();
         if (var6 != null) {
            String var4 = var6.toLowerCase();
            if (var4.contains("win")) {
               Runtime.getRuntime()
                  .exec(new String[]{"cmd", "/c", "start", "", var3});
               return;
            }

            if (var4.contains("mac")) {
               Runtime.getRuntime().exec(new String[]{"open", var3});
               return;
            }
         }

         Runtime.getRuntime().exec(new String[]{"xdg-open", var3});
      } catch (Exception var5) {
         var5.printStackTrace();
      }
   }
}
