Allows choosing and managing each tool
This commit is contained in:
@@ -6,6 +6,8 @@ import com.github.gtache.autosubtitle.translation.deepl.DeepLTranslator;
|
||||
import dagger.Binds;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import dagger.multibindings.IntoMap;
|
||||
import dagger.multibindings.StringKey;
|
||||
import org.apache.tika.language.detect.LanguageDetector;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
@@ -18,6 +20,11 @@ import java.io.UncheckedIOException;
|
||||
@Module(includes = DeepLSetupModule.class)
|
||||
public abstract class DeepLModule {
|
||||
|
||||
@Binds
|
||||
@IntoMap
|
||||
@StringKey("deepl")
|
||||
abstract Translator<?> bindsTranslatorInMap(final DeepLTranslator translator);
|
||||
|
||||
@Binds
|
||||
abstract Translator bindsTranslator(final DeepLTranslator translator);
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ import com.github.gtache.autosubtitle.setup.SetupManager;
|
||||
import com.github.gtache.autosubtitle.setup.deepl.DeepLSetupManager;
|
||||
import dagger.Binds;
|
||||
import dagger.Module;
|
||||
import dagger.multibindings.IntoMap;
|
||||
import dagger.multibindings.StringKey;
|
||||
|
||||
/**
|
||||
* Dagger module for DeepL setup
|
||||
@@ -16,6 +18,12 @@ public abstract class DeepLSetupModule {
|
||||
|
||||
@Binds
|
||||
@TranslatorSetup
|
||||
@IntoMap
|
||||
@StringKey("deepl")
|
||||
abstract SetupManager bindsSetupManager(final DeepLSetupManager setupManager);
|
||||
|
||||
@Binds
|
||||
@TranslatorSetup
|
||||
abstract SetupManager bindsDefaultSetupManager(final DeepLSetupManager setupManager);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.github.gtache.autosubtitle.setup.deepl;
|
||||
|
||||
import com.github.gtache.autosubtitle.ToolType;
|
||||
import com.github.gtache.autosubtitle.process.ProcessRunner;
|
||||
import com.github.gtache.autosubtitle.setup.SetupException;
|
||||
import com.github.gtache.autosubtitle.setup.SetupManager;
|
||||
@@ -8,6 +9,7 @@ import com.github.gtache.autosubtitle.setup.SetupUserBridge;
|
||||
import com.github.gtache.autosubtitle.setup.impl.AbstractSetupManager;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.net.http.HttpClient;
|
||||
import java.util.Objects;
|
||||
import java.util.prefs.BackingStoreException;
|
||||
@@ -16,6 +18,7 @@ import java.util.prefs.Preferences;
|
||||
/**
|
||||
* {@link SetupManager} for DeepL
|
||||
*/
|
||||
@Singleton
|
||||
public class DeepLSetupManager extends AbstractSetupManager {
|
||||
|
||||
private static final String DEEPL_API_KEY = "deepl.api.key";
|
||||
@@ -42,6 +45,11 @@ public class DeepLSetupManager extends AbstractSetupManager {
|
||||
return "DeepL";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ToolType type() {
|
||||
return ToolType.TRANSLATOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void install() throws SetupException {
|
||||
final var key = userBridge.askForUserInput("Please enter your DeepL API key - https://www.deepl.com/pro-api? (It will be stored unencrypted)");
|
||||
|
||||
@@ -7,7 +7,10 @@ module com.github.gtache.autosubtitle.deepl {
|
||||
requires transitive java.prefs;
|
||||
requires transitive org.apache.tika.core;
|
||||
requires transitive language.detector;
|
||||
exports com.github.gtache.autosubtitle.modules.deepl;
|
||||
exports com.github.gtache.autosubtitle.translation.deepl;
|
||||
|
||||
exports com.github.gtache.autosubtitle.setup.deepl;
|
||||
exports com.github.gtache.autosubtitle.translation.deepl;
|
||||
|
||||
exports com.github.gtache.autosubtitle.modules.deepl;
|
||||
exports com.github.gtache.autosubtitle.modules.setup.deepl;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.github.gtache.autosubtitle.setup.deepl;
|
||||
|
||||
import com.github.gtache.autosubtitle.ToolType;
|
||||
import com.github.gtache.autosubtitle.process.ProcessRunner;
|
||||
import com.github.gtache.autosubtitle.setup.SetupException;
|
||||
import com.github.gtache.autosubtitle.setup.SetupStatus;
|
||||
@@ -44,6 +45,11 @@ class TestDeepLSetupManager {
|
||||
assertEquals(SetupStatus.BUNDLE_INSTALLED, setupManager.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testType() {
|
||||
assertEquals(ToolType.TRANSLATOR, setupManager.type());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInstall() throws BackingStoreException, SetupException {
|
||||
final var key = "key";
|
||||
|
||||
Reference in New Issue
Block a user