Skip to content
This repository has been archived by the owner on Sep 6, 2019. It is now read-only.

Commit

Permalink
Move overlay icon support to common project (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaloyan-raev authored Jan 20, 2018
1 parent 5ec8c87 commit f3fe43d
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 274 deletions.
14 changes: 2 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>io.goobox</groupId>
<artifactId>goobox-sync-storj</artifactId>
<version>0.0.15</version>
<version>0.0.16</version>
<packaging>jar</packaging>

<name>Goobox sync app for Storj</name>
Expand Down Expand Up @@ -57,23 +57,13 @@
<dependency>
<groupId>io.goobox</groupId>
<artifactId>goobox-sync-common</artifactId>
<version>0.0.4</version>
<version>0.0.5</version>
</dependency>
<dependency>
<groupId>io.storj</groupId>
<artifactId>libstorj-java</artifactId>
<version>0.5.1</version>
</dependency>
<dependency>
<groupId>com.liferay</groupId>
<artifactId>com.liferay.nativity</artifactId>
<version>1.0.5</version>
</dependency>
<dependency>
<groupId>org.dizitart</groupId>
<artifactId>nitrite</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>net.harawata</groupId>
<artifactId>appdirs</artifactId>
Expand Down
74 changes: 19 additions & 55 deletions src/main/java/io/goobox/sync/storj/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.concurrent.CountDownLatch;

import org.apache.commons.cli.CommandLine;
Expand All @@ -30,18 +29,12 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.liferay.nativity.control.NativityControl;
import com.liferay.nativity.control.NativityControlUtil;
import com.liferay.nativity.modules.fileicon.FileIconControl;
import com.liferay.nativity.modules.fileicon.FileIconControlCallback;
import com.liferay.nativity.modules.fileicon.FileIconControlUtil;
import com.liferay.nativity.util.OSDetector;

import io.goobox.sync.common.ShutdownListener;
import io.goobox.sync.common.Utils;
import io.goobox.sync.common.systemtray.ShutdownListener;
import io.goobox.sync.common.overlay.OverlayHelper;
import io.goobox.sync.storj.db.DB;
import io.goobox.sync.storj.ipc.IpcExecutor;
import io.goobox.sync.storj.overlay.OverlayHelper;
import io.goobox.sync.storj.overlay.StorjOverlayIconProvider;
import io.storj.libstorj.Bucket;
import io.storj.libstorj.CreateBucketCallback;
import io.storj.libstorj.GetBucketsCallback;
Expand All @@ -62,6 +55,7 @@ public class App implements ShutdownListener {
private TaskExecutor taskExecutor;
private FileWatcher fileWatcher;
private IpcExecutor ipcExecutor;
private OverlayHelper overlayHelper;

public App() {
this.syncDir = Utils.getSyncDir();
Expand Down Expand Up @@ -97,7 +91,14 @@ public static void main(String[] args) {
boolean resetAuthFile = cmd.hasOption("reset-auth-file");

if (cmd.hasOption("sync-dir")) {
instance = new App(Paths.get(cmd.getParsedOptionValue("sync-dir").toString()));
String syncDirParam = (String) cmd.getParsedOptionValue("sync-dir");
try {
Path syncDir = new java.io.File(syncDirParam).getCanonicalFile().toPath();
instance = new App(syncDir);
} catch (IOException e) {
logger.error("Cannot resolve sync dir path: " + syncDirParam);
System.exit(1);
}
} else {
instance = new App();
}
Expand All @@ -107,49 +108,6 @@ public static void main(String[] args) {
logger.error("Failed to parse command line options", e);
System.exit(1);
}

NativityControl nativityControl = NativityControlUtil.getNativityControl();
nativityControl.connect();

// Setting filter folders is required for Mac's Finder Sync plugin
// nativityControl.setFilterFolder(Utils.getSyncDir().toString());

/* File Icons */

int testIconId = 1;

// FileIconControlCallback used by Windows and Mac
FileIconControlCallback fileIconControlCallback = new FileIconControlCallback() {
@Override
public int getIconForFile(String path) {
return 1; // testIconId;
}
};

FileIconControl fileIconControl = FileIconControlUtil.getFileIconControl(nativityControl,
fileIconControlCallback);

fileIconControl.enableFileIcons();

String testFilePath = instance.getSyncDir().toString();

if (OSDetector.isWindows()) {
// This id is determined when building the DLL
testIconId = 1;
} else if (OSDetector.isMinimumAppleVersion(OSDetector.MAC_YOSEMITE_10_10)) {
// Used by Mac Finder Sync. This unique id can be set at runtime.
testIconId = 1;

fileIconControl.registerIconWithId("/tmp/goobox.icns",
"test label", "" + testIconId);
} else if (OSDetector.isLinux()) {
// Used by Mac Injector and Linux
testIconId = fileIconControl.registerIcon("/tmp/git-clean.png");
}

// FileIconControl.setFileIcon() method only used by Linux
fileIconControl.setFileIcon(testFilePath, testIconId);
nativityControl.disconnect();
}

public static App getInstance() {
Expand Down Expand Up @@ -184,6 +142,10 @@ public FileWatcher getFileWatcher() {
return fileWatcher;
}

public OverlayHelper getOverlayHelper() {
return overlayHelper;
}

private void init(boolean resetAuthFile) {
storj = new Storj();
storj.setConfigDirectory(Utils.getDataDir().toFile());
Expand All @@ -208,6 +170,8 @@ private void init(boolean resetAuthFile) {
if (gooboxBucket == null) {
System.exit(1);
}

overlayHelper = new OverlayHelper(syncDir, new StorjOverlayIconProvider());

tasks = new TaskQueue();
tasks.add(new CheckStateTask());
Expand All @@ -222,7 +186,7 @@ private void init(boolean resetAuthFile) {
@Override
public void shutdown() {
logger.info("Shutting down");
OverlayHelper.getInstance().shutdown();
overlayHelper.shutdown();
System.exit(0);
}

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/io/goobox/sync/storj/CheckStateTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import io.goobox.sync.storj.db.DB;
import io.goobox.sync.storj.db.SyncFile;
import io.goobox.sync.storj.db.SyncState;
import io.goobox.sync.storj.overlay.OverlayHelper;
import io.storj.libstorj.Bucket;
import io.storj.libstorj.File;
import io.storj.libstorj.ListFilesCallback;
Expand All @@ -60,7 +59,7 @@ public void run() {

logger.info("Checking for changes");
App.getInstance().getIpcExecutor().sendSyncEvent();
OverlayHelper.getInstance().setSynchronizing();
App.getInstance().getOverlayHelper().setSynchronizing();

App.getInstance().getStorj().listFiles(gooboxBucket, new ListFilesCallback() {
@Override
Expand All @@ -73,7 +72,7 @@ public void onFilesReceived(File[] files) {
// Sleep some time to avoid overloading the bridge
tasks.add(new SleepTask());
App.getInstance().getIpcExecutor().sendIdleEvent();
OverlayHelper.getInstance().setOK();
App.getInstance().getOverlayHelper().setOK();
}
// Add itself to the queueAdd itself to the queue
tasks.add(CheckStateTask.this);
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/io/goobox/sync/storj/db/DB.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import org.slf4j.LoggerFactory;

import io.goobox.sync.common.Utils;
import io.goobox.sync.storj.App;
import io.goobox.sync.storj.StorjUtil;
import io.goobox.sync.storj.overlay.OverlayHelper;
import io.storj.libstorj.File;

public class DB {
Expand Down Expand Up @@ -158,7 +158,7 @@ public synchronized static void setSynced(File storjFile, Path localFile) throws
syncFile.setLocalData(localFile);
syncFile.setState(SyncState.SYNCED);
repo().update(syncFile);
OverlayHelper.getInstance().refresh(localFile);
App.getInstance().getOverlayHelper().refresh(localFile);
}

public synchronized static void addForDownload(File file) {
Expand All @@ -175,7 +175,7 @@ public synchronized static void addForDownload(File storjFile, Path localFile) t
syncFile.setLocalData(localFile);
syncFile.setState(SyncState.FOR_DOWNLOAD);
repo().update(syncFile);
OverlayHelper.getInstance().refresh(localFile);
App.getInstance().getOverlayHelper().refresh(localFile);
}

public synchronized static void addForUpload(Path path) throws IOException {
Expand All @@ -184,7 +184,7 @@ public synchronized static void addForUpload(Path path) throws IOException {
syncFile.setLocalData(path);
syncFile.setState(SyncState.FOR_UPLOAD);
repo().update(syncFile);
OverlayHelper.getInstance().refresh(path);
App.getInstance().getOverlayHelper().refresh(path);
}

public synchronized static void addForUpload(File storjFile, Path localFile) throws IOException {
Expand All @@ -193,7 +193,7 @@ public synchronized static void addForUpload(File storjFile, Path localFile) thr
syncFile.setLocalData(localFile);
syncFile.setState(SyncState.FOR_UPLOAD);
repo().update(syncFile);
OverlayHelper.getInstance().refresh(localFile);
App.getInstance().getOverlayHelper().refresh(localFile);
}

public synchronized static void setDownloadFailed(File storjFile, Path localFile) throws IOException {
Expand All @@ -204,7 +204,7 @@ public synchronized static void setDownloadFailed(File storjFile, Path localFile
}
syncFile.setState(SyncState.DOWNLOAD_FAILED);
repo().update(syncFile);
OverlayHelper.getInstance().refresh(localFile);
App.getInstance().getOverlayHelper().refresh(localFile);
}

public synchronized static void setUploadFailed(Path path) throws IOException {
Expand All @@ -214,15 +214,15 @@ public synchronized static void setUploadFailed(Path path) throws IOException {
}
syncFile.setState(SyncState.UPLOAD_FAILED);
repo().update(syncFile);
OverlayHelper.getInstance().refresh(path);
App.getInstance().getOverlayHelper().refresh(path);
}

public synchronized static void setForLocalDelete(Path path) throws IOException {
SyncFile syncFile = get(path);
syncFile.setLocalData(path);
syncFile.setState(SyncState.FOR_LOCAL_DELETE);
repo().update(syncFile);
OverlayHelper.getInstance().refresh(path);
App.getInstance().getOverlayHelper().refresh(path);
}

public synchronized static void setForCloudDelete(File file) {
Expand All @@ -244,7 +244,7 @@ public synchronized static void addForCloudCreateDir(Path path) throws IOExcepti
syncFile.setLocalData(path);
syncFile.setState(SyncState.FOR_CLOUD_CREATE_DIR);
repo().update(syncFile);
OverlayHelper.getInstance().refresh(path);
App.getInstance().getOverlayHelper().refresh(path);
}

public synchronized static void setConflict(File storjFile, Path localFile) throws IOException {
Expand All @@ -253,7 +253,7 @@ public synchronized static void setConflict(File storjFile, Path localFile) thro
syncFile.setLocalData(localFile);
syncFile.setState(SyncState.CONFLICT);
repo().update(syncFile);
OverlayHelper.getInstance().refresh(localFile);
App.getInstance().getOverlayHelper().refresh(localFile);
}

public static void main(String[] args) {
Expand Down
Loading

0 comments on commit f3fe43d

Please sign in to comment.