diff --git a/api/src/test/java/module-info.java b/api/src/test/java/module-info.java index 401865d77..4820ba2b4 100644 --- a/api/src/test/java/module-info.java +++ b/api/src/test/java/module-info.java @@ -3,6 +3,5 @@ module io.xpipe.api.test { requires io.xpipe.api; requires io.xpipe.beacon; - requires io.xpipe.app; requires org.junit.jupiter.api; } \ No newline at end of file diff --git a/extension/build.gradle b/extension/build.gradle new file mode 100644 index 000000000..309c231a7 --- /dev/null +++ b/extension/build.gradle @@ -0,0 +1,20 @@ +plugins { + id 'java' + id "org.moditect.gradleplugin" version "1.0.0-rc3" +} + +java { + modularity.inferModulePath = true + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 +} + +apply from: "$rootDir/deps/javafx.gradle" + +repositories { + mavenCentral() +} + +dependencies { + implementation project(':core') +} diff --git a/extension/src/main/java/io/xpipe/extension/DataSourceGuiProvider.java b/extension/src/main/java/io/xpipe/extension/DataSourceGuiProvider.java new file mode 100644 index 000000000..464280877 --- /dev/null +++ b/extension/src/main/java/io/xpipe/extension/DataSourceGuiProvider.java @@ -0,0 +1,36 @@ +package io.xpipe.extension; + +import io.xpipe.core.source.DataSource; +import io.xpipe.core.store.DataStore; +import javafx.beans.property.Property; +import javafx.scene.image.Image; +import javafx.scene.layout.Region; + +import java.nio.file.Path; +import java.util.Map; +import java.util.function.Supplier; + +public interface DataSourceGuiProvider { + + default boolean isHidden() { + return false; + } + + boolean supportsFile(Path file); + + Region createConfigOptions(DataStore input, Property> source); + + DataSource createDefaultDataSource(DataStore input); + + String getDisplayName(); + + Image getImage(); + + Supplier getFileName(); + + Map, String> getFileExtensions(); + + String getDataSourceDescription(DataSource source); + + Class> getType(); +} diff --git a/extension/src/main/java/io/xpipe/extension/DataSourceGuiProviders.java b/extension/src/main/java/io/xpipe/extension/DataSourceGuiProviders.java new file mode 100644 index 000000000..9b5cd37c1 --- /dev/null +++ b/extension/src/main/java/io/xpipe/extension/DataSourceGuiProviders.java @@ -0,0 +1,34 @@ +package io.xpipe.extension; + +import java.util.HashSet; +import java.util.Optional; +import java.util.ServiceLoader; +import java.util.Set; +import java.util.stream.Collectors; + +public class DataSourceGuiProviders { + + private static Set ALL; + + public static void loadAll(ModuleLayer layer) { + if (ALL == null) { + ALL = new HashSet<>(); + ALL.addAll(ServiceLoader.load(layer, DataSourceGuiProvider.class).stream() + .map(ServiceLoader.Provider::get).collect(Collectors.toSet())); + } + } + + public static Optional byClass(Class clazz) { + if (ALL == null) { + throw new IllegalStateException("Not initialized"); + } + return ALL.stream().filter(d -> d.getType().equals(clazz)).findAny(); + } + + public static Set getAll() { + if (ALL == null) { + throw new IllegalStateException("Not initialized"); + } + return ALL; + } +} diff --git a/extension/src/main/java/io/xpipe/extension/DataSourceProvider.java b/extension/src/main/java/io/xpipe/extension/DataSourceProvider.java new file mode 100644 index 000000000..ddb2a3013 --- /dev/null +++ b/extension/src/main/java/io/xpipe/extension/DataSourceProvider.java @@ -0,0 +1,10 @@ +package io.xpipe.extension; + +import io.xpipe.core.source.DataSource; + +public interface DataSourceProvider { + + String getId(); + + Class getType(); +} diff --git a/extension/src/main/java/io/xpipe/extension/DataSourceProviders.java b/extension/src/main/java/io/xpipe/extension/DataSourceProviders.java new file mode 100644 index 000000000..9546bc58f --- /dev/null +++ b/extension/src/main/java/io/xpipe/extension/DataSourceProviders.java @@ -0,0 +1,40 @@ +package io.xpipe.extension; + +import io.xpipe.core.source.DataSource; + +import java.util.Optional; +import java.util.ServiceLoader; +import java.util.Set; +import java.util.stream.Collectors; + +public class DataSourceProviders { + + private static Set ALL; + + public static void init(ModuleLayer layer) { + if (ALL == null) { + ALL = ServiceLoader.load(layer, DataSourceProvider.class).stream() + .map(ServiceLoader.Provider::get).collect(Collectors.toSet()); + } + } + + public static Optional byDataSourceClass(Class clazz) { + if (ALL == null) { + throw new IllegalStateException("Not initialized"); + } + + return ALL.stream().filter(d -> d.getType().equals(clazz)).findAny(); + } + + public static Optional byId(String name) { + if (ALL == null) { + throw new IllegalStateException("Not initialized"); + } + + return ALL.stream().filter(d -> d.getId().equals(name)).findAny(); + } + + public static Set getAll() { + return ALL; + } +} diff --git a/extension/src/main/java/io/xpipe/extension/SupportedApplicationProvider.java b/extension/src/main/java/io/xpipe/extension/SupportedApplicationProvider.java new file mode 100644 index 000000000..3bc5b27f9 --- /dev/null +++ b/extension/src/main/java/io/xpipe/extension/SupportedApplicationProvider.java @@ -0,0 +1,17 @@ +package io.xpipe.extension; + +import io.xpipe.core.source.DataSourceId; +import javafx.beans.value.ObservableValue; +import javafx.scene.image.Image; +import javafx.scene.layout.Region; + +public interface SupportedApplicationProvider { + + Region createRetrieveInstructions(ObservableValue id); + + Image getLogo(); + + String getId(); + + String getName(); +} diff --git a/extension/src/main/java/io/xpipe/extension/SupportedApplicationProviders.java b/extension/src/main/java/io/xpipe/extension/SupportedApplicationProviders.java new file mode 100644 index 000000000..0fc9534c3 --- /dev/null +++ b/extension/src/main/java/io/xpipe/extension/SupportedApplicationProviders.java @@ -0,0 +1,34 @@ +package io.xpipe.extension; + +import java.util.Optional; +import java.util.ServiceLoader; +import java.util.Set; +import java.util.stream.Collectors; + +public class SupportedApplicationProviders { + + private static Set ALL; + + public static void loadAll(ModuleLayer layer) { + if (ALL == null) { + ALL = ServiceLoader.load(layer, SupportedApplicationProvider.class).stream() + .map(ServiceLoader.Provider::get).collect(Collectors.toSet()); + } + } + + public static Optional byId(String id) { + if (ALL == null) { + throw new IllegalStateException("Not initialized"); + } + + return ALL.stream().filter(d -> d.getId().equals(id)).findAny(); + } + + public static Set getAll() { + if (ALL == null) { + throw new IllegalStateException("Not initialized"); + } + + return ALL; + } +} diff --git a/extension/src/main/java/module-info.java b/extension/src/main/java/module-info.java new file mode 100644 index 000000000..e8b1472fe --- /dev/null +++ b/extension/src/main/java/module-info.java @@ -0,0 +1,6 @@ +module io.xpipe.extension { + requires io.xpipe.core; + requires javafx.base; + + exports io.xpipe.extension; +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index c50fb1fe8..817556c03 100644 --- a/settings.gradle +++ b/settings.gradle @@ -3,5 +3,6 @@ rootProject.name = 'xpipe_java' include 'core' include 'beacon' include 'api' +include 'extension'