electrobun 0.0.19-beta.89 → 0.0.19-beta.91
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/dist/api/bun/core/Updater.ts +76 -31
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { join, dirname, resolve, basename } from "path";
|
|
2
2
|
import { homedir } from "os";
|
|
3
3
|
import { renameSync, unlinkSync, mkdirSync, rmdirSync, statSync, readdirSync, cpSync } from "fs";
|
|
4
|
+
import { execSync } from "child_process";
|
|
4
5
|
import tar from "tar";
|
|
5
6
|
import { ZstdInit } from "@oneidentity/zstd-js/wasm";
|
|
6
7
|
import { OS as currentOS, ARCH as currentArch } from '../../shared/platform';
|
|
@@ -321,26 +322,55 @@ const Updater = {
|
|
|
321
322
|
let appBundleSubpath: string = "";
|
|
322
323
|
|
|
323
324
|
if (await Bun.file(latestTarPath).exists()) {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
325
|
+
// Windows needs a temporary directory to avoid file locking issues
|
|
326
|
+
const extractionDir = currentOS === 'win'
|
|
327
|
+
? join(extractionFolder, `temp-${latestHash}`)
|
|
328
|
+
: extractionFolder;
|
|
329
|
+
|
|
330
|
+
if (currentOS === 'win') {
|
|
331
|
+
mkdirSync(extractionDir, { recursive: true });
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// Use Windows native tar.exe on Windows due to npm tar library issues (same as CLI)
|
|
335
|
+
if (currentOS === 'win') {
|
|
336
|
+
console.log(`Using Windows native tar.exe to extract ${latestTarPath} to ${extractionDir}...`);
|
|
337
|
+
try {
|
|
338
|
+
execSync(`tar -xf "${latestTarPath}" -C "${extractionDir}"`, {
|
|
339
|
+
stdio: 'inherit',
|
|
340
|
+
cwd: extractionDir
|
|
341
|
+
});
|
|
342
|
+
console.log('Windows tar.exe extraction completed successfully');
|
|
343
|
+
|
|
344
|
+
// For Windows/Linux, the app bundle is at root level
|
|
345
|
+
appBundleSubpath = "./";
|
|
346
|
+
} catch (error) {
|
|
347
|
+
console.error('Windows tar.exe extraction failed:', error);
|
|
348
|
+
throw error;
|
|
349
|
+
}
|
|
350
|
+
} else {
|
|
351
|
+
// Use npm tar library on macOS/Linux (keep original behavior)
|
|
352
|
+
await tar.x({
|
|
353
|
+
// gzip: false,
|
|
354
|
+
file: latestTarPath,
|
|
355
|
+
cwd: extractionDir,
|
|
356
|
+
onentry: (entry) => {
|
|
357
|
+
if (currentOS === 'macos') {
|
|
358
|
+
// find the first .app bundle in the tarball
|
|
359
|
+
// Some apps may have nested .app bundles
|
|
360
|
+
if (!appBundleSubpath && entry.path.endsWith(".app/")) {
|
|
361
|
+
appBundleSubpath = entry.path;
|
|
362
|
+
}
|
|
363
|
+
} else {
|
|
364
|
+
// For Linux, look for the main executable
|
|
365
|
+
if (!appBundleSubpath) {
|
|
366
|
+
appBundleSubpath = "./";
|
|
367
|
+
}
|
|
340
368
|
}
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
}
|
|
369
|
+
},
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
console.log(`Tar extraction completed. Found appBundleSubpath: ${appBundleSubpath}`);
|
|
344
374
|
|
|
345
375
|
if (!appBundleSubpath) {
|
|
346
376
|
console.error("Failed to find app in tarball");
|
|
@@ -349,7 +379,7 @@ const Updater = {
|
|
|
349
379
|
|
|
350
380
|
// Note: resolve here removes the extra trailing / that the tar file adds
|
|
351
381
|
const extractedAppPath = resolve(
|
|
352
|
-
join(
|
|
382
|
+
join(extractionDir, appBundleSubpath)
|
|
353
383
|
);
|
|
354
384
|
|
|
355
385
|
// Platform-specific path handling
|
|
@@ -359,11 +389,20 @@ const Updater = {
|
|
|
359
389
|
// Use same sanitization as extractor: remove spaces and dots
|
|
360
390
|
// Note: localInfo.name already includes the channel (e.g., "test1-canary")
|
|
361
391
|
const appBundleName = localInfo.name.replace(/ /g, "").replace(/\./g, "-");
|
|
362
|
-
newAppBundlePath = join(
|
|
392
|
+
newAppBundlePath = join(extractionDir, appBundleName);
|
|
363
393
|
|
|
364
394
|
// Verify the extracted app exists
|
|
365
395
|
if (!statSync(newAppBundlePath, { throwIfNoEntry: false })) {
|
|
366
396
|
console.error(`Extracted app not found at: ${newAppBundlePath}`);
|
|
397
|
+
console.log("Contents of extraction directory:");
|
|
398
|
+
try {
|
|
399
|
+
const files = readdirSync(extractionDir);
|
|
400
|
+
for (const file of files) {
|
|
401
|
+
console.log(` - ${file}`);
|
|
402
|
+
}
|
|
403
|
+
} catch (e) {
|
|
404
|
+
console.log("Could not list directory contents:", e);
|
|
405
|
+
}
|
|
367
406
|
return;
|
|
368
407
|
}
|
|
369
408
|
} else {
|
|
@@ -458,26 +497,30 @@ const Updater = {
|
|
|
458
497
|
}
|
|
459
498
|
}
|
|
460
499
|
|
|
461
|
-
//
|
|
462
|
-
|
|
500
|
+
// Clean up the temporary extraction directory on Windows
|
|
501
|
+
if (currentOS === 'win') {
|
|
502
|
+
rmdirSync(extractionDir, { recursive: true });
|
|
503
|
+
}
|
|
463
504
|
|
|
464
505
|
// Create/update the launcher batch file
|
|
465
506
|
const launcherPath = join(parentDir, "run.bat");
|
|
466
507
|
const launcherContent = `@echo off
|
|
467
508
|
:: Electrobun App Launcher
|
|
468
|
-
:: This file launches the current version
|
|
509
|
+
:: This file launches the current version
|
|
469
510
|
|
|
470
511
|
:: Set current version
|
|
471
512
|
set CURRENT_HASH=${latestHash}
|
|
472
513
|
set APP_DIR=%~dp0app-%CURRENT_HASH%
|
|
473
514
|
|
|
474
|
-
::
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
515
|
+
:: TODO: Implement proper cleanup mechanism that checks for running processes
|
|
516
|
+
:: For now, old versions are kept to avoid race conditions during updates
|
|
517
|
+
:: :: Clean up old app versions (keep current and one backup)
|
|
518
|
+
:: for /d %%D in ("%~dp0app-*") do (
|
|
519
|
+
:: if not "%%~nxD"=="app-%CURRENT_HASH%" (
|
|
520
|
+
:: echo Removing old version: %%~nxD
|
|
521
|
+
:: rmdir /s /q "%%D" 2>nul
|
|
522
|
+
:: )
|
|
523
|
+
:: )
|
|
481
524
|
|
|
482
525
|
:: Launch the app
|
|
483
526
|
cd /d "%APP_DIR%\\bin"
|
|
@@ -505,6 +548,8 @@ start "" launcher.exe
|
|
|
505
548
|
// On Windows, launch the run.bat file which handles versioning
|
|
506
549
|
const parentDir = dirname(runningAppBundlePath);
|
|
507
550
|
const runBatPath = join(parentDir, "run.bat");
|
|
551
|
+
|
|
552
|
+
|
|
508
553
|
await Bun.spawn(["cmd", "/c", runBatPath], { detached: true });
|
|
509
554
|
break;
|
|
510
555
|
case 'linux':
|
package/package.json
CHANGED