From 358a3143e89db3e5351822fbde63c1a6f9c5f301 Mon Sep 17 00:00:00 2001 From: Eser DENIZ Date: Mon, 7 Apr 2025 13:52:19 +0200 Subject: [PATCH 1/2] fix: App::version() not returning the correct version --- src/Commands/BuildCommand.php | 8 ++++---- src/Commands/BundleCommand.php | 6 +++--- src/Commands/DevelopCommand.php | 6 +++--- src/Commands/ResetCommand.php | 6 +++--- src/Traits/{SetsAppName.php => PatchesPackagesJson.php} | 5 +++-- 5 files changed, 16 insertions(+), 15 deletions(-) rename src/Traits/{SetsAppName.php => PatchesPackagesJson.php} (81%) diff --git a/src/Commands/BuildCommand.php b/src/Commands/BuildCommand.php index bd1497a..d7b5a61 100644 --- a/src/Commands/BuildCommand.php +++ b/src/Commands/BuildCommand.php @@ -14,7 +14,7 @@ use Native\Electron\Traits\LocatesPhpBinary; use Native\Electron\Traits\OsAndArch; use Native\Electron\Traits\PrunesVendorDirectory; -use Native\Electron\Traits\SetsAppName; +use Native\Electron\Traits\PatchesPackagesJson; use Symfony\Component\Process\Process as SymfonyProcess; use function Laravel\Prompts\intro; @@ -29,7 +29,7 @@ class BuildCommand extends Command use LocatesPhpBinary; use OsAndArch; use PrunesVendorDirectory; - use SetsAppName; + use PatchesPackagesJson; protected $signature = 'native:build {os? : The operating system to build for (all, linux, mac, win)} @@ -78,7 +78,7 @@ public function handle(): void private function buildBundle(): void { - $this->setAppName(); + $this->setAppNameAndVersion(); $this->updateElectronDependencies(); @@ -101,7 +101,7 @@ private function buildUnsecure(): void { $this->preProcess(); - $this->setAppName(); + $this->setAppNameAndVersion(); $this->updateElectronDependencies(); diff --git a/src/Commands/BundleCommand.php b/src/Commands/BundleCommand.php index 0957491..a0918ea 100644 --- a/src/Commands/BundleCommand.php +++ b/src/Commands/BundleCommand.php @@ -16,7 +16,7 @@ use Native\Electron\Traits\InstallsAppIcon; use Native\Electron\Traits\LocatesPhpBinary; use Native\Electron\Traits\PrunesVendorDirectory; -use Native\Electron\Traits\SetsAppName; +use Native\Electron\Traits\PatchesPackagesJson; use Symfony\Component\Finder\Finder; use ZipArchive; @@ -31,7 +31,7 @@ class BundleCommand extends Command use InstallsAppIcon; use LocatesPhpBinary; use PrunesVendorDirectory; - use SetsAppName; + use PatchesPackagesJson; protected $signature = 'native:bundle {--fetch} {--clear} {--without-cleanup}'; @@ -87,7 +87,7 @@ public function handle(): int $this->preProcess(); - $this->setAppName(); + $this->setAppNameAndVersion(); intro('Copying App to build directory...'); // We update composer.json later, diff --git a/src/Commands/DevelopCommand.php b/src/Commands/DevelopCommand.php index e2ffadf..9a5d7f9 100644 --- a/src/Commands/DevelopCommand.php +++ b/src/Commands/DevelopCommand.php @@ -7,7 +7,7 @@ use Native\Electron\Traits\Developer; use Native\Electron\Traits\Installer; use Native\Electron\Traits\InstallsAppIcon; -use Native\Electron\Traits\SetsAppName; +use Native\Electron\Traits\PatchesPackagesJson; use function Laravel\Prompts\intro; use function Laravel\Prompts\note; @@ -18,7 +18,7 @@ class DevelopCommand extends Command use Developer; use Installer; use InstallsAppIcon; - use SetsAppName; + use PatchesPackagesJson; protected $signature = 'native:serve {--no-queue} {--D|no-dependencies} {--installer=npm}'; @@ -42,7 +42,7 @@ public function handle(): void $this->patchPlist(); } - $this->setAppName(developmentMode: true); + $this->setAppNameAndVersion(developmentMode: true); $this->installIcon(); diff --git a/src/Commands/ResetCommand.php b/src/Commands/ResetCommand.php index 8a6b67b..ab3ffde 100644 --- a/src/Commands/ResetCommand.php +++ b/src/Commands/ResetCommand.php @@ -3,14 +3,14 @@ namespace Native\Electron\Commands; use Illuminate\Console\Command; -use Native\Electron\Traits\SetsAppName; +use Native\Electron\Traits\PatchesPackagesJson; use Symfony\Component\Filesystem\Filesystem; use function Laravel\Prompts\intro; class ResetCommand extends Command { - use SetsAppName; + use PatchesPackagesJson; protected $signature = 'native:reset {--with-app-data : Clear the app data as well}'; @@ -49,7 +49,7 @@ public function handle(): int if ($this->option('with-app-data')) { foreach ([true, false] as $developmentMode) { - $appName = $this->setAppName($developmentMode); + $appName = $this->setAppNameAndVersion($developmentMode); // Eh, just in case, I don't want to delete all user data by accident. if (! empty($appName)) { diff --git a/src/Traits/SetsAppName.php b/src/Traits/PatchesPackagesJson.php similarity index 81% rename from src/Traits/SetsAppName.php rename to src/Traits/PatchesPackagesJson.php index c97f148..79ad2d6 100644 --- a/src/Traits/SetsAppName.php +++ b/src/Traits/PatchesPackagesJson.php @@ -2,9 +2,9 @@ namespace Native\Electron\Traits; -trait SetsAppName +trait PatchesPackagesJson { - protected function setAppName($developmentMode = false): string + protected function setAppNameAndVersion($developmentMode = false): string { $packageJsonPath = __DIR__.'/../../resources/js/package.json'; $packageJson = json_decode(file_get_contents($packageJsonPath), true); @@ -21,6 +21,7 @@ protected function setAppName($developmentMode = false): string } $packageJson['name'] = $name; + $packageJson['version'] = config('nativephp.version'); file_put_contents($packageJsonPath, json_encode($packageJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); From 811e64e7dbb2a017f6e4afb2c8a9901e80e24df9 Mon Sep 17 00:00:00 2001 From: SRWieZ <1408020+SRWieZ@users.noreply.github.com> Date: Mon, 7 Apr 2025 11:54:14 +0000 Subject: [PATCH 2/2] Fix styling --- src/Commands/BuildCommand.php | 4 ++-- src/Commands/BundleCommand.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Commands/BuildCommand.php b/src/Commands/BuildCommand.php index d7b5a61..6f6eac1 100644 --- a/src/Commands/BuildCommand.php +++ b/src/Commands/BuildCommand.php @@ -13,8 +13,8 @@ use Native\Electron\Traits\InstallsAppIcon; use Native\Electron\Traits\LocatesPhpBinary; use Native\Electron\Traits\OsAndArch; -use Native\Electron\Traits\PrunesVendorDirectory; use Native\Electron\Traits\PatchesPackagesJson; +use Native\Electron\Traits\PrunesVendorDirectory; use Symfony\Component\Process\Process as SymfonyProcess; use function Laravel\Prompts\intro; @@ -28,8 +28,8 @@ class BuildCommand extends Command use InstallsAppIcon; use LocatesPhpBinary; use OsAndArch; - use PrunesVendorDirectory; use PatchesPackagesJson; + use PrunesVendorDirectory; protected $signature = 'native:build {os? : The operating system to build for (all, linux, mac, win)} diff --git a/src/Commands/BundleCommand.php b/src/Commands/BundleCommand.php index a0918ea..4af749e 100644 --- a/src/Commands/BundleCommand.php +++ b/src/Commands/BundleCommand.php @@ -15,8 +15,8 @@ use Native\Electron\Traits\HasPreAndPostProcessing; use Native\Electron\Traits\InstallsAppIcon; use Native\Electron\Traits\LocatesPhpBinary; -use Native\Electron\Traits\PrunesVendorDirectory; use Native\Electron\Traits\PatchesPackagesJson; +use Native\Electron\Traits\PrunesVendorDirectory; use Symfony\Component\Finder\Finder; use ZipArchive; @@ -30,8 +30,8 @@ class BundleCommand extends Command use HasPreAndPostProcessing; use InstallsAppIcon; use LocatesPhpBinary; - use PrunesVendorDirectory; use PatchesPackagesJson; + use PrunesVendorDirectory; protected $signature = 'native:bundle {--fetch} {--clear} {--without-cleanup}';