Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

199
LINES

< > BotCompany Repo | #1033509 // Standalone Gazelle V [previous head]

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Uses 1663K of libraries. Click here for Pure Java version (27870L/153K).

/*       WELCOME!! This is THE PROGRAM YOU ARE LOOKING FOR.

There is a SLIGHT COMPILE ISSUE which we are RESOLVING RIGHT NOW.
-Stefan Reich, 2021/10/29 05:34:21 UTC
*/

!7

sS windowTitle = "Gazelle V 2020-10-28 .09";
sS downloadURL = "https://botcompany.de/jar/1033411?withLibs=1&noCompiler=1";
sS trayIconImageID = #1103047;
static int borderSize = 5;
static Color color1 = awtColor("ADD8E6");
static Color color2 = awtColor("EEEEEE");
static Color color3 = awtColor("A3C0AA");

lib 1400521 // FlatLAF

set flag PingV3.
set flag NotifyingPrintLog.

static IF0<PingSource> ping_v3_pingSourceMaker() { ret () -> new PingSource; }

sclass Stem {
  JFrame window;
  
  Rect getFrameRect() {
    ret toRect(getBounds(window));
  }
}

static Stem stem;
static GazelleV gazelle;
static TrayIcon trayIcon;
static JFrame mainWindow;
static Set<S> argsSet;

svoid trayIconLeftClick {
  activateFrame_v3(mainWindow);
}

svoid makeTrayIcon {
  pcall-short {
    trayIcon_imageAutoSize = false;
    trayIcon = installTrayIcon(trayIconImageID, windowTitle,
      r trayIconLeftClick,
      "Show Gazelle", r { activateFrame(mainWindow) },
      "Exit Gazelle", r cleanExit
    );
  }
}

p {
  __javax = x30.class;
  loadableUtils.utils.__setJavaX(x30.class);
  vm_generalMap_put(stefansOS := mc());
  __javax = x30.class;
  x30.__javax = x30.class; // for hotwire
  x30_pkg.x30_util.__setJavaX(x30.class);
  x30.cleanKillMsg = "";
  callOnLoadMethods(mc());
  
  argsSet = asSet(args);
  
  if (!argsSet.contains("noflatlaf"))
    com.formdev.flatlaf.FlatLightLaf.setup();
  
  if (contains(args, "profile"))
    profileToConsole(() -> actualMain(args));
  else
    actualMain(args);
    
  if (argsSet.contains("brexit")) System.exit(0);
  
  temp gazelle.enter();
  gazelle.start();
}

svoid actualMain(S... args) {
  // Do the JavaX init
  
  System.out.println(hmsWithColonsAndMS() + ": Init");
  //x30.coreInit();
  
  // Ready to roll
  
  if (containsOneOf(argsSet, "upgrade", "update"))
    ret with upgradeGazelle();

  makeTrayIcon();
  
  printWithMS("new GazelleV");
  gazelle = new GazelleV;
  stem = new Stem;
  gazelle._host = stem;
  copyLocalLog(gazelle, mc());

  temp gazelle.enter();
  printWithMS("Visualize");
  var vis = swing(() -> gazelle.visualize());
  
  vis = makeWindowBorderAndTitle(vis, windowTitle);
  printWithMS("Show frame");
  //stem.window = showMainFrame("Gazella", vis);
  JFrame frame = makeUndecoratedFrame(windowTitle, vis);
  setFrameIcon(frame, trayIconImageID);
  stem.window = mainWindow = frame;
  onWindowClosing(stem.window, r cleanExit);
  showWindow(stem.window);
  printWithMS("Dudadoneski");
}

svoid minimize {
  if (trayIcon == null)
    minimizeWindow(mainWindow);
  else
    hideWindow(mainWindow);
}  

static JComponent makeWindowBorderAndTitle(JComponent contents, S title) {
  //ret jCenteredSection_fontSizePlus(10, title, vis);
  
  var icons = jline();
  icons.add(jbutton("Minimize", r minimize));
  icons.add(jbutton("Close", r { disposeWindow(icons) }));
  icons.add(jPopDownButton_noText(
    "Update Gazelle", rThread upgradeGazelle,
    "Dump threads", rThread { showText("User threads", renderUserThreadsWithStackTraces()); },
  ));
  
  var actualTitle = fontSizePlus(7, jCenteredLabel(title));
  var spacer = gazelle_wavySpacer();
  var titleBarMain = setOpaqueBackground(color1,
    westCenterAndEastWithMargin(
      jImage_scaledToHeight(24, trayIconImageID),
      actualTitle,
      setOpaqueBackground(color2, spacer));
  
  installWindowDragger(actualTitle);
  installWindowDragger(spacer);
  
  var titleBar = setBackground(color2, centerAndEast(
    titleBarMain,
    icons));
  
  var border =
    // createBevelBorder();
    BorderFactory.createLineBorder(color1, borderSize);
    
  var outerPanel = withBorder(border,
    northAndCenter(titleBar, contents));
    
  installWindowResizeDraggerOnBorder(outerPanel);
  ret outerPanel;
}

sO dm_getStem(O moduleOrID) {
  ret stem;
}

sO resolveModule(O moduleOrID) { ret moduleOrID == stem ? gazelle : moduleOrID; }

svoid cleanExit {
  System.exit(0);
}

svoid upgradeGazelle {
  File myJar = getBytecodePathForClass(mc());
  print(+myJar);
  
  S javaCmd = or2(currentProcessCommand(), "java");
  S date = ymdMinusHMS();
  File f = javaxCodeDir("Downloaded Updates/" + "gazelle-" + date + ".jar");
  infoBox("Downloading Update...");
  loadBinaryPageToFile(downloadURL, f);
  printFileInfo(f);
  if (!isNonEmptySingleZip_byMagicHeader(f))
    ret with  infoBox("Bad file downloaded... :(");
    
  bool replaced;
  if (isFile(myJar)) {
    print("Loaded " + nClasses(loadAllClassesInByteCodePath(myJar)));
    print("Replacing with new version: " + myJar);
    renameFile(myJar, appendToBaseName(myJar, ".bak." + date));
    copyFile(f, myJar);
    printFileInfo(myJar);
    set replaced;
  }
    
  infoBox(replaced
    ? "Installed update, replaced " + f2s(myJar) + " - now starting"
    : "Starting update, but could not replace originally downloaded jar");
  S cmd = pqO(javaCmd) + " -jar " + pqO(replaced ? myJar : f);
  print(cmd);
  nohup(cmd);
  cleanExit();
}

!include early #1033309 // GazelleV

Author comment

Began life as a copy of #1033411

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): bhatertpkbcr, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1033509
Snippet name: Standalone Gazelle V [previous head]
Eternal ID of this version: #1033509/5
Text MD5: 480f923a1bd9adf5d0e6fb3ff7e4d48c
Transpilation MD5: 4805576a848aca038d52b2d4de6a46e6
Author: stefan
Category: javax / screen recognition
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-29 08:11:50
Source code size: 5329 bytes / 199 lines
Pitched / IR pitched: No / No
Views / Downloads: 191 / 715
Version history: 4 change(s)
Referenced in: [show references]