@jetpack-desktop/client 0.1.2-rc.2 → 0.1.3-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,50 @@
1
+ import { resolveJetPackDownloadUrl } from './download-url.js';
2
+ import { createI18n, resolveLanguage } from './i18n.js';
1
3
  const DEFAULT_CONTROL_CENTER_URL = 'http://127.0.0.1:9470/#apps';
2
- const DEFAULT_CONFIRM_TITLE = 'Stop Worker Process?';
3
- const DEFAULT_CONFIRM_MESSAGE = 'Stopping this worker may discard unsaved work or active tasks. Do you want to continue?';
4
+ const CONTROL_BAR_LOCALES = {
5
+ en: {
6
+ defaultAppName: 'JetPack App',
7
+ statusConnecting: 'Connecting',
8
+ statusRunning: 'Running',
9
+ statusStopped: 'Stopped',
10
+ statusError: 'Error',
11
+ downloadJetpack: 'Download JetPack',
12
+ controlCenter: 'Control Center',
13
+ launch: 'Launch',
14
+ launching: 'Launching...',
15
+ stop: 'Stop',
16
+ stopping: 'Stopping...',
17
+ modalTitle: 'Stop Worker Process?',
18
+ modalMessage: 'Stopping this worker may discard unsaved work or active tasks. Do you want to continue?',
19
+ modalCancel: 'Cancel',
20
+ modalConfirm: 'Stop Worker',
21
+ poweredBy: 'Powered by JetPack',
22
+ installWaitText: 'Click "Download JetPack" above — waiting for JetPack to start...',
23
+ installDefaultMessage: 'To use {appName}, install and run the free JetPack app.',
24
+ installPosterAlt: '{appName} poster',
25
+ },
26
+ uk: {
27
+ defaultAppName: 'Застосунок JetPack',
28
+ statusConnecting: 'Підключення',
29
+ statusRunning: 'Працює',
30
+ statusStopped: 'Зупинено',
31
+ statusError: 'Помилка',
32
+ downloadJetpack: 'Завантажити JetPack',
33
+ controlCenter: 'Центр керування',
34
+ launch: 'Запустити',
35
+ launching: 'Запуск...',
36
+ stop: 'Зупинити',
37
+ stopping: 'Зупинення...',
38
+ modalTitle: 'Зупинити робочий процес?',
39
+ modalMessage: 'Зупинка цього процесу може призвести до втрати незбереженої роботи або активних завдань. Продовжити?',
40
+ modalCancel: 'Скасувати',
41
+ modalConfirm: 'Зупинити процес',
42
+ poweredBy: 'Працює на JetPack',
43
+ installWaitText: 'Натисніть «Завантажити JetPack» угорі — очікування запуску JetPack...',
44
+ installDefaultMessage: 'Щоб користуватися {appName}, встановіть і запустіть безкоштовний застосунок JetPack.',
45
+ installPosterAlt: 'Постер {appName}',
46
+ },
47
+ };
4
48
  const CONTROL_BAR_STYLES = `
5
49
  :host {
6
50
  all: initial;
@@ -74,6 +118,25 @@ const CONTROL_BAR_STYLES = `
74
118
  text-overflow: ellipsis;
75
119
  }
76
120
 
121
+ .jp-env-badge {
122
+ display: inline-flex;
123
+ align-items: center;
124
+ padding: 2px 7px;
125
+ border-radius: 999px;
126
+ font-size: 10px;
127
+ font-weight: 700;
128
+ letter-spacing: 0.06em;
129
+ text-transform: uppercase;
130
+ color: #f0b72f;
131
+ background: rgba(210, 153, 34, 0.16);
132
+ border: 1px solid rgba(210, 153, 34, 0.48);
133
+ flex-shrink: 0;
134
+ }
135
+
136
+ .jp-env-badge[hidden] {
137
+ display: none;
138
+ }
139
+
77
140
  .jp-right {
78
141
  display: flex;
79
142
  align-items: center;
@@ -160,8 +223,7 @@ const CONTROL_BAR_STYLES = `
160
223
  }
161
224
 
162
225
  .jp-link-btn,
163
- .jp-relaunch-btn,
164
- .jp-stop-btn,
226
+ .jp-action-btn,
165
227
  .jp-modal-btn {
166
228
  appearance: none;
167
229
  font: inherit;
@@ -191,37 +253,32 @@ const CONTROL_BAR_STYLES = `
191
253
  }
192
254
 
193
255
  .jp-download-btn,
194
- .jp-relaunch-btn {
256
+ .jp-action-btn[data-jp-action="launch"] {
195
257
  color: #ffffff;
196
258
  background: #1f6feb;
197
259
  border: 1px solid #388bfd;
198
260
  }
199
261
 
200
262
  .jp-download-btn:hover,
201
- .jp-relaunch-btn:hover:not(:disabled) {
263
+ .jp-action-btn[data-jp-action="launch"]:hover:not(:disabled) {
202
264
  background: #388bfd;
203
265
  border-color: #58a6ff;
204
266
  color: #ffffff;
205
267
  }
206
268
 
207
- .jp-relaunch-btn:disabled {
208
- opacity: 0.55;
209
- cursor: not-allowed;
210
- }
211
-
212
- .jp-stop-btn {
269
+ .jp-action-btn[data-jp-action="stop"] {
213
270
  color: #ffdcd9;
214
271
  background: rgba(248, 81, 73, 0.18);
215
272
  border: 1px solid rgba(248, 81, 73, 0.5);
216
273
  }
217
274
 
218
- .jp-stop-btn:hover:not(:disabled) {
275
+ .jp-action-btn[data-jp-action="stop"]:hover:not(:disabled) {
219
276
  background: rgba(248, 81, 73, 0.3);
220
277
  border-color: #f85149;
221
278
  color: #ffffff;
222
279
  }
223
280
 
224
- .jp-stop-btn:disabled {
281
+ .jp-action-btn:disabled {
225
282
  opacity: 0.45;
226
283
  cursor: not-allowed;
227
284
  }
@@ -544,24 +601,6 @@ function isLoopbackHost(hostname) {
544
601
  const lower = hostname.toLowerCase();
545
602
  return lower === '127.0.0.1' || lower === 'localhost' || lower === '[::1]' || lower === '::1';
546
603
  }
547
- function sanitizeHttpsDownloadUrl(rawUrl) {
548
- if (typeof rawUrl !== 'string')
549
- return null;
550
- const trimmed = rawUrl.trim();
551
- if (!trimmed || /[\s\u0000-\u001f\u007f]/.test(trimmed)) {
552
- return null;
553
- }
554
- try {
555
- const parsed = new URL(trimmed);
556
- if (parsed.protocol !== 'https:' || parsed.username || parsed.password) {
557
- return null;
558
- }
559
- return parsed.toString();
560
- }
561
- catch {
562
- return null;
563
- }
564
- }
565
604
  export function sanitizePosterUrl(rawUrl) {
566
605
  if (typeof rawUrl !== 'string')
567
606
  return null;
@@ -645,16 +684,17 @@ function clamp(val, min, max) {
645
684
  * Shadow-DOM isolated top control bar for standalone and third-party JetPack web applications.
646
685
  *
647
686
  * Displays the JetPack logo, current app name, live worker status (`Connecting`, `Running`,
648
- * `Stopped`, `Error`), `"Control Center"` link, `"Stop"` button, an encapsulated confirmation
649
- * modal when stopping could lose unsaved work, and a blocking install-gate overlay when
650
- * JetPack Desktop is unreachable (`DAEMON_NOT_RUNNING`).
687
+ * `Stopped`, `Error`), `"Control Center"` link, unified `"Launch"` / `"Stop"` action button,
688
+ * an encapsulated confirmation modal when stopping could lose unsaved work, and a blocking
689
+ * install-gate overlay when JetPack Desktop is unreachable (`DAEMON_NOT_RUNNING`).
651
690
  */
652
691
  export class JetPackControlBar {
653
692
  options;
693
+ i18n;
654
694
  status;
655
695
  currentDownloadUrl = null;
656
696
  stopping = false;
657
- relaunching = false;
697
+ launching = false;
658
698
  modalOpen = false;
659
699
  posterLoadFailed = false;
660
700
  lastResolvedPosterUrl = null;
@@ -662,14 +702,14 @@ export class JetPackControlBar {
662
702
  shadow = null;
663
703
  headerEl = null;
664
704
  appNameEl = null;
705
+ envBadgeEl = null;
665
706
  statusPillEl = null;
666
707
  statusTextEl = null;
667
708
  errorNoteEl = null;
668
709
  statusNoteEl = null;
669
710
  downloadLinkEl = null;
670
711
  controlCenterLinkEl = null;
671
- relaunchBtnEl = null;
672
- stopBtnEl = null;
712
+ actionBtnEl = null;
673
713
  modalBackdropEl = null;
674
714
  modalTitleEl = null;
675
715
  modalMessageEl = null;
@@ -682,8 +722,10 @@ export class JetPackControlBar {
682
722
  installPosterImgEl = null;
683
723
  installPosterFallbackEl = null;
684
724
  installPosterAppNameEl = null;
725
+ installPosterPoweredEl = null;
685
726
  installMessageBoxEl = null;
686
727
  installMessageEl = null;
728
+ installWaitTextEl = null;
687
729
  installArrowSvgEl = null;
688
730
  installArrowPathEl = null;
689
731
  keydownHandler = null;
@@ -693,13 +735,34 @@ export class JetPackControlBar {
693
735
  arrowRafId = null;
694
736
  constructor(options = {}) {
695
737
  this.options = { ...options };
738
+ const initialLocale = options.language !== undefined
739
+ ? resolveLanguage({
740
+ preferredLanguage: options.language,
741
+ search: '',
742
+ supportedLocales: ['en', 'uk'],
743
+ })
744
+ : resolveLanguage({ supportedLocales: ['en', 'uk'] });
745
+ this.i18n = createI18n({
746
+ catalogs: CONTROL_BAR_LOCALES,
747
+ initialLocale,
748
+ });
696
749
  this.status = options.initialStatus ?? 'Connecting';
697
750
  this.currentDownloadUrl =
698
- this.status === 'Error' ? sanitizeHttpsDownloadUrl(options.downloadUrl) : null;
751
+ this.status === 'Error' ? resolveJetPackDownloadUrl(options.downloadUrl) : null;
699
752
  if (typeof document !== 'undefined' && options.mountTarget !== null) {
700
753
  this.mount(options.mountTarget);
701
754
  }
702
755
  }
756
+ /** Returns the currently active UI language (`'en'` or `'uk'`). */
757
+ getLanguage() {
758
+ return this.i18n.getLocale();
759
+ }
760
+ /** Switches the Shadow-DOM chrome language (`'en'` or `'uk'`, falling back to `'en'`) and re-renders immediately. */
761
+ setLanguage(language) {
762
+ this.options.language = language;
763
+ this.i18n.setLocale(language);
764
+ this.syncUi();
765
+ }
703
766
  /** Mounts the control bar host element at the top of `target` (or `document.body`). */
704
767
  mount(target) {
705
768
  if (typeof document === 'undefined') {
@@ -771,6 +834,20 @@ export class JetPackControlBar {
771
834
  this.host = null;
772
835
  this.shadow = null;
773
836
  this.headerEl = null;
837
+ this.appNameEl = null;
838
+ this.envBadgeEl = null;
839
+ this.statusPillEl = null;
840
+ this.statusTextEl = null;
841
+ this.errorNoteEl = null;
842
+ this.statusNoteEl = null;
843
+ this.downloadLinkEl = null;
844
+ this.controlCenterLinkEl = null;
845
+ this.actionBtnEl = null;
846
+ this.modalBackdropEl = null;
847
+ this.modalTitleEl = null;
848
+ this.modalMessageEl = null;
849
+ this.modalCancelBtnEl = null;
850
+ this.modalConfirmBtnEl = null;
774
851
  this.installBannerHost = null;
775
852
  this.installBannerShadow = null;
776
853
  this.installBackdropEl = null;
@@ -778,8 +855,10 @@ export class JetPackControlBar {
778
855
  this.installPosterImgEl = null;
779
856
  this.installPosterFallbackEl = null;
780
857
  this.installPosterAppNameEl = null;
858
+ this.installPosterPoweredEl = null;
781
859
  this.installMessageBoxEl = null;
782
860
  this.installMessageEl = null;
861
+ this.installWaitTextEl = null;
783
862
  this.installArrowSvgEl = null;
784
863
  this.installArrowPathEl = null;
785
864
  }
@@ -792,11 +871,14 @@ export class JetPackControlBar {
792
871
  updateOptions(partial) {
793
872
  const posterChanged = 'posterUrl' in partial || 'installBanner' in partial;
794
873
  this.options = { ...this.options, ...partial };
874
+ if ('language' in partial) {
875
+ this.i18n.setLocale(partial.language);
876
+ }
795
877
  if (posterChanged) {
796
878
  this.posterLoadFailed = false;
797
879
  }
798
880
  if (this.status === 'Error' && 'downloadUrl' in partial) {
799
- this.currentDownloadUrl = sanitizeHttpsDownloadUrl(partial.downloadUrl);
881
+ this.currentDownloadUrl = resolveJetPackDownloadUrl(partial.downloadUrl);
800
882
  }
801
883
  this.syncUi();
802
884
  }
@@ -807,10 +889,11 @@ export class JetPackControlBar {
807
889
  /** Updates the live worker status pill, optional detail text, and optional HTTPS download link. */
808
890
  setStatus(status, detail, statusOptions) {
809
891
  this.status = status;
892
+ if (status === 'Running' || status === 'Error') {
893
+ this.launching = false;
894
+ }
810
895
  this.currentDownloadUrl =
811
- status === 'Error'
812
- ? sanitizeHttpsDownloadUrl(statusOptions?.downloadUrl ?? this.options.downloadUrl)
813
- : null;
896
+ status === 'Error' ? resolveJetPackDownloadUrl(statusOptions?.downloadUrl) : null;
814
897
  if (this.errorNoteEl) {
815
898
  const msg = status === 'Error' && detail ? detail.trim() : '';
816
899
  this.errorNoteEl.textContent = msg;
@@ -865,20 +948,19 @@ export class JetPackControlBar {
865
948
  return this.modalOpen;
866
949
  }
867
950
  /**
868
- * Handles a Relaunch button click while `status === 'Stopped'`.
869
- * Invokes `options.onRelaunch()` and transitions to `'Running'` on success.
951
+ * Handles a Launch button click while `status === 'Stopped'`.
952
+ * Invokes `options.onLaunch()` (or legacy `options.onRelaunch()`) and transitions to `'Running'` on success.
870
953
  */
871
- async triggerRelaunch() {
872
- if (this.status !== 'Stopped' ||
873
- this.relaunching ||
874
- typeof this.options.onRelaunch !== 'function') {
954
+ async triggerLaunch() {
955
+ const launchHandler = this.options.onLaunch ?? this.options.onRelaunch;
956
+ if (this.status !== 'Stopped' || this.launching || typeof launchHandler !== 'function') {
875
957
  return false;
876
958
  }
877
- this.relaunching = true;
959
+ this.launching = true;
878
960
  this.syncUi();
879
961
  try {
880
- await this.options.onRelaunch();
881
- this.relaunching = false;
962
+ await launchHandler();
963
+ this.launching = false;
882
964
  if (this.status === 'Stopped') {
883
965
  this.setStatus('Running');
884
966
  }
@@ -888,12 +970,24 @@ export class JetPackControlBar {
888
970
  return true;
889
971
  }
890
972
  catch (err) {
891
- this.relaunching = false;
973
+ this.launching = false;
892
974
  const error = err instanceof Error ? err : new Error(String(err));
893
- this.setStatus('Error', error.message);
975
+ const dlUrl = err &&
976
+ typeof err === 'object' &&
977
+ 'downloadUrl' in err &&
978
+ typeof err.downloadUrl === 'string'
979
+ ? err.downloadUrl
980
+ : this.status === 'Error'
981
+ ? (this.currentDownloadUrl ?? undefined)
982
+ : undefined;
983
+ this.setStatus('Error', error.message, dlUrl ? { downloadUrl: dlUrl } : undefined);
894
984
  return false;
895
985
  }
896
986
  }
987
+ /** Backwards-compatible alias for `triggerLaunch()`. */
988
+ async triggerRelaunch() {
989
+ return this.triggerLaunch();
990
+ }
897
991
  /**
898
992
  * Handles a Stop button click: opens the styled Shadow-DOM confirmation modal if
899
993
  * `warnOnUnsavedWork` evaluates to `true` or `onBeforeStop` is configured (with
@@ -952,11 +1046,11 @@ export class JetPackControlBar {
952
1046
  openModal() {
953
1047
  this.modalOpen = true;
954
1048
  if (this.modalTitleEl) {
955
- this.modalTitleEl.textContent = this.options.stopConfirmTitle ?? DEFAULT_CONFIRM_TITLE;
1049
+ this.modalTitleEl.textContent = this.options.stopConfirmTitle ?? this.i18n.t('modalTitle');
956
1050
  }
957
1051
  if (this.modalMessageEl) {
958
1052
  this.modalMessageEl.textContent =
959
- this.options.stopConfirmMessage ?? DEFAULT_CONFIRM_MESSAGE;
1053
+ this.options.stopConfirmMessage ?? this.i18n.t('modalMessage');
960
1054
  }
961
1055
  if (this.modalBackdropEl) {
962
1056
  this.modalBackdropEl.hidden = false;
@@ -1038,10 +1132,16 @@ export class JetPackControlBar {
1038
1132
  const appNameEl = document.createElement('span');
1039
1133
  appNameEl.className = 'jp-app-name';
1040
1134
  appNameEl.setAttribute('data-jp-field', 'app-name');
1135
+ const envBadgeEl = document.createElement('span');
1136
+ envBadgeEl.className = 'jp-env-badge';
1137
+ envBadgeEl.setAttribute('data-jp-field', 'env-badge');
1138
+ envBadgeEl.textContent = 'DEV';
1139
+ envBadgeEl.hidden = true;
1041
1140
  left.appendChild(brand);
1042
1141
  left.appendChild(divider);
1043
1142
  left.appendChild(appNameEl);
1044
- // Right cluster: optional error/status note + live status pill + Control Center link + Relaunch + Stop
1143
+ left.appendChild(envBadgeEl);
1144
+ // Right cluster: optional error/status note + live status pill + Control Center link + unified Launch/Stop action button
1045
1145
  const right = document.createElement('div');
1046
1146
  right.className = 'jp-right';
1047
1147
  const errorNoteEl = document.createElement('span');
@@ -1075,30 +1175,25 @@ export class JetPackControlBar {
1075
1175
  ccLink.target = '_blank';
1076
1176
  ccLink.rel = 'noopener noreferrer';
1077
1177
  ccLink.textContent = 'Control Center';
1078
- const relaunchBtn = document.createElement('button');
1079
- relaunchBtn.type = 'button';
1080
- relaunchBtn.className = 'jp-relaunch-btn';
1081
- relaunchBtn.setAttribute('data-jp-action', 'relaunch');
1082
- relaunchBtn.textContent = 'Relaunch';
1083
- relaunchBtn.hidden = true;
1084
- relaunchBtn.addEventListener('click', () => {
1085
- void this.triggerRelaunch();
1086
- });
1087
- const stopBtn = document.createElement('button');
1088
- stopBtn.type = 'button';
1089
- stopBtn.className = 'jp-stop-btn';
1090
- stopBtn.setAttribute('data-jp-action', 'stop');
1091
- stopBtn.textContent = 'Stop';
1092
- stopBtn.addEventListener('click', () => {
1093
- void this.triggerStop();
1178
+ const actionBtn = document.createElement('button');
1179
+ actionBtn.type = 'button';
1180
+ actionBtn.className = 'jp-action-btn';
1181
+ actionBtn.setAttribute('data-jp-action', 'launch');
1182
+ actionBtn.textContent = 'Launch';
1183
+ actionBtn.addEventListener('click', () => {
1184
+ if (this.status === 'Running') {
1185
+ void this.triggerStop();
1186
+ }
1187
+ else if (this.status === 'Stopped') {
1188
+ void this.triggerLaunch();
1189
+ }
1094
1190
  });
1095
1191
  right.appendChild(errorNoteEl);
1096
1192
  right.appendChild(statusNoteEl);
1097
1193
  right.appendChild(downloadLink);
1098
1194
  right.appendChild(statusPillEl);
1099
1195
  right.appendChild(ccLink);
1100
- right.appendChild(relaunchBtn);
1101
- right.appendChild(stopBtn);
1196
+ right.appendChild(actionBtn);
1102
1197
  header.appendChild(left);
1103
1198
  header.appendChild(right);
1104
1199
  shadow.appendChild(header);
@@ -1159,14 +1254,14 @@ export class JetPackControlBar {
1159
1254
  this.shadow = shadow;
1160
1255
  this.headerEl = header;
1161
1256
  this.appNameEl = appNameEl;
1257
+ this.envBadgeEl = envBadgeEl;
1162
1258
  this.statusPillEl = statusPillEl;
1163
1259
  this.statusTextEl = statusTextEl;
1164
1260
  this.errorNoteEl = errorNoteEl;
1165
1261
  this.statusNoteEl = statusNoteEl;
1166
1262
  this.downloadLinkEl = downloadLink;
1167
1263
  this.controlCenterLinkEl = ccLink;
1168
- this.relaunchBtnEl = relaunchBtn;
1169
- this.stopBtnEl = stopBtn;
1264
+ this.actionBtnEl = actionBtn;
1170
1265
  this.modalBackdropEl = backdrop;
1171
1266
  this.modalTitleEl = modalTitle;
1172
1267
  this.modalMessageEl = modalMessage;
@@ -1216,7 +1311,8 @@ export class JetPackControlBar {
1216
1311
  fallbackAppName.setAttribute('data-jp-field', 'install-poster-app-name');
1217
1312
  const poweredLabel = document.createElement('div');
1218
1313
  poweredLabel.className = 'jp-poster-powered';
1219
- poweredLabel.textContent = 'Powered by JetPack';
1314
+ poweredLabel.setAttribute('data-jp-field', 'install-poster-powered');
1315
+ poweredLabel.textContent = this.i18n.t('poweredBy');
1220
1316
  posterFallback.appendChild(grid);
1221
1317
  posterFallback.appendChild(emblem);
1222
1318
  posterFallback.appendChild(fallbackAppName);
@@ -1236,7 +1332,8 @@ export class JetPackControlBar {
1236
1332
  waitDot.className = 'jp-install-wait-dot';
1237
1333
  waitDot.setAttribute('aria-hidden', 'true');
1238
1334
  const waitText = document.createElement('span');
1239
- waitText.textContent = 'Click "Download JetPack" above — waiting for JetPack to start...';
1335
+ waitText.setAttribute('data-jp-field', 'install-wait-text');
1336
+ waitText.textContent = this.i18n.t('installWaitText');
1240
1337
  waitEl.appendChild(waitDot);
1241
1338
  waitEl.appendChild(waitText);
1242
1339
  messageBox.appendChild(messageEl);
@@ -1279,44 +1376,82 @@ export class JetPackControlBar {
1279
1376
  this.installPosterImgEl = posterImg;
1280
1377
  this.installPosterFallbackEl = posterFallback;
1281
1378
  this.installPosterAppNameEl = fallbackAppName;
1379
+ this.installPosterPoweredEl = poweredLabel;
1282
1380
  this.installMessageBoxEl = messageBox;
1283
1381
  this.installMessageEl = messageEl;
1382
+ this.installWaitTextEl = waitText;
1284
1383
  this.installArrowSvgEl = arrowSvg;
1285
1384
  this.installArrowPathEl = arrowPath;
1286
1385
  }
1386
+ getStatusLabel(status) {
1387
+ switch (status) {
1388
+ case 'Connecting':
1389
+ return this.i18n.t('statusConnecting');
1390
+ case 'Running':
1391
+ return this.i18n.t('statusRunning');
1392
+ case 'Stopped':
1393
+ return this.i18n.t('statusStopped');
1394
+ case 'Error':
1395
+ default:
1396
+ return this.i18n.t('statusError');
1397
+ }
1398
+ }
1287
1399
  syncUi() {
1288
- const resolvedName = this.options.appName?.trim() || this.options.appId?.trim() || 'JetPack App';
1400
+ const resolvedName = this.options.appName?.trim() || this.options.appId?.trim() || this.i18n.t('defaultAppName');
1289
1401
  if (this.appNameEl) {
1290
1402
  this.appNameEl.textContent = resolvedName;
1291
1403
  }
1404
+ if (this.envBadgeEl) {
1405
+ this.envBadgeEl.hidden = this.options.env !== 'dev';
1406
+ }
1292
1407
  if (this.statusPillEl) {
1293
1408
  this.statusPillEl.setAttribute('data-status', this.status);
1294
1409
  }
1295
1410
  if (this.statusTextEl) {
1296
- this.statusTextEl.textContent = this.status;
1411
+ this.statusTextEl.textContent = this.getStatusLabel(this.status);
1297
1412
  }
1298
1413
  if (this.downloadLinkEl) {
1299
1414
  const showDownload = this.status === 'Error' && this.currentDownloadUrl !== null;
1300
1415
  this.downloadLinkEl.hidden = !showDownload;
1301
1416
  this.downloadLinkEl.href = showDownload ? this.currentDownloadUrl : '';
1417
+ this.downloadLinkEl.textContent = this.i18n.t('downloadJetpack');
1302
1418
  }
1303
1419
  if (this.controlCenterLinkEl) {
1304
1420
  this.controlCenterLinkEl.href = this.options.controlCenterUrl ?? DEFAULT_CONTROL_CENTER_URL;
1421
+ this.controlCenterLinkEl.textContent = this.i18n.t('controlCenter');
1422
+ }
1423
+ if (this.actionBtnEl) {
1424
+ this.actionBtnEl.hidden = false;
1425
+ if (this.status === 'Running') {
1426
+ this.actionBtnEl.setAttribute('data-jp-action', 'stop');
1427
+ this.actionBtnEl.disabled = this.stopping;
1428
+ this.actionBtnEl.textContent = this.stopping
1429
+ ? this.i18n.t('stopping')
1430
+ : this.i18n.t('stop');
1431
+ }
1432
+ else {
1433
+ const hasLaunchHandler = typeof (this.options.onLaunch ?? this.options.onRelaunch) === 'function';
1434
+ this.actionBtnEl.setAttribute('data-jp-action', 'launch');
1435
+ this.actionBtnEl.disabled =
1436
+ this.status !== 'Stopped' || this.launching || !hasLaunchHandler;
1437
+ this.actionBtnEl.textContent = this.launching
1438
+ ? this.i18n.t('launching')
1439
+ : this.i18n.t('launch');
1440
+ }
1305
1441
  }
1306
- if (this.relaunchBtnEl) {
1307
- const showRelaunch = this.status === 'Stopped' && typeof this.options.onRelaunch === 'function';
1308
- this.relaunchBtnEl.hidden = !showRelaunch;
1309
- this.relaunchBtnEl.disabled = !showRelaunch || this.relaunching;
1310
- this.relaunchBtnEl.textContent = this.relaunching ? 'Relaunching...' : 'Relaunch';
1442
+ if (this.modalTitleEl) {
1443
+ this.modalTitleEl.textContent = this.options.stopConfirmTitle ?? this.i18n.t('modalTitle');
1311
1444
  }
1312
- if (this.stopBtnEl) {
1313
- this.stopBtnEl.disabled = this.status !== 'Running' || this.stopping;
1314
- this.stopBtnEl.textContent = this.stopping ? 'Stopping...' : 'Stop';
1445
+ if (this.modalMessageEl) {
1446
+ this.modalMessageEl.textContent =
1447
+ this.options.stopConfirmMessage ?? this.i18n.t('modalMessage');
1315
1448
  }
1316
1449
  if (this.modalCancelBtnEl) {
1450
+ this.modalCancelBtnEl.textContent = this.i18n.t('modalCancel');
1317
1451
  this.modalCancelBtnEl.disabled = this.stopping;
1318
1452
  }
1319
1453
  if (this.modalConfirmBtnEl) {
1454
+ this.modalConfirmBtnEl.textContent = this.i18n.t('modalConfirm');
1320
1455
  this.modalConfirmBtnEl.disabled = this.stopping;
1321
1456
  }
1322
1457
  this.syncInstallBannerUi(resolvedName);
@@ -1324,7 +1459,8 @@ export class JetPackControlBar {
1324
1459
  syncInstallBannerUi(resolvedName) {
1325
1460
  if (!this.installBannerHost)
1326
1461
  return;
1327
- const appDisplayName = resolvedName ?? (this.options.appName?.trim() || this.options.appId?.trim() || 'JetPack App');
1462
+ const appDisplayName = resolvedName ??
1463
+ (this.options.appName?.trim() || this.options.appId?.trim() || this.i18n.t('defaultAppName'));
1328
1464
  const visible = this.shouldShowInstallBanner();
1329
1465
  this.installBannerHost.hidden = !visible;
1330
1466
  this.installBannerHost.style.display = visible ? 'block' : 'none';
@@ -1354,7 +1490,7 @@ export class JetPackControlBar {
1354
1490
  if (this.installPosterImgEl.src !== candidateUrl) {
1355
1491
  this.installPosterImgEl.src = candidateUrl;
1356
1492
  }
1357
- this.installPosterImgEl.alt = `${appDisplayName} poster`;
1493
+ this.installPosterImgEl.alt = this.i18n.t('installPosterAlt', { appName: appDisplayName });
1358
1494
  this.installPosterImgEl.hidden = false;
1359
1495
  }
1360
1496
  else {
@@ -1368,6 +1504,12 @@ export class JetPackControlBar {
1368
1504
  if (this.installPosterAppNameEl) {
1369
1505
  this.installPosterAppNameEl.textContent = appDisplayName;
1370
1506
  }
1507
+ if (this.installPosterPoweredEl) {
1508
+ this.installPosterPoweredEl.textContent = this.i18n.t('poweredBy');
1509
+ }
1510
+ if (this.installWaitTextEl) {
1511
+ this.installWaitTextEl.textContent = this.i18n.t('installWaitText');
1512
+ }
1371
1513
  const customMsg = typeof this.options.installBanner === 'object' && this.options.installBanner !== null
1372
1514
  ? this.options.installBanner.message?.trim()
1373
1515
  : undefined;
@@ -1375,7 +1517,7 @@ export class JetPackControlBar {
1375
1517
  this.installMessageEl.textContent =
1376
1518
  customMsg && customMsg.length > 0
1377
1519
  ? customMsg
1378
- : `To use ${appDisplayName}, install and run the free JetPack app.`;
1520
+ : this.i18n.t('installDefaultMessage', { appName: appDisplayName });
1379
1521
  }
1380
1522
  this.attachInstallLayoutTracking();
1381
1523
  this.scheduleInstallArrowUpdate();