-Clipboard spy fix.
This commit is contained in:
tonikelope 2016-12-13 18:19:24 +01:00
parent 7b6c948b7b
commit dab1948c5e
2 changed files with 37 additions and 5 deletions

View File

@ -8,10 +8,11 @@ import static java.lang.Thread.sleep;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import static java.util.logging.Level.SEVERE; import static java.util.logging.Level.SEVERE;
import static java.util.logging.Logger.getLogger; import static java.util.logging.Logger.getLogger;
import static megabasterd.MainPanel.THREAD_POOL;
public final class ClipboardSpy implements Runnable, ClipboardOwner, SecureNotifiable, ClipboardChangeObservable { public final class ClipboardSpy implements Runnable, ClipboardOwner, SecureNotifiable, ClipboardChangeObservable {
private static final int SLEEP = 50; private static final int SLEEP = 250;
private final Clipboard _sysClip; private final Clipboard _sysClip;
@ -22,11 +23,14 @@ public final class ClipboardSpy implements Runnable, ClipboardOwner, SecureNotif
private Transferable _contents; private Transferable _contents;
private final Object _secure_notify_lock; private final Object _secure_notify_lock;
private volatile boolean _gaining_ownership;
public ClipboardSpy() { public ClipboardSpy() {
_sysClip = getDefaultToolkit().getSystemClipboard(); _sysClip = getDefaultToolkit().getSystemClipboard();
_notified = false; _notified = false;
_contents = null; _contents = null;
_gaining_ownership = false;
_secure_notify_lock = new Object(); _secure_notify_lock = new Object();
_observers = new ConcurrentLinkedQueue<>(); _observers = new ConcurrentLinkedQueue<>();
} }
@ -36,6 +40,10 @@ public final class ClipboardSpy implements Runnable, ClipboardOwner, SecureNotif
return _contents; return _contents;
} }
public Clipboard getSysClip() {
return _sysClip;
}
@Override @Override
public void secureNotify() { public void secureNotify() {
synchronized (_secure_notify_lock) { synchronized (_secure_notify_lock) {
@ -89,15 +97,33 @@ public final class ClipboardSpy implements Runnable, ClipboardOwner, SecureNotif
@Override @Override
public void lostOwnership(Clipboard c, Transferable t) { public void lostOwnership(Clipboard c, Transferable t) {
_contents = getClipboardContents(); if(!_gaining_ownership)
{
_gaining_ownership = true;
THREAD_POOL.execute(new Runnable() {
@Override
public void run() {
_contents = getClipboardContents();
notifyChangeToMyObservers(); notifyChangeToMyObservers();
gainOwnership(_contents); gainOwnership(_contents);
_gaining_ownership = false;
}});
}
} }
private Transferable getClipboardContents() { private Transferable getClipboardContents() {
try{
sleep(SLEEP);
} catch (InterruptedException ex1) {
getLogger(ClipboardSpy.class.getName()).log(SEVERE, null, ex1);
}
boolean error; boolean error;
Transferable c = null; Transferable c = null;
@ -127,6 +153,12 @@ public final class ClipboardSpy implements Runnable, ClipboardOwner, SecureNotif
private void gainOwnership(Transferable t) { private void gainOwnership(Transferable t) {
try{
sleep(SLEEP);
} catch (InterruptedException ex1) {
getLogger(ClipboardSpy.class.getName()).log(SEVERE, null, ex1);
}
boolean error; boolean error;
do { do {

View File

@ -61,7 +61,7 @@ import org.apache.http.auth.UsernamePasswordCredentials;
*/ */
public final class MainPanel { public final class MainPanel {
public static final String VERSION = "1.64"; public static final String VERSION = "1.65";
public static final int THROTTLE_SLICE_SIZE = 16 * 1024; public static final int THROTTLE_SLICE_SIZE = 16 * 1024;
public static final int STREAMER_PORT = 1337; public static final int STREAMER_PORT = 1337;
public static final int WATCHDOG_PORT = 1338; public static final int WATCHDOG_PORT = 1338;