From 216e9a8b136867926921a07a7ebd6834be323043 Mon Sep 17 00:00:00 2001 From: "opacity@t-win.kr" Date: Tue, 16 Sep 2025 09:34:14 +0900 Subject: [PATCH] =?UTF-8?q?QEVENT=20remider=20=EC=98=88=EC=95=BD=EC=8B=9C?= =?UTF-8?q?=20webos=20=EB=AF=B8=ED=98=B8=EC=B6=9C=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/actions/commonActions.js | 15 +- com.twin.app.shoptime/src/lunaSend/common.js | 177 ++++++++++++++---- .../src/utils/helperMethods.js | 42 +++++ 3 files changed, 192 insertions(+), 42 deletions(-) diff --git a/com.twin.app.shoptime/src/actions/commonActions.js b/com.twin.app.shoptime/src/actions/commonActions.js index 09d7371c..58981fbe 100644 --- a/com.twin.app.shoptime/src/actions/commonActions.js +++ b/com.twin.app.shoptime/src/actions/commonActions.js @@ -10,6 +10,7 @@ import { handleBypassLink } from "../App/bypassLinkHandler"; import * as lunaSend from "../lunaSend"; import { initialLocalSettings } from "../reducers/localSettingsReducer"; import * as Config from "../utils/Config"; +import * as HelperMethods from "../utils/helperMethods"; import { types } from "./actionTypes"; export const changeAppStatus = (status) => ({ @@ -504,10 +505,20 @@ export const requestLiveSubtitle = export const addReservation = (data) => (dispatch) => { lunaSend.addReservation(data, { onSuccess: (res) => { - console.log(res); + console.log("addReservation success:", res); + // Optionally show success toast + if (res && res.returnValue) { + dispatch(alertToast("Reminder set successfully")); + } }, onFailure: (err) => { - console.log(err); + console.error("addReservation failed:", err); + // Use the helper function for better error handling + const errorMessage = HelperMethods.getReservationErrorMessage(err); + dispatch(alertToast(errorMessage)); + }, + onComplete: () => { + console.log("addReservation completed"); }, }); }; diff --git a/com.twin.app.shoptime/src/lunaSend/common.js b/com.twin.app.shoptime/src/lunaSend/common.js index 65a3db16..bdc3ba41 100644 --- a/com.twin.app.shoptime/src/lunaSend/common.js +++ b/com.twin.app.shoptime/src/lunaSend/common.js @@ -236,56 +236,108 @@ export const setSubtitleEnableOver5 = ( } }; -// system Alert +// system Alert with time validation export const addReservation = (data, { onSuccess, onFailure, onComplete }) => { if (typeof window === "object" && !window.PalmSystem) { console.log("LUNA SEND addReservation data", data); return; } - return new LS2Request().send({ - service: "luna://com.webos.service.tvReservationAgent", - method: "add", - parameters: { - scheduleType: "LGShopping", - startTime: { - year: data.startTime.year, - month: data.startTime.month, - day: data.startTime.day, - hour: data.startTime.hour, - minute: data.startTime.minute, - second: data.startTime.second, - }, - callback: { - method: "luna://com.webos.notification/createAlert", - params: { - message: data.params.message, - buttons: [ - { - label: data.params.buttons[0].label, - onclick: "luna://com.webos.applicationManager/launch", - params: { - id: window.PalmSystem.identifier ?? appinfo.id, - params: data.params.launch, + const createReservation = () => { + return new LS2Request().send({ + service: "luna://com.webos.service.tvReservationAgent", + method: "add", + parameters: { + scheduleType: "LGShopping", + startTime: { + year: data.startTime.year, + month: data.startTime.month, + day: data.startTime.day, + hour: data.startTime.hour, + minute: data.startTime.minute, + second: data.startTime.second, + }, + callback: { + method: "luna://com.webos.notification/createAlert", + params: { + message: data.params.message, + buttons: [ + { + label: data.params.buttons[0].label, + onclick: "luna://com.webos.applicationManager/launch", + params: { + id: window.PalmSystem.identifier ?? appinfo.id, + params: data.params.launch, + }, }, - }, - { - label: data.params.buttons[1].label, - }, - ], - - autoTimeout: 30, + { + label: data.params.buttons[1].label, + }, + ], + autoTimeout: 30, + }, + }, + information: { + showId: data.params.showId, + chanId: data.params.chanId, }, }, - information: { - showId: data.params.showId, - chanId: data.params.chanId, + onSuccess, + onFailure: (err) => { + console.log("LUNA SEND addReservation failed", err); + // Check if error is related to invalid current time + if ( + err && + err.errorText && + err.errorText.includes("Invalid current time") + ) { + console.log( + "Invalid current time error detected, will retry after time validation" + ); + // Don't call onFailure immediately, let the retry logic handle it + return; + } + onFailure(err); }, - }, - onSuccess, - onFailure, - onComplete, - }); + onComplete, + }); + }; + + // First, validate system time before creating reservation + const validateTimeAndCreateReservation = (retryCount = 0, maxRetries = 3) => { + console.log(`LUNA SEND validating system time, attempt ${retryCount + 1}`); + + getSystemTime({ + onSuccess: (timeRes) => { + console.log("LUNA SEND system time validation success", timeRes); + // Time is available, proceed with reservation + createReservation(); + }, + onFailure: (timeErr) => { + console.log("LUNA SEND system time validation failed", timeErr); + + if (retryCount < maxRetries) { + // Retry with exponential backoff + const delay = Math.min(1000 * Math.pow(2, retryCount), 5000); // Max 5 seconds + console.log(`LUNA SEND retrying time validation in ${delay}ms`); + + setTimeout(() => { + validateTimeAndCreateReservation(retryCount + 1, maxRetries); + }, delay); + } else { + console.log("LUNA SEND max retries exceeded for time validation"); + // Still try to create reservation as fallback + createReservation(); + } + }, + onComplete: () => { + console.log("LUNA SEND system time validation complete"); + }, + }); + }; + + // Start the validation and reservation process + validateTimeAndCreateReservation(); }; export const deleteReservationCallback = ( @@ -454,3 +506,48 @@ export const getConnectionInfo = ({ onSuccess, onFailure, onComplete }) => { }); } }; + +// Check system time availability +export const getSystemTime = ({ onSuccess, onFailure, onComplete }) => { + if (typeof window === "object" && !window.PalmSystem) { + console.log("LUNA SEND getSystemTime - mock environment"); + onSuccess({ returnValue: true, utc: Date.now() / 1000 }); + return; + } + + return new LS2Request().send({ + service: "luna://com.webos.settingsservice", + method: "getSystemSettings", + subscribe: false, + parameters: { + category: "time", + keys: ["autoClock"], + }, + onSuccess: (res) => { + console.log("LUNA SEND getSystemTime success", res); + if (res && res.returnValue) { + // If autoClock is available, try to get actual time + new LS2Request().send({ + service: "luna://com.webos.service.systemservice", + method: "clock/getTime", + subscribe: false, + parameters: {}, + onSuccess: (timeRes) => { + console.log("LUNA SEND clock/getTime success", timeRes); + onSuccess(timeRes); + }, + onFailure: (timeErr) => { + console.log("LUNA SEND clock/getTime failed", timeErr); + // Fallback to settings response if getTime fails + onSuccess(res); + }, + onComplete, + }); + } else { + onFailure(res); + } + }, + onFailure, + onComplete, + }); +}; diff --git a/com.twin.app.shoptime/src/utils/helperMethods.js b/com.twin.app.shoptime/src/utils/helperMethods.js index 704fe362..9ce8a7e7 100644 --- a/com.twin.app.shoptime/src/utils/helperMethods.js +++ b/com.twin.app.shoptime/src/utils/helperMethods.js @@ -577,3 +577,45 @@ export const getErrorMessage = ( return errorPrefix + "An unknown error occurred. Please try again later."; } }; + +/** + * Check if the reservation error is related to system time issues + * @param {Object} error - The error object from Luna service + * @returns {boolean} - True if error is time-related + */ +export const isTimeRelatedError = (error) => { + if (!error) return false; + + const timeErrorPatterns = [ + "Invalid current time", + "Fail to get Current Time", + "time not available", + "clock not set", + ]; + + const errorText = error.errorText || error.message || ""; + return timeErrorPatterns.some((pattern) => + errorText.toLowerCase().includes(pattern.toLowerCase()) + ); +}; + +/** + * Get user-friendly error message for reservation failures + * @param {Object} error - The error object from Luna service + * @returns {string} - User-friendly error message + */ +export const getReservationErrorMessage = (error) => { + if (!error) return $L("Failed to set reminder. Please try again."); + + if (isTimeRelatedError(error)) { + return $L( + "Unable to set reminder: System time not available. Please check your TV's time settings and try again." + ); + } + + if (error.errorText) { + return $L(`Failed to set reminder: ${error.errorText}`); + } + + return $L("Failed to set reminder. Please try again."); +};