From bbb076ae4533a7684d55ff5d3d66a278af24f2d4 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Fri, 20 Jan 2023 15:04:32 +0100 Subject: [PATCH] wip #5661 @5 --- app/Fluidbook/Packager/MacOS.php | 32 ++++--- app/Fluidbook/Packager/Packager.php | 17 ++-- app/Fluidbook/Packager/WindowsZIP.php | 126 +++++++++++++++++--------- 3 files changed, 112 insertions(+), 63 deletions(-) diff --git a/app/Fluidbook/Packager/MacOS.php b/app/Fluidbook/Packager/MacOS.php index b55c984e0..e5f49680a 100644 --- a/app/Fluidbook/Packager/MacOS.php +++ b/app/Fluidbook/Packager/MacOS.php @@ -7,12 +7,12 @@ use Cubist\Util\CommandLine; class MacOS extends WindowsZIP { protected $nwplatform = 'osx'; - protected $arch='x64'; - protected $nwversion = '0.71.0'; + protected $arch = 'x64'; + protected $nwversion = '0.72.0'; protected $node_platform = 'mac'; protected $exenameMaxlength = 28; public $type = 'mac_exe_html'; - protected $packageIconExt='icns'; + protected $packageIconExt = 'icns'; public function makePackage($zip) @@ -36,13 +36,20 @@ class MacOS extends WindowsZIP public function getAppPath() { - return $this->getFinalPackageDir() . '/' . $this->exeName . '.app'; + return $this->getFinalPackageDir() . $this->exeName . '.app'; + } + + /** + * @return bool + */ + public function nwBuildOK() + { + return file_exists($this->getAppPath() . '/Contents/Resources/app.nw/index.html'); } public function getFinalPackageDir() { - $res = parent::getFinalPackageDir(); - return $res; + return parent::getFinalPackageDir(); } @@ -51,6 +58,12 @@ class MacOS extends WindowsZIP $this->signApp(); } + public function setIcon() + { + copy($this->vdir . 'icon.icns', $this->getAppPath() . '/Contents/Resources/app.icns'); + copy($this->vdir . 'icon.icns', $this->getAppPath() . '/Contents/Resources/document.icns'); + } + function replaceFFMpeg() { copy($this->resource_path('_ffmpeg/libffmpeg.dylib'), $this->getAppPath() . '/Contents/Frameworks/nwjs Framework.framework/Versions/Current/libffmpeg.dylib'); @@ -75,14 +88,12 @@ class MacOS extends WindowsZIP $cp->setArg(null, $appPath); $cp->setArg(null, $path); $cp->execute(); - $cp->debug(); // Sign app $cl = new CommandLine($local_root . 'sign'); $cl->setSSH('paris.cubedesigners.com', 'vincent', 'atacama', 22022); $cl->setArg(null, $local_root . $f); $cl->execute(); - $cl->debug(); $res = $cl->output; if ($back) { @@ -95,12 +106,9 @@ class MacOS extends WindowsZIP $cp->setArg('v'); $cp->setArg(null, $path . '/'); $cp->setArg(null, $appPath . '/'); - $cp->setArg('delete'); $cp->execute(); - $cp->debug(); } - - // `rm -rf $path`; + //`rm -rf $path`; return $res; } } diff --git a/app/Fluidbook/Packager/Packager.php b/app/Fluidbook/Packager/Packager.php index 555c4510c..11f4f808d 100644 --- a/app/Fluidbook/Packager/Packager.php +++ b/app/Fluidbook/Packager/Packager.php @@ -74,6 +74,7 @@ class Packager extends \App\Jobs\Base break; case 'mac_exe_html': case 'mac_exe': + case 'mac': $packager = new MacOS($book_id, null, $options); break; case 'win_ins_html': @@ -317,34 +318,34 @@ class Packager extends \App\Jobs\Base } /** - * @return string + * @return string|null */ - public function getFinalPath(): string + public function getFinalPath(): string|null { return $this->_finalPath; } /** - * @param string $finalPath + * @param string|null $finalPath */ - public function setFinalPath(string $finalPath): void + public function setFinalPath(string|null $finalPath): void { $this->_finalPath = $finalPath; } /** - * @return string + * @return string|null */ - public function getFinalURL(): string + public function getFinalURL(): string|null { return $this->_finalURL; } /** - * @param string $finalURL + * @param string|null $finalURL */ - public function setFinalURL(string $finalURL): void + public function setFinalURL(string|null $finalURL): void { $this->_finalURL = $finalURL; } diff --git a/app/Fluidbook/Packager/WindowsZIP.php b/app/Fluidbook/Packager/WindowsZIP.php index a7884fbfd..cfe1fd16c 100644 --- a/app/Fluidbook/Packager/WindowsZIP.php +++ b/app/Fluidbook/Packager/WindowsZIP.php @@ -14,13 +14,14 @@ class WindowsZIP extends Packager protected $buildPath; protected $nwplatform = 'win'; protected $arch = 'x64'; - protected $nwversion = '0.71.0'; + protected $nwversion = '0.72.0'; protected $appversion = ''; protected $node_platform = 'win'; protected $exenameMaxlength = 30; protected $_compileOnConstruct = true; protected $packageIconExt = 'ico'; protected $nwbuildVersion = '4.0.7'; + protected $nwCacheDir; protected $_ext = 'html'; @@ -28,6 +29,7 @@ class WindowsZIP extends Packager public function __construct($book_id, $vdir = null, $options = []) { + $this->nwCacheDir = Files::mkdir(base_path('cache/nwbuild')); parent::__construct($book_id, $vdir, $options); $this->appName = ''; $this->appversion = '1.0.' . $this->_time; @@ -49,64 +51,91 @@ class WindowsZIP extends Packager } } + /** + * @throws \Exception + */ protected function preparePackage() { parent::preparePackage(); - $this->makeJSON(); + $this->buildNW(); - $this->buildPath = Files::mkdir($this->packager_path('/nwbuild/' . $this->type . '/' . $this->book_id)); + $this->setIcon(); + $this->replaceFFMpeg(); + $this->signExe(); + } - `umask 0000;sudo rm -rf $this->buildPath;mkdir -p 0777 $this->buildPath;chmod -R 777 $this->vdir;mkdir -p 0777 /application/tmp;chmod -R 777 /application/tmp`; + protected function setIcon() + { -// For -// $cl = new CommandLine('nwbuild'); -// $cl->setArg('platform', $this->nwplatform); -// $cl->setArg('outDir', $this->buildPath); -// $cl->setArg('flavour', "normal"); -// $cl->setArg('version', $this->nwversion); -// $cl->setArg('arch', $this->arch); -// $cl->setArg(null, $this->vdir); -// $cl->execute(); + } + + protected function buildNW() + { + $this->buildPath = Files::mkdir($this->packager_path('/nwbuild/' . $this->type . '/' . $this->book_id)); + $this->makeJSON(); + `umask 0000;sudo rm -rf $this->buildPath;mkdir -p 0777 $this->buildPath;chmod -R 777 $this->vdir;mkdir -p 0777 /application/tmp;chmod -R 777 /application/tmp`; if (version_compare($this->nwbuildVersion, 4, '<')) { - $platform = $this->getNWbuilder3Platform(); - - $cl = new CommandLine('nwbuild'); - $cl->setArg(null, $this->vdir . '**'); - $cl->setLongArgumentSeparator(' '); - $cl->setArg('platforms', $platform); - $cl->setArg('buildDir', $this->buildPath); - $cl->setArg('version', $this->nwversion); - $cl->setArg('mode', 'build'); - $cl->setArg('flavor', 'normal'); - if ($this->nwplatform === 'win') { - $cl->setArg('winIco', $this->vdir . 'icon.ico'); - $cl->setArg('useRcedit', 'true'); - } elseif ($this->nwplatform === 'osx') { - $cl->setArg('macIcns', $this->vdir . 'icon.icns'); - } - $cl->execute(); + $cl = $this->_nwbuilder3(); } else { - $cl = new CommandLine('nwbuild'); - $cl->cd($this->vdir); - $cl->setArg(null, 'package.json'); - $cl->setArg('platform', $this->nwplatform); - $cl->setArg('outDir', $this->buildPath); - $cl->setArg('flavour', "normal"); - $cl->setArg('version', $this->nwversion); - $cl->setArg('arch', $this->arch); - $cl->execute(); + $cl = $this->_nwbuilder4(); } `sudo chown -R 1001:33 $this->buildPath`; - if (!file_exists($this->buildPath)) { + if (!$this->nwBuildOK()) { throw new \Exception('Error while making exe : ' . $cl->commande . ' // ' . $cl->output); } + } - $this->replaceFFMpeg(); + /** + * @return bool + */ + public function nwBuildOK() + { + return file_exists($this->buildPath); + } - $this->signExe(); + /** + * @return CommandLine + */ + protected function _nwbuilder3() + { + $platform = $this->getNWbuilder3Platform(); + + $cl = new CommandLine('nwbuild'); + $cl->setArg(null, $this->vdir . '**'); + $cl->setLongArgumentSeparator(' '); + $cl->setArg('platforms', $platform); + $cl->setArg('buildDir', $this->buildPath); + $cl->setArg('version', $this->nwversion); + $cl->setArg('mode', 'build'); + $cl->setArg('flavor', 'normal'); + if ($this->nwplatform === 'win') { + $cl->setArg('winIco', $this->vdir . 'icon.ico'); + $cl->setArg('useRcedit', 'true'); + } elseif ($this->nwplatform === 'osx') { + $cl->setArg('macIcns', $this->vdir . 'icon.icns'); + } + $cl->execute(); + return $cl; + } + + /** + * @return CommandLine + */ + protected function _nwbuilder4() + { + $cl = new CommandLine('nwbuild'); + $cl->cd($this->vdir); + $cl->setArg(null, 'package.json *'); + $cl->setArg('platform', $this->nwplatform); + $cl->setArg('outDir', $this->buildPath); + $cl->setArg('flavour', "normal"); + $cl->setArg('version', $this->nwversion); + $cl->setArg('arch', $this->arch); + $cl->execute(); + return $cl; } protected function getNWBuilder3Platform() @@ -171,7 +200,6 @@ class WindowsZIP extends Packager 'main' => 'index.html', 'name' => $this->exeName, 'version' => '1.0.' . $this->_time, - 'icon' => 'icon.' . $this->packageIconExt, 'webkit' => [], 'window' => [ 'height' => 768, @@ -180,6 +208,18 @@ class WindowsZIP extends Packager 'id' => 'main', 'icon' => 'icon.png', ], + 'nwbuild' => [ + 'platform' => $this->nwplatform, + 'outDir' => $this->buildPath, + 'cacheDir' => $this->nwCacheDir, + 'flavour' => 'normal', + 'version' => $this->nwversion, + 'arch' => $this->arch, + 'app' => [ + 'name' => $this->appName, + 'icon' => $this->vdir . 'icon.' . $this->packageIconExt, + ], + ], 'dependencies' => [ 'child_process' => "^1.0.2", -- 2.39.5