Skip to content

Commit 7e8cca5

Browse files
authored
Merge pull request #36 from cryptomator/feature/quick-access-api
Feature: Quick Access API
2 parents a44d0f1 + 6572fe4 commit 7e8cca5

3 files changed

Lines changed: 70 additions & 0 deletions

File tree

src/main/java/module-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import org.cryptomator.integrations.quickaccess.QuickAccessService;
12
import org.cryptomator.integrations.mount.MountService;
23
import org.cryptomator.integrations.revealpath.RevealPathService;
34
import org.cryptomator.integrations.tray.TrayMenuController;
@@ -18,6 +19,7 @@
1819
exports org.cryptomator.integrations.revealpath;
1920
exports org.cryptomator.integrations.tray;
2021
exports org.cryptomator.integrations.uiappearance;
22+
exports org.cryptomator.integrations.quickaccess;
2123

2224
uses AutoStartProvider;
2325
uses KeychainAccessProvider;
@@ -26,4 +28,5 @@
2628
uses TrayIntegrationProvider;
2729
uses TrayMenuController;
2830
uses UiAppearanceProvider;
31+
uses QuickAccessService;
2932
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package org.cryptomator.integrations.quickaccess;
2+
3+
import org.cryptomator.integrations.common.IntegrationsLoader;
4+
import org.jetbrains.annotations.Blocking;
5+
import org.jetbrains.annotations.NotNull;
6+
7+
import java.nio.file.Path;
8+
import java.util.stream.Stream;
9+
10+
/**
11+
* Service adding a system path link to a quick access area of the OS or an application (e.g. file manager).
12+
*
13+
* @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.
14+
*/
15+
@FunctionalInterface
16+
public interface QuickAccessService {
17+
18+
/**
19+
* Creates an entry in the quick access area.
20+
*
21+
* @param target The filesystem path the quick access entry points to
22+
* @param displayName The display name of the quick access entry
23+
* @return a {@link QuickAccessEntry }, used to remove the entry again
24+
* @throws QuickAccessServiceException if adding an entry to the quick access area fails
25+
* @apiNote It depends on the service implementation wether the display name is used or not.
26+
*/
27+
@Blocking
28+
QuickAccessEntry add(@NotNull Path target, @NotNull String displayName) throws QuickAccessServiceException;
29+
30+
/**
31+
* An entry of the quick access area, created by a service implementation.
32+
*/
33+
@FunctionalInterface
34+
interface QuickAccessEntry {
35+
36+
/**
37+
* Removes this entry from the quick access area.
38+
*
39+
* @throws QuickAccessServiceException if removal fails.
40+
* @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.
41+
*/
42+
@Blocking
43+
void remove() throws QuickAccessServiceException;
44+
45+
}
46+
47+
/**
48+
* Loads all supported service providers.
49+
*
50+
* @return Stream of supported {@link QuickAccessService} implementations (may be empty)
51+
*/
52+
static Stream<QuickAccessService> get() {
53+
return IntegrationsLoader.loadAll(QuickAccessService.class);
54+
}
55+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.cryptomator.integrations.quickaccess;
2+
3+
public class QuickAccessServiceException extends Exception {
4+
5+
public QuickAccessServiceException(String message) {
6+
super(message);
7+
}
8+
9+
public QuickAccessServiceException(String message, Throwable t) {
10+
super(message, t);
11+
}
12+
}

0 commit comments

Comments
 (0)