diff --git a/app/Http/Controllers/Admin/UiElementController.php b/app/Http/Controllers/Admin/UiElementController.php index 69030de..bbb9c1b 100644 --- a/app/Http/Controllers/Admin/UiElementController.php +++ b/app/Http/Controllers/Admin/UiElementController.php @@ -186,7 +186,7 @@ class UiElementController extends Controller ]); } - public function updateMachineBundle(Request $request, Machine $machine) + public function updateMachineBundle(Request $request, Machine $machine, \App\Services\Machine\MqttService $mqttService) { $validated = $request->validate([ 'ui_bundle_id' => 'nullable|integer|exists:ui_bundles,id', @@ -201,6 +201,26 @@ class UiElementController extends Controller $machine->settings = $settings; $machine->save(); - return redirect()->route('admin.app.ui-machines')->with('success', __('Saved')); + // 儲存後主動推送,讓機台立即重拉設定並套用 UI 換膚。 + // 沿用 app 端既有的 update_settings 處理(MqttService → downloadSetting → 解析 UISet),APK 不需改動。 + $command = \App\Models\Machine\RemoteCommand::create([ + 'machine_id' => $machine->id, + 'user_id' => auth()->id(), + 'command_type' => 'update_settings', + 'payload' => [], + 'status' => 'pending', + 'remark' => __('Sync UI bundle'), + ]); + + $pushed = $mqttService->pushCommand($machine->serial_no, 'update_settings', [], (string) $command->id); + if (!$pushed) { + $command->update(['status' => 'failed', 'note' => 'MQTT push failed']); + } + + $message = $pushed + ? __('Saved and update pushed to machine.') + : __('Saved. Machine will apply on next sync/reboot.'); + + return redirect()->route('admin.app.ui-machines')->with('success', $message); } } diff --git a/lang/en.json b/lang/en.json index dfe40dd..d3e8d68 100644 --- a/lang/en.json +++ b/lang/en.json @@ -2343,6 +2343,9 @@ "UI element deleted": "UI element deleted", "UI bundle created": "UI bundle created", "UI bundle deleted": "UI bundle deleted", + "Sync UI bundle": "Sync UI bundle", + "Saved and update pushed to machine.": "Saved and update pushed to machine.", + "Saved. Machine will apply on next sync/reboot.": "Saved. Machine will apply on next sync/reboot.", "No data": "No data", "Back": "Back", "Rename": "Rename", diff --git a/lang/zh_TW.json b/lang/zh_TW.json index ed3f24b..4adbaaf 100644 --- a/lang/zh_TW.json +++ b/lang/zh_TW.json @@ -2344,6 +2344,9 @@ "UI element deleted": "UI 元素已刪除", "UI bundle created": "UI 組合已新增", "UI bundle deleted": "UI 組合已刪除", + "Sync UI bundle": "同步 UI 組合", + "Saved and update pushed to machine.": "已儲存,並已推送更新到機台(機台將立即重拉並套用)。", + "Saved. Machine will apply on next sync/reboot.": "已儲存。推送未成功(機台可能離線),將於下次同步/重開機時套用。", "No data": "無資料", "Back": "返回", "Rename": "重新命名",