!7 !include #1015939 // PC Awareness Include sclass PCAwareness > DynModule { transient JLabel lblStatus; visualize { ret lblStatus; } start { 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, r updateStatus); installTimer(lblStatus, 30000, r 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); } } } }); } }); } thread { 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(); } } void status(S s) { setText(lblStatus, print(s)); } void updateStatus enter { new L l; int meCount = 0; 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]" : "")); if (info.me) ++meCount; } S text = isEmpty(l) ? "Looking for peers" : n(l(l)-max(0, meCount-1), "machine") + ": " + join(", ", l); setText(lblStatus, text); } }