mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-13 15:07:49 +00:00
add features
* feat: autojoin toggle * feat: auto add devices * feat: proxy feature * feat: support puppeteer in docker * feat: toggle to activate cloud proxy * feat: relay device information * feat: relay logs to cloud * feat: migrate on start * feat: calculate battery state, wifi signal * feat: eye candy for configure view * feat: update via api
This commit is contained in:
parent
d4eb832186
commit
715e6a2562
53 changed files with 1459 additions and 460 deletions
|
|
@ -2,11 +2,8 @@
|
|||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Device;
|
||||
use App\Jobs\GenerateScreenJob;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Spatie\Browsershot\Browsershot;
|
||||
|
||||
class ScreenGeneratorCommand extends Command
|
||||
{
|
||||
|
|
@ -22,101 +19,28 @@ class ScreenGeneratorCommand extends Command
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '';
|
||||
protected $description = 'Generate a screen for a terminal device';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
$deviceId = $this->argument('deviceId');
|
||||
$view = $this->argument('view');
|
||||
|
||||
$uuid = Uuid::uuid4()->toString();
|
||||
$pngPath = Storage::disk('public')->path('/images/generated/'.$uuid.'.png');
|
||||
$bmpPath = Storage::disk('public')->path('/images/generated/'.$uuid.'.bmp');
|
||||
|
||||
// Generate PNG
|
||||
try {
|
||||
Browsershot::html(view($view)->render())
|
||||
->windowSize(800, 480)
|
||||
->save($pngPath);
|
||||
} catch (\Exception $e) {
|
||||
$this->error('Failed to generate PNG: '.$e->getMessage());
|
||||
$markup = view($view)->render();
|
||||
} catch (\Throwable $e) {
|
||||
$this->error('Failed to render view: '.$e->getMessage());
|
||||
|
||||
return;
|
||||
return 1;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->convertToBmpImageMagick($pngPath, $bmpPath);
|
||||
GenerateScreenJob::dispatchSync($deviceId, $markup);
|
||||
|
||||
} catch (\ImagickException $e) {
|
||||
$this->error('Failed to convert image to BMP: '.$e->getMessage());
|
||||
}
|
||||
$this->info('Screen generation job finished.');
|
||||
|
||||
Device::find($deviceId)->update(['current_screen_image' => $uuid]);
|
||||
|
||||
$this->cleanupFolder();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public function convertToBmpImageMagick(string $pngPath, string $bmpPath): void
|
||||
{
|
||||
$imagick = new \Imagick($pngPath);
|
||||
$imagick->setImageType(\Imagick::IMGTYPE_GRAYSCALE);
|
||||
$imagick->quantizeImage(2, \Imagick::COLORSPACE_GRAY, 0, true, false);
|
||||
$imagick->setImageDepth(1);
|
||||
$imagick->stripImage();
|
||||
$imagick->setFormat('BMP3');
|
||||
$imagick->writeImage($bmpPath);
|
||||
$imagick->clear();
|
||||
}
|
||||
|
||||
// TODO retuns 8-bit BMP
|
||||
|
||||
// public function convertToBmpGD(string $pngPath, string $bmpPath): void
|
||||
// {
|
||||
// // Load the PNG image
|
||||
// $image = imagecreatefrompng($pngPath);
|
||||
//
|
||||
// // Create a new true color image with the same dimensions
|
||||
// $bwImage = imagecreatetruecolor(imagesx($image), imagesy($image));
|
||||
//
|
||||
// // Convert to black and white
|
||||
// imagefilter($image, IMG_FILTER_GRAYSCALE);
|
||||
//
|
||||
// // Copy the grayscale image to the new image
|
||||
// imagecopy($bwImage, $image, 0, 0, 0, 0, imagesx($image), imagesy($image));
|
||||
//
|
||||
// // Create a 1-bit palette
|
||||
// imagetruecolortopalette($bwImage, true, 2);
|
||||
//
|
||||
// // Save as BMP
|
||||
//
|
||||
// imagebmp($bwImage, $bmpPath, false);
|
||||
//
|
||||
// // Free up memory
|
||||
// imagedestroy($image);
|
||||
// imagedestroy($bwImage);
|
||||
// }
|
||||
public function cleanupFolder(): void
|
||||
{
|
||||
$activeImageUuids = Device::pluck('current_screen_image')->filter()->toArray();
|
||||
|
||||
$files = Storage::disk('public')->files('/images/generated/');
|
||||
foreach ($files as $file) {
|
||||
if (basename($file) === '.gitignore') {
|
||||
continue;
|
||||
}
|
||||
// Get filename without path and extension
|
||||
$fileUuid = pathinfo($file, PATHINFO_FILENAME);
|
||||
// If the UUID is not in use by any device, move it to archive
|
||||
if (! in_array($fileUuid, $activeImageUuids)) {
|
||||
Storage::disk('public')->delete($file);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue