fix launchUI button

This commit is contained in:
Aiden McClelland
2024-07-25 16:14:04 -06:00
parent 854044229c
commit 370c38ec76
7 changed files with 59 additions and 43 deletions

View File

@@ -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,

View File

@@ -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)
"

View File

@@ -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)
}
}

View File

@@ -56,13 +56,13 @@
</ion-button>
<ion-button
*ngIf="pkgStatus && interfaces && (interfaces | hasUi)"
*ngIf="pkgStatus && interfaces && (interfaces | hasUi) && hosts"
class="action-button"
color="primary"
[disabled]="
!(pkg.stateInfo.state | isLaunchable: pkgStatus.main.status)
"
(click)="launchUi(interfaces)"
(click)="launchUi(interfaces, hosts)"
>
<ion-icon slot="start" name="open-outline"></ion-icon>
Launch UI

View File

@@ -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<void> {

View File

@@ -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

View File

@@ -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',
)