Skip to content

Commit

Permalink
Merge branch 'release/1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
infeo committed Feb 21, 2023
2 parents d736cd8 + ead844d commit 951bbba
Show file tree
Hide file tree
Showing 17 changed files with 244 additions and 67 deletions.
29 changes: 19 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ jobs:
runs-on: windows-latest
if: "!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]')"
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v2
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17
Expand All @@ -24,17 +24,26 @@ jobs:
run: mvn versions:set --file ./pom.xml -DnewVersion=${GITHUB_REF##*/}
- name: Build and Test
id: buildAndTest
run: mvn -B clean install -Pdependency-check
- uses: actions/upload-artifact@v2
run: mvn -B clean test -Pdependency-check
- name: Codesign DLL
uses: skymatic/code-sign-action@v2
with:
certificate: ${{ secrets.WIN_CODESIGN_P12_BASE64 }}
password: ${{ secrets.WIN_CODESIGN_P12_PW }}
certificatesha1: 5FC94CE149E5B511E621F53A060AC67CBD446B3A
timestampUrl: 'http://timestamp.digicert.com'
folder: ./src/main/resources
- name: Package and Install
id: packAndInstall
run: mvn -B install -DskipNativeCompile
- uses: actions/upload-artifact@v3
with:
name: artifacts
path: target/*.jar
- name: Create Release
uses: actions/create-release@v1
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
env:
GITHUB_TOKEN: ${{ secrets.CRYPTOBOT_RELEASE_TOKEN }} # release as "cryptobot"
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
prerelease: true
prerelease: true
token: ${{ secrets.CRYPTOBOT_RELEASE_TOKEN }}
generate_release_notes: true
8 changes: 4 additions & 4 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ jobs:
runs-on: windows-2019
if: "!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]')"
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 2
- uses: actions/setup-java@v2
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17
cache: 'maven'
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v2
with:
languages: java
- name: Build
run: mvn -B compile
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v2
4 changes: 2 additions & 2 deletions .github/workflows/publish-central.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
publish:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
ref: "refs/tags/${{ github.event.inputs.tag }}"
- uses: actions/setup-java@v2
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17
Expand Down
22 changes: 19 additions & 3 deletions .github/workflows/publish-github.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ jobs:
runs-on: windows-latest
if: startsWith(github.ref, 'refs/tags/') # only allow publishing tagged versions
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v2
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17
Expand All @@ -26,4 +26,20 @@ jobs:
run: mvn deploy -B -DskipTests -Psign,deploy-github --no-transfer-progress
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.RELEASES_GPG_PASSPHRASE }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.RELEASES_GPG_PASSPHRASE }}
notify:
runs-on: ubuntu-latest
needs: [publish]
steps:
- name: Slack Notification
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_USERNAME: 'Cryptobot'
SLACK_ICON:
SLACK_ICON_EMOJI: ':bot:'
SLACK_CHANNEL: 'cryptomator-desktop'
SLACK_TITLE: "Published ${{ github.event.repository.name }} ${{ github.event.release.tag_name }}"
SLACK_MESSAGE: "Ready to <https://github.com/${{ github.repository }}/actions/workflows/publish-central.yml|deploy to Maven Central>."
SLACK_FOOTER:
MSG_MINIMAL: true
63 changes: 38 additions & 25 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.cryptomator</groupId>
<artifactId>integrations-win</artifactId>
<version>1.1.2</version>
<version>1.2.0</version>

<name>Cryptomator Integrations for Windows</name>
<description>Provides optional Windows services used by Cryptomator</description>
Expand Down Expand Up @@ -37,7 +37,7 @@
<project.jdk.version>17</project.jdk.version>

<!-- runtime dependencies -->
<api.version>1.1.0</api.version>
<api.version>1.2.0-beta4</api.version>
<slf4j.version>1.7.36</slf4j.version>
<gson.version>2.9.0</gson.version>

Expand Down Expand Up @@ -147,29 +147,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
<phase>compile</phase>
<configuration>
<executable>make</executable>
<workingDirectory>${project.basedir}</workingDirectory>
<environmentVariables>
<JAVA_HOME>${java.home}</JAVA_HOME>
</environmentVariables>
<arguments>
<argument>install</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
Expand Down Expand Up @@ -285,6 +262,42 @@
</build>
</profile>

<profile>
<id>compile-native</id>
<activation>
<property>
<name>!skipNativeCompile</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
<phase>compile</phase>
<configuration>
<executable>make</executable>
<workingDirectory>${project.basedir}</workingDirectory>
<environmentVariables>
<JAVA_HOME>${java.home}</JAVA_HOME>
</environmentVariables>
<arguments>
<argument>install</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

<profile>
<id>sign</id>
<build>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import org.cryptomator.integrations.autostart.AutoStartProvider;
import org.cryptomator.integrations.keychain.KeychainAccessProvider;
import org.cryptomator.integrations.revealpath.RevealPathService;
import org.cryptomator.integrations.uiappearance.UiAppearanceProvider;
import org.cryptomator.windows.autostart.WindowsAutoStart;
import org.cryptomator.windows.keychain.WindowsProtectedKeychainAccess;
import org.cryptomator.windows.revealpath.ExplorerRevealPathService;
import org.cryptomator.windows.uiappearance.WinUiAppearanceProvider;

module org.cryptomator.integrations.win {
Expand All @@ -15,4 +17,5 @@
provides AutoStartProvider with WindowsAutoStart;
provides KeychainAccessProvider with WindowsProtectedKeychainAccess;
provides UiAppearanceProvider with WinUiAppearanceProvider;
provides RevealPathService with ExplorerRevealPathService;
}
17 changes: 14 additions & 3 deletions src/main/java/org/cryptomator/windows/autostart/WinShellLinks.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public class WinShellLinks {
/**
* Create a Windows shortcut file to the given target, at the specified location and with a description.
*
* @param target path of the target the shortcut points to
* @param storagePath path where the shortcut is created
* @param target path of the shortcut target
* @param storagePath full path where the shortcut will be created (including filename &amp; file extension)
* @param description string inserted in the description field of the shortcut.
* @return {@code 0} if everything worked, otherwise an HRESULT error code
*/
Expand All @@ -28,6 +28,15 @@ public int createShortcut(String target, String storagePath, String description)
);
}

/**
* Gets the file system path of the startup folder. Creates all directories in the path, if necessary.
*
* @return path to the startup folder with no trailing \, or {@code null} if the folder is not defined and cannot be created
*/
public String getPathToStartupFolder() {
return Native.INSTANCE.createAndGetStartupFolderPath();
}

// visible for testing
byte[] getNullTerminatedUTF16Representation(String source) {
byte[] bytes = source.getBytes(StandardCharsets.UTF_16LE);
Expand All @@ -41,6 +50,8 @@ private Native() {
NativeLibLoader.loadLib();
}

public synchronized native int createShortcut(byte[] target, byte[] storagePath, byte[] description);
synchronized native int createShortcut(byte[] target, byte[] storagePath, byte[] description);

native String createAndGetStartupFolderPath();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,33 @@
/**
* Checks, en- and disables autostart for an application on Windows using the startup folder.
* <p>
* The above actions are done by checking/adding/removing in the directory {@value RELATIVE_STARTUP_FOLDER} a shell link (.lnk).
* The above actions are done by checking/adding/removing a shell link (.lnk) in the Windows defined Startup directory (see also https://learn.microsoft.com/en-us/windows/win32/shell/knownfolderid#constants).
* 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.
*/
@Priority(1000)
@OperatingSystem(OperatingSystem.Value.WINDOWS)
public class WindowsAutoStart implements AutoStartProvider {

private static final Logger LOG = LoggerFactory.getLogger(WindowsAutoStart.class);
private static final String RELATIVE_STARTUP_FOLDER = "AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\";
private static final String LNK_FILE_EXTENSION = ".lnk";
private static final String LNK_NAME_PROPERTY = "cryptomator.integrationsWin.autoStartShellLinkName";

private final WinShellLinks winShellLinks;
private final Optional<String> shellLinkName;
private final Optional<Path> absStartupEntryPath;
private final Optional<Path> absShellLinkPath;
private final Optional<Path> exePath;

@SuppressWarnings("unused") // default constructor required by ServiceLoader
public WindowsAutoStart() {
this.winShellLinks = new WinShellLinks();
this.exePath = ProcessHandle.current().info().command().map(Path::of);
this.shellLinkName = Optional.ofNullable(System.getProperty(LNK_NAME_PROPERTY)).or(() -> exePath.map(this::getExeBaseName));
this.absStartupEntryPath = shellLinkName.map(name -> Path.of(System.getProperty("user.home"), RELATIVE_STARTUP_FOLDER, name + LNK_FILE_EXTENSION).toAbsolutePath());
this.absShellLinkPath = Optional.ofNullable(winShellLinks.getPathToStartupFolder()).flatMap(p -> shellLinkName.map(name -> p + "\\" + name + LNK_FILE_EXTENSION)).map(Path::of);
}

@Override
public boolean isEnabled() {
return absStartupEntryPath.map(Files::exists).orElse(false);
return absShellLinkPath.map(Files::exists).orElse(false);
}

@Override
Expand All @@ -53,10 +52,10 @@ public synchronized void enable() throws ToggleAutoStartFailedException {
throw new ToggleAutoStartFailedException("Enabling autostart using the startup folder failed: Path to executable is not set");
}

assert exePath.isPresent() && absStartupEntryPath.isPresent() && shellLinkName.isPresent();
int returnCode = winShellLinks.createShortcut(exePath.get().toString(), absStartupEntryPath.get().toString(), shellLinkName.get());
assert exePath.isPresent() && absShellLinkPath.isPresent() && shellLinkName.isPresent();
int returnCode = winShellLinks.createShortcut(exePath.get().toString(), absShellLinkPath.get().toString(), shellLinkName.get());
if (returnCode == 0) {
LOG.debug("Successfully created {}.", absStartupEntryPath.get());
LOG.debug("Successfully created {}.", absShellLinkPath.get());
} else {
throw new ToggleAutoStartFailedException("Enabling autostart using the startup folder failed. Windows error code: " + Integer.toHexString(returnCode));
}
Expand All @@ -65,13 +64,13 @@ public synchronized void enable() throws ToggleAutoStartFailedException {
@Override
public synchronized void disable() throws ToggleAutoStartFailedException {
try {
Files.delete(absStartupEntryPath.get());
LOG.debug("Successfully deleted {}.", absStartupEntryPath.get());
Files.delete(absShellLinkPath.get());
LOG.debug("Successfully deleted {}.", absShellLinkPath.get());
} catch (NoSuchElementException e) { //thrown by Optional::get
throw new ToggleAutoStartFailedException("Disabling auto start failed using startup folder: Name of shell link is not defined.");
} catch (NoSuchFileException e) {
//also okay
LOG.debug("File {} not present. Nothing to do.", absStartupEntryPath.get());
LOG.debug("File {} not present. Nothing to do.", absShellLinkPath.get());
} catch (IOException e) {
LOG.debug("Failed to delete entry from auto start folder.", e);
throw new ToggleAutoStartFailedException("Disabling auto start failed using startup folder.", e);
Expand Down
Loading

0 comments on commit 951bbba

Please sign in to comment.