Remove base::Observable / base::Variable.

This commit is contained in:
John Preston 2022-11-11 11:21:40 +04:00
parent 73e2cc96d1
commit 644ec1f599
22 changed files with 112 additions and 108 deletions

View file

@ -829,10 +829,6 @@ rpl::producer<bool> Application::appDeactivatedValue() const {
});
}
void Application::call_handleObservables() {
base::HandleObservables();
}
void Application::switchDebugMode() {
if (Logs::DebugEnabled()) {
Logs::SetDebugEnabled(false);

View file

@ -297,8 +297,6 @@ public:
void preventOrInvoke(Fn<void()> &&callback);
void call_handleObservables();
// Global runtime variables.
void setScreenIsLocked(bool locked);
bool screenIsLocked() const;

View file

@ -85,11 +85,6 @@ Sandbox::Sandbox(
char **argv)
: QApplication(argc, argv)
, _mainThreadId(QThread::currentThreadId())
, _handleObservables([=] {
if (_application) {
_application->call_handleObservables();
}
})
, _launcher(launcher) {
setQuitOnLastWindowClosed(false);
}
@ -201,10 +196,6 @@ void Sandbox::launchApplication() {
}
setupScreenScale();
base::InitObservables([] {
Instance()._handleObservables.call();
});
_application = std::make_unique<Application>(_launcher);
// Ideally this should go to constructor.

View file

@ -112,7 +112,6 @@ private:
int _loopNestingLevel = 0;
std::vector<int> _previousLoopNestingLevels;
std::vector<PostponedCall> _postponedCalls;
SingleQueuedInvokation _handleObservables;
not_null<Launcher*> _launcher;
std::unique_ptr<Application> _application;

View file

@ -2508,9 +2508,8 @@ void InnerWidget::refresh(bool toTop) {
_mustScrollTo.fire({ 0, 0 });
loadPeerPhotos();
}
_controller->dialogsListDisplayForced().set(
_searchInChat || !_filter.isEmpty(),
true);
_controller->setDialogsListDisplayForced(
_searchInChat || !_filter.isEmpty());
update();
}
@ -2648,9 +2647,8 @@ void InnerWidget::searchInChat(Key key, PeerData *from) {
}
moveCancelSearchButtons();
_controller->dialogsListDisplayForced().set(
_searchInChat || !_filter.isEmpty(),
true);
_controller->setDialogsListDisplayForced(
_searchInChat || !_filter.isEmpty());
}
void InnerWidget::refreshSearchInChatLabel() {

View file

@ -294,12 +294,13 @@ MainWidget::MainWidget(
_player->finishAnimating();
}
subscribe(_controller->dialogsListFocused(), [this](bool) {
rpl::merge(
_controller->dialogsListFocusedChanges(),
_controller->dialogsListDisplayForcedChanges()
) | rpl::start_with_next([=] {
updateDialogsWidthAnimated();
});
subscribe(_controller->dialogsListDisplayForced(), [this](bool) {
updateDialogsWidthAnimated();
});
}, lifetime());
rpl::merge(
Core::App().settings().dialogsWidthRatioChanges() | rpl::to_empty,
Core::App().settings().thirdColumnWidthChanges() | rpl::to_empty
@ -1396,7 +1397,7 @@ void MainWidget::ui_showPeerHistory(
}
}
_controller->dialogsListFocused().set(false, true);
_controller->setDialogsListFocused(false);
_a_dialogsWidth.stop();
using Way = SectionShow::Way;
@ -1751,7 +1752,7 @@ void MainWidget::showNewSection(
controller()->window().hideSettingsAndLayer();
}
_controller->dialogsListFocused().set(false, true);
_controller->setDialogsListFocused(false);
_a_dialogsWidth.stop();
auto mainSectionTop = getMainSectionTop();
@ -2619,10 +2620,10 @@ bool MainWidget::eventFilter(QObject *o, QEvent *e) {
if (_history == widget || _history->isAncestorOf(widget)
|| (_mainSection && (_mainSection == widget || _mainSection->isAncestorOf(widget)))
|| (_thirdSection && (_thirdSection == widget || _thirdSection->isAncestorOf(widget)))) {
_controller->dialogsListFocused().set(false);
_controller->setDialogsListFocused(false);
} else if (_dialogs
&& (_dialogs == widget || _dialogs->isAncestorOf(widget))) {
_controller->dialogsListFocused().set(true);
_controller->setDialogsListFocused(true);
}
}
} else if (e->type() == QEvent::MouseButtonPress) {

View file

@ -113,8 +113,7 @@ class ItemBase;
class MainWidget
: public Ui::RpWidget
, private Media::Player::FloatDelegate
, private base::Subscriber {
, private Media::Player::FloatDelegate {
public:
using SectionShow = Window::SectionShow;

View file

@ -305,12 +305,12 @@ constexpr auto kCheckPlaybackPositionTimeout = crl::time(100); // 100ms per chec
constexpr auto kCheckPlaybackPositionDelta = 2400LL; // update position called each 2400 samples
constexpr auto kCheckFadingTimeout = crl::time(7); // 7ms
base::Observable<AudioMsgId> UpdatedObservable;
rpl::event_stream<AudioMsgId> UpdatedStream;
} // namespace
base::Observable<AudioMsgId> &Updated() {
return UpdatedObservable;
rpl::producer<AudioMsgId> Updated() {
return UpdatedStream.events();
}
// Thread: Any. Must be locked: AudioMutex.
@ -648,7 +648,11 @@ void Mixer::onUpdated(const AudioMsgId &audio) {
if (audio.externalPlayId()) {
externalSoundProgress(audio);
}
Media::Player::Updated().notify(audio);
crl::on_main([=] {
// We've replaced base::Observable with on_main, because
// base::Observable::notify is not syncronous by default.
UpdatedStream.fire_copy(audio);
});
}
// Thread: Any. Must be locked: AudioMutex.

View file

@ -12,7 +12,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/file_location.h"
#include "data/data_audio_msg_id.h"
#include "base/bytes.h"
#include "base/observer.h"
#include "base/timer.h"
#include <QtCore/QTimer>
@ -60,7 +59,7 @@ constexpr auto kWaveformSamplesCount = 100;
class Fader;
class Loaders;
base::Observable<AudioMsgId> &Updated();
[[nodiscard]] rpl::producer<AudioMsgId> Updated();
float64 ComputeVolume(AudioMsgId::Type type);

View file

@ -11,7 +11,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/rect_part.h"
#include "ui/effects/animations.h"
#include "base/object_ptr.h"
#include "base/observer.h"
namespace Window {
class SessionController;
@ -48,7 +47,7 @@ private:
};
class Float : public Ui::RpWidget, private base::Subscriber {
class Float final : public Ui::RpWidget {
public:
Float(
QWidget *parent,
@ -210,12 +209,13 @@ private:
};
class FloatController : private base::Subscriber {
class FloatController final {
public:
explicit FloatController(not_null<FloatDelegate*> delegate);
void replaceDelegate(not_null<FloatDelegate*> delegate);
rpl::producer<FullMsgId> closeEvents() const {
[[nodiscard]] rpl::producer<FullMsgId> closeEvents() const {
return _closeEvents.events();
}

View file

@ -146,9 +146,10 @@ Instance::Data::~Data() = default;
Instance::Instance()
: _songData(AudioMsgId::Type::Song, SharedMediaType::MusicFile)
, _voiceData(AudioMsgId::Type::Voice, SharedMediaType::RoundVoiceFile) {
subscribe(Media::Player::Updated(), [this](const AudioMsgId &audioId) {
Media::Player::Updated(
) | rpl::start_with_next([=](const AudioMsgId &audioId) {
handleSongUpdate(audioId);
});
}, _lifetime);
repeatChanges(
&_songData
@ -157,6 +158,7 @@ Instance::Instance()
refreshPlaylist(&_songData);
}
}, _lifetime);
orderChanges(
&_songData
) | rpl::start_with_next([=](OrderMode mode) {

View file

@ -7,7 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "base/observer.h"
#include "data/data_audio_msg_id.h"
#include "data/data_shared_media.h"
@ -70,7 +69,7 @@ void SaveLastPlaybackPosition(
not_null<Instance*> instance();
class Instance : private base::Subscriber {
class Instance final {
public:
enum class Seeking {
Start,

View file

@ -198,7 +198,7 @@ rpl::producer<crl::time> AudioTrack::playPosition() {
if (!_subscription) {
_subscription = Media::Player::Updated(
).add_subscription([=](const AudioMsgId &id) {
) | rpl::start_with_next([=](const AudioMsgId &id) {
using State = Media::Player::State;
if (id != _audioId) {
return;

View file

@ -7,7 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "base/observer.h"
#include "media/streaming/media_streaming_utility.h"
namespace Media {
@ -80,7 +79,7 @@ private:
crl::time _startedPosition = kTimeUnknown;
// Accessed from the main thread.
base::Subscription _subscription;
rpl::lifetime _subscription;
rpl::event_stream<> _waitingForData;
// First set from the same unspecified thread before _ready is called.
// After that accessed from the main thread.

View file

@ -8,7 +8,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "media/system_media_controls_manager.h"
#include "media/audio/media_audio.h"
#include "base/observer.h"
#include "base/platform/base_platform_system_media_controls.h"
#include "core/application.h"
#include "core/core_settings.h"

View file

@ -201,7 +201,7 @@ QString bytesToUtf8(QLatin1String bytes) {
} // namespace
class Editor::Inner : public Ui::RpWidget, private base::Subscriber {
class Editor::Inner final : public Ui::RpWidget {
public:
Inner(QWidget *parent, const QString &path);
@ -397,24 +397,36 @@ Editor::Inner::Inner(QWidget *parent, const QString &path)
, _existingRows(this, EditorBlock::Type::Existing, &_context)
, _newRows(this, EditorBlock::Type::New, &_context) {
resize(st::windowMinWidth, st::windowMinHeight);
subscribe(_context.resized, [this] {
_context.resized.events(
) | rpl::start_with_next([=] {
resizeToWidth(width());
});
subscribe(_context.pending, [this](const EditorBlock::Context::EditionData &data) {
}, lifetime());
using Context = EditorBlock::Context;
_context.pending.events(
) | rpl::start_with_next([=](const Context::EditionData &data) {
applyEditing(data.name, data.copyOf, data.value);
});
subscribe(_context.updated, [this] {
}, lifetime());
_context.updated.events(
) | rpl::start_with_next([=] {
if (_context.name.isEmpty() && _focusCallback) {
_focusCallback();
}
});
subscribe(_context.scroll, [this](const EditorBlock::Context::ScrollData &data) {
}, lifetime());
_context.scroll.events(
) | rpl::start_with_next([=](const Context::ScrollData &data) {
if (_scrollCallback) {
auto top = (data.type == EditorBlock::Type::Existing ? _existingRows : _newRows)->y();
auto top = (data.type == EditorBlock::Type::Existing
? _existingRows
: _newRows)->y();
top += data.position;
_scrollCallback(top, top + data.height);
}
});
}, lifetime());
Background()->updates(
) | rpl::start_with_next([=](const BackgroundUpdate &update) {
if (_applyingUpdate || !Background()->editingTheme()) {

View file

@ -167,20 +167,25 @@ void EditorBlock::Row::fillSearchIndex() {
}
}
EditorBlock::EditorBlock(QWidget *parent, Type type, Context *context) : TWidget(parent)
EditorBlock::EditorBlock(QWidget *parent, Type type, Context *context)
: RpWidget(parent)
, _type(type)
, _context(context)
, _transparent(style::TransparentPlaceholder()) {
setMouseTracking(true);
subscribe(_context->updated, [this] {
_context->updated.events(
) | rpl::start_with_next([=] {
if (_mouseSelection) {
_lastGlobalPos = QCursor::pos();
updateSelected(mapFromGlobal(_lastGlobalPos));
}
update();
});
}, lifetime());
if (_type == Type::Existing) {
subscribe(_context->appended, [this](const Context::AppendData &added) {
_context->appended.events(
) | rpl::start_with_next([=](const Context::AppendData &added) {
auto name = added.name;
auto value = added.value;
feed(name, value);
@ -194,14 +199,15 @@ EditorBlock::EditorBlock(QWidget *parent, Type type, Context *context) : TWidget
row->setCopyOf(copyOf);
addToSearch(*row);
_context->changed.notify({ QStringList(name), value }, true);
_context->resized.notify();
_context->pending.notify({ name, copyOf, value }, true);
});
_context->changed.fire({ QStringList(name), value });
_context->resized.fire({});
_context->pending.fire({ name, copyOf, value });
}, lifetime());
} else {
subscribe(_context->changed, [this](const Context::ChangeData &data) {
_context->changed.events(
) | rpl::start_with_next([=](const Context::ChangeData &data) {
checkCopiesChanged(0, data.names, data.value);
});
}, lifetime());
}
}
@ -310,7 +316,7 @@ void EditorBlock::activateRow(const Row &row) {
}));
_context->box = box;
_context->name = row.name();
_context->updated.notify();
_context->updated.fire({});
}
}
}
@ -335,11 +341,8 @@ bool EditorBlock::selectSkip(int direction) {
void EditorBlock::scrollToSelected() {
if (_selected >= 0) {
Context::ScrollData update;
update.type = _type;
update.position = rowAtIndex(_selected).top();
update.height = rowAtIndex(_selected).height();
_context->scroll.notify(update, true);
const auto &row = rowAtIndex(_selected);
_context->scroll.fire({ _type, row.top(), row.height() });
}
}
@ -383,7 +386,7 @@ void EditorBlock::searchByQuery(QString query) {
}
}
_context->resized.notify(true);
_context->resized.fire({});
}
}
@ -556,7 +559,7 @@ void EditorBlock::saveEditing(QColor value) {
removeRow(name, false);
_context->appended.notify({ name, possibleCopyOf, color, description }, true);
_context->appended.fire({ name, possibleCopyOf, color, description });
} else if (_type == Type::Existing) {
removeFromSearch(row);
@ -576,7 +579,7 @@ void EditorBlock::saveEditing(QColor value) {
if (valueChanged || copyOfChanged) {
checkCopiesChanged(_editing + 1, QStringList(name), value);
_context->pending.notify({ name, copyOf, value }, true);
_context->pending.fire({ name, copyOf, value });
}
}
cancelEditing();
@ -593,7 +596,7 @@ void EditorBlock::checkCopiesChanged(int startIndex, QStringList names, QColor v
}
}
if (_type == Type::Existing) {
_context->changed.notify({ names, value }, true);
_context->changed.fire({ names, value });
}
}
@ -608,7 +611,7 @@ void EditorBlock::cancelEditing() {
_context->possibleCopyOf = QString();
if (!_context->name.isEmpty()) {
_context->name = QString();
_context->updated.notify();
_context->updated.fire({});
}
}

View file

@ -7,7 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "base/observer.h"
#include "ui/rp_widget.h"
class EditColorBox;
@ -15,7 +14,7 @@ class EditColorBox;
namespace Window {
namespace Theme {
class EditorBlock : public TWidget, private base::Subscriber {
class EditorBlock final : public Ui::RpWidget {
public:
enum class Type {
Existing,
@ -26,8 +25,8 @@ public:
QString name;
QString possibleCopyOf;
base::Observable<void> updated;
base::Observable<void> resized;
rpl::event_stream<> updated;
rpl::event_stream<> resized;
struct AppendData {
QString name;
@ -35,27 +34,27 @@ public:
QColor value;
QString description;
};
base::Observable<AppendData> appended;
rpl::event_stream<AppendData> appended;
struct ChangeData {
QStringList names;
QColor value;
};
base::Observable<ChangeData> changed;
rpl::event_stream<ChangeData> changed;
struct EditionData {
QString name;
QString copyOf;
QColor value;
};
base::Observable<EditionData> pending;
rpl::event_stream<EditionData> pending;
struct ScrollData {
Type type;
int position;
int height;
Type type = {};
int position = 0;
int height = 0;
};
base::Observable<ScrollData> scroll;
rpl::event_stream<ScrollData> scroll;
};
EditorBlock(QWidget *parent, Type type, Context *context);

View file

@ -41,7 +41,7 @@ not_null<Controller*> LockWidget::window() const {
void LockWidget::setInnerFocus() {
if (const auto controller = _window->sessionController()) {
controller->dialogsListFocused().set(false, true);
controller->setDialogsListFocused(false);
}
setFocus();
}

View file

@ -1234,9 +1234,9 @@ int SessionController::minimalThreeColumnWidth() const {
}
bool SessionController::forceWideDialogs() const {
if (dialogsListDisplayForced().value()) {
if (_dialogsListDisplayForced.current()) {
return true;
} else if (dialogsListFocused().value()) {
} else if (_dialogsListFocused.current()) {
return true;
}
return !content()->isMainSectionShown();

View file

@ -9,7 +9,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/flags.h"
#include "base/object_ptr.h"
#include "base/observer.h"
#include "base/weak_ptr.h"
#include "base/timer.h"
#include "boxes/gift_premium_box.h" // GiftPremiumValidator.
@ -480,17 +479,24 @@ public:
void toggleChooseChatTheme(not_null<PeerData*> peer);
base::Variable<bool> &dialogsListFocused() {
return _dialogsListFocused;
[[nodiscard]] bool dialogsListFocused() const {
return _dialogsListFocused.current();
}
const base::Variable<bool> &dialogsListFocused() const {
return _dialogsListFocused;
[[nodiscard]] rpl::producer<bool> dialogsListFocusedChanges() const {
return _dialogsListFocused.changes();
}
base::Variable<bool> &dialogsListDisplayForced() {
return _dialogsListDisplayForced;
void setDialogsListFocused(bool value) {
_dialogsListFocused = value;
}
const base::Variable<bool> &dialogsListDisplayForced() const {
return _dialogsListDisplayForced;
[[nodiscard]] bool dialogsListDisplayForced() const {
return _dialogsListDisplayForced.current();
}
[[nodiscard]] auto dialogsListDisplayForcedChanges() const
-> rpl::producer<bool> {
return _dialogsListDisplayForced.changes();
}
void setDialogsListDisplayForced(bool value) {
_dialogsListDisplayForced = value;
}
not_null<SessionController*> parentController() override {
@ -611,8 +617,8 @@ private:
rpl::variable<Dialogs::RowDescriptor> _activeChatEntry;
rpl::lifetime _activeHistoryLifetime;
base::Variable<bool> _dialogsListFocused = { false };
base::Variable<bool> _dialogsListDisplayForced = { false };
rpl::variable<bool> _dialogsListFocused = false;
rpl::variable<bool> _dialogsListDisplayForced = false;
std::deque<Dialogs::RowDescriptor> _chatEntryHistory;
int _chatEntryHistoryPosition = -1;
bool _filtersActivated = false;

@ -1 +1 @@
Subproject commit ff0d99dea36c80650acc2cd9c0dd3b24db6b8c1d
Subproject commit 4560884973dd855d9d06f0a9c09f5156e5a06dde