From 39995509b1b7dace94030391117f92097ae2b4d7 Mon Sep 17 00:00:00 2001 From: Kaloyan Raev Date: Mon, 11 Dec 2017 18:51:26 +0200 Subject: [PATCH] Fixes #2: Display tray icon with current status (#58) In addition there is a basic context menu with the following actions: - Open Goobox Folder - Quit Goobox --- pom.xml | 7 +------ src/main/java/io/goobox/sync/storj/App.java | 13 ++++++++++++- .../java/io/goobox/sync/storj/CheckStateTask.java | 4 ++++ src/main/resources/logback.xml | 2 ++ 4 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 src/main/resources/logback.xml diff --git a/pom.xml b/pom.xml index 4bac063..1219a1b 100644 --- a/pom.xml +++ b/pom.xml @@ -57,7 +57,7 @@ io.goobox goobox-sync-common - 0.0.1 + 0.0.2 io.storj @@ -74,11 +74,6 @@ appdirs 1.0.0 - - org.slf4j - slf4j-nop - 1.7.21 - net.java.dev.jna jna-platform diff --git a/src/main/java/io/goobox/sync/storj/App.java b/src/main/java/io/goobox/sync/storj/App.java index 185c7c4..2068585 100644 --- a/src/main/java/io/goobox/sync/storj/App.java +++ b/src/main/java/io/goobox/sync/storj/App.java @@ -22,13 +22,15 @@ import java.util.concurrent.CountDownLatch; import io.goobox.sync.common.Utils; +import io.goobox.sync.common.systemtray.ShutdownListener; +import io.goobox.sync.common.systemtray.SystemTrayHelper; import io.storj.libstorj.Bucket; import io.storj.libstorj.CreateBucketCallback; import io.storj.libstorj.GetBucketsCallback; import io.storj.libstorj.KeysNotFoundException; import io.storj.libstorj.Storj; -public class App { +public class App implements ShutdownListener { private static App instance; @@ -63,6 +65,9 @@ public FileWatcher getFileWatcher() { } private void init() { + SystemTrayHelper.setIdle(); + SystemTrayHelper.setShutdownListener(this); + Storj.setConfigDirectory(StorjUtil.getStorjConfigDir()); Storj.setDownloadDirectory(Utils.getSyncDir()); @@ -89,6 +94,12 @@ private void init() { taskExecutor.start(); } + @Override + public void shutdown() { + // TODO graceful shutdown + System.exit(0); + } + private boolean checkAndCreateSyncDir() { System.out.print("Checking if local Goobox sync folder exists... "); return checkAndCreateFolder(Utils.getSyncDir()); diff --git a/src/main/java/io/goobox/sync/storj/CheckStateTask.java b/src/main/java/io/goobox/sync/storj/CheckStateTask.java index da6ef3a..1293502 100644 --- a/src/main/java/io/goobox/sync/storj/CheckStateTask.java +++ b/src/main/java/io/goobox/sync/storj/CheckStateTask.java @@ -27,6 +27,7 @@ import java.util.List; import io.goobox.sync.common.Utils; +import io.goobox.sync.common.systemtray.SystemTrayHelper; import io.goobox.sync.storj.db.DB; import io.goobox.sync.storj.db.SyncFile; import io.goobox.sync.storj.db.SyncState; @@ -54,6 +55,8 @@ public void run() { } System.out.println("Checking for changes..."); + SystemTrayHelper.setSynchronizing(); + Storj.getInstance().listFiles(gooboxBucket, new ListFilesCallback() { @Override public void onFilesReceived(File[] files) { @@ -64,6 +67,7 @@ public void onFilesReceived(File[] files) { if (tasks.isEmpty()) { // Sleep some time to avoid overloading the bridge tasks.add(new SleepTask()); + SystemTrayHelper.setIdle(); } // Add itself to the queueAdd itself to the queue tasks.add(CheckStateTask.this); diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml new file mode 100644 index 0000000..9fc1778 --- /dev/null +++ b/src/main/resources/logback.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file