From 370c38ec76d6d5429f894a27c9c282bc7f7d478f Mon Sep 17 00:00:00 2001 From: Aiden McClelland Date: Thu, 25 Jul 2024 16:14:04 -0600 Subject: [PATCH] fix launchUI button --- .../Systems/SystemForEmbassy/index.ts | 6 +- .../app-list-pkg/app-list-pkg.component.html | 2 +- .../app-list-pkg/app-list-pkg.component.ts | 8 ++- .../app-show-status.component.html | 4 +- .../app-show-status.component.ts | 11 +++- .../ui/src/app/services/config.service.ts | 62 +++++++++---------- .../src/app/services/ui-launcher.service.ts | 9 +-- 7 files changed, 59 insertions(+), 43 deletions(-) diff --git a/container-runtime/src/Adapters/Systems/SystemForEmbassy/index.ts b/container-runtime/src/Adapters/Systems/SystemForEmbassy/index.ts index 2e0836bb0..eabe1401d 100644 --- a/container-runtime/src/Adapters/Systems/SystemForEmbassy/index.ts +++ b/container-runtime/src/Adapters/Systems/SystemForEmbassy/index.ts @@ -444,7 +444,11 @@ export class SystemForEmbassy implements System { description: interfaceValue.description, hasPrimary: false, disabled: false, - type: "api", + type: + interfaceValue.ui && + (origin.scheme === "http" || origin.sslScheme === "https") + ? "ui" + : "api", masked: false, path: "", schemeOverride: null, diff --git a/web/projects/ui/src/app/pages/apps-routes/app-list/app-list-pkg/app-list-pkg.component.html b/web/projects/ui/src/app/pages/apps-routes/app-list/app-list-pkg/app-list-pkg.component.html index e353cf9b2..8225d7e53 100644 --- a/web/projects/ui/src/app/pages/apps-routes/app-list/app-list-pkg/app-list-pkg.component.html +++ b/web/projects/ui/src/app/pages/apps-routes/app-list/app-list-pkg/app-list-pkg.component.html @@ -25,7 +25,7 @@ slot="end" fill="clear" color="primary" - (click)="launchUi($event, pkg.entry.serviceInterfaces)" + (click)="launchUi($event, pkg.entry.serviceInterfaces, pkg.entry.hosts)" [disabled]=" !(pkg.entry.stateInfo.state | isLaunchable : pkgMainStatus.status) " diff --git a/web/projects/ui/src/app/pages/apps-routes/app-list/app-list-pkg/app-list-pkg.component.ts b/web/projects/ui/src/app/pages/apps-routes/app-list/app-list-pkg/app-list-pkg.component.ts index 4df818956..1464ac8a2 100644 --- a/web/projects/ui/src/app/pages/apps-routes/app-list/app-list-pkg/app-list-pkg.component.ts +++ b/web/projects/ui/src/app/pages/apps-routes/app-list/app-list-pkg/app-list-pkg.component.ts @@ -27,9 +27,13 @@ export class AppListPkgComponent { return this.pkgMainStatus.status === 'stopping' ? '30s' : null // @dr-bonez TODO } - launchUi(e: Event, interfaces: PackageDataEntry['serviceInterfaces']): void { + launchUi( + e: Event, + interfaces: PackageDataEntry['serviceInterfaces'], + hosts: PackageDataEntry['hosts'], + ): void { e.stopPropagation() e.preventDefault() - this.launcherService.launch(interfaces) + this.launcherService.launch(interfaces, hosts) } } diff --git a/web/projects/ui/src/app/pages/apps-routes/app-show/components/app-show-status/app-show-status.component.html b/web/projects/ui/src/app/pages/apps-routes/app-show/components/app-show-status/app-show-status.component.html index be7bc1c30..c5d18907c 100644 --- a/web/projects/ui/src/app/pages/apps-routes/app-show/components/app-show-status/app-show-status.component.html +++ b/web/projects/ui/src/app/pages/apps-routes/app-show/components/app-show-status/app-show-status.component.html @@ -56,13 +56,13 @@ Launch UI diff --git a/web/projects/ui/src/app/pages/apps-routes/app-show/components/app-show-status/app-show-status.component.ts b/web/projects/ui/src/app/pages/apps-routes/app-show/components/app-show-status/app-show-status.component.ts index 186bbe39a..308db67be 100644 --- a/web/projects/ui/src/app/pages/apps-routes/app-show/components/app-show-status/app-show-status.component.ts +++ b/web/projects/ui/src/app/pages/apps-routes/app-show/components/app-show-status/app-show-status.component.ts @@ -55,6 +55,10 @@ export class AppShowStatusComponent { return this.pkg.serviceInterfaces } + get hosts(): PackageDataEntry['hosts'] { + return this.pkg.hosts + } + get pkgStatus(): T.Status { return this.pkg.status } @@ -79,8 +83,11 @@ export class AppShowStatusComponent { return this.pkgStatus?.main.status === 'stopping' ? '30s' : null // @dr-bonez TODO } - launchUi(interfaces: PackageDataEntry['serviceInterfaces']): void { - this.launcherService.launch(interfaces) + launchUi( + interfaces: PackageDataEntry['serviceInterfaces'], + hosts: PackageDataEntry['hosts'], + ): void { + this.launcherService.launch(interfaces, hosts) } async presentModalConfig(): Promise { diff --git a/web/projects/ui/src/app/services/config.service.ts b/web/projects/ui/src/app/services/config.service.ts index 42116bdd8..a148112f0 100644 --- a/web/projects/ui/src/app/services/config.service.ts +++ b/web/projects/ui/src/app/services/config.service.ts @@ -59,50 +59,50 @@ export class ConfigService { /** ${scheme}://${username}@${host}:${externalPort}${suffix} */ launchableAddress( interfaces: PackageDataEntry['serviceInterfaces'], - host: T.Host, + hosts: PackageDataEntry['hosts'], ): string { - const ui = Object.values(interfaces).find(i => i.type === 'ui') + const ui = Object.values(interfaces).find( + i => + i.type === 'ui' && + (i.addressInfo.scheme === 'http' || + i.addressInfo.sslScheme === 'https'), + ) // TODO: select if multiple if (!ui) return '' + const hostnameInfo = + hosts[ui.addressInfo.hostId]?.hostnameInfo[ui.addressInfo.internalPort] + + console.debug(hostnameInfo) + + if (!hostnameInfo) return '' + const addressInfo = ui.addressInfo - const scheme = this.isHttps() ? 'https' : 'http' + const scheme = this.isHttps() + ? ui.addressInfo.sslScheme === 'https' + ? 'https' + : 'http' + : ui.addressInfo.scheme === 'http' + ? 'http' + : 'https' const username = addressInfo.username ? addressInfo.username + '@' : '' const suffix = addressInfo.suffix || '' const url = new URL(`${scheme}://${username}placeholder${suffix}`) - if (host.kind === 'multi') { - const onionHostname = host.addresses.find(h => h.kind === 'onion') - ?.address as T.OnionHostname | undefined + const onionHostname = hostnameInfo.find(h => h.kind === 'onion') + ?.hostname as T.OnionHostname | undefined - if (!onionHostname) - throw new Error('Expecting that there is an onion hostname') - - if (this.isTor() && onionHostname) { - url.hostname = onionHostname.value - } - // TODO Handle single - // else { - // const ipHostname = host.addresses.find(h => h.kind === 'ip') - // ?.hostname as T.ExportedIpHostname - - // if (!ipHostname) return '' - - // url.hostname = this.hostname - // url.port = String(ipHostname.sslPort || ipHostname.port) - // } + if (this.isTor() && onionHostname) { + url.hostname = onionHostname.value } else { - throw new Error('unimplemented') - // const hostname = {} as T.ExportedHostnameInfo // host.hostname + const ipHostname = hostnameInfo.find(h => h.kind === 'ip')?.hostname as + | T.IpHostname + | undefined - // if (!hostname) return '' + if (!ipHostname) return '' - // if (this.isTor() && hostname.kind === 'onion') { - // url.hostname = (hostname.hostname as T.ExportedOnionHostname).value - // } else { - // url.hostname = this.hostname - // url.port = String(hostname.hostname.sslPort || hostname.hostname.port) - // } + url.hostname = this.hostname + url.port = String(ipHostname.sslPort || ipHostname.port) } return url.href diff --git a/web/projects/ui/src/app/services/ui-launcher.service.ts b/web/projects/ui/src/app/services/ui-launcher.service.ts index 9c36036f3..7c3475fc0 100644 --- a/web/projects/ui/src/app/services/ui-launcher.service.ts +++ b/web/projects/ui/src/app/services/ui-launcher.service.ts @@ -13,11 +13,12 @@ export class UiLauncherService { private readonly config: ConfigService, ) {} - launch(interfaces: PackageDataEntry['serviceInterfaces']): void { - // TODO @Matt - const host = {} as any + launch( + interfaces: PackageDataEntry['serviceInterfaces'], + hosts: PackageDataEntry['hosts'], + ): void { this.windowRef.open( - this.config.launchableAddress(interfaces, host), + this.config.launchableAddress(interfaces, hosts), '_blank', 'noreferrer', )