Fix saving of playback position for long videos.

This commit is contained in:
John Preston 2019-12-27 17:09:55 +03:00
parent ac48ec5969
commit 79870600d9
4 changed files with 20 additions and 2 deletions

View File

@ -123,7 +123,14 @@ Application::Application(not_null<Launcher*> launcher)
Application::~Application() {
_window.reset();
_mediaView.reset();
if (_mediaView) {
_mediaView->clearData();
_mediaView = nullptr;
}
if (activeAccount().sessionExists()) {
activeAccount().session().saveSettingsNowIfNeeded();
}
// This can call writeMap() that serializes Main::Session.
// In case it gets called after destroySession() we get missing data.

View File

@ -203,6 +203,13 @@ Support::Templates& Session::supportTemplates() const {
return supportHelper().templates();
}
void Session::saveSettingsNowIfNeeded() {
if (_saveSettingsTimer.isActive()) {
_saveSettingsTimer.cancel();
Local::writeUserSettings();
}
}
} // namespace Main
Main::Session &Auth() {

View File

@ -106,6 +106,7 @@ public:
return _settings;
}
void saveSettingsDelayed(crl::time delay = kDefaultSaveDelay);
void saveSettingsNowIfNeeded();
[[nodiscard]] not_null<MTP::Instance*> mtp();
[[nodiscard]] ApiWrap &api() {

View File

@ -439,9 +439,12 @@ bool OverlayWidget::documentBubbleShown() const {
void OverlayWidget::clearStreaming(bool savePosition) {
if (_streamed && _doc && savePosition) {
using State = Media::Player::State;
const auto state = _streamed->instance.player().prepareLegacyState();
const auto time = (state.position == kTimeUnknown
|| state.length == kTimeUnknown)
|| state.length == kTimeUnknown
|| state.state == State::PausedAtEnd
|| Media::Player::IsStopped(state.state))
? TimeId(0)
: (state.length >= kMinLengthForSavePosition * state.frequency)
? (state.position / state.frequency) * crl::time(1000)