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

View file

@ -16,6 +16,7 @@ import java.util.ServiceLoader;
public interface ActionProvider { public interface ActionProvider {
List<ActionProvider> ALL = new ArrayList<>(); List<ActionProvider> ALL = new ArrayList<>();
List<ActionProvider> ALL_STANDALONE = new ArrayList<>();
static void initProviders() { static void initProviders() {
for (ActionProvider actionProvider : ALL) { for (ActionProvider actionProvider : ALL) {
@ -111,7 +112,7 @@ public interface ActionProvider {
String getIcon(DataStoreEntryRef<T> store); String getIcon(DataStoreEntryRef<T> store);
Class<T> getApplicableClass(); Class<?> getApplicableClass();
default boolean showBusy() { default boolean showBusy() {
return true; return true;
@ -120,9 +121,7 @@ public interface ActionProvider {
interface BranchDataStoreCallSite<T extends DataStore> extends DataStoreCallSite<T> { interface BranchDataStoreCallSite<T extends DataStore> extends DataStoreCallSite<T> {
default List<ActionProvider> getChildren() { List<ActionProvider> getChildren();
return List.of();
}
} }
interface LeafDataStoreCallSite<T extends DataStore> extends DataStoreCallSite<T> { interface LeafDataStoreCallSite<T extends DataStore> extends DataStoreCallSite<T> {
@ -145,6 +144,10 @@ public interface ActionProvider {
ALL.addAll(ServiceLoader.load(layer, ActionProvider.class).stream() ALL.addAll(ServiceLoader.load(layer, ActionProvider.class).stream()
.map(actionProviderProvider -> actionProviderProvider.get()) .map(actionProviderProvider -> actionProviderProvider.get())
.toList()); .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.core.AppI18n;
import io.xpipe.app.ext.ActionProvider; import io.xpipe.app.ext.ActionProvider;
import io.xpipe.app.storage.DataStoreEntryRef; import io.xpipe.app.storage.DataStoreEntryRef;
import io.xpipe.app.util.Hyperlinks; import io.xpipe.core.store.DataStore;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
import lombok.Value; import java.util.List;
public class ServiceOpenAction implements ActionProvider { public class ServiceOpenAction implements ActionProvider {
@Override @Override
public LeafDataStoreCallSite<?> getLeafDataStoreCallSite() { public BranchDataStoreCallSite<?> getBranchDataStoreCallSite() {
return new LeafDataStoreCallSite<AbstractServiceStore>() { return new BranchDataStoreCallSite<DataStore>() {
@Override @Override
public boolean isMajor(DataStoreEntryRef<AbstractServiceStore> o) { public boolean isMajor(DataStoreEntryRef<DataStore> o) {
return true; return true;
} }
@Override @Override
public boolean canLinkTo() { public ObservableValue<String> getName(DataStoreEntryRef<DataStore> store) {
return true; return AppI18n.observable("openWebsite");
} }
@Override @Override
public ActionProvider.Action createAction(DataStoreEntryRef<AbstractServiceStore> store) { public String getIcon(DataStoreEntryRef<DataStore> store) {
return new Action(store.getStore()); return "mdi2s-search-web";
} }
@Override @Override
@ -36,27 +34,9 @@ public class ServiceOpenAction implements ActionProvider {
} }
@Override @Override
public ObservableValue<String> getName(DataStoreEntryRef<AbstractServiceStore> store) { public List<ActionProvider> getChildren() {
return AppI18n.observable("openWebsite"); return List.of(new ServiceOpenHttpAction(), new ServiceOpenHttpsAction());
}
@Override
public String getIcon(DataStoreEntryRef<AbstractServiceStore> store) {
return "mdi2s-search-web";
} }
}; };
} }
@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; JarAction;
provides ActionProvider with provides ActionProvider with
ServiceOpenAction, ServiceOpenAction,
ServiceOpenHttpAction,
ServiceOpenHttpsAction,
ServiceCopyUrlAction, ServiceCopyUrlAction,
CloneStoreAction, CloneStoreAction,
RefreshChildrenStoreAction, RefreshChildrenStoreAction,

View file

@ -170,3 +170,5 @@ fixedService.displayDescription=Brug en foruddefineret tjeneste
noServices=Ingen tilgængelige tjenester noServices=Ingen tilgængelige tjenester
hasServices=$COUNT$ tilgængelige tjenester hasServices=$COUNT$ tilgængelige tjenester
hasService=$COUNT$ tilgængelig tjeneste 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 noServices=Keine verfügbaren Dienste
hasServices=$COUNT$ verfügbare Dienste hasServices=$COUNT$ verfügbare Dienste
hasService=$COUNT$ verfügbarer Dienst 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 noServices=No available services
hasServices=$COUNT$ available services hasServices=$COUNT$ available services
hasService=$COUNT$ available service 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 noServices=No hay servicios disponibles
hasServices=$COUNT$ servicios disponibles hasServices=$COUNT$ servicios disponibles
hasService=$COUNT$ servicio disponible 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 noServices=Aucun service disponible
hasServices=$COUNT$ services disponibles hasServices=$COUNT$ services disponibles
hasService=$COUNT$ service disponible 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 noServices=Nessun servizio disponibile
hasServices=$COUNT$ servizi disponibili hasServices=$COUNT$ servizi disponibili
hasService=$COUNT$ servizio disponibile hasService=$COUNT$ servizio disponibile
openHttp=Servizio HTTP aperto
openHttps=Servizio HTTPS aperto

View file

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

View file

@ -159,3 +159,5 @@ fixedService.displayDescription=Een vooraf gedefinieerde service gebruiken
noServices=Geen beschikbare diensten noServices=Geen beschikbare diensten
hasServices=$COUNT$ beschikbare diensten hasServices=$COUNT$ beschikbare diensten
hasService=$COUNT$ beschikbare dienst 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 noServices=Não há serviços disponíveis
hasServices=$COUNT$ serviços disponíveis hasServices=$COUNT$ serviços disponíveis
hasService=$COUNT$ serviço disponível 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=Нет доступных сервисов noServices=Нет доступных сервисов
hasServices=$COUNT$ доступные сервисы hasServices=$COUNT$ доступные сервисы
hasService=$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 noServices=Mevcut hizmet yok
hasServices=$COUNT$ mevcut hi̇zmetler hasServices=$COUNT$ mevcut hi̇zmetler
hasService=$COUNT$ mevcut hizmet hasService=$COUNT$ mevcut hizmet
openHttp=ık HTTP hizmeti
openHttps=HTTPS hizmetini açın

View file

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