Skip to content
This repository has been archived by the owner on Jul 26, 2022. It is now read-only.

Commit

Permalink
Move pixel back and forth, relates to #164
Browse files Browse the repository at this point in the history
  • Loading branch information
binwiederhier committed Aug 8, 2014
1 parent 36f95d0 commit bc5d0dc
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public class DaemonOperation extends Operation {
private WebServer webServer;
private WatchServer watchServer;
private ControlServer controlServer;
private StandbyPreventor standbyPreventor;
private LocalEventBus eventBus;
private DaemonConfigTO daemonConfig;
private PortTO portTO;
Expand All @@ -85,6 +86,7 @@ public DaemonOperation(Config config) {

this.pidFile = new File(UserConfig.getUserConfigDir(), PID_FILE);
this.daemonConfigFile = new File(UserConfig.getUserConfigDir(), DAEMON_FILE);
this.standbyPreventor = new StandbyPreventor();
}

@Override
Expand All @@ -107,10 +109,11 @@ private void startOperation() throws ServiceAlreadyStartedException, ConfigExcep

startWebServer();
startWatchServer();
startStandbyPreventor();

enterControlLoop(); // This blocks until SHUTDOWN is received!
}

@Subscribe
public void onControlCommand(ControlCommand controlCommand) {
switch (controlCommand) {
Expand Down Expand Up @@ -145,6 +148,7 @@ private void enterControlLoop() throws IOException, ServiceAlreadyStartedExcepti
private void stopOperation() {
stopWebServer();
stopWatchServer();
stopStandbyPreventor();
}

private void reloadOperation() {
Expand Down Expand Up @@ -257,4 +261,16 @@ private void stopWatchServer() {
logger.log(Level.INFO, "Stopping watch server ...");
watchServer.stop();
}

// Standby preventor

private void startStandbyPreventor() {
logger.log(Level.INFO, "Starting standby preventor...");
new Thread(standbyPreventor).start();
}

private void stopStandbyPreventor() {
logger.log(Level.INFO, "Stopping standby preventor ...");
standbyPreventor.stop();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Syncany, www.syncany.org
* Copyright (C) 2011-2014 Philipp C. Heckel <philipp.heckel@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.syncany.operations.daemon;

import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.Robot;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.logging.Logger;

public class StandbyPreventor implements Runnable {
private static final Logger logger = Logger.getLogger(StandbyPreventor.class.getSimpleName());
private AtomicBoolean running = new AtomicBoolean(true);

@Override
public void run() {
try {
Robot robot = new Robot();

while (running.get()) {
Point currentMousePosition = MouseInfo.getPointerInfo().getLocation();
Point tempMousePosition = (currentMousePosition.x > 0) ? new Point(currentMousePosition.x-10, currentMousePosition.y) : new Point(currentMousePosition.x+10, currentMousePosition.y);

logger.log(Level.INFO, "Standby prevention: Moving mouse 1px (and back): " + currentMousePosition);

robot.mouseMove(tempMousePosition.x, tempMousePosition.y);
robot.mouseMove(currentMousePosition.x, currentMousePosition.y);

Thread.sleep(60000);
}

logger.log(Level.INFO, "Standby prevention stopped (gracefully).");
}
catch (InterruptedException e) {
logger.log(Level.INFO, "Standby prevention stopped (interrupted).", e);
}
catch (Exception e) {
logger.log(Level.WARNING, "Standby prevention failed.", e);
}
}

public void stop() {
running.set(false);
}
}

0 comments on commit bc5d0dc

Please sign in to comment.