Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellacosse committed Oct 13, 2023
1 parent 421758b commit 793c640
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 13 deletions.
4 changes: 3 additions & 1 deletion x/examples/outline-connectivity-app/app_mobile/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ SharedFrontend.registerAllElements();
@customElement("app-main")
export class AppMain extends LitElement {
render() {
return html`<connectivity-test-page .onSubmit=${
return html`<connectivity-test-page
.resolvePlatform=${() => requestBackend<void, SharedFrontend.PlatformMetadata>("PlatformMetadata", void 0)}
.onSubmit=${
(parameters: ConnectivityTestRequest) =>
requestBackend<ConnectivityTestRequest, ConnectivityTestResponse>(
"ConnectivityTest", parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func HandleRequest(rawRequest []byte) []byte {

result, resultError = ConnectivityTest(parameters)
} else if request.ResourceName == "Platform" {
result = Platform(parameters)
result = Platform()
} else {
response.Error = "HandleRequest: method name not found"
}
Expand Down
2 changes: 1 addition & 1 deletion x/examples/outline-connectivity-app/shared_backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ type PlatformMetadata struct {
}

func Platform() PlatformMetadata {
return []PlatformMetadata{ OS: runtime.GOOS }
return PlatformMetadata{OS: runtime.GOOS}
}

func makeErrorRecord(err error) *ConnectivityTestError {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
// limitations under the License.

import { configureLocalization, msg, localized } from "@lit/localize";
import { css, html, LitElement } from "lit";
import { css, html, LitElement, nothing } from "lit";
import { property } from "lit/decorators.js";
import { sourceLocale, targetLocales } from "./generated/messages";
import type { ConnectivityTestRequest, ConnectivityTestResponse, ConnectivityTestResult } from "./types";
import { ConnectivityTestRequest, ConnectivityTestResponse, ConnectivityTestResult, OperatingSystem, PlatformMetadata } from "./types";

export * from "./types";

Expand All @@ -31,14 +31,20 @@ const Localization = configureLocalization({
// @ts-ignore-next-line
@localized()
export class ConnectivityTestPage extends LitElement {
@property({ type: Function })
resolvePlatform?: () => Promise<PlatformMetadata>;

@property({ type: Function })
onSubmit?: (request: ConnectivityTestRequest) => Promise<ConnectivityTestResponse>;

@property({ attribute: false })
platform?: PlatformMetadata;

@property({ attribute: false })
isSubmitting = false;

@property({ attribute: false })
testResponse: ConnectivityTestResponse = null;
testResponse?: ConnectivityTestResponse;

get locale() {
return Localization.getLocale();
Expand Down Expand Up @@ -84,6 +90,14 @@ export class ConnectivityTestPage extends LitElement {
};
}

protected async performUpdate() {
if (!this.platform && this.resolvePlatform) {
this.platform = await this.resolvePlatform();
}

super.performUpdate();
}

async testConnectivity(event: SubmitEvent) {
event.preventDefault();

Expand Down Expand Up @@ -572,17 +586,13 @@ export class ConnectivityTestPage extends LitElement {
.field-header-info {
display: none;
}
/* if ios */
.header {
padding-top: 3.7rem;
}
}
`;

render() {
// TODO: move language definitions to a centralized place
return html`<main dir="${this.locale === "fa-IR" ? "rtl" : "ltr"}">
${this.renderPlatformStyles()}
<header class="header">
<h1 class="header-text">${msg("Outline Connectivity Test")}</h1>
</header>
Expand Down Expand Up @@ -742,9 +752,28 @@ export class ConnectivityTestPage extends LitElement {
</main>`;
}

renderPlatformStyles() {
if (!this.platform) {
return nothing;
}

// TODO: changes how switches look on android
switch (this.platform.operatingSystem) {
case OperatingSystem.IOS:
return html`
<style>
.header {
padding-top: 3.7rem;
}
</style>`;
default:
return nothing;
}
}

renderResults() {
if (!this.testResponse) {
return;
return nothing;
}

return html`<dialog open class="results">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,16 @@ export interface ConnectivityTestResult {
};
}

export type ConnectivityTestResponse = ConnectivityTestResult[] | Error | null;
export type ConnectivityTestResponse = ConnectivityTestResult[] | Error | null;

export enum OperatingSystem {
ANDROID = "android",
IOS = "ios",
LINUX = "linux",
MACOS = "darwin",
WINDOWS = "windows"
}

export interface PlatformMetadata {
operatingSystem: OperatingSystem;
}

0 comments on commit 793c640

Please sign in to comment.