-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a8cf0a
commit 2db5d87
Showing
34 changed files
with
532 additions
and
155 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
29 changes: 29 additions & 0 deletions
29
Projects/Core/BackgroundTaskClient/Interface/BackgroundTaskClientInterface.swift
This file contains 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,29 @@ | ||
// | ||
// BackgroundTaskClientInterface.swift | ||
// BackgroundTaskClient | ||
// | ||
// Created by MinseokKang on 12/5/24. | ||
// | ||
|
||
import Foundation | ||
import BackgroundTasks | ||
|
||
import Dependencies | ||
import DependenciesMacros | ||
|
||
@DependencyClient | ||
public struct BackgroundTaskClient { | ||
public var registerTask: @Sendable ( | ||
_ identifier: String, | ||
_ queue: DispatchQueue?, | ||
_ launchHandler: @escaping (BGTask) -> Void | ||
) -> Bool = { _, _, _ in false } | ||
|
||
public var submit: @Sendable (_ taskRequest: BGTaskRequest) throws -> Void | ||
|
||
public var cancel: @Sendable (_ identifier: String) -> Void | ||
|
||
public var cancelAllTaskRequests: @Sendable () -> Void | ||
|
||
public var pendingTaskRequests: () async -> [BGTaskRequest] = { [] } | ||
} |
14 changes: 14 additions & 0 deletions
14
Projects/Core/BackgroundTaskClient/Interface/TestKey.swift
This file contains 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,14 @@ | ||
// | ||
// TestKey.swift | ||
// BackgroundTaskClientInterface | ||
// | ||
// Created by devMinseok on 12/5/24. | ||
// Copyright © 2024 PomoNyang. All rights reserved. | ||
// | ||
|
||
import Dependencies | ||
|
||
extension BackgroundTaskClient: TestDependencyKey { | ||
public static let previewValue = Self() | ||
public static let testValue = Self() | ||
} |
This file contains 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,27 @@ | ||
// | ||
// Project.swift | ||
// BackgroundTaskClientManifests | ||
// | ||
// Created by MinseokKang on 12/5/24. | ||
// | ||
|
||
import ProjectDescription | ||
import ProjectDescriptionHelpers | ||
|
||
@_spi(Core) | ||
@_spi(Shared) | ||
import DependencyPlugin | ||
|
||
let project: Project = .makeTMABasedProject( | ||
module: Core.BackgroundTaskClient, | ||
scripts: [], | ||
targets: [ | ||
.sources, | ||
.interface | ||
], | ||
dependencies: [ | ||
.interface: [ | ||
.dependency(rootModule: Shared.self) | ||
] | ||
] | ||
) |
39 changes: 39 additions & 0 deletions
39
Projects/Core/BackgroundTaskClient/Sources/BackgroundTaskClient.swift
This file contains 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,39 @@ | ||
// | ||
// BackgroundTaskClient.swift | ||
// BackgroundTaskClient | ||
// | ||
// Created by MinseokKang on 12/5/24. | ||
// | ||
|
||
import Foundation | ||
import BackgroundTasks | ||
|
||
import BackgroundTaskClientInterface | ||
|
||
import Dependencies | ||
|
||
extension BackgroundTaskClient: DependencyKey { | ||
public static let liveValue: BackgroundTaskClient = .live() | ||
|
||
public static func live() -> BackgroundTaskClient { | ||
let backgroundTaskScheduler = BGTaskScheduler.shared | ||
|
||
return .init( | ||
registerTask: { identifier, queue, handler in | ||
return backgroundTaskScheduler.register(forTaskWithIdentifier: identifier, using: queue, launchHandler: handler) | ||
}, | ||
submit: { request in | ||
try backgroundTaskScheduler.submit(request) | ||
}, | ||
cancel: { identifier in | ||
backgroundTaskScheduler.cancel(taskRequestWithIdentifier: identifier) | ||
}, | ||
cancelAllTaskRequests: { | ||
backgroundTaskScheduler.cancelAllTaskRequests() | ||
}, | ||
pendingTaskRequests: { | ||
await backgroundTaskScheduler.pendingTaskRequests() | ||
} | ||
) | ||
} | ||
} |
This file contains 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 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 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 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 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 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 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 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 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.