• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * @file Describe the file
3 * Copyright (c) 2023 Huawei Device Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import { sendBroadcast } from '@ohos/common/src/main/ets/broadcast/BroadcastHelper';
18import { CommonEventConstants } from '../CommonEventConstants';
19import { runScheduleNextAlarm } from '../../processor/alerts/AlertsProcessor';
20
21/**
22 * 在需要提醒的时间发送 Event_Reminder 广播通知,如果提醒时间小于当前时间,则返回false
23 *
24 * @param nextAlarmTime 提醒的时间
25 * @return 提醒时间是否小于当前时间
26 */
27export async function notifyEventReminder(nextAlarmTime: number): Promise<boolean> {
28  // 设置定时器发送 EVENT_REMINDER 广播
29  let currentMillis = new Date().getTime();
30  if (nextAlarmTime < currentMillis) {
31    return false;
32  }
33  setTimeout(() => {
34    sendBroadcast(CommonEventConstants.EVENT_REMINDER);
35    runScheduleNextAlarm();
36  }, nextAlarmTime - currentMillis);
37  return true;
38}