From 526c8328f6192ee41d1540a36033daa1f15a623a Mon Sep 17 00:00:00 2001 From: Martin Beyer Date: Mon, 13 Jul 2020 15:21:24 +0200 Subject: [PATCH] Refactoring - Removing unnecessary environment variable --- .../java/org/cryptomator/common/Environment.java | 3 --- .../cryptomator/ui/preferences/AutoStartModule.java | 2 +- .../ui/preferences/AutoStartWinStrategy.java | 13 +++++-------- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/main/commons/src/main/java/org/cryptomator/common/Environment.java b/main/commons/src/main/java/org/cryptomator/common/Environment.java index 54e29df8b..890840b7d 100644 --- a/main/commons/src/main/java/org/cryptomator/common/Environment.java +++ b/main/commons/src/main/java/org/cryptomator/common/Environment.java @@ -40,7 +40,6 @@ public class Environment { LOG.debug("cryptomator.mountPointsDir: {}", System.getProperty("cryptomator.mountPointsDir")); LOG.debug("cryptomator.minPwLength: {}", System.getProperty("cryptomator.minPwLength")); LOG.debug("cryptomator.buildNumber: {}", System.getProperty("cryptomator.buildNumber")); - LOG.debug("cryptomator.binaryPath: {}", System.getProperty("cryptomator.binaryPath")); } public boolean useCustomLogbackConfig() { @@ -75,8 +74,6 @@ public class Environment { return getInt("cryptomator.minPwLength", DEFAULT_MIN_PW_LENGTH); } - public Optional getBinaryPath() { return getPath("cryptomator.binaryPath"); } - private int getInt(String propertyName, int defaultValue) { String value = System.getProperty(propertyName); try { diff --git a/main/ui/src/main/java/org/cryptomator/ui/preferences/AutoStartModule.java b/main/ui/src/main/java/org/cryptomator/ui/preferences/AutoStartModule.java index 1909b6af2..fa01756ab 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/preferences/AutoStartModule.java +++ b/main/ui/src/main/java/org/cryptomator/ui/preferences/AutoStartModule.java @@ -18,7 +18,7 @@ abstract class AutoStartModule { return Optional.of(new AutoStartMacStrategy(macFunctions.get())); } else if (SystemUtils.IS_OS_WINDOWS) { Optional exeName = ProcessHandle.current().info().command(); - return exeName.map(x -> new AutoStartWinStrategy(x, env)); + return exeName.map(AutoStartWinStrategy::new); } else { return Optional.empty(); } diff --git a/main/ui/src/main/java/org/cryptomator/ui/preferences/AutoStartWinStrategy.java b/main/ui/src/main/java/org/cryptomator/ui/preferences/AutoStartWinStrategy.java index f863cec61..02e4faa26 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/preferences/AutoStartWinStrategy.java +++ b/main/ui/src/main/java/org/cryptomator/ui/preferences/AutoStartWinStrategy.java @@ -17,11 +17,9 @@ class AutoStartWinStrategy implements AutoStartStrategy { private static final String AUTOSTART_VALUE = "Cryptomator"; private final String exePath; private static final String WINDOWS_START_MENU_FOLDER = "\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs"; - private Environment env; - public AutoStartWinStrategy(String exePath, Environment env) { + public AutoStartWinStrategy(String exePath) { this.exePath = exePath; - this.env = env; } @Override @@ -99,9 +97,8 @@ class AutoStartWinStrategy implements AutoStartStrategy { } private void addShortcutOfAppToAutostartFolder() throws TogglingAutoStartWithPowershellFailedException { - String startmenueDirectory = System.getProperty("user.home") + WINDOWS_START_MENU_FOLDER + "\\Cryptomator.lnk"; - String cryptomator = env.getBinaryPath().get().toString(); - String createShortcutCommand = "$s=(New-Object -COM WScript.Shell).CreateShortcut('" + startmenueDirectory + "');$s.TargetPath='" + cryptomator + "';$s.Save();"; + String startMenuDirectory = System.getProperty("user.home") + WINDOWS_START_MENU_FOLDER + "\\Cryptomator.lnk"; + String createShortcutCommand = "$s=(New-Object -COM WScript.Shell).CreateShortcut('" + startMenuDirectory + "');$s.TargetPath='" + exePath + "';$s.Save();"; ProcessBuilder shortcutAdd = new ProcessBuilder("cmd", "/c", "Start powershell " + createShortcutCommand); try { shortcutAdd.start(); @@ -111,8 +108,8 @@ class AutoStartWinStrategy implements AutoStartStrategy { } private void removeShortcutOfAppFromAutostartFolder() throws TogglingAutoStartWithPowershellFailedException { - String startmenueDirectory = System.getProperty("user.home") + WINDOWS_START_MENU_FOLDER + "\\Cryptomator.lnk"; - ProcessBuilder shortcutRemove = new ProcessBuilder("cmd", "/c del \"" + startmenueDirectory + "\""); + String startMenuDirectory = System.getProperty("user.home") + WINDOWS_START_MENU_FOLDER + "\\Cryptomator.lnk"; + ProcessBuilder shortcutRemove = new ProcessBuilder("cmd", "/c del \"" + startMenuDirectory + "\""); try { shortcutRemove.start(); } catch (IOException e) {