Skip to content

Commit

Permalink
Version 2.12.2 build 486 for TestFlight testing
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyLB committed Aug 2, 2022
1 parent 9f80573 commit 2fc8063
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 127 deletions.
2 changes: 1 addition & 1 deletion Supporting Targets/piwigoKit/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>485</string>
<string>486</string>
</dict>
</plist>
11 changes: 10 additions & 1 deletion piwigo.xcodeproj/xcshareddata/xcschemes/piwigo.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
enableASanStackUseAfterReturn = "YES"
enableUBSanitizer = "YES"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand All @@ -70,9 +72,16 @@
<CommandLineArguments>
<CommandLineArgument
argument = "-com.apple.CoreData.concurrencyDebug 1"
isEnabled = "NO">
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
<AdditionalOptions>
<AdditionalOption
key = "MallocStackLogging"
value = ""
isEnabled = "YES">
</AdditionalOption>
</AdditionalOptions>
<LocationScenarioReference
identifier = "com.apple.dt.IDEFoundation.CurrentLocationScenarioIdentifier"
referenceType = "1">
Expand Down
2 changes: 1 addition & 1 deletion piwigo/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>485</string>
<string>486</string>
<key>INIntentsSupported</key>
<array>
<string>AutoUploadIntent</string>
Expand Down
250 changes: 126 additions & 124 deletions piwigoKit/Upload/UploadManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,144 +159,146 @@ public class UploadManager: NSObject {
print("\(debugFormatter.string(from: Date())) > findNextImageToUpload() in", queueName())
print("\(debugFormatter.string(from: Date())) > preparing:\(isPreparing ? "Yes" : "No"), uploading:\(isUploading.count), finishing:\(isFinishing ? "Yes" : "No")")

// Update app badge and Upload button in root/default album
// Considers only uploads to the server to which the user is logged in
var states: [kPiwigoUploadState] = [.waiting, .preparing, .preparingError,
.preparingFail, .formatError, .prepared,
.uploading, .uploadingError, .uploadingFail, .uploaded,
.finishing, .finishingError]
nberOfUploadsToComplete = uploadsProvider.getRequests(inStates: states).0.count
// return // for debugging background tasks

// Pause upload manager if:
/// - app not in the foreground anymore
/// - executing a background task
if isPaused || isExecutingBackgroundUploadTask { return }

// Determine the Power State and if it should wait
if ProcessInfo.processInfo.isLowPowerModeEnabled || isPaused {
// Low Power Mode is enabled. Stop transferring images.
return
}

// Check network access and status
if !NetworkVars.isConnectedToWiFi() && UploadVars.wifiOnlyUploading {
return
}
autoreleasepool {
// Update app badge and Upload button in root/default album
// Considers only uploads to the server to which the user is logged in
var states: [kPiwigoUploadState] = [.waiting, .preparing, .preparingError,
.preparingFail, .formatError, .prepared,
.uploading, .uploadingError, .uploadingFail, .uploaded,
.finishing, .finishingError]
nberOfUploadsToComplete = uploadsProvider.getRequests(inStates: states).0.count
// return // for debugging background tasks

// Pause upload manager if:
/// - app not in the foreground anymore
/// - executing a background task
if isPaused || isExecutingBackgroundUploadTask { return }

// Determine the Power State and if it should wait
if ProcessInfo.processInfo.isLowPowerModeEnabled || isPaused {
// Low Power Mode is enabled. Stop transferring images.
return
}

// Check network access and status
if !NetworkVars.isConnectedToWiFi() && UploadVars.wifiOnlyUploading {
return
}

// Interrupted work should be set as if an error was encountered
/// - case of finishes
let finishingIDs = uploadsProvider.getRequests(inStates: [.finishing]).1
if !isFinishing {
// Transfers encountered an error
for uploadID in finishingIDs {
print("\(debugFormatter.string(from: Date())) > Interrupted finish —> \(uploadID.uriRepresentation())")
uploadsProvider.updateStatusOfUpload(with: uploadID, to: .finishingError, error: JsonError.networkUnavailable.errorDescription) { [unowned self] (_) in
self.findNextImageToUpload()
return
// Interrupted work should be set as if an error was encountered
/// - case of finishes
let finishingIDs = uploadsProvider.getRequests(inStates: [.finishing]).1
if !isFinishing {
// Transfers encountered an error
for uploadID in finishingIDs {
print("\(debugFormatter.string(from: Date())) > Interrupted finish —> \(uploadID.uriRepresentation())")
uploadsProvider.updateStatusOfUpload(with: uploadID, to: .finishingError, error: JsonError.networkUnavailable.errorDescription) { [unowned self] (_) in
self.findNextImageToUpload()
return
}
}
}
}
/// - case of transfers (a few transfers may be running in parallel)
let uploadingIDs = uploadsProvider.getRequests(inStates: [.uploading]).1
for uploadID in uploadingIDs {
if !isUploading.contains(uploadID) {
// Transfer encountered an error
print("\(debugFormatter.string(from: Date())) > Interrupted transfer —> \(uploadID.uriRepresentation())")
uploadsProvider.updateStatusOfUpload(with: uploadID, to: .uploadingError, error: JsonError.networkUnavailable.errorDescription) { [unowned self] (_) in
self.findNextImageToUpload()
return
/// - case of transfers (a few transfers may be running in parallel)
let uploadingIDs = uploadsProvider.getRequests(inStates: [.uploading]).1
for uploadID in uploadingIDs {
if !isUploading.contains(uploadID) {
// Transfer encountered an error
print("\(debugFormatter.string(from: Date())) > Interrupted transfer —> \(uploadID.uriRepresentation())")
uploadsProvider.updateStatusOfUpload(with: uploadID, to: .uploadingError, error: JsonError.networkUnavailable.errorDescription) { [unowned self] (_) in
self.findNextImageToUpload()
return
}
}
}
}
/// - case of preparations
let preparingIDs = uploadsProvider.getRequests(inStates: [.preparing]).1
if !isPreparing {
// Preparations encountered an error
for uploadID in preparingIDs {
print("\(debugFormatter.string(from: Date())) > Interrupted preparation —> \(uploadID.uriRepresentation())")
uploadsProvider.updateStatusOfUpload(with: uploadID, to: .preparingError, error: UploadError.missingAsset.errorDescription) { [unowned self] (_) in
self.findNextImageToUpload()
return
/// - case of preparations
let preparingIDs = uploadsProvider.getRequests(inStates: [.preparing]).1
if !isPreparing {
// Preparations encountered an error
for uploadID in preparingIDs {
print("\(debugFormatter.string(from: Date())) > Interrupted preparation —> \(uploadID.uriRepresentation())")
uploadsProvider.updateStatusOfUpload(with: uploadID, to: .preparingError, error: UploadError.missingAsset.errorDescription) { [unowned self] (_) in
self.findNextImageToUpload()
return
}
}
}
}

// How many upload requests did fail?
let failedUploads = uploadsProvider.getRequests(inStates: [.preparingError, .preparingFail,
.uploadingError, .uploadingFail]).1.count
// Too many failures?
if failedUploads >= maxNberOfFailedUploads { return }

// Not finishing and upload request to finish?
/// Called when:
/// - uploading with pwg.images.upload because the title cannot be set during the upload.
/// - uploading with pwg.images.uploadAsync to empty the lounge as from the version 12 of the Piwigo server.
if !isFinishing,
let uploadID = uploadsProvider.getRequests(inStates: [.uploaded]).1.first {

// Pause upload manager if the app is not in the foreground anymore
if isPaused { return }

// Upload file ready, so we start the transfer
self.finishTransfer(of: uploadID)
return
}

// Not transferring and file ready for transfer?
if isUploading.count < maxNberOfTransfers,
let uploadID = uploadsProvider.getRequests(inStates: [.prepared]).1.first {

// Pause upload manager if the app is not in the foreground anymore
if isPaused { return }
// How many upload requests did fail?
let failedUploads = uploadsProvider.getRequests(inStates: [.preparingError, .preparingFail,
.uploadingError, .uploadingFail]).1.count
// Too many failures?
if failedUploads >= maxNberOfFailedUploads { return }

// Not finishing and upload request to finish?
/// Called when:
/// - uploading with pwg.images.upload because the title cannot be set during the upload.
/// - uploading with pwg.images.uploadAsync to empty the lounge as from the version 12 of the Piwigo server.
if !isFinishing,
let uploadID = uploadsProvider.getRequests(inStates: [.uploaded]).1.first {

// Pause upload manager if the app is not in the foreground anymore
if isPaused { return }

// Upload file ready, so we start the transfer
self.finishTransfer(of: uploadID)
return
}

// Upload file ready, so we start the transfer
self.launchTransfer(of: uploadID)
return
}

// Not preparing and upload request waiting?
let nberPrepared = uploadsProvider.getRequests(inStates: [.prepared]).0.count
if !isPreparing, nberPrepared < maxNberPreparedUploads,
let uploadID = uploadsProvider.getRequests(inStates: [.waiting]).1.first {
// Not transferring and file ready for transfer?
if isUploading.count < maxNberOfTransfers,
let uploadID = uploadsProvider.getRequests(inStates: [.prepared]).1.first {

// Pause upload manager if the app is not in the foreground anymore
if isPaused { return }
// Pause upload manager if the app is not in the foreground anymore
if isPaused { return }

// Prepare the next upload
self.prepare(for: uploadID)
return
}

// No more image to transfer ;-)
// Moderate images uploaded by Community regular user
// Considers only uploads to the server to which the user is logged in
let finishedUploads = uploadsProvider.getRequests(inStates: [.finished]).1
if NetworkVars.hasNormalRights,
NetworkVars.usesCommunityPluginV29, finishedUploads.count > 0 {
// Upload file ready, so we start the transfer
self.launchTransfer(of: uploadID)
return
}

// Not preparing and upload request waiting?
let nberPrepared = uploadsProvider.getRequests(inStates: [.prepared]).0.count
if !isPreparing, nberPrepared < maxNberPreparedUploads,
let uploadID = uploadsProvider.getRequests(inStates: [.waiting]).1.first {

// Pause upload manager if the app is not in the foreground anymore
if isPaused { return }
// Pause upload manager if the app is not in the foreground anymore
if isPaused { return }

// Moderate uploaded images
self.moderate(completedRequests: finishedUploads)
return
}
// Prepare the next upload
self.prepare(for: uploadID)
return
}

// No more image to transfer ;-)
// Moderate images uploaded by Community regular user
// Considers only uploads to the server to which the user is logged in
let finishedUploads = uploadsProvider.getRequests(inStates: [.finished]).1
if NetworkVars.hasNormalRights,
NetworkVars.usesCommunityPluginV29, finishedUploads.count > 0 {

// Pause upload manager if the app is not in the foreground anymore
if isPaused { return }

// Moderate uploaded images
self.moderate(completedRequests: finishedUploads)
return
}

// Suggest to delete images from the Photo Library if the user wanted it.
// The deletion is suggested when there is no more upload to perform.
// Note that some uploads may have failed and waiting a user decision.
states = [.waiting, .preparing, .prepared,
.uploading, .uploaded, .finishing]
if uploadsProvider.getRequests(inStates: states).0.count > 0 { return }

// Upload requests are completed
// Considers only uploads to the server to which the user is logged in
let (imageIDs, uploadIDs) = uploadsProvider.getRequests(inStates: [.finished, .moderated],
markedForDeletion: true)
if imageIDs.isEmpty == false, uploadIDs.isEmpty == false {
print("\(debugFormatter.string(from: Date())) > (\(imageIDs.count),\(uploadIDs.count)) should be deleted")
self.delete(uploadedImages: imageIDs, with: uploadIDs)
// Suggest to delete images from the Photo Library if the user wanted it.
// The deletion is suggested when there is no more upload to perform.
// Note that some uploads may have failed and waiting a user decision.
states = [.waiting, .preparing, .prepared,
.uploading, .uploaded, .finishing]
if uploadsProvider.getRequests(inStates: states).0.count > 0 { return }

// Upload requests are completed
// Considers only uploads to the server to which the user is logged in
let (imageIDs, uploadIDs) = uploadsProvider.getRequests(inStates: [.finished, .moderated],
markedForDeletion: true)
if imageIDs.isEmpty == false, uploadIDs.isEmpty == false {
print("\(debugFormatter.string(from: Date())) > (\(imageIDs.count),\(uploadIDs.count)) should be deleted")
self.delete(uploadedImages: imageIDs, with: uploadIDs)
}
}
}

Expand Down

0 comments on commit 2fc8063

Please sign in to comment.