mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Fix adding downloaded files to Downloads.
This commit is contained in:
parent
653d7aadb1
commit
b610de30f4
3 changed files with 43 additions and 22 deletions
|
@ -74,7 +74,8 @@ void DocumentOpenClickHandler::onClickImpl() const {
|
||||||
void DocumentSaveClickHandler::Save(
|
void DocumentSaveClickHandler::Save(
|
||||||
Data::FileOrigin origin,
|
Data::FileOrigin origin,
|
||||||
not_null<DocumentData*> data,
|
not_null<DocumentData*> data,
|
||||||
Mode mode) {
|
Mode mode,
|
||||||
|
Fn<void()> started) {
|
||||||
if (data->isNull()) {
|
if (data->isNull()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -89,6 +90,9 @@ void DocumentSaveClickHandler::Save(
|
||||||
// background thread timers from working which would
|
// background thread timers from working which would
|
||||||
// stop audio playback in voice chats / live streams.
|
// stop audio playback in voice chats / live streams.
|
||||||
if (mode != Mode::ToNewFile && data->saveFromData()) {
|
if (mode != Mode::ToNewFile && data->saveFromData()) {
|
||||||
|
if (started) {
|
||||||
|
started();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto filepath = data->filepath(true);
|
const auto filepath = data->filepath(true);
|
||||||
|
@ -107,6 +111,9 @@ void DocumentSaveClickHandler::Save(
|
||||||
filedir);
|
filedir);
|
||||||
if (!savename.isEmpty()) {
|
if (!savename.isEmpty()) {
|
||||||
data->save(origin, savename);
|
data->save(origin, savename);
|
||||||
|
if (started) {
|
||||||
|
started();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -114,16 +121,21 @@ void DocumentSaveClickHandler::Save(
|
||||||
void DocumentSaveClickHandler::SaveAndTrack(
|
void DocumentSaveClickHandler::SaveAndTrack(
|
||||||
FullMsgId itemId,
|
FullMsgId itemId,
|
||||||
not_null<DocumentData*> document,
|
not_null<DocumentData*> document,
|
||||||
Mode mode) {
|
Mode mode,
|
||||||
Save(itemId ? itemId : Data::FileOrigin(), document, mode);
|
Fn<void()> started) {
|
||||||
if (document->loading() && !document->loadingFilePath().isEmpty()) {
|
Save(itemId ? itemId : Data::FileOrigin(), document, mode, [=] {
|
||||||
if (const auto item = document->owner().message(itemId)) {
|
if (document->loading() && !document->loadingFilePath().isEmpty()) {
|
||||||
Core::App().downloadManager().addLoading({
|
if (const auto item = document->owner().message(itemId)) {
|
||||||
.item = item,
|
Core::App().downloadManager().addLoading({
|
||||||
.document = document,
|
.item = item,
|
||||||
});
|
.document = document,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if (started) {
|
||||||
|
started();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void DocumentSaveClickHandler::onClickImpl() const {
|
void DocumentSaveClickHandler::onClickImpl() const {
|
||||||
|
|
|
@ -53,11 +53,13 @@ public:
|
||||||
static void Save(
|
static void Save(
|
||||||
Data::FileOrigin origin,
|
Data::FileOrigin origin,
|
||||||
not_null<DocumentData*> document,
|
not_null<DocumentData*> document,
|
||||||
Mode mode = Mode::ToCacheOrFile);
|
Mode mode = Mode::ToCacheOrFile,
|
||||||
|
Fn<void()> started = nullptr);
|
||||||
static void SaveAndTrack(
|
static void SaveAndTrack(
|
||||||
FullMsgId itemId,
|
FullMsgId itemId,
|
||||||
not_null<DocumentData*> document,
|
not_null<DocumentData*> document,
|
||||||
Mode mode = Mode::ToCacheOrFile);
|
Mode mode = Mode::ToCacheOrFile,
|
||||||
|
Fn<void()> started = nullptr);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void onClickImpl() const override;
|
void onClickImpl() const override;
|
||||||
|
|
|
@ -2512,19 +2512,26 @@ void OverlayWidget::downloadMedia() {
|
||||||
} else {
|
} else {
|
||||||
if (_document->filepath(true).isEmpty()
|
if (_document->filepath(true).isEmpty()
|
||||||
&& !_document->loading()) {
|
&& !_document->loading()) {
|
||||||
|
const auto document = _document;
|
||||||
|
const auto checkSaveStarted = [=] {
|
||||||
|
if (isHidden() || _document != document) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_documentLoadingTo = _document->loadingFilePath();
|
||||||
|
if (_stories && _documentLoadingTo.isEmpty()) {
|
||||||
|
const auto toName = _document->filepath(true);
|
||||||
|
if (!toName.isEmpty()) {
|
||||||
|
showSaveMsgToast(
|
||||||
|
toName,
|
||||||
|
tr::lng_mediaview_video_saved_to);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
DocumentSaveClickHandler::SaveAndTrack(
|
DocumentSaveClickHandler::SaveAndTrack(
|
||||||
_message ? _message->fullId() : FullMsgId(),
|
_message ? _message->fullId() : FullMsgId(),
|
||||||
_document,
|
_document,
|
||||||
DocumentSaveClickHandler::Mode::ToFile);
|
DocumentSaveClickHandler::Mode::ToFile,
|
||||||
_documentLoadingTo = _document->loadingFilePath();
|
crl::guard(_widget, checkSaveStarted));
|
||||||
if (_stories && _documentLoadingTo.isEmpty()) {
|
|
||||||
toName = _document->filepath(true);
|
|
||||||
if (!toName.isEmpty()) {
|
|
||||||
showSaveMsgToast(
|
|
||||||
toName,
|
|
||||||
tr::lng_mediaview_video_saved_to);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
_saveVisible = computeSaveButtonVisible();
|
_saveVisible = computeSaveButtonVisible();
|
||||||
update(_saveNavOver);
|
update(_saveNavOver);
|
||||||
|
|
Loading…
Add table
Reference in a new issue