|
6 | 6 | import { EventName, GcpdTab, StatusIcon, SyncStatus } from '../../types/enums'; |
7 | 7 | import { isRuntimeMessage, isSyncStatusEventBody, SyncStatusEventBody } from '../../types/interfaces'; |
8 | 8 |
|
| 9 | +interface StatusLoginMessage { |
| 10 | + loginMessage: string; |
| 11 | + loginUrl: string; |
| 12 | + message: string; |
| 13 | +} |
| 14 | + |
9 | 15 | export class Sync { |
10 | 16 | protected readonly statusIconElement = document.querySelector('#status-icon') as HTMLImageElement | null; |
11 | 17 | protected readonly statusMessageElement = document.querySelector('#status-message') as HTMLElement | null; |
@@ -44,7 +50,19 @@ export class Sync { |
44 | 50 | console.info(new Date().toJSON(), '[SyncStatus]', JSON.stringify(data)); |
45 | 51 |
|
46 | 52 | if (this.statusMessageElement) { |
47 | | - this.statusMessageElement.innerText = this.getStatusMessage(data); |
| 53 | + const statusMessage = this.getStatusMessage(data); |
| 54 | + |
| 55 | + if (typeof statusMessage === 'string') { |
| 56 | + this.statusMessageElement.innerText = statusMessage; |
| 57 | + } else { |
| 58 | + this.statusMessageElement.innerText = statusMessage.message; |
| 59 | + |
| 60 | + const anchor = document.createElement('a'); |
| 61 | + anchor.href = statusMessage.loginUrl; |
| 62 | + anchor.target = '_blank'; |
| 63 | + anchor.innerText = statusMessage.loginMessage; |
| 64 | + this.statusMessageElement.appendChild(anchor); |
| 65 | + } |
48 | 66 | } |
49 | 67 |
|
50 | 68 | if (this.statusIconElement) { |
@@ -89,23 +107,38 @@ export class Sync { |
89 | 107 | } |
90 | 108 | } |
91 | 109 |
|
92 | | - protected getStatusMessage(data: SyncStatusEventBody): string { |
| 110 | + protected getStatusMessage(data: SyncStatusEventBody): string | StatusLoginMessage { |
93 | 111 | switch (data.status) { |
94 | 112 | case SyncStatus.BEGINNING_SYNC: return `Requesting matches from Steam... (${data.tab === GcpdTab.WINGMAN ? 'Wingman' : 'Unranked 5v5'})`; |
95 | 113 | case SyncStatus.FINISHED_GCPD: return `Received ${data.found === 1 ? 'one match' : `${data.found} matches`} from Steam.`; |
96 | 114 | case SyncStatus.FINISHED_SYNC: return `Synchronized ${data.tab === GcpdTab.WINGMAN ? 'Wingman' : 'Unranked 5v5'} matches.`; |
97 | 115 | case SyncStatus.GCPD_PARSER_INITIALIZED: return 'Steam GCPD response handler prepared.'; |
98 | 116 | case SyncStatus.GCPD_PARSER_INITIALIZING: return 'Preparing Steam GCPD response handler...'; |
99 | 117 | case SyncStatus.IDLE: return 'Idle. Press the button to sync your matches.'; |
100 | | - case SyncStatus.INVALID_GCPD_RESPONSE: return 'Something went wrong (GCPD). Please make sure you\'re logged in to Steam.'; |
101 | | - case SyncStatus.LEETIFY_AUTH_FAILED: return 'Could not authenticate with Leetify. Please make sure you\'re logged in.'; |
102 | 118 | case SyncStatus.LEETIFY_AUTH_SUCCESSFUL: return 'Logged in to Leetify.'; |
103 | 119 | case SyncStatus.REQUESTING_GCPD_PAGE: return `Requesting matches from Steam... (Iteration ${data.depth} of up to 16)`; |
104 | | - case SyncStatus.STEAM_AUTH_FAILED: return 'Could not authenticate with Steam. Please make sure you\'re logged in.'; |
105 | 120 | case SyncStatus.UPLOADING_TO_LEETIFY_FAILED: return 'Could not upload matches to Leetify :('; |
106 | 121 | case SyncStatus.UPLOADING_TO_LEETIFY: return 'Uploading matches to Leetify...'; |
107 | 122 | case SyncStatus.WAITING_FOR_LEETIFY_AUTH: return 'Logging in to Leetify...'; |
108 | 123 |
|
| 124 | + case SyncStatus.INVALID_GCPD_RESPONSE: return { |
| 125 | + message: 'Something went wrong (GCPD).', |
| 126 | + loginMessage: 'Please make sure you\'re logged in to Steam.', |
| 127 | + loginUrl: 'https://steamcommunity.com/my/gcpd/730?tab=matchhistoryscrimmage', |
| 128 | + }; |
| 129 | + |
| 130 | + case SyncStatus.LEETIFY_AUTH_FAILED: return { |
| 131 | + message: 'Could not authenticate with Leetify.', |
| 132 | + loginMessage: 'Please make sure you\'re logged in.', |
| 133 | + loginUrl: 'https://leetify.com/auth/login', |
| 134 | + }; |
| 135 | + |
| 136 | + case SyncStatus.STEAM_AUTH_FAILED: return { |
| 137 | + message: 'Could not authenticate with Steam.', |
| 138 | + loginMessage: 'Please make sure you\'re logged in.', |
| 139 | + loginUrl: 'https://steamcommunity.com/my/gcpd/730?tab=matchhistoryscrimmage', |
| 140 | + }; |
| 141 | + |
109 | 142 | case SyncStatus.DONE: { |
110 | 143 | const now = new Date(); |
111 | 144 | const f = (n: number): string => n.toString().padStart(2, '0'); |
|
0 commit comments