32 const auto parsedUri =
ParseUri(uri);
34 if (parsedUri.Scheme !=
"audacity" || parsedUri.Host !=
"generate-audio")
39 if (queryParameters.empty())
42 const auto projectId = queryParameters.find(
"projectId");
44 if (projectId == queryParameters.end())
49 const auto hasOpenProject = openedProject !=
nullptr;
51 const auto project = hasOpenProject ?
55 std::string_view {},
false);
77 [&
project, onComplete = std::move(onComplete)](
const auto& response)
82 XO(
"Save to audio.com"),
XO(
"Generating audio preview..."),
87 [progressDialog = progressDialog.get(),
88 cancellationContext](
auto progress)
92 static_cast<unsigned>(progress * 10000), 10000) !=
93 BasicUI::ProgressResult::Success)
94 cancellationContext->Cancel();
97 mixdownUploader->SetUrls(response.SyncState.MixdownUrls);
101 progressDialog = std::shared_ptr { std::move(progressDialog) },
102 mixdownUploader, cancellationContext, onComplete]()
mutable
104 auto& projectCloudExtension =
107 auto subscription = projectCloudExtension.SubscribeStatusChanged(
108 [progressDialog = progressDialog.get(), mixdownUploader,
109 cancellationContext](
112 if (message.Status != ProjectSyncStatus::Failed)
115 cancellationContext->Cancel();
119 auto future = mixdownUploader->GetResultFuture();
121 while (future.wait_for(std::chrono::milliseconds(50)) !=
122 std::future_status::ready)
125 auto result = future.get();
127 progressDialog.reset();
130 onComplete(
project, result.State);
Toolkit-neutral facade for basic user interface services.
#define ASSERT_MAIN_THREAD()
QueryFields ParseUriQuery(std::string_view query, std::string_view delimiter) noexcept
Parses URI query and returns QueryFields structure with parsed fields.
UriFields ParseUri(std::string_view uri) noexcept
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
static ProjectWindow & Get(AudacityProject &project)
static std::shared_ptr< MixdownUploader > Upload(concurrency::CancellationContextPtr cancellationContext, const ServiceConfig &config, const AudacityProject &project, MixdownProgressCallback progressCallback)
static ProjectCloudExtension & Get(AudacityProject &project)
static CancellationContextPtr Create()
void CallAfter(Action action)
Schedule an action to be done later, and in the main thread.
void Yield()
Dispatch waiting events, including actions enqueued by CallAfter.
std::unique_ptr< ProgressDialog > MakeProgress(const TranslatableString &title, const TranslatableString &message, unsigned flags=(ProgressShowStop|ProgressShowCancel), const TranslatableString &remainingLabelText={})
Create and display a progress dialog.
void UploadMixdown(AudacityProject &project, std::function< void(AudacityProject &, MixdownState)> onComplete)
void SaveToCloud(AudacityProject &project, UploadMode mode, CreateSnapshotCallback snapshotCallback)
AudacityProject * OpenProjectFromCloud(AudacityProject *potentialTarget, std::string_view projectId, std::string_view snapshotId, CloudSyncService::SyncMode mode)
bool HandleMixdownLink(std::string_view uri)
AudacityProject * GetOpenedProject(std::string_view projectId)
AudacityProject * GetPotentialTarget()
const ServiceConfig & GetServiceConfig()
Returns the instance of the ServiceConfig.