Skip to content

Commit

Permalink
fixup! Added sleep prevention during file transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
Polyfish0 committed Oct 15, 2023
1 parent 26486e7 commit 6735b52
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 0 additions & 2 deletions NearbyShare/NearbyConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class NearbyConnection{

internal func handleConnectionClosure(){
print("Connection closed")
SleepManager.shared.enableSleep()
}

internal func protocolError(){
Expand Down Expand Up @@ -120,7 +119,6 @@ class NearbyConnection{
self.protocolError()
return
}
SleepManager.shared.disableSleep()
self.receiveFrameAsync(length: frameLength)
}
}
Expand Down
6 changes: 6 additions & 0 deletions NearbyShare/NearbyConnectionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ public class NearbyConnectionManager : NSObject, NetServiceDelegate, InboundNear
let id=UUID().uuidString
let conn=InboundNearbyConnection(connection: connection, id: id)
self.activeConnections[id]=conn
SleepManager.shared.disableSleep()
conn.delegate=self
conn.start()
}
Expand Down Expand Up @@ -226,6 +227,7 @@ public class NearbyConnectionManager : NSObject, NetServiceDelegate, InboundNear
guard let delegate=mainAppDelegate else {return}
delegate.incomingTransfer(id: connection.id, didFinishWith: error)
activeConnections.removeValue(forKey: connection.id)
SleepManager.shared.enableSleep()
}

public func submitUserConsent(transferID:String, accept:Bool){
Expand Down Expand Up @@ -385,5 +387,9 @@ public class NearbyConnectionManager : NSObject, NetServiceDelegate, InboundNear
}
outgoingTransfers.removeValue(forKey: connection.id)
}

public func getActiveConnections() -> Int {
return activeConnections.count
}
}

2 changes: 1 addition & 1 deletion NearbyShare/SleepManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SleepManager{
}

public func enableSleep(){
if(assertionID == 0){
if(assertionID == 0 || NearbyConnectionManager.shared.getActiveConnections() != 0){
return
}

Expand Down

0 comments on commit 6735b52

Please sign in to comment.