Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
devMinseok committed Nov 27, 2024
1 parent 67a885e commit 440cadc
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 46 deletions.
Binary file added Projects/App/Resources/DEV/timer_end_sound.caf
Binary file not shown.
Binary file added Projects/App/Resources/PROD/timer_end_sound.caf
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
// Copyright © 2024 PomoNyang. All rights reserved.
//

import UserNotifications.UNNotificationSound

import CatServiceInterface

public enum LocalPushNotiContent {
case focusEnd(SomeCat)
case restEnd(SomeCat)
case disturb(SomeCat)

public var title: String {
return ""
}
Expand Down Expand Up @@ -42,4 +44,17 @@ public enum LocalPushNotiContent {
return "disturb"
}
}

public var sound: UNNotificationSound {
switch self {
case .focusEnd:
return .init(named: UNNotificationSoundName("timer_end_sound.caf"))

case .restEnd:
return .init(named: UNNotificationSoundName("timer_end_sound.caf"))

case .disturb:
return .default
}
}
}
2 changes: 1 addition & 1 deletion Projects/Domain/PushService/Sources/PushService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public func scheduleNotification(
content.title = contentType.title
content.subtitle = contentType.title
content.body = contentType.body
content.sound = UNNotificationSound.default
content.sound = contentType.sound
let request = UNNotificationRequest(
identifier: contentType.identifier,
content: content,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public struct FocusPomodoroCore {
case catTapped
case setupFocusTime
case catSetInput
case _pushNotificationTrigger
case setupLiveActivity
case setupPushNotification

case goToHome
case saveHistory(focusTimeBySeconds: Int, restTimeBySeconds: Int)
Expand Down Expand Up @@ -153,6 +153,7 @@ public struct FocusPomodoroCore {
await send(.set(\.selectedCategory, selectedCategory))
await send(.setupFocusTime)
await send(.setupLiveActivity)
await send(.setupPushNotification)
await send(.timer(.start))
}

Expand Down Expand Up @@ -187,23 +188,6 @@ public struct FocusPomodoroCore {
state.catRiv.setInput(selectedCat.rivInputName, value: true)
return .none

case ._pushNotificationTrigger:
let isTimerAlarmOn = getTimerAlarm(userDefaultsClient: self.userDefaultsClient)
guard isTimerAlarmOn,
let selectedCat = state.selectedCat
else { return .none }
return .run { _ in
let trigger = UNTimeIntervalNotificationTrigger(
timeInterval: 0.1,
repeats: false
)
try await scheduleNotification(
userNotificationClient: self.userNotificationClient,
contentType: .focusEnd(selectedCat),
trigger: trigger
)
}

case .setupLiveActivity:
let isLiveActivityAllowed = getLiveActivityState(userDefaultsClient: self.userDefaultsClient)
guard isLiveActivityAllowed,
Expand Down Expand Up @@ -234,6 +218,33 @@ public struct FocusPomodoroCore {
}
}

case .setupPushNotification:
let isTimerAlarmOn = getTimerAlarm(userDefaultsClient: self.userDefaultsClient)
guard isTimerAlarmOn,
let selectedCat = state.selectedCat,
let timeInterval = state.goalDatetime?.timeIntervalSinceNow
else { return .none }
return .run { _ in
let trigger = UNTimeIntervalNotificationTrigger(
timeInterval: timeInterval,
repeats: false
)
try await scheduleNotification(
userNotificationClient: self.userNotificationClient,
contentType: .focusEnd(selectedCat),
trigger: trigger
)

do {
try await Task.never()
} catch {
await removePendingNotification(
userNotificationClient: self.userNotificationClient,
identifier: ["focusEnd"]
)
}
}

case .goToHome:
return .none

Expand All @@ -246,13 +257,6 @@ public struct FocusPomodoroCore {
let timeDifference = timeDifferenceInSeconds(from: Date.now, to: goalDatetime)

if state.focusTimeBySeconds == 0 {
if !state.pushTriggered {
state.pushTriggered = true
return .run { send in
await send(._pushNotificationTrigger)
try await self.audioClient.playSound(fileURL: Files.timerEndSoundMp3.url) // 개선
}
}
if state.overTimeBySeconds == 3600 { // 60분 초과시 휴식 대기화면으로 이동
return .run { [state] send in
await send(.timer(.stop)) // task가 cancel을 해주지만 일단 action 중복을 방지하기 위해 명시적으로 stop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ public struct RestPomodoroCore {
case catTapped
case catSetInput
case setupLiveActivity
case setupPushNotification

case goToHome
case goToFocus
case saveHistory(focusTimeBySeconds: Int, restTimeBySeconds: Int)
case _pushNotificationTrigger

case timer(TimerCore.Action)
}
Expand Down Expand Up @@ -120,6 +120,7 @@ public struct RestPomodoroCore {
await send(.set(\.selectedCategory, selectedCategory))
await send(.setupRestTime)
await send(.setupLiveActivity)
await send(.setupPushNotification)
await send(.timer(.start))
}

Expand Down Expand Up @@ -208,45 +209,49 @@ public struct RestPomodoroCore {
}
}

case .goToHome:
return .none

case .goToFocus:
return .none

case .saveHistory:
return .none

case ._pushNotificationTrigger:
case .setupPushNotification:
let isTimerAlarmOn = getTimerAlarm(userDefaultsClient: self.userDefaultsClient)
guard isTimerAlarmOn,
let selectedCat = state.selectedCat
let selectedCat = state.selectedCat,
let timeInterval = state.goalDatetime?.timeIntervalSinceNow
else { return .none }
return .run { _ in
let trigger = UNTimeIntervalNotificationTrigger(
timeInterval: 0.1,
timeInterval: timeInterval,
repeats: false
)
try await scheduleNotification(
userNotificationClient: self.userNotificationClient,
contentType: .restEnd(selectedCat),
trigger: trigger
)

do {
try await Task.never()
} catch {
await removePendingNotification(
userNotificationClient: self.userNotificationClient,
identifier: ["restEnd"]
)
}
}

case .goToHome:
return .none

case .goToFocus:
return .none

case .saveHistory:
return .none

case .timer(.tick):
// date 처이 계산
guard let goalDatetime = state.goalDatetime else { return .none }

let timeDifference = timeDifferenceInSeconds(from: Date.now, to: goalDatetime)

if state.restTimeBySeconds == 0 {
if !state.pushTriggered {
state.pushTriggered = true
return .run { send in
await send(._pushNotificationTrigger)
}
}
if state.overTimeBySeconds == 1800 { // 30분 초과시 휴식 대기화면으로 이동
return .run { [state] send in
await send(.timer(.stop)) // task가 cancel을 해주지만 일단 action 중복을 방지하기 위해 명시적으로 stop
Expand Down

0 comments on commit 440cadc

Please sign in to comment.