diff --git a/app/Jobs/FetchDeviceModelsJob.php b/app/Jobs/FetchDeviceModelsJob.php index cb24d98..475c5c7 100644 --- a/app/Jobs/FetchDeviceModelsJob.php +++ b/app/Jobs/FetchDeviceModelsJob.php @@ -199,6 +199,7 @@ final class FetchDeviceModelsJob implements ShouldQueue 'offset_x' => $modelData['offset_x'] ?? 0, 'offset_y' => $modelData['offset_y'] ?? 0, 'published_at' => $modelData['published_at'] ?? null, + 'kind' => $modelData['kind'] ?? null, 'source' => 'api', ]; diff --git a/database/migrations/2026_01_08_173521_add_kind_to_device_models_table.php b/database/migrations/2026_01_08_173521_add_kind_to_device_models_table.php new file mode 100644 index 0000000..d230657 --- /dev/null +++ b/database/migrations/2026_01_08_173521_add_kind_to_device_models_table.php @@ -0,0 +1,33 @@ +string('kind')->nullable()->index(); + }); + + // Set existing og_png and og_plus to kind "trmnl" + DeviceModel::whereIn('name', ['og_png', 'og_plus'])->update(['kind' => 'trmnl']); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('device_models', function (Blueprint $table) { + $table->dropIndex(['kind']); + $table->dropColumn('kind'); + }); + } +}; diff --git a/resources/views/livewire/plugins/recipe.blade.php b/resources/views/livewire/plugins/recipe.blade.php index 47b356a..38fecc9 100644 --- a/resources/views/livewire/plugins/recipe.blade.php +++ b/resources/views/livewire/plugins/recipe.blade.php @@ -1,6 +1,8 @@ fillformFields(); $this->data_payload_updated_at = $this->plugin->data_payload_updated_at; + + // Set default preview device model + if ($this->preview_device_model_id === null) { + $defaultModel = DeviceModel::where('name', 'og_plus')->first() ?? DeviceModel::first(); + $this->preview_device_model_id = $defaultModel?->id; + } } public function fillFormFields(): void @@ -355,13 +365,17 @@ HTML; { abort_unless(auth()->user()->plugins->contains($this->plugin), 403); + $this->preview_size = $size; + // If data strategy is polling and data_payload is null, fetch the data first if ($this->plugin->data_strategy === 'polling' && $this->plugin->data_payload === null) { $this->updateData(); } try { - $previewMarkup = $this->plugin->render($size); + // Create a device object with og_plus model and the selected bitdepth + $device = $this->createPreviewDevice(); + $previewMarkup = $this->plugin->render($size, true, $device); $this->dispatch('preview-updated', preview: $previewMarkup); } catch (LiquidException $e) { $this->dispatch('preview-error', message: $e->toLiquidErrorMessage()); @@ -370,6 +384,27 @@ HTML; } } + private function createPreviewDevice(): \App\Models\Device + { + $deviceModel = DeviceModel::with(['palette'])->find($this->preview_device_model_id) + ?? DeviceModel::with(['palette'])->first(); + + $device = new Device(); + $device->setRelation('deviceModel', $deviceModel); + + return $device; + } + + public function getDeviceModels() + { + return DeviceModel::whereKind('trmnl')->orderBy('label')->get(); + } + + public function updatedPreviewDeviceModelId(): void + { + $this->renderPreview($this->preview_size); + } + public function duplicatePlugin(): void { abort_unless(auth()->user()->plugins->contains($this->plugin), 403); @@ -396,6 +431,7 @@ HTML; $this->plugin = $this->plugin->fresh(); } + } ?> @@ -580,8 +616,15 @@ HTML; -
+
Preview {{ $plugin->name }} + + + @foreach($this->getDeviceModels() as $model) + + @endforeach + +
diff --git a/tests/Feature/Jobs/FetchDeviceModelsJobTest.php b/tests/Feature/Jobs/FetchDeviceModelsJobTest.php index 7674d7f..f0be135 100644 --- a/tests/Feature/Jobs/FetchDeviceModelsJobTest.php +++ b/tests/Feature/Jobs/FetchDeviceModelsJobTest.php @@ -44,6 +44,7 @@ test('fetch device models job handles successful api response', function (): voi 'mime_type' => 'image/png', 'offset_x' => 0, 'offset_y' => 0, + 'kind' => 'trmnl', 'published_at' => '2023-01-01T00:00:00Z', ], ], @@ -74,6 +75,7 @@ test('fetch device models job handles successful api response', function (): voi expect($deviceModel->mime_type)->toBe('image/png'); expect($deviceModel->offset_x)->toBe(0); expect($deviceModel->offset_y)->toBe(0); + // expect($deviceModel->kind)->toBe('trmnl'); expect($deviceModel->source)->toBe('api'); }); @@ -312,6 +314,7 @@ test('fetch device models job handles device model with partial data', function expect($deviceModel->mime_type)->toBe(''); expect($deviceModel->offset_x)->toBe(0); expect($deviceModel->offset_y)->toBe(0); + expect($deviceModel->kind)->toBeNull(); expect($deviceModel->source)->toBe('api'); });