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

89
LINES

< > BotCompany Repo | #1020554 // VNC Viewer Tray Icon

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 1689K of libraries. Click here for Pure Java version (23720L/125K).

!7

concept Profile {
  S name, options;
  S computerID; // to send clipboard etc (optional)
  S passwordID; // global ID to send to #1029670

  bool hasPassword() { ret nempty(passwordID); }
  bool hasComputerID() { ret nempty(computerID); }
}

cmodule2 VNCViewerTrayIcon > DynCRUD<Profile> {
  transient TrayIcon trayIcon;
  switchable bool inProcess; // don't think true works yet
  transient ReliableSingleThread rstMakeTrayIcon = dm_rst(this, r makeTrayIcon);

  SimpleCRUD<Profile> makeCRUD() {
    var crud = super.makeCRUD();
    //crud.editOnDoubleClick = false;
    ret crud;
  }
  
  start {
    db();
    onConceptsChangeAndNow(r { doLater(2.0, rstMakeTrayIcon) });
  }

  void makeTrayIcon enter {
    disposeTrayIcon(trayIcon);
    new L menuItems; // no left-click action
    for (Profile p : sortConceptsByID(list(Profile)))
      if (nemptyAfterTrim(p.options))
        addAll(menuItems, "VNC to " + p.name, rThread { launch(p) });
    add(menuItems, "---");
    L<Profile> withComputerID = filter(p -> p.hasComputerID(), list(Profile));
    if (nempty(withComputerID)) {
      for (Profile p : withComputerID) {
        addAll(menuItems, "Send clipboard to " + p.name, rThreadEnter { dm_sendClipboardTo_verbose(p.computerID) });
        addAll(menuItems, "Grab clipboard from " + p.name, rThreadEnter { dm_grabClipboardFrom_verbose(p.computerID) });
      }
      add(menuItems, "---");
    }
    addAll(menuItems, "VNC Viewer Connection Dialog", rThread { if (inProcess) launchVNCViewer_inProcess(); else launchVNCViewer() });
    addAll(menuItems, "Edit Profiles...", rThread dm_activateOSAndModule);
    pcall {
      trayIcon = installTrayIcon(#1101468, "Start VNC Viewer", menuItems);
    }
  }
  
  afterVisualize {
    // TODO: disable when at beginning/end of list
    addSelectionDependentButton("Move Up", r {
      Profile a = selected(), b = itemBefore(list(), a);
      if (a != null && b != null)
        swapConceptIDs(a, b);
    });
    addSelectionDependentButton("Move Down", r {
      Profile a = selected(), b = itemAfter(list(), a);
      if (a != null && b != null)
        swapConceptIDs(a, b);
    });
    addSelectionDependentButton("Connect", rThread {
      launch(selected());
    });

    tablePopupMenu_first(table(), voidfunc(JPopupMenu menu, int row) {
      Profile p = selected(), ret if null;
      addMenuItem(menu, "Connect", r { launch(p) });
      if (p.hasPassword())
        addMenuItem(menu, "Copy password", rThreadEnter { copyPassword(p) });
      if (p.hasComputerID())
        addMenuItem(menu, "Send clipboard there", rThreadEnter { dm_sendClipboardTo_verbose(p.computerID) });
    });
  }

  void cleanMeUp {
    disposeTrayIcon(trayIcon);
  }

  void copyPassword(Profile p) {
    dm_copyPasswordForGlobalIDToClipboard(p.passwordID);
  }

  void launch(Profile p) {
    if (p == null) ret;
    copyPassword(p);
    if (inProcess) launchVNCViewer_inProcess(p.options); else launchVNCViewer(p.options);
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 9 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1020554
Snippet name: VNC Viewer Tray Icon
Eternal ID of this version: #1020554/52
Text MD5: 987e04e916dd27f00f33cdf7d402f372
Transpilation MD5: 213fa6f7910838af9fcfb43c0e98e361
Author: stefan
Category: javax
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2023-04-17 08:24:32
Source code size: 3061 bytes / 89 lines
Pitched / IR pitched: No / No
Views / Downloads: 406 / 12157
Version history: 51 change(s)
Referenced in: [show references]