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

92
LINES

< > BotCompany Repo | #1015941 // PC Awareness [Dyn Module, old]

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

Download Jar. Libraryless. Click here for Pure Java version (17680L/132K).

!7

!include #1015939 // PC Awareness Include

static JLabel lblStatus;

static JLabel visualize() { ret lblStatus; }

p {
  lblStatus = jcenteredboldlabel("Setting Up Awareness...");
  
  db();
  
  if (match("i am aware", sendToLocalBotOpt_original("Awareness Bot", "are you aware"))) {
    setText(lblStatus, "Has awareness elsewhere.");
    ret;
  }
  
  swing {
    awtOnConceptChanges(lblStatus, 1000, f updateStatus);
    installTimer(lblStatus, 30000, f updateStatus);
    
    componentPopupMenu(lblStatus, voidfunc(JPopupMenu menu) {
      for (final MachineInfo info : findConcepts(MachineInfo, "me", false)) {
        if (!validPeer(info) || eq(osName(info), "Android")) continue;
        
        // Remote PC popup items follow
        addMenuItem(menu, "Grab clipboard from " + info.ip, r {
          S s = sendToAwareness(info.ip, "get clipboard");
          if (nempty(s) && neq(s, "empty or unknown")) {
            L l = cast safeUnstructure(s);
            S type = cast first(l);
            if (eq(type, "text")) {
              S text = (S) l.get(1);
              copyTextToClipboard(text);
              print("Copied text to clipboard: " + quote(shorten(text, 100)));
            } else if (eq(type, "png")) {
              copyImageToClipboard(fromPNG((byte[]) l.get(1)));
              print("Copied image to clipboard.");
            } else
              print("Unknown clipboard type: " + type);
          }
        });
        
        addMenuItem(menu, "Grab screenshot from " + info.ip, r-thread {
          loading "Grabbing Screenshot Through Network" {
            S s = sendToAwareness(info.ip, "screenshot");
            if (startsWith(s, "[")) {
              L l = cast safeUnstructure(s);
              S type = cast first(l);
              if (eq(type, "png")) {
                BufferedImage img = fromPNG((byte[]) l.get(1));  
                showImage("Screenshot from " + info.ip + " at " + ymd_hms(), img);
              }
            }
          }
        });
      }
    });
  }

  print("Yo Setting Up Awareness...");

  makeBot("Awareness Bot.");
  phonePublicCommBot(); // works for PCs too
  findBot_timeout = 1000*60;
  pingThread(null);
  
  status("Awareness Set Up!");
  printMyIPs();
  
  scanSubnet_parallel();
}

svoid status(S s) {
  setText(lblStatus, print(s));
}

svoid updateStatus {
  new L<S> l;
  for (MachineInfo info : concatLists(
    findConcepts(MachineInfo, "me", true),
    findConcepts(MachineInfo, "me", false))) {
    if (!validPeer(info)) continue;
    
    l.add(info.ip + ": " + /*info.computerID*/ osName(info)
      + (info.me ? " [me]" : ""));
  }
  S text = isEmpty(l) ? "Looking for peers"
    : n(l, "machine") + ": " + join(", ", l);
  lblStatus.setText(text);
}

Author comment

Began life as a copy of #1005411

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1015941
Snippet name: PC Awareness [Dyn Module, old]
Eternal ID of this version: #1015941/7
Text MD5: 4fab5178ad43e37ba92316c6156daf6f
Transpilation MD5: 3314f7c2babe06833123289cc465320d
Author: stefan
Category: javax
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-11-25 04:20:21
Source code size: 2841 bytes / 92 lines
Pitched / IR pitched: No / No
Views / Downloads: 422 / 1264
Version history: 6 change(s)
Referenced in: [show references]