when using
photo:applyDevelopPreset(preset)
with a preset containing AI Settings, this will trigger the calculating ai settings dialog in newer LrC versions most of the times.
Issue 1)
When calling LrTasks.sleep(1) immediately after the call and keeping the withWriteAccess lock some time does prevent the dialog from showing up and seems to bring LrC in a state where it won't show the dialog anymore even without the LrTasks.sleep(1). This seems pretty random to me (maybe some race condition). But sometimes my LrC is in a state where it won't trigger the dialog.
This is rather annoying and inconvinient, but the more serious issue is:
Issue 2)
When LrC does show the dialog, it seems to show it for every photo separately, leading to many dialogs popping up and blocking each other as seen in my screenshot
One cannot cancel the below dialogs and when trying to cancel the frontmost it just sits in the "stopping" state forever.
Generally as i said it seems somewhat fragile to get LrC to show this dialog at all (sometimes it is in a state when it wont show it and sometimes it does). So there is some smell of race conditions.
Generally from my perspective the best solution would be to allow the plugin to trigger the AI Settings calculations via the SDK, so that it can be triggered under a controlled flow after all photos have been updated.
Alternatively it would probably be good to only trigger one update after all photos have been updated and the writeAccessLock has been freed.
In order to reproduce, one can use the following code
local LrTasks = import "LrTasks"
local LrApplication = import "LrApplication"
local LrDialogs = import "LrDialogs"
LrTasks.startAsyncTask(function()
local success, error = LrTasks.pcall(function()
local catalog = LrApplication.activeCatalog()
local photos = catalog:getTargetPhotos()
local presetUuid = "8A9FF6C8654BA338F601B854EF008497"
local preset = LrApplication.developPresetByUuid(presetUuid)
if preset then
if true then
-- we go through all photos and apply the preset
-- this seems to trigger the "calculate AI settings"
-- for each photo and leads to a lockup situation
catalog:withWriteAccessDo("Apply preset", function(context)
for _, photo in ipairs(photos) do
photo:applyDevelopPreset(preset)
end
end)
else
-- for test, we apply the preset and sleep to give some time
-- interestingly, this way does not trigger the "calculate AI settings" at all
-- and once we ran like this, the other way also no longer brings up the
-- "calculate AI settings" dialog anymore until LrC is restarted
for _, photo in ipairs(photos) do
catalog:withWriteAccessDo("Apply preset", function(context)
photo:applyDevelopPreset(preset)
end)
LrTasks.sleep(1)
end
end
else
LrDialogs.message("Preset not found", "Preset with UUID " .. presetUuid .. " not found", "critical")
end
end)
if not success then
LrDialogs.showError("Error: " .. tostring(error))
end
end)