Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
infeo marked this conversation as resolved.

* `cryptomator.integrationsLinux.autoStartCmd` - specifies the command used for starting Cryptomator

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
* `cryptomator.integrationsLinux.autoStartCmd` - specifies the command used for starting Cryptomator
* `cryptomator.integrationsLinux.autoStartCmd` - specifies the command used for starting Cryptomator
Tools
Markdownlint

8-8: Expected: 0 or 2; Actual: 1
Trailing spaces

(MD009, no-trailing-spaces)


8-8: null
Files should end with a single newline character

(MD047, single-trailing-newline)


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 Cryptomator
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
* `cryptomator.integrationsLinux.autoStartCmd` - specifies the command used for starting Cryptomator
* `cryptomator.integrationsLinux.autoStartCmd` - specifies the command used for starting Cryptomator
Tools
Markdownlint

8-8: Expected: 0 or 2; Actual: 1
Trailing spaces

(MD009, no-trailing-spaces)


8-8: null
Files should end with a single newline character

(MD047, single-trailing-newline)

Comment thread
infeo marked this conversation as resolved.
3 changes: 3 additions & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import org.cryptomator.integrations.autostart.AutoStartProvider;
import org.cryptomator.integrations.keychain.KeychainAccessProvider;
import org.cryptomator.integrations.revealpath.RevealPathService;
import org.cryptomator.integrations.tray.TrayMenuController;
import org.cryptomator.linux.autostart.FreedesktopAutoStartService;
import org.cryptomator.linux.keychain.KDEWalletKeychainAccess;
import org.cryptomator.linux.keychain.SecretServiceKeychainAccess;
import org.cryptomator.linux.revealpath.DBusSendRevealPathService;
Expand All @@ -14,6 +16,7 @@
requires org.purejava.kwallet;
requires de.swiesend.secretservice;

provides AutoStartProvider with FreedesktopAutoStartService;
provides KeychainAccessProvider with SecretServiceKeychainAccess, KDEWalletKeychainAccess;
provides RevealPathService with DBusSendRevealPathService;
provides TrayMenuController with AppindicatorTrayMenuController;
Expand Down
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);
}
Comment thread
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);
}
Comment thread
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of isSupported method.

The method checks if the autostart is supported by verifying the execValue and the existence of the parent directory of the autostart file. The TODO comment suggests further research is needed. It would be beneficial to address this TODO to ensure the method's reliability across different environments.

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();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initialize FreedesktopAutoStartService directly in tests.

Direct initialization of inTest as a field might not be the best approach in tests, especially if state between tests needs to be isolated. Consider using @BeforeEach for initialization to ensure tests do not affect each other.


@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());
}
}