Skip to content

Commit

Permalink
Merge pull request #36 from cryptomator/feature/quick-access-api
Browse files Browse the repository at this point in the history
Feature: Quick Access API
  • Loading branch information
infeo committed Jun 27, 2024
2 parents a44d0f1 + 6572fe4 commit 7e8cca5
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import org.cryptomator.integrations.quickaccess.QuickAccessService;
import org.cryptomator.integrations.mount.MountService;
import org.cryptomator.integrations.revealpath.RevealPathService;
import org.cryptomator.integrations.tray.TrayMenuController;
Expand All @@ -18,6 +19,7 @@
exports org.cryptomator.integrations.revealpath;
exports org.cryptomator.integrations.tray;
exports org.cryptomator.integrations.uiappearance;
exports org.cryptomator.integrations.quickaccess;

uses AutoStartProvider;
uses KeychainAccessProvider;
Expand All @@ -26,4 +28,5 @@
uses TrayIntegrationProvider;
uses TrayMenuController;
uses UiAppearanceProvider;
uses QuickAccessService;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.cryptomator.integrations.quickaccess;

import org.cryptomator.integrations.common.IntegrationsLoader;
import org.jetbrains.annotations.Blocking;
import org.jetbrains.annotations.NotNull;

import java.nio.file.Path;
import java.util.stream.Stream;

/**
* Service adding a system path link to a quick access area of the OS or an application (e.g. file manager).
*
* @apiNote On purpose this service does not define, what an "link to a quick access area" is. The defintion depends on the OS. For example, the quick access area can be the home screen/desktop and the link would be an icon leading to the linked path.
*/
@FunctionalInterface
public interface QuickAccessService {

/**
* Creates an entry in the quick access area.
*
* @param target The filesystem path the quick access entry points to
* @param displayName The display name of the quick access entry
* @return a {@link QuickAccessEntry }, used to remove the entry again
* @throws QuickAccessServiceException if adding an entry to the quick access area fails
* @apiNote It depends on the service implementation wether the display name is used or not.
*/
@Blocking
QuickAccessEntry add(@NotNull Path target, @NotNull String displayName) throws QuickAccessServiceException;

/**
* An entry of the quick access area, created by a service implementation.
*/
@FunctionalInterface
interface QuickAccessEntry {

/**
* Removes this entry from the quick access area.
*
* @throws QuickAccessServiceException if removal fails.
* @implSpec Service implementations should make this function <em>idempotent</em>, i.e. after the method is called once and succeeded, consecutive calls should not change anything or throw an error.
*/
@Blocking
void remove() throws QuickAccessServiceException;

}

/**
* Loads all supported service providers.
*
* @return Stream of supported {@link QuickAccessService} implementations (may be empty)
*/
static Stream<QuickAccessService> get() {
return IntegrationsLoader.loadAll(QuickAccessService.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.cryptomator.integrations.quickaccess;

public class QuickAccessServiceException extends Exception {

public QuickAccessServiceException(String message) {
super(message);
}

public QuickAccessServiceException(String message, Throwable t) {
super(message, t);
}
}

0 comments on commit 7e8cca5

Please sign in to comment.