-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update implementation to align with frontend
- Loading branch information
Showing
7 changed files
with
119 additions
and
86 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import Foundation | ||
import Shared | ||
|
||
final class BarcodeScannerViewModel: ObservableObject { | ||
enum AbortReason: String { | ||
case canceled | ||
case alternativeOptions = "alternative_options" | ||
} | ||
|
||
private let incomingMessageId: Int | ||
|
||
init(incomingMessageId: Int) { | ||
self.incomingMessageId = incomingMessageId | ||
} | ||
|
||
func scannedCode(_ code: String, format: String) { | ||
Current.sceneManager.webViewWindowControllerPromise.then(\.webViewControllerPromise) | ||
.done { [weak self] controller in | ||
guard let incomingMessageId = self?.incomingMessageId else { return } | ||
controller | ||
.sendExternalBus(message: .init( | ||
id: incomingMessageId, | ||
command: WebViewExternalBusOutgoingMessage.barCodeScanResult.rawValue, | ||
payload: [ | ||
"rawValue": code, | ||
"format": format, | ||
] | ||
)) | ||
} | ||
} | ||
|
||
func aborted(_ reason: AbortReason) { | ||
Current.sceneManager.webViewWindowControllerPromise.then(\.webViewControllerPromise) | ||
.done { [weak self] controller in | ||
guard let incomingMessageId = self?.incomingMessageId else { return } | ||
controller.sendExternalBus(message: .init( | ||
id: incomingMessageId, | ||
command: WebViewExternalBusOutgoingMessage.barCodeScanAborted.rawValue, | ||
payload: [ | ||
"reason": reason.rawValue, | ||
] | ||
)) | ||
} | ||
} | ||
} |
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