pinokiod 7.1.65 → 7.1.66

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "7.1.65",
3
+ "version": "7.1.66",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -558,8 +558,10 @@
558
558
  const name = "<%=name%>"
559
559
  const SECURE_CONNECT_POLL_INTERVAL = 2000
560
560
  const SECURE_CONNECT_TIMEOUT = 120000
561
+ const SECURE_CONNECT_BROWSER_RETRY_DELAY = 1200
561
562
  let secureConnectPollTimer = null
562
563
  let secureConnectTimeoutHandle = null
564
+ let secureConnectBrowserRetryHandle = null
563
565
 
564
566
  function generateRandomString(length) {
565
567
  const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
@@ -591,6 +593,21 @@
591
593
  .replace(/=/g, '');
592
594
  }
593
595
 
596
+ async function openAuthInBrowser(authUrl) {
597
+ const response = await fetch('/go', {
598
+ method: 'POST',
599
+ headers: { 'Content-Type': 'application/json' },
600
+ body: JSON.stringify({ url: authUrl })
601
+ });
602
+ if (!response.ok) {
603
+ throw new Error(`Browser launch failed with status ${response.status}`);
604
+ }
605
+ const payload = await response.json().catch(() => ({}));
606
+ if (payload && payload.error) {
607
+ throw new Error(payload.error);
608
+ }
609
+ }
610
+
594
611
  // OAuth functions
595
612
  async function login() {
596
613
  try {
@@ -624,7 +641,22 @@
624
641
  startSecureConnectPolling();
625
642
  setStatus(`Continue the ${name} login in your browser.`, 'warning');
626
643
  try {
627
- window.open(authUrl, '_blank', 'browser');
644
+ if (secureConnectBrowserRetryHandle) {
645
+ clearTimeout(secureConnectBrowserRetryHandle);
646
+ secureConnectBrowserRetryHandle = null;
647
+ }
648
+ await openAuthInBrowser(authUrl);
649
+ secureConnectBrowserRetryHandle = setTimeout(async () => {
650
+ secureConnectBrowserRetryHandle = null;
651
+ try {
652
+ const token = await ensureValidToken();
653
+ if (!token && document.visibilityState === 'visible' && document.hasFocus()) {
654
+ await openAuthInBrowser(authUrl);
655
+ }
656
+ } catch (retryError) {
657
+ console.warn('Retry browser launch failed:', retryError);
658
+ }
659
+ }, SECURE_CONNECT_BROWSER_RETRY_DELAY);
628
660
  } catch (openError) {
629
661
  stopSecureConnectPolling(`Could not open the browser automatically. Please open ${authUrl} manually.`, 'error');
630
662
  return;
@@ -652,6 +684,10 @@
652
684
  clearTimeout(secureConnectTimeoutHandle);
653
685
  secureConnectTimeoutHandle = null;
654
686
  }
687
+ if (secureConnectBrowserRetryHandle) {
688
+ clearTimeout(secureConnectBrowserRetryHandle);
689
+ secureConnectBrowserRetryHandle = null;
690
+ }
655
691
  if (message) {
656
692
  hideLoader();
657
693
  setStatus(message, type);