Skip to content

Commit

Permalink
seems to almost work
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellacosse committed Feb 9, 2024
1 parent 69bdfd7 commit f2ac0af
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 1 deletion.
8 changes: 8 additions & 0 deletions resources/original_messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,14 @@
"description": "The success message after renaming a server in the application.",
"message": "Server renamed"
},
"server_share": {
"description": "The text of an option displayed in a server card's options menu to tell the application to share the server's access key with another application.",
"message": "Share"
},
"server_share_text": {
"description": "The text of a message that appears when the user clicks the Share option in a server card's options menu.",
"message": "This is an access key for an Outline Server. To use it, download the Outline app from the App Store or Google Play."
},
"servers_menu_item": {
"description": "The menu item text to navigate to the list of servers.",
"message": "Servers"
Expand Down
23 changes: 23 additions & 0 deletions src/www/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ export class App {
this.rootEl.addEventListener('DisconnectPressed', this.disconnectServer.bind(this));
this.rootEl.addEventListener('ForgetPressed', this.forgetServer.bind(this));
this.rootEl.addEventListener('RenameRequested', this.renameServer.bind(this));
this.rootEl.addEventListener('ForgetPressed', this.forgetServer.bind(this));
this.rootEl.addEventListener('ShareServer', this.shareServer.bind(this));

Check warning on line 134 in src/www/app/app.ts

View check run for this annotation

Codecov / codecov/patch

src/www/app/app.ts#L133-L134

Added lines #L133 - L134 were not covered by tests
this.rootEl.addEventListener('QuitPressed', this.quitApplication.bind(this));
this.rootEl.addEventListener('AutoConnectDialogDismissed', this.autoConnectDialogDismissed.bind(this));
this.rootEl.addEventListener('ShowServerRename', this.rootEl.showServerRename.bind(this.rootEl));
Expand Down Expand Up @@ -378,6 +380,23 @@ export class App {
this.serverRepo.rename(serverId, newName);
}

private async shareServer(event: CustomEvent) {

Check warning on line 383 in src/www/app/app.ts

View check run for this annotation

Codecov / codecov/patch

src/www/app/app.ts#L383

Added line #L383 was not covered by tests
const {serverId} = event.detail;
const server = this.getServerByServerId(serverId);

// TODO: fallback to copying to clipboard if share is not available

Check warning on line 387 in src/www/app/app.ts

View check run for this annotation

Codecov / codecov/patch

src/www/app/app.ts#L385-L387

Added lines #L385 - L387 were not covered by tests
if (!navigator.share) {
console.warn('Web Share API not available');
return;

Check warning on line 390 in src/www/app/app.ts

View check run for this annotation

Codecov / codecov/patch

src/www/app/app.ts#L389-L390

Added lines #L389 - L390 were not covered by tests
}

await navigator.share({
title: server.name || 'Outline Server',
text: this.localize('share-server-text'),
url: server.accessKey,
});
}

Check warning on line 399 in src/www/app/app.ts

View check run for this annotation

Codecov / codecov/patch

src/www/app/app.ts#L395-L399

Added lines #L395 - L399 were not covered by tests
private async connectServer(event: CustomEvent) {
event.stopImmediatePropagation();

Expand Down Expand Up @@ -614,6 +633,10 @@ export class App {
email: extraParams.email,
};
}

Check warning on line 636 in src/www/app/app.ts

View check run for this annotation

Codecov / codecov/patch

src/www/app/app.ts#L636

Added line #L636 was not covered by tests
if (extraParams.share) {
serverListItem.canShare = true;
}

Check warning on line 639 in src/www/app/app.ts

View check run for this annotation

Codecov / codecov/patch

src/www/app/app.ts#L639

Added line #L639 was not covered by tests
}

return serverListItem;
Expand Down
1 change: 1 addition & 0 deletions src/www/app/outline_server_repository/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class OutlineServer implements Server {
break;
case ServerType.STATIC_CONNECTION:
default:
this.accessKey = accessKey;
this.sessionConfig = staticKeyToShadowsocksSessionConfig(accessKey);
break;
}
Expand Down
2 changes: 2 additions & 0 deletions src/www/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@
"server-forgotten-undo": "Server “{serverName}” has been restored.",
"server-rename": "Rename",
"server-rename-complete": "Server renamed",
"server-share": "Share",
"server-share-text": "This is an access key for an Outline Server. To use it, download the Outline app from the App Store or Google Play.",
"servers-menu-item": "Servers",
"servers-page-title": "Outline",
"submit": "Submit",
Expand Down
3 changes: 3 additions & 0 deletions src/www/model/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export interface Server {
// A type specifying the manner in which the Server connects.
readonly type: ServerType;

// The access key used to connect to the server.
accessKey: string;

// The name of this server, as given by the user.
name: string;

Expand Down
2 changes: 2 additions & 0 deletions src/www/views/servers_view/server_list_item/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export enum ServerListItemEvent {
DISCONNECT = 'DisconnectPressed',
FORGET = 'ForgetPressed',
RENAME = 'ShowServerRename',
SHARE = 'ShareServer',
}

/**
Expand All @@ -41,6 +42,7 @@ export interface ServerListItem {
contact?: {
email: string;
};
canShare?: boolean;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import '@material/mwc-icon-button';
import '@material/mwc-menu';
import '../../server_connection_indicator';

import {css, html, LitElement} from 'lit';
import {css, html, LitElement, nothing} from 'lit';
import {customElement, property} from 'lit/decorators.js';
import {createRef, Ref, ref} from 'lit/directives/ref.js';

Expand Down Expand Up @@ -200,6 +200,10 @@ const getSharedComponents = (element: ServerListItemElement & LitElement) => {
element.dispatchEvent(
new CustomEvent(ServerListItemEvent.FORGET, {detail: {serverId: server.id}, bubbles: true, composed: true})
),
share: () =>
element.dispatchEvent(
new CustomEvent(ServerListItemEvent.SHARE, {detail: {serverId: server.id}, bubbles: true, composed: true})
),

Check warning on line 206 in src/www/views/servers_view/server_list_item/server_card/index.ts

View check run for this annotation

Codecov / codecov/patch

src/www/views/servers_view/server_list_item/server_card/index.ts#L204-L206

Added lines #L204 - L206 were not covered by tests
connectToggle: () =>
element.dispatchEvent(
new CustomEvent(isConnectedState ? ServerListItemEvent.DISCONNECT : ServerListItemEvent.CONNECT, {
Expand Down Expand Up @@ -237,6 +241,9 @@ const getSharedComponents = (element: ServerListItemElement & LitElement) => {
`,
menu: html`
<mwc-menu ${ref(menu)} menuCorner="END">
${server.canShare
? html`<mwc-list-item @click="${dispatchers.share}">${localize('server-share')}</mwc-list-item>`
: nothing}
<mwc-list-item @click="${dispatchers.beginRename}">${localize('server-rename')}</mwc-list-item>
<mwc-list-item @click="${dispatchers.forget}">${localize('server-forget')}</mwc-list-item>
</mwc-menu>
Expand Down

0 comments on commit f2ac0af

Please sign in to comment.