mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +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(
|
||||
Data::FileOrigin origin,
|
||||
not_null<DocumentData*> data,
|
||||
Mode mode) {
|
||||
Mode mode,
|
||||
Fn<void()> started) {
|
||||
if (data->isNull()) {
|
||||
return;
|
||||
}
|
||||
|
@ -89,6 +90,9 @@ void DocumentSaveClickHandler::Save(
|
|||
// background thread timers from working which would
|
||||
// stop audio playback in voice chats / live streams.
|
||||
if (mode != Mode::ToNewFile && data->saveFromData()) {
|
||||
if (started) {
|
||||
started();
|
||||
}
|
||||
return;
|
||||
}
|
||||
const auto filepath = data->filepath(true);
|
||||
|
@ -107,6 +111,9 @@ void DocumentSaveClickHandler::Save(
|
|||
filedir);
|
||||
if (!savename.isEmpty()) {
|
||||
data->save(origin, savename);
|
||||
if (started) {
|
||||
started();
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
@ -114,16 +121,21 @@ void DocumentSaveClickHandler::Save(
|
|||
void DocumentSaveClickHandler::SaveAndTrack(
|
||||
FullMsgId itemId,
|
||||
not_null<DocumentData*> document,
|
||||
Mode mode) {
|
||||
Save(itemId ? itemId : Data::FileOrigin(), document, mode);
|
||||
if (document->loading() && !document->loadingFilePath().isEmpty()) {
|
||||
if (const auto item = document->owner().message(itemId)) {
|
||||
Core::App().downloadManager().addLoading({
|
||||
.item = item,
|
||||
.document = document,
|
||||
});
|
||||
Mode mode,
|
||||
Fn<void()> started) {
|
||||
Save(itemId ? itemId : Data::FileOrigin(), document, mode, [=] {
|
||||
if (document->loading() && !document->loadingFilePath().isEmpty()) {
|
||||
if (const auto item = document->owner().message(itemId)) {
|
||||
Core::App().downloadManager().addLoading({
|
||||
.item = item,
|
||||
.document = document,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
if (started) {
|
||||
started();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void DocumentSaveClickHandler::onClickImpl() const {
|
||||
|
|
|
@ -53,11 +53,13 @@ public:
|
|||
static void Save(
|
||||
Data::FileOrigin origin,
|
||||
not_null<DocumentData*> document,
|
||||
Mode mode = Mode::ToCacheOrFile);
|
||||
Mode mode = Mode::ToCacheOrFile,
|
||||
Fn<void()> started = nullptr);
|
||||
static void SaveAndTrack(
|
||||
FullMsgId itemId,
|
||||
not_null<DocumentData*> document,
|
||||
Mode mode = Mode::ToCacheOrFile);
|
||||
Mode mode = Mode::ToCacheOrFile,
|
||||
Fn<void()> started = nullptr);
|
||||
|
||||
protected:
|
||||
void onClickImpl() const override;
|
||||
|
|
|
@ -2512,19 +2512,26 @@ void OverlayWidget::downloadMedia() {
|
|||
} else {
|
||||
if (_document->filepath(true).isEmpty()
|
||||
&& !_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(
|
||||
_message ? _message->fullId() : FullMsgId(),
|
||||
_document,
|
||||
DocumentSaveClickHandler::Mode::ToFile);
|
||||
_documentLoadingTo = _document->loadingFilePath();
|
||||
if (_stories && _documentLoadingTo.isEmpty()) {
|
||||
toName = _document->filepath(true);
|
||||
if (!toName.isEmpty()) {
|
||||
showSaveMsgToast(
|
||||
toName,
|
||||
tr::lng_mediaview_video_saved_to);
|
||||
}
|
||||
}
|
||||
DocumentSaveClickHandler::Mode::ToFile,
|
||||
crl::guard(_widget, checkSaveStarted));
|
||||
} else {
|
||||
_saveVisible = computeSaveButtonVisible();
|
||||
update(_saveNavOver);
|
||||
|
|
Loading…
Add table
Reference in a new issue