-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from cryptomator/feature/quick-access-api
Feature: Quick Access API
- Loading branch information
Showing
3 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/main/java/org/cryptomator/integrations/quickaccess/QuickAccessService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/org/cryptomator/integrations/quickaccess/QuickAccessServiceException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |