Service open fixes

This commit is contained in:
crschnick 2024-07-20 13:10:27 +00:00
parent 6887f9b4ca
commit 68e29efd1a
18 changed files with 167 additions and 38 deletions

View file

@ -45,7 +45,7 @@ public class StoreEntryWrapper {
this.entry = entry;
this.name = new SimpleStringProperty(entry.getName());
this.lastAccess = new SimpleObjectProperty<>(entry.getLastAccess().minus(Duration.ofMillis(500)));
ActionProvider.ALL.stream()
ActionProvider.ALL_STANDALONE.stream()
.filter(dataStoreActionProvider -> {
return !entry.isDisabled()
&& dataStoreActionProvider.getLeafDataStoreCallSite() != null
@ -163,7 +163,7 @@ public class StoreEntryWrapper {
defaultActionProvider.setValue(null);
} else {
try {
var defaultProvider = ActionProvider.ALL.stream()
var defaultProvider = ActionProvider.ALL_STANDALONE.stream()
.filter(e -> entry.getStore() != null
&& e.getDefaultDataStoreCallSite() != null
&& e.getDefaultDataStoreCallSite()
@ -174,7 +174,7 @@ public class StoreEntryWrapper {
.orElse(null);
this.defaultActionProvider.setValue(defaultProvider);
var newProviders = ActionProvider.ALL.stream()
var newProviders = ActionProvider.ALL_STANDALONE.stream()
.filter(dataStoreActionProvider -> {
return showActionProvider(dataStoreActionProvider);
})

View file

@ -16,6 +16,7 @@ import java.util.ServiceLoader;
public interface ActionProvider {
List<ActionProvider> ALL = new ArrayList<>();
List<ActionProvider> ALL_STANDALONE = new ArrayList<>();
static void initProviders() {
for (ActionProvider actionProvider : ALL) {
@ -111,7 +112,7 @@ public interface ActionProvider {
String getIcon(DataStoreEntryRef<T> store);
Class<T> getApplicableClass();
Class<?> getApplicableClass();
default boolean showBusy() {
return true;
@ -120,9 +121,7 @@ public interface ActionProvider {
interface BranchDataStoreCallSite<T extends DataStore> extends DataStoreCallSite<T> {
default List<ActionProvider> getChildren() {
return List.of();
}
List<ActionProvider> getChildren();
}
interface LeafDataStoreCallSite<T extends DataStore> extends DataStoreCallSite<T> {
@ -145,6 +144,10 @@ public interface ActionProvider {
ALL.addAll(ServiceLoader.load(layer, ActionProvider.class).stream()
.map(actionProviderProvider -> actionProviderProvider.get())
.toList());
var menuProviders = ALL.stream().map(actionProvider -> actionProvider.getBranchDataStoreCallSite() != null ?
actionProvider.getBranchDataStoreCallSite().getChildren() : List.of()).flatMap(List::stream).toList();
ALL_STANDALONE.addAll(ALL.stream().filter(actionProvider -> menuProviders.stream().noneMatch(menuItem -> menuItem.getClass().equals(actionProvider.getClass()))).toList());
}
}
}

View file

@ -3,31 +3,29 @@ package io.xpipe.ext.base.service;
import io.xpipe.app.core.AppI18n;
import io.xpipe.app.ext.ActionProvider;
import io.xpipe.app.storage.DataStoreEntryRef;
import io.xpipe.app.util.Hyperlinks;
import io.xpipe.core.store.DataStore;
import javafx.beans.value.ObservableValue;
import lombok.Value;
import java.util.List;
public class ServiceOpenAction implements ActionProvider {
@Override
public LeafDataStoreCallSite<?> getLeafDataStoreCallSite() {
return new LeafDataStoreCallSite<AbstractServiceStore>() {
public BranchDataStoreCallSite<?> getBranchDataStoreCallSite() {
return new BranchDataStoreCallSite<DataStore>() {
@Override
public boolean isMajor(DataStoreEntryRef<AbstractServiceStore> o) {
public boolean isMajor(DataStoreEntryRef<DataStore> o) {
return true;
}
@Override
public boolean canLinkTo() {
return true;
public ObservableValue<String> getName(DataStoreEntryRef<DataStore> store) {
return AppI18n.observable("openWebsite");
}
@Override
public ActionProvider.Action createAction(DataStoreEntryRef<AbstractServiceStore> store) {
return new Action(store.getStore());
public String getIcon(DataStoreEntryRef<DataStore> store) {
return "mdi2s-search-web";
}
@Override
@ -36,27 +34,9 @@ public class ServiceOpenAction implements ActionProvider {
}
@Override
public ObservableValue<String> getName(DataStoreEntryRef<AbstractServiceStore> store) {
return AppI18n.observable("openWebsite");
}
@Override
public String getIcon(DataStoreEntryRef<AbstractServiceStore> store) {
return "mdi2s-search-web";
public List<ActionProvider> getChildren() {
return List.of(new ServiceOpenHttpAction(), new ServiceOpenHttpsAction());
}
};
}
@Value
static class Action implements ActionProvider.Action {
AbstractServiceStore serviceStore;
@Override
public void execute() throws Exception {
serviceStore.startSessionIfNeeded();
var l = serviceStore.getSession().getLocalPort();
Hyperlinks.open("http://localhost:" + l);
}
}
}

View file

@ -0,0 +1,60 @@
package io.xpipe.ext.base.service;
import io.xpipe.app.core.AppI18n;
import io.xpipe.app.ext.ActionProvider;
import io.xpipe.app.storage.DataStoreEntryRef;
import io.xpipe.app.util.Hyperlinks;
import javafx.beans.value.ObservableValue;
import lombok.Value;
public class ServiceOpenHttpAction implements ActionProvider {
@Override
public String getId() {
return "serviceOpenHttp";
}
@Override
public LeafDataStoreCallSite<?> getLeafDataStoreCallSite() {
return new LeafDataStoreCallSite<AbstractServiceStore>() {
@Override
public boolean canLinkTo() {
return true;
}
@Override
public ActionProvider.Action createAction(DataStoreEntryRef<AbstractServiceStore> store) {
return new Action(store.getStore());
}
@Override
public Class<AbstractServiceStore> getApplicableClass() {
return AbstractServiceStore.class;
}
@Override
public ObservableValue<String> getName(DataStoreEntryRef<AbstractServiceStore> store) {
return AppI18n.observable("openHttp");
}
@Override
public String getIcon(DataStoreEntryRef<AbstractServiceStore> store) {
return "mdi2s-shield-off-outline";
}
};
}
@Value
static class Action implements ActionProvider.Action {
AbstractServiceStore serviceStore;
@Override
public void execute() throws Exception {
serviceStore.startSessionIfNeeded();
var l = serviceStore.getSession().getLocalPort();
Hyperlinks.open("http://localhost:" + l);
}
}
}

View file

@ -0,0 +1,60 @@
package io.xpipe.ext.base.service;
import io.xpipe.app.core.AppI18n;
import io.xpipe.app.ext.ActionProvider;
import io.xpipe.app.storage.DataStoreEntryRef;
import io.xpipe.app.util.Hyperlinks;
import javafx.beans.value.ObservableValue;
import lombok.Value;
public class ServiceOpenHttpsAction implements ActionProvider {
@Override
public String getId() {
return "serviceOpenHttps";
}
@Override
public LeafDataStoreCallSite<?> getLeafDataStoreCallSite() {
return new LeafDataStoreCallSite<AbstractServiceStore>() {
@Override
public boolean canLinkTo() {
return true;
}
@Override
public ActionProvider.Action createAction(DataStoreEntryRef<AbstractServiceStore> store) {
return new Action(store.getStore());
}
@Override
public Class<AbstractServiceStore> getApplicableClass() {
return AbstractServiceStore.class;
}
@Override
public ObservableValue<String> getName(DataStoreEntryRef<AbstractServiceStore> store) {
return AppI18n.observable("openHttps");
}
@Override
public String getIcon(DataStoreEntryRef<AbstractServiceStore> store) {
return "mdi2s-shield-lock-outline";
}
};
}
@Value
static class Action implements ActionProvider.Action {
AbstractServiceStore serviceStore;
@Override
public void execute() throws Exception {
serviceStore.startSessionIfNeeded();
var l = serviceStore.getSession().getLocalPort();
Hyperlinks.open("https://localhost:" + l);
}
}
}

View file

@ -61,6 +61,8 @@ open module io.xpipe.ext.base {
JarAction;
provides ActionProvider with
ServiceOpenAction,
ServiceOpenHttpAction,
ServiceOpenHttpsAction,
ServiceCopyUrlAction,
CloneStoreAction,
RefreshChildrenStoreAction,

View file

@ -170,3 +170,5 @@ fixedService.displayDescription=Brug en foruddefineret tjeneste
noServices=Ingen tilgængelige tjenester
hasServices=$COUNT$ tilgængelige tjenester
hasService=$COUNT$ tilgængelig tjeneste
openHttp=Åben HTTP-tjeneste
openHttps=Åben HTTPS-tjeneste

View file

@ -161,3 +161,5 @@ fixedService.displayDescription=Einen vordefinierten Dienst verwenden
noServices=Keine verfügbaren Dienste
hasServices=$COUNT$ verfügbare Dienste
hasService=$COUNT$ verfügbarer Dienst
openHttp=Offener HTTP-Dienst
openHttps=HTTPS-Dienst öffnen

View file

@ -159,5 +159,7 @@ fixedService.displayDescription=Use a predefined service
noServices=No available services
hasServices=$COUNT$ available services
hasService=$COUNT$ available service
openHttp=Open HTTP service
openHttps=Open HTTPS service

View file

@ -159,3 +159,5 @@ fixedService.displayDescription=Utilizar un servicio predefinido
noServices=No hay servicios disponibles
hasServices=$COUNT$ servicios disponibles
hasService=$COUNT$ servicio disponible
openHttp=Servicio HTTP abierto
openHttps=Abrir servicio HTTPS

View file

@ -159,3 +159,5 @@ fixedService.displayDescription=Utiliser un service prédéfini
noServices=Aucun service disponible
hasServices=$COUNT$ services disponibles
hasService=$COUNT$ service disponible
openHttp=Service HTTP ouvert
openHttps=Service HTTPS ouvert

View file

@ -159,3 +159,5 @@ fixedService.displayDescription=Utilizzare un servizio predefinito
noServices=Nessun servizio disponibile
hasServices=$COUNT$ servizi disponibili
hasService=$COUNT$ servizio disponibile
openHttp=Servizio HTTP aperto
openHttps=Servizio HTTPS aperto

View file

@ -159,3 +159,5 @@ fixedService.displayDescription=定義済みのサービスを使う
noServices=利用可能なサービスはない
hasServices=$COUNT$ 利用可能なサービス
hasService=$COUNT$ 利用可能なサービス
openHttp=オープンHTTPサービス
openHttps=HTTPSサービスを開く

View file

@ -159,3 +159,5 @@ fixedService.displayDescription=Een vooraf gedefinieerde service gebruiken
noServices=Geen beschikbare diensten
hasServices=$COUNT$ beschikbare diensten
hasService=$COUNT$ beschikbare dienst
openHttp=Open HTTP service
openHttps=Open HTTPS service

View file

@ -159,3 +159,5 @@ fixedService.displayDescription=Utiliza um serviço predefinido
noServices=Não há serviços disponíveis
hasServices=$COUNT$ serviços disponíveis
hasService=$COUNT$ serviço disponível
openHttp=Abre o serviço HTTP
openHttps=Abre o serviço HTTPS

View file

@ -159,3 +159,5 @@ fixedService.displayDescription=Использовать предопредел
noServices=Нет доступных сервисов
hasServices=$COUNT$ доступные сервисы
hasService=$COUNT$ доступный сервис
openHttp=Открытый HTTP-сервис
openHttps=Открытая служба HTTPS

View file

@ -159,3 +159,5 @@ fixedService.displayDescription=Önceden tanımlanmış bir hizmet kullanın
noServices=Mevcut hizmet yok
hasServices=$COUNT$ mevcut hi̇zmetler
hasService=$COUNT$ mevcut hizmet
openHttp=ık HTTP hizmeti
openHttps=HTTPS hizmetini açın

View file

@ -159,3 +159,5 @@ fixedService.displayDescription=使用预定义服务
noServices=无可用服务
hasServices=$COUNT$ 可用服务
hasService=$COUNT$ 可用服务
openHttp=开放式 HTTP 服务
openHttps=打开 HTTPS 服务