Skip to content

Commit

Permalink
Use static sdk instance
Browse files Browse the repository at this point in the history
  • Loading branch information
roeierez committed Dec 10, 2023
1 parent c6fe681 commit e57aff0
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ class NotificationService: UNNotificationServiceExtension {
private var logger: XCGLogger = {
let logsDir = FileManager
.default.containerURL(forSecurityApplicationGroupIdentifier: "group.F7R2LZH3W5.com.cBreez.client")!.appendingPathComponent("logs")
let extensionLogFile = logsDir.appendingPathComponent("extension.log")
let extensionLogFile = logsDir.appendingPathComponent("extension-\(Date().timeIntervalSince1970).log")
let log = XCGLogger.default
log.setup(level: .debug, showThreadName: true, showLevel: true, showFileNames: true, showLineNumbers: true, writeToFile: extensionLogFile.path)
return log
}()

private var breezSDK: BlockingBreezServices?
private static var breezSDK: BlockingBreezServices?
private var paymentReceivers: [PaymentReceiver] = []
private var paymentHashPollerTimer: Timer?

Expand All @@ -46,11 +46,11 @@ class NotificationService: UNNotificationServiceExtension {

DispatchQueue.main.async {
self.paymentReceivers.append(paymentReciever)
if self.breezSDK == nil {
if NotificationService.breezSDK == nil {
do {
self.logger.info("Breez SDK is not connected, connecting....")
try setLogStream(logStream: SDKLogListener(logger: self.logger))
self.breezSDK = try connectSDK(paymentListener: {[weak self](payment: Payment) in
NotificationService.breezSDK = try connectSDK(paymentListener: {[weak self](payment: Payment) in
DispatchQueue.main.async {
self?.onPaymentReceived(payment: payment)
}
Expand All @@ -76,7 +76,7 @@ class NotificationService: UNNotificationServiceExtension {
if let self = self {
self.logger.info("paymentHashPollerTimer.fire()")
for r in self.paymentReceivers {
if let payment = try? self.breezSDK!.paymentByHash(hash: r.paymentHash) {
if let payment = try? NotificationService.breezSDK!.paymentByHash(hash: r.paymentHash) {
if payment.status == PaymentStatus.complete {
self.onPaymentReceived(payment: payment)
}
Expand Down

0 comments on commit e57aff0

Please sign in to comment.