Skip to content

Commit 07b89f5

Browse files
committed
Merge branch 'release/1.1.1'
2 parents e34f365 + cf42aa3 commit 07b89f5

File tree

5 files changed

+40
-17
lines changed

5 files changed

+40
-17
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
Windows-specific implementations of [integrations-api](https://github.com/cryptomator/integrations-api).
44

5+
## Config
6+
7+
This project uses the following JVM properties:
8+
* `cryptomator.integrationsWin.autoStartShellLinkName` - Name of the shell link, which is placed in the Windows startup folder to start application on user login
9+
510
## Building
611

712
This project uses JNI, hence you'll nedd Java as well as GCC build tools:

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>org.cryptomator</groupId>
77
<artifactId>integrations-win</artifactId>
8-
<version>1.1.0</version>
8+
<version>1.1.1</version>
99

1010
<name>Cryptomator Integrations for Windows</name>
1111
<description>Provides optional Windows services used by Cryptomator</description>

src/main/java/org/cryptomator/windows/autostart/WindowsAutoStart.java

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,46 +11,52 @@
1111
import java.nio.file.Files;
1212
import java.nio.file.NoSuchFileException;
1313
import java.nio.file.Path;
14+
import java.util.NoSuchElementException;
1415
import java.util.Optional;
1516

1617
/**
17-
* Checks, en- and disables autostart for Cryptomator on Windows using the startup folder.
18+
* Checks, en- and disables autostart for an application on Windows using the startup folder.
1819
* <p>
19-
* The above actions are done by checking/adding/removing in the directory {@value RELATIVE_STARTUP_FOLDER_ENTRY} a resource (.lnk file) for Cryptomator.
20+
* The above actions are done by checking/adding/removing in the directory {@value RELATIVE_STARTUP_FOLDER} a shell link (.lnk).
21+
* The filename of the shell link is given by the JVM property {@value LNK_NAME_PROPERTY}. If the property is not set before object creation, the start command of the calling process is used.
2022
*/
2123
@Priority(1000)
2224
@OperatingSystem(OperatingSystem.Value.WINDOWS)
2325
public class WindowsAutoStart implements AutoStartProvider {
2426

2527
private static final Logger LOG = LoggerFactory.getLogger(WindowsAutoStart.class);
26-
private static final String RELATIVE_STARTUP_FOLDER_ENTRY = "\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\Cryptomator.lnk";
28+
private static final String RELATIVE_STARTUP_FOLDER = "AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\";
29+
private static final String LNK_FILE_EXTENSION = ".lnk";
30+
private static final String LNK_NAME_PROPERTY = "cryptomator.integrationsWin.autoStartShellLinkName";
2731

2832
private final WinShellLinks winShellLinks;
29-
private final Path absoluteStartupEntryPath;
30-
private final Optional<String> exePath;
33+
private final Optional<String> shellLinkName;
34+
private final Optional<Path> absStartupEntryPath;
35+
private final Optional<Path> exePath;
3136

3237
@SuppressWarnings("unused") // default constructor required by ServiceLoader
3338
public WindowsAutoStart() {
3439
this.winShellLinks = new WinShellLinks();
35-
this.exePath = ProcessHandle.current().info().command();
36-
this.absoluteStartupEntryPath = Path.of(System.getProperty("user.home"), RELATIVE_STARTUP_FOLDER_ENTRY).toAbsolutePath();
40+
this.exePath = ProcessHandle.current().info().command().map(Path::of);
41+
this.shellLinkName = Optional.ofNullable(System.getProperty(LNK_NAME_PROPERTY)).or(() -> exePath.map(this::getExeBaseName));
42+
this.absStartupEntryPath = shellLinkName.map(name -> Path.of(System.getProperty("user.home"), RELATIVE_STARTUP_FOLDER, name + LNK_FILE_EXTENSION).toAbsolutePath());
3743
}
3844

3945
@Override
4046
public boolean isEnabled() {
41-
return Files.exists(absoluteStartupEntryPath);
47+
return absStartupEntryPath.map(Files::exists).orElse(false);
4248
}
4349

4450
@Override
4551
public synchronized void enable() throws ToggleAutoStartFailedException {
4652
if (exePath.isEmpty()) {
47-
throw new ToggleAutoStartFailedException("Enabling autostart using the startup folder failed: Path to Cryptomator executable is not set");
53+
throw new ToggleAutoStartFailedException("Enabling autostart using the startup folder failed: Path to executable is not set");
4854
}
4955

50-
assert exePath.isPresent();
51-
int returnCode = winShellLinks.createShortcut(exePath.get(), absoluteStartupEntryPath.toString(), "Cryptomator");
56+
assert exePath.isPresent() && absStartupEntryPath.isPresent() && shellLinkName.isPresent();
57+
int returnCode = winShellLinks.createShortcut(exePath.get().toString(), absStartupEntryPath.get().toString(), shellLinkName.get());
5258
if (returnCode == 0) {
53-
LOG.debug("Successfully created {}.", absoluteStartupEntryPath);
59+
LOG.debug("Successfully created {}.", absStartupEntryPath.get());
5460
} else {
5561
throw new ToggleAutoStartFailedException("Enabling autostart using the startup folder failed. Windows error code: " + Integer.toHexString(returnCode));
5662
}
@@ -59,15 +65,26 @@ public synchronized void enable() throws ToggleAutoStartFailedException {
5965
@Override
6066
public synchronized void disable() throws ToggleAutoStartFailedException {
6167
try {
62-
Files.delete(absoluteStartupEntryPath);
63-
LOG.debug("Successfully deleted {}.", absoluteStartupEntryPath);
68+
Files.delete(absStartupEntryPath.get());
69+
LOG.debug("Successfully deleted {}.", absStartupEntryPath.get());
70+
} catch (NoSuchElementException e) { //thrown by Optional::get
71+
throw new ToggleAutoStartFailedException("Disabling auto start failed using startup folder: Name of shell link is not defined.");
6472
} catch (NoSuchFileException e) {
6573
//also okay
66-
LOG.debug("File {} not present. Nothing to do.", absoluteStartupEntryPath);
74+
LOG.debug("File {} not present. Nothing to do.", absStartupEntryPath.get());
6775
} catch (IOException e) {
6876
LOG.debug("Failed to delete entry from auto start folder.", e);
6977
throw new ToggleAutoStartFailedException("Disabling auto start failed using startup folder.", e);
7078
}
7179
}
7280

81+
private String getExeBaseName(Path exePath) {
82+
var name = exePath.getFileName().toString();
83+
if (name.lastIndexOf('.') != -1) {
84+
return name.substring(0, name.lastIndexOf('.'));
85+
} else {
86+
return name;
87+
}
88+
}
89+
7390
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
org.cryptomator.windows.keychain.displayName=Windows Data Protection
1+
org.cryptomator.windows.keychain.displayName=Windows zaštita podataka
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.cryptomator.windows.keychain.displayName=Ulinzi wa Data ya Windows

0 commit comments

Comments
 (0)