electrobun 0.13.0-beta.22 → 0.13.0-beta.23

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.
@@ -7,6 +7,7 @@ import { ZstdInit } from "@oneidentity/zstd-js/wasm";
7
7
  import { OS as currentOS, ARCH as currentArch } from '../../shared/platform';
8
8
  import { getPlatformFolder, getTarballFileName } from '../../shared/naming';
9
9
  import { native } from '../proc/native';
10
+ import { quit } from './Utils';
10
11
 
11
12
  // Helper to join URL paths without breaking the protocol (path.join mangles https:// to https:/)
12
13
  function urlJoin(...parts: string[]): string {
@@ -624,6 +625,14 @@ const Updater = {
624
625
  const parentDir = dirname(runningAppBundlePath);
625
626
  const updateScriptPath = join(parentDir, 'update.bat');
626
627
  const backupDir = join(parentDir, 'app-backup');
628
+ const launcherPath = join(runningAppBundlePath, 'bin', 'launcher.exe');
629
+
630
+ // Convert paths to Windows format
631
+ const backupDirWin = backupDir.replace(/\//g, '\\');
632
+ const runningAppWin = runningAppBundlePath.replace(/\//g, '\\');
633
+ const newAppWin = newAppBundlePath.replace(/\//g, '\\');
634
+ const extractionDirWin = extractionDir.replace(/\//g, '\\');
635
+ const launcherPathWin = launcherPath.replace(/\//g, '\\');
627
636
 
628
637
  // Create a batch script that will:
629
638
  // 1. Wait for the current app to exit
@@ -644,47 +653,51 @@ if "%ERRORLEVEL%"=="0" (
644
653
  )
645
654
 
646
655
  :: Small extra delay to ensure all file handles are released
647
- timeout /t 1 /nobreak >nul
656
+ timeout /t 2 /nobreak >nul
648
657
 
649
658
  :: Remove old backup if exists
650
- if exist "${backupDir.replace(/\//g, '\\')}" (
651
- rmdir /s /q "${backupDir.replace(/\//g, '\\')}"
659
+ if exist "${backupDirWin}" (
660
+ rmdir /s /q "${backupDirWin}"
652
661
  )
653
662
 
654
663
  :: Backup current app folder
655
- if exist "${runningAppBundlePath.replace(/\//g, '\\')}" (
656
- move "${runningAppBundlePath.replace(/\//g, '\\')}" "${backupDir.replace(/\//g, '\\')}"
664
+ if exist "${runningAppWin}" (
665
+ move "${runningAppWin}" "${backupDirWin}"
657
666
  )
658
667
 
659
668
  :: Move new app to current location
660
- move "${newAppBundlePath.replace(/\//g, '\\')}" "${runningAppBundlePath.replace(/\//g, '\\')}"
669
+ move "${newAppWin}" "${runningAppWin}"
661
670
 
662
671
  :: Clean up extraction directory
663
- rmdir /s /q "${extractionDir.replace(/\//g, '\\')}" 2>nul
672
+ rmdir /s /q "${extractionDirWin}" 2>nul
664
673
 
665
674
  :: Launch the new app
666
- start "" /d "${join(runningAppBundlePath, 'bin').replace(/\//g, '\\')}" launcher.exe
675
+ start "" "${launcherPathWin}"
676
+
677
+ :: Clean up scheduled tasks starting with ElectrobunUpdate_
678
+ for /f "tokens=1" %%t in ('schtasks /query /fo list ^| findstr /i "ElectrobunUpdate_"') do (
679
+ schtasks /delete /tn "%%t" /f >nul 2>&1
680
+ )
667
681
 
668
- :: Delete this update script
682
+ :: Delete this update script after a short delay
683
+ ping -n 2 127.0.0.1 >nul
669
684
  del "%~f0"
670
685
  `;
671
686
 
672
687
  await Bun.write(updateScriptPath, updateScript);
673
688
 
674
- // Launch the update script detached - it will wait for us to exit
675
- await Bun.spawn(["cmd", "/c", "start", "", "/min", updateScriptPath], { detached: true });
689
+ // Use Windows Task Scheduler to run the update script independently
690
+ // This ensures the script runs even after the app exits
691
+ const scriptPathWin = updateScriptPath.replace(/\//g, '\\');
692
+ const taskName = `ElectrobunUpdate_${Date.now()}`;
676
693
 
677
- // Small delay to ensure the script starts
678
- await new Promise(resolve => setTimeout(resolve, 200));
694
+ // Create a scheduled task that runs immediately and deletes itself
695
+ execSync(`schtasks /create /tn "${taskName}" /tr "cmd /c \\"${scriptPathWin}\\"" /sc once /st 00:00 /f`, { stdio: 'ignore' });
696
+ execSync(`schtasks /run /tn "${taskName}"`, { stdio: 'ignore' });
697
+ // The task will be cleaned up by Windows after it runs, or we delete it in the batch script
679
698
 
680
- // Now exit - the script will take over
681
- try {
682
- native.symbols.killApp();
683
- process.exit(0);
684
- } catch (e) {
685
- process.exit(0);
686
- }
687
- return; // Won't reach here, but for clarity
699
+ // Use quit() for graceful shutdown - this closes all windows and processes
700
+ quit();
688
701
  }
689
702
  } catch (error) {
690
703
  console.error("Failed to replace app with new version", error);
@@ -707,16 +720,8 @@ del "%~f0"
707
720
  Bun.spawn(["sh", "-c", `"${runningAppBundlePath}" &`], { detached: true});
708
721
  }
709
722
 
710
- // Use native killApp to properly clean up all resources
711
- try {
712
- native.symbols.killApp();
713
- // Still call process.exit as a fallback
714
- process.exit(0);
715
- } catch (e) {
716
- // Fallback if native binding fails
717
- console.error('Failed to call native killApp:', e);
718
- process.exit(0);
719
- }
723
+ // Use quit() for graceful shutdown
724
+ quit();
720
725
  }
721
726
  }
722
727
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "electrobun",
3
- "version": "0.13.0-beta.22",
3
+ "version": "0.13.0-beta.23",
4
4
  "description": "Build ultra fast, tiny, and cross-platform desktop apps with Typescript.",
5
5
  "license": "MIT",
6
6
  "author": "Blackboard Technologies Inc.",