mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-08-19 13:46:04 +00:00
Implemented AutoStart integration for macOS
This commit is contained in:
@@ -3,6 +3,7 @@ package org.cryptomator.ui.launcher;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import org.cryptomator.common.JniModule;
|
||||
import org.cryptomator.integrations.autostart.AutoStartProvider;
|
||||
import org.cryptomator.integrations.tray.TrayIntegrationProvider;
|
||||
import org.cryptomator.integrations.uiappearance.UiAppearanceProvider;
|
||||
import org.cryptomator.ui.fxapp.FxApplicationComponent;
|
||||
@@ -25,6 +26,13 @@ public abstract class UiLauncherModule {
|
||||
return ServiceLoader.load(UiAppearanceProvider.class).findFirst();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
static Optional<AutoStartProvider> provideAutostartProvider() {
|
||||
return ServiceLoader.load(AutoStartProvider.class).findFirst();
|
||||
}
|
||||
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
static Optional<TrayIntegrationProvider> provideTrayIntegrationProvider() {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.cryptomator.ui.preferences;
|
||||
|
||||
import org.cryptomator.integrations.autostart.AutoStartProvider;
|
||||
import org.cryptomator.integrations.autostart.ToggleAutoStartFailedException;
|
||||
import org.cryptomator.jni.MacFunctions;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -7,36 +9,38 @@ import org.slf4j.LoggerFactory;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
|
||||
@Deprecated
|
||||
class AutoStartMacStrategy implements AutoStartStrategy {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AutoStartMacStrategy.class);
|
||||
|
||||
private final MacFunctions macFunctions;
|
||||
private final AutoStartProvider autoStartProvider;
|
||||
|
||||
public AutoStartMacStrategy(MacFunctions macFunctions) {
|
||||
this.macFunctions = macFunctions;
|
||||
public AutoStartMacStrategy(AutoStartProvider autoStartProvider) {
|
||||
this.autoStartProvider = autoStartProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletionStage<Boolean> isAutoStartEnabled() {
|
||||
boolean enabled = macFunctions.launchServices().isLoginItemEnabled();
|
||||
return CompletableFuture.completedFuture(enabled);
|
||||
return CompletableFuture.completedFuture(autoStartProvider.isEnabled());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableAutoStart() throws TogglingAutoStartFailedException {
|
||||
if (macFunctions.launchServices().enableLoginItem()) {
|
||||
try {
|
||||
autoStartProvider.enable();
|
||||
LOG.debug("Added login item.");
|
||||
} else {
|
||||
} catch (ToggleAutoStartFailedException e) {
|
||||
throw new TogglingAutoStartFailedException("Failed to add login item.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableAutoStart() throws TogglingAutoStartFailedException {
|
||||
if (macFunctions.launchServices().disableLoginItem()) {
|
||||
try {
|
||||
autoStartProvider.disable();
|
||||
LOG.debug("Removed login item.");
|
||||
} else {
|
||||
} catch (ToggleAutoStartFailedException e) {
|
||||
throw new TogglingAutoStartFailedException("Failed to remove login item.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,18 +4,20 @@ import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
import org.cryptomator.common.Environment;
|
||||
import org.cryptomator.integrations.autostart.AutoStartProvider;
|
||||
import org.cryptomator.jni.MacFunctions;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Deprecated
|
||||
@Module
|
||||
abstract class AutoStartModule {
|
||||
|
||||
@Provides
|
||||
@PreferencesScoped
|
||||
public static Optional<AutoStartStrategy> provideAutoStartStrategy(Optional<MacFunctions> macFunctions, Environment env) {
|
||||
if (SystemUtils.IS_OS_MAC_OSX && macFunctions.isPresent()) {
|
||||
return Optional.of(new AutoStartMacStrategy(macFunctions.get()));
|
||||
public static Optional<AutoStartStrategy> provideAutoStartStrategy(Optional<AutoStartProvider> autoStartProvider) {
|
||||
if (SystemUtils.IS_OS_MAC_OSX && autoStartProvider.isPresent()) {
|
||||
return Optional.of(new AutoStartMacStrategy(autoStartProvider.get()));
|
||||
} else if (SystemUtils.IS_OS_WINDOWS) {
|
||||
Optional<String> exeName = ProcessHandle.current().info().command();
|
||||
return exeName.map(AutoStartWinStrategy::new);
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.cryptomator.ui.preferences;
|
||||
|
||||
import java.util.concurrent.CompletionStage;
|
||||
|
||||
@Deprecated
|
||||
public interface AutoStartStrategy {
|
||||
|
||||
CompletionStage<Boolean> isAutoStartEnabled();
|
||||
|
||||
@@ -25,7 +25,9 @@ import java.util.concurrent.TimeUnit;
|
||||
* To disable it, first it is determined by an internal state, which strategies must be used and in the second step those are executed.
|
||||
*
|
||||
* @apiNote This class is not thread safe, hence it should be avoided to call its methods simultaniously by different threads.
|
||||
* @deprecated To be moved to integration-win project
|
||||
*/
|
||||
@Deprecated
|
||||
class AutoStartWinStrategy implements AutoStartStrategy {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AutoStartWinStrategy.class);
|
||||
|
||||
Reference in New Issue
Block a user