Skip to content
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

Feature: Autostart for DE following the freedesktop standard #80

Merged
merged 4 commits into from
Jul 17, 2024

Conversation

infeo
Copy link
Member

@infeo infeo commented Jul 2, 2024

This PR adds an implementation of the AutoStart SPI: The FreeDesktopAutostartService.

The implementation is based on the freedesktop autostart specificiation.

Copy link

coderabbitai bot commented Jul 2, 2024

Walkthrough

These changes introduce a new JVM property, cryptomator.integrationsLinux.autoStartCmd, which allows specifying the command for starting Cryptomator on Linux systems. Additionally, a new service FreedesktopAutoStartService has been implemented to manage the autostart functionality according to the freedesktop standard. This service can enable, disable, and check the autostart status. Unit tests ensure the reliability of the new functionality.

Changes

File/Path Change Summary
README.md Added documentation for the new JVM property cryptomator.integrationsLinux.autoStartCmd.
src/main/java/module-info.java Added imports for FreedesktopAutoStartService and provided AutoStartProvider with this new service.
.../org/cryptomator/linux/autostart/FreedesktopAutoStartService.java Implemented FreedesktopAutoStartService class with methods to manage autostart functionality.
src/main/resources/.../AutoStartProvider Added service provider configuration for FreedesktopAutoStartService.
src/test/java/.../FreedesktopAutoStartIT.java Added integration tests for FreedesktopAutoStartService to test enabling and disabling autostart.

Poem

In the code where changes bloom,
New properties come to life.
Linux autostart will now zoom,
No more manual strife.
Freedesktop standards set the pace,
Cryptomator's in the race.
Tests ensure it keeps its grace.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 7

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7b72518 and f2881b8.

Files selected for processing (5)
  • README.md (1 hunks)
  • src/main/java/module-info.java (2 hunks)
  • src/main/java/org/cryptomator/linux/autostart/FreedesktopAutoStartService.java (1 hunks)
  • src/main/resources/META-INF/services/org.cryptomator.integrations.autostart.AutoStartProvider (1 hunks)
  • src/test/java/org/cryptomator/linux/autostart/FreeDesktopAutoStartIT.java (1 hunks)
Additional context used
LanguageTool
README.md

[style] ~7-~7: This phrase is redundant (‘G’ stands for ‘graphic’). Use simply “svgs”.
Context: ...r- specifies the directory from which svg images for the tray icon are loaded *cryptom...

(ACRONYM_TAUTOLOGY)

Markdownlint
README.md

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

(MD009, no-trailing-spaces)


7-7: null
Lists should be surrounded by blank lines

(MD032, blanks-around-lists)


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

(MD047, single-trailing-newline)

Additional comments not posted (8)
src/main/resources/META-INF/services/org.cryptomator.integrations.autostart.AutoStartProvider (1)

1-1: LGTM! Verify the class existence.

The changes are approved.

However, ensure that the class org.cryptomator.linux.autostart.FreedesktopAutoStartService exists and is correctly named.

Verification successful

Class Verified:

The class org.cryptomator.linux.autostart.FreedesktopAutoStartService exists in the codebase.

  • Location: src/main/java/org/cryptomator/linux/autostart/FreedesktopAutoStartService.java
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the existence of the class `FreedesktopAutoStartService`.

# Test: Search for the class file. Expect: The class file should exist.
fd 'FreedesktopAutoStartService.java'

Length of output: 116

src/test/java/org/cryptomator/linux/autostart/FreeDesktopAutoStartIT.java (2)

12-12: Consider making the service instance final.

The service instance can be made final for better immutability.

- FreedesktopAutoStartService inTest = new FreedesktopAutoStartService();
+ final FreedesktopAutoStartService inTest = new FreedesktopAutoStartService();

21-21: Remove unnecessary blank line.

There is an unnecessary blank line between the test methods.

- 
src/main/java/module-info.java (1)

5-5: LGTM! Verify the import and provision.

The changes are approved.

However, ensure that the import and provision for FreedesktopAutoStartService are accurate.

Also applies to: 19-19

Verification successful

Verification Successful: The import and provision for FreedesktopAutoStartService are accurate.

  • The file FreedesktopAutoStartService.java exists in the expected directory.
  • AutoStartProvider is correctly provided with FreedesktopAutoStartService in the module-info.java file.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the import and provision for `FreedesktopAutoStartService`.

# Test: Search for the class file. Expect: The class file should exist.
fd 'FreedesktopAutoStartService.java'

Length of output: 116



Script:

#!/bin/bash
# Description: Verify the provision of `AutoStartProvider` with `FreedesktopAutoStartService`.

# Test: Search for the provision of `AutoStartProvider` with `FreedesktopAutoStartService`.
rg 'AutoStartProvider.*FreedesktopAutoStartService'

Length of output: 146

src/main/java/org/cryptomator/linux/autostart/FreedesktopAutoStartService.java (4)

42-52: Ensure proper handling of execValue and xdgConfigDirString.

The constructor correctly initializes the autostartFile and handles the execValue based on system properties. However, consider adding a check to ensure execValue is not empty after the fallback logic.

-    execValue = ProcessHandle.current().info().command().orElse("");
+    execValue = ProcessHandle.current().info().command().orElseThrow(() -> new IllegalStateException("Command path not found"));

72-75: LGTM!

The isEnabled method correctly checks if the autostartFile exists.


1-41: LGTM!

The class-level annotations and field definitions are appropriate and correctly used.


77-81: Verify the correctness of isSupported and address the TODO comment.

The method checks if the parent directory of autostartFile exists, which is a good initial check. However, the TODO comment suggests further research might be needed to ensure comprehensive support.

Do you want me to assist with the research on which Desktop Environments support this feature?

README.md Show resolved Hide resolved
@@ -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
Copy link

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)

README.md Show resolved Hide resolved
Comment on lines 63 to 70
@Override
public void disable() throws ToggleAutoStartFailedException {
try {
Files.deleteIfExists(autostartFile);
} catch (IOException e) {
throw new ToggleAutoStartFailedException("Failed to deactivate Cryptomator autostart for GNOME desktop environment.", e);
}
}
Copy link

Choose a reason for hiding this comment

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

Add logging for exceptions in disable method.

While the method correctly handles IOException by throwing ToggleAutoStartFailedException, consider logging the exception details for better debugging.

-    throw new ToggleAutoStartFailedException("Failed to deactivate Cryptomator autostart for GNOME desktop environment.", e);
+    LOG.error("Failed to delete autostart file", e);
+    throw new ToggleAutoStartFailedException("Failed to deactivate Cryptomator autostart for GNOME desktop environment.", e);
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
@Override
public void disable() throws ToggleAutoStartFailedException {
try {
Files.deleteIfExists(autostartFile);
} catch (IOException e) {
throw new ToggleAutoStartFailedException("Failed to deactivate Cryptomator autostart for GNOME desktop environment.", e);
}
}
@Override
public void disable() throws ToggleAutoStartFailedException {
try {
Files.deleteIfExists(autostartFile);
} catch (IOException e) {
LOG.error("Failed to delete autostart file", e);
throw new ToggleAutoStartFailedException("Failed to deactivate Cryptomator autostart for GNOME desktop environment.", e);
}
}

Comment on lines 54 to 61
@Override
public 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);
}
}
Copy link

Choose a reason for hiding this comment

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

Add logging for exceptions in enable method.

While the method correctly handles IOException by throwing ToggleAutoStartFailedException, consider logging the exception details for better debugging.

-    throw new ToggleAutoStartFailedException("Failed to activate Cryptomator autostart for GNOME desktop environment.", e);
+    LOG.error("Failed to write autostart file", e);
+    throw new ToggleAutoStartFailedException("Failed to activate Cryptomator autostart for GNOME desktop environment.", e);
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
@Override
public 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);
}
}
@Override
public void enable() throws ToggleAutoStartFailedException {
try {
Files.writeString(autostartFile, content, StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);
} catch (IOException e) {
LOG.error("Failed to write autostart file", e);
throw new ToggleAutoStartFailedException("Failed to activate Cryptomator autostart for GNOME desktop environment.", e);
}
}

import org.junit.jupiter.api.TestMethodOrder;

@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class FreeDesktopAutoStartIT {
Copy link

Choose a reason for hiding this comment

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

Class name should be consistent.

The class name FreeDesktopAutoStartIT should be consistent with the service class name FreedesktopAutoStartService.

- public class FreeDesktopAutoStartIT {
+ public class FreedesktopAutoStartIT {
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
public class FreeDesktopAutoStartIT {
public class FreedesktopAutoStartIT {

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Outside diff range, codebase verification and nitpick comments (1)
src/main/java/org/cryptomator/linux/autostart/FreedesktopAutoStartService.java (1)

43-53: Constructor review of FreedesktopAutoStartService.

The constructor handles the default value for XDG_CONFIG_HOME and initializes autostartFile and content. Using ProcessHandle as a fallback for the command is a clever use of Java APIs. However, ensure that an empty command (execValue) does not lead to unintended behavior or security issues.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f2881b8 and 2c0f834.

Files selected for processing (2)
  • src/main/java/org/cryptomator/linux/autostart/FreedesktopAutoStartService.java (1 hunks)
  • src/test/java/org/cryptomator/linux/autostart/FreedesktopAutoStartIT.java (1 hunks)
Additional comments not posted (2)
src/test/java/org/cryptomator/linux/autostart/FreedesktopAutoStartIT.java (2)

14-19: Review of testAutostartEnable method.

This test checks if the autostart can be enabled without throwing an exception and verifies the enabled state. It's good to see use of assertDoesNotThrow to explicitly check for no exceptions. However, consider adding more assertions to verify the actual effects on the filesystem or system configuration, if possible.


22-27: Review of testAutostartDisable method.

Similar to the enable test, this test checks for no exceptions and a correct disabled state. Again, additional assertions to check the actual file system or system state changes would make these tests more robust.

@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class FreedesktopAutoStartIT {

FreedesktopAutoStartService inTest = new FreedesktopAutoStartService();
Copy link

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.

Comment on lines +79 to +83
@CheckAvailability
public boolean isSupported() {
//TODO: might need to research which Desktop Environments support this
return hasExecValue && Files.exists(autostartFile.getParent());
}
Copy link

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?

@infeo
Copy link
Member Author

infeo commented Jul 17, 2024

@overheadhunter Fyi, i synchronized the methods enable, disable and isEnabled to prevent racing conditions when editing the autostart file (e.g. a lib consumers calls furiosly these method). Also, since the isSuppported check is non-static, i added the condition that the exec field must not be blank

@infeo infeo added this to the next milestone Jul 17, 2024
@infeo infeo merged commit de95ce2 into develop Jul 17, 2024
4 checks passed
@infeo infeo deleted the feature/freedesktop-autostart branch July 17, 2024 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants