-
Notifications
You must be signed in to change notification settings - Fork 3
Feature: Autostart for DE following the freedesktop standard #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,4 +5,4 @@ Linux-specific implemenations of the [integrations-api](https://github.com/crypt | |||||||||||
|
|
||||||||||||
| This project uses the following JVM properties: | ||||||||||||
| * `cryptomator.integrationsLinux.trayIconsDir` - specifies the directory from which svg images for the tray icon are loaded | ||||||||||||
|
|
||||||||||||
| * `cryptomator.integrationsLinux.autoStartCmd` - specifies the command used for starting Cryptomator | ||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure the file ends with a single newline character. The file should end with a single newline character. - * `cryptomator.integrationsLinux.autoStartCmd` - specifies the command used for starting Cryptomator
+ * `cryptomator.integrationsLinux.autoStartCmd` - specifies the command used for starting Cryptomator
+Committable suggestion
Suggested change
ToolsMarkdownlint
Remove trailing spaces. There is a trailing space at the end of the line. - * `cryptomator.integrationsLinux.autoStartCmd` - specifies the command used for starting Cryptomator
+ * `cryptomator.integrationsLinux.autoStartCmd` - specifies the command used for starting CryptomatorCommittable suggestion
Suggested change
ToolsMarkdownlint
infeo marked this conversation as resolved.
|
||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| package org.cryptomator.linux.autostart; | ||
|
|
||
| import org.cryptomator.integrations.autostart.AutoStartProvider; | ||
| import org.cryptomator.integrations.autostart.ToggleAutoStartFailedException; | ||
| import org.cryptomator.integrations.common.CheckAvailability; | ||
| import org.cryptomator.integrations.common.OperatingSystem; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.io.IOException; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.StandardOpenOption; | ||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * Enables autostart for Linux desktop environments following the freedesktop standard. | ||
| * <p> | ||
| * This service is based on <a href=https://specifications.freedesktop.org/autostart-spec/autostart-spec-0.5.html>version 0.5 of the freedesktop autostart-spec</a>. | ||
| */ | ||
| @CheckAvailability | ||
| @OperatingSystem(OperatingSystem.Value.LINUX) | ||
| public class FreedesktopAutoStartService implements AutoStartProvider { | ||
|
|
||
| private static final Logger LOG = LoggerFactory.getLogger(FreedesktopAutoStartService.class); | ||
| private static final String CMD_PROPERTY = "cryptomator.integrationsLinux.autoStartCmd"; | ||
| private static final String AUTOSTART_FILENAME = "Cryptomator.desktop"; | ||
| private static final String CONTENT_TEMPLATE = """ | ||
| [Desktop Entry] | ||
| Type=Application | ||
| Exec=%s | ||
| Hidden=false | ||
| NoDisplay=false | ||
| X-GNOME-Autostart-enabled=true | ||
| Name=Cryptomator | ||
| Comment=Created with %s | ||
| """; | ||
|
|
||
| private final Path autostartFile; | ||
| private final String content; | ||
| private final boolean hasExecValue; | ||
|
|
||
| public FreedesktopAutoStartService() { | ||
| var xdgConfigDirString = Objects.requireNonNullElse(System.getenv("XDG_CONFIG_HOME"), System.getProperty("user.home") + "/.config"); | ||
| this.autostartFile = Path.of(xdgConfigDirString, "autostart", AUTOSTART_FILENAME); | ||
|
|
||
| var execValue = System.getProperty(CMD_PROPERTY); | ||
| if (execValue == null) { | ||
| LOG.debug("JVM property {} not set, using command path", CMD_PROPERTY); | ||
| execValue = ProcessHandle.current().info().command().orElse(""); | ||
| } | ||
| this.hasExecValue = execValue.isBlank(); | ||
| this.content = CONTENT_TEMPLATE.formatted(execValue, this.getClass().getName()); | ||
| } | ||
|
|
||
| @Override | ||
| public synchronized void enable() throws ToggleAutoStartFailedException { | ||
| try { | ||
| Files.writeString(autostartFile, content, StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING); | ||
| } catch (IOException e) { | ||
| throw new ToggleAutoStartFailedException("Failed to activate Cryptomator autostart for GNOME desktop environment.", e); | ||
| } | ||
|
infeo marked this conversation as resolved.
|
||
| } | ||
|
|
||
| @Override | ||
| public synchronized void disable() throws ToggleAutoStartFailedException { | ||
| try { | ||
| Files.deleteIfExists(autostartFile); | ||
| } catch (IOException e) { | ||
| throw new ToggleAutoStartFailedException("Failed to deactivate Cryptomator autostart for GNOME desktop environment.", e); | ||
| } | ||
|
infeo marked this conversation as resolved.
|
||
| } | ||
|
|
||
| @Override | ||
| public synchronized boolean isEnabled() { | ||
| return Files.exists(autostartFile); | ||
| } | ||
|
|
||
| @CheckAvailability | ||
| public boolean isSupported() { | ||
| //TODO: might need to research which Desktop Environments support this | ||
| return hasExecValue && Files.exists(autostartFile.getParent()); | ||
| } | ||
|
Comment on lines
+79
to
+83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Review of The method checks if the autostart is supported by verifying the Would you like me to help with the research or should I open a GitHub issue to track this task? |
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| org.cryptomator.linux.autostart.FreedesktopAutoStartService |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package org.cryptomator.linux.autostart; | ||
|
|
||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.MethodOrderer; | ||
| import org.junit.jupiter.api.Order; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.TestMethodOrder; | ||
|
|
||
| @TestMethodOrder(MethodOrderer.OrderAnnotation.class) | ||
| public class FreedesktopAutoStartIT { | ||
|
|
||
| FreedesktopAutoStartService inTest = new FreedesktopAutoStartService(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Initialize Direct initialization of |
||
|
|
||
| @Test | ||
| @Order(1) | ||
| public void testAutostartEnable() { | ||
| Assertions.assertDoesNotThrow(() -> inTest.enable()); | ||
| Assertions.assertTrue(inTest.isEnabled()); | ||
| } | ||
|
|
||
|
|
||
| @Test | ||
| @Order(2) | ||
| public void testAutostartDisable() { | ||
| Assertions.assertDoesNotThrow(() -> inTest.disable()); | ||
| Assertions.assertFalse(inTest.isEnabled()); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.