-
Notifications
You must be signed in to change notification settings - Fork 0
[#415] 위젯 싱크 트리거를 수정한다 #511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
47618d2
fix: Todo 변경 시 위젯 동기화 트리거 추가
opficdev 1e119d2
chore: DevLogData 프로젝트 포맷 갱신
opficdev f7d7834
fix: 위젯 설정 변경 시 동기화 트리거 추가
opficdev 2916a1a
fix: 세션 복구 시 위젯 동기화 트리거 추가
opficdev e9b9894
refactor: 푸시 알림 핸들러 서비스 의존성 적용
opficdev fecfa51
fix: 위젯 세션 동기화 메인 스레드 처리
opficdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
Application/DevLogApp/Sources/App/Handler/WidgetSessionSyncHandler.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| // | ||
| // WidgetSessionSyncHandler.swift | ||
| // DevLog | ||
| // | ||
| // Created by opfic on 6/1/26. | ||
| // | ||
|
|
||
| import Combine | ||
| import DevLogData | ||
|
|
||
| final class WidgetSessionSyncHandler { | ||
| private let authService: AuthService | ||
| private let widgetSyncEventBus: WidgetSyncEventBus | ||
| private var hasRequestedWidgetSync = false | ||
| private var cancellables = Set<AnyCancellable>() | ||
|
|
||
| init( | ||
| authService: AuthService, | ||
| widgetSyncEventBus: WidgetSyncEventBus | ||
| ) { | ||
| self.authService = authService | ||
| self.widgetSyncEventBus = widgetSyncEventBus | ||
|
|
||
| authService.observeSignedIn() | ||
| .removeDuplicates() | ||
| .sink { [weak self] isSignedIn in | ||
| self?.handleSessionUpdate(isSignedIn: isSignedIn) | ||
| } | ||
| .store(in: &cancellables) | ||
| } | ||
| } | ||
|
|
||
| private extension WidgetSessionSyncHandler { | ||
| func handleSessionUpdate(isSignedIn: Bool) { | ||
| guard isSignedIn else { | ||
| hasRequestedWidgetSync = false | ||
| return | ||
| } | ||
|
|
||
| guard hasRequestedWidgetSync == false else { | ||
| return | ||
| } | ||
|
|
||
| hasRequestedWidgetSync = true | ||
| widgetSyncEventBus.publish(.syncRequested) | ||
| } | ||
| } | ||
82 changes: 82 additions & 0 deletions
82
Application/DevLogApp/Tests/App/WidgetSessionSyncHandlerTests.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| // | ||
| // WidgetSessionSyncHandlerTests.swift | ||
| // DevLogAppTests | ||
| // | ||
| // Created by opfic on 6/1/26. | ||
| // | ||
|
|
||
| import Combine | ||
| import Testing | ||
| import DevLogData | ||
| @testable import DevLog | ||
|
|
||
| struct WidgetSessionSyncHandlerTests { | ||
| @Test("로그인 세션 true 첫 진입에서만 위젯 초기 동기화를 요청한다") | ||
| func 로그인_세션_true_첫_진입에서만_위젯_초기_동기화를_요청한다() { | ||
| let authServiceSpy = AuthServiceSpy() | ||
| let widgetSyncEventBusSpy = WidgetSyncEventBusSpy() | ||
| let widgetSessionSyncHandler = WidgetSessionSyncHandler( | ||
| authService: authServiceSpy, | ||
| widgetSyncEventBus: widgetSyncEventBusSpy | ||
| ) | ||
|
|
||
| authServiceSpy.send(true) | ||
| authServiceSpy.send(true) | ||
|
|
||
| #expect(widgetSyncEventBusSpy.events == [.syncRequested]) | ||
| _ = widgetSessionSyncHandler | ||
| } | ||
|
|
||
| @Test("로그아웃 이후 재로그인 시 위젯 초기 동기화를 다시 요청한다") | ||
| func 로그아웃_이후_재로그인_시_위젯_초기_동기화를_다시_요청한다() { | ||
| let authServiceSpy = AuthServiceSpy() | ||
| let widgetSyncEventBusSpy = WidgetSyncEventBusSpy() | ||
| let widgetSessionSyncHandler = WidgetSessionSyncHandler( | ||
| authService: authServiceSpy, | ||
| widgetSyncEventBus: widgetSyncEventBusSpy | ||
| ) | ||
|
|
||
| authServiceSpy.send(true) | ||
| authServiceSpy.send(false) | ||
| authServiceSpy.send(true) | ||
|
|
||
| #expect(widgetSyncEventBusSpy.events == [.syncRequested, .syncRequested]) | ||
| _ = widgetSessionSyncHandler | ||
| } | ||
| } | ||
|
|
||
| private final class AuthServiceSpy: AuthService { | ||
| private let currentValueSubject = CurrentValueSubject<Bool, Never>(false) | ||
|
|
||
| var uid: String? { nil } | ||
| var providerIDs: [String] { [] } | ||
| var currentUserEmail: String? { nil } | ||
| var providerCount: Int { 0 } | ||
|
|
||
| func observeSignedIn() -> AnyPublisher<Bool, Never> { | ||
| currentValueSubject.eraseToAnyPublisher() | ||
| } | ||
|
|
||
| func beginSignIn() { } | ||
| func completeSignIn() { } | ||
| func cancelSignIn() { } | ||
| func getProviderID() async throws -> String? { nil } | ||
| func deleteCurrentUser() async throws { } | ||
| func clearCurrentSession() async throws { } | ||
|
|
||
| func send(_ isSignedIn: Bool) { | ||
| currentValueSubject.send(isSignedIn) | ||
| } | ||
| } | ||
|
|
||
| private final class WidgetSyncEventBusSpy: WidgetSyncEventBus { | ||
| private(set) var events = [WidgetSyncEvent]() | ||
|
|
||
| func publish(_ event: WidgetSyncEvent) { | ||
| events.append(event) | ||
| } | ||
|
|
||
| func observe() -> AnyPublisher<WidgetSyncEvent, Never> { | ||
| Empty().eraseToAnyPublisher() | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.