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

84
LINES

< > BotCompany Repo | #1005411 // PC Awareness

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

Download Jar. Libraryless. Click here for Pure Java version (15009L/110K).

1  
!7
2  
3  
!include #1015939 // PC Awareness Include
4  
5  
static JLabel lblStatus;
6  
7  
p {
8  
  db();
9  
  
10  
  if (match("i am aware", sendToLocalBotOpt_original("Awareness Bot", "are you aware"))) {
11  
    print("Has awareness.");
12  
    ret;
13  
  }
14  
  
15  
  awt {
16  
    showControls(lblStatus = jlabel("Setting Up Awareness..."));
17  
    awtOnConceptChanges(lblStatus, 1000, f updateStatus);
18  
    installTimer(lblStatus, 30000, f updateStatus);
19  
    
20  
    componentPopupMenu(lblStatus, voidfunc(JPopupMenu menu) {
21  
      for (final MachineInfo info : findConcepts(MachineInfo, "me", false)) {
22  
        if (!validPeer(info) || eq(osName(info), "Android")) continue;
23  
        
24  
        // Remote PC popup items follow
25  
        addMenuItem(menu, "Grab clipboard from " + info.ip, r {
26  
          S s = sendToAwareness(info.ip, "get clipboard");
27  
          if (nempty(s) && neq(s, "empty or unknown")) {
28  
            L l = cast safeUnstructure(s);
29  
            S type = cast first(l);
30  
            if (eq(type, "text")) {
31  
              S text = (S) l.get(1);
32  
              copyTextToClipboard(text);
33  
              print("Copied text to clipboard: " + quote(shorten(text, 100)));
34  
            } else if (eq(type, "png")) {
35  
              copyImageToClipboard(fromPNG((byte[]) l.get(1)));
36  
              print("Copied image to clipboard.");
37  
            } else
38  
              print("Unknown clipboard type: " + type);
39  
          }
40  
        });
41  
        
42  
        addMenuItem(menu, "Grab screenshot from " + info.ip, r {
43  
          S s = sendToAwareness(info.ip, "screenshot");
44  
          if (startsWith(s, "[")) {
45  
            L l = cast safeUnstructure(s);
46  
            S type = cast first(l);
47  
            if (eq(type, "png")) {
48  
              BufferedImage img = fromPNG((byte[]) l.get(1));  
49  
              showImage("Screenshot from " + info.ip + " at " + ymd_hms(), img);
50  
            }
51  
          }
52  
        });
53  
      }
54  
    });
55  
  }
56  
57  
  print("Yo Setting Up Awareness...");
58  
59  
  makeBot("Awareness Bot.");
60  
  phonePublicCommBot(); // works for PCs too
61  
  findBot_timeout = 1000*60;
62  
  pingThread(null);
63  
  
64  
  print("Awareness Set Up!");
65  
  printMyIPs();
66  
  
67  
  scanSubnet_parallel();
68  
  notDoneQuietly();
69  
}
70  
71  
svoid updateStatus {
72  
  new L<S> l;
73  
  for (MachineInfo info : concatLists(
74  
    findConcepts(MachineInfo, "me", true),
75  
    findConcepts(MachineInfo, "me", false))) {
76  
    if (!validPeer(info)) continue;
77  
    
78  
    l.add(info.ip + ": " + /*info.computerID*/ osName(info)
79  
      + (info.me ? " [me]" : ""));
80  
  }
81  
  S text = isEmpty(l) ? "Looking for peers"
82  
    : n(l, "machine") + ": " + join(", ", l);
83  
  lblStatus.setText(text);
84  
}

Author comment

Began life as a copy of #1004078

download  show line numbers  debug dex  old transpilations   

Travelled to 17 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, sawdedvomwva, tslmcundralx, tvejysmllsmz, vouqrxazstgt, wtqryiryparv, zluxfztcnsid

No comments. add comment

Snippet ID: #1005411
Snippet name: PC Awareness
Eternal ID of this version: #1005411/7
Text MD5: b644e72df5381291427e22f3b630104c
Transpilation MD5: 4ac04b58e4720f93a9fdea81ab253354
Author: stefan
Category: javax
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-05-31 23:03:04
Source code size: 2632 bytes / 84 lines
Pitched / IR pitched: No / No
Views / Downloads: 763 / 2341
Version history: 6 change(s)
Referenced in: [show references]