|
| 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 | +} |
0 commit comments