From ff1adea54c9001b5e589ad390ec7648908e6fcf9 Mon Sep 17 00:00:00 2001 From: terrylee Date: Wed, 15 Jul 2026 13:17:54 +0800 Subject: [PATCH] =?UTF-8?q?feat(app-ui):=20=E6=A9=9F=E5=8F=B0=E7=B6=81?= =?UTF-8?q?=E5=AE=9A=E5=84=B2=E5=AD=98=E5=BE=8C=E4=B8=BB=E5=8B=95=E6=8E=A8?= =?UTF-8?q?=E9=80=81=20update=5Fsettings=EF=BC=8C=E6=A9=9F=E5=8F=B0?= =?UTF-8?q?=E7=AB=8B=E5=8D=B3=E5=A5=97=E7=94=A8=20UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 沿用 app 既有 update_settings→downloadSetting 處理(APK 不需改);推送失敗(離線)則下次同步套用 Co-Authored-By: Claude Opus 4.8 (1M context) --- .../Controllers/Admin/UiElementController.php | 24 +++++++++++++++++-- lang/en.json | 3 +++ lang/zh_TW.json | 3 +++ 3 files changed, 28 insertions(+), 2 deletions(-) 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": "重新命名",