From 6ce43742b03fb5abbe2c46d1f9ec7a6904eff1b0 Mon Sep 17 00:00:00 2001 From: liuwenfeng Date: Thu, 21 Nov 2024 12:42:47 +0000 Subject: [PATCH] fix discovery printer missing in UI Signed-off-by: liuwenfeng --- .../src/print_service_ability.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/services/print_service/src/print_service_ability.cpp b/services/print_service/src/print_service_ability.cpp index e9f3ffc..7fa53ad 100644 --- a/services/print_service/src/print_service_ability.cpp +++ b/services/print_service/src/print_service_ability.cpp @@ -3156,22 +3156,22 @@ bool PrintServiceAbility::AddVendorPrinterToDiscovery(const std::string &globalV printerInfo->SetPrinterName(cupsPrinter.name); } printerInfo->SetPrinterId(globalPrinterId); - printerInfo->SetPrinterState(PRINTER_ADDED); printSystemData_.AddPrinterToDiscovery(printerInfo); } + printerInfo->SetPrinterState(PRINTER_ADDED); SendPrinterDiscoverEvent(PRINTER_ADDED, *printerInfo); SendPrinterEvent(*printerInfo); if (printSystemData_.IsPrinterAdded(printerInfo->GetPrinterId()) && !printSystemData_.CheckPrinterBusy(printerInfo->GetPrinterId())) { - if (CheckPrinterUriDifferent(printerInfo)) { - PRINT_HILOGW("different printer uri, ignore it"); - } else { - PRINT_HILOGI("added printer, update status to idle"); - printerInfo->SetPrinterStatus(PRINTER_STATUS_IDLE); - printSystemData_.UpdatePrinterStatus(printerInfo->GetPrinterId(), PRINTER_STATUS_IDLE); - SendPrinterEventChangeEvent(PRINTER_EVENT_STATE_CHANGED, *printerInfo); - SendPrinterChangeEvent(PRINTER_EVENT_STATE_CHANGED, *printerInfo); + if (CheckPrinterUriDifferent(printerInfo) && + UpdateAddedPrinterInCups(printerInfo->GetPrinterId(), printerInfo->GetUri())) { + printSystemData_.UpdatePrinterUri(printerInfo); + printSystemData_.SaveCupsPrinterMap(); } + printerInfo->SetPrinterStatus(PRINTER_STATUS_IDLE); + printSystemData_.UpdatePrinterStatus(printerInfo->GetPrinterId(), PRINTER_STATUS_IDLE); + SendPrinterEventChangeEvent(PRINTER_EVENT_STATE_CHANGED, *printerInfo); + SendPrinterChangeEvent(PRINTER_EVENT_STATE_CHANGED, *printerInfo); } return true; }