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).

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

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: 310 / 1004
Version history: 6 change(s)
Referenced in: [show references]