mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-07-25 06:54:43 +00:00
fix: possible translator crash
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "api/api_text_entities.h"
|
||||
#include "ayu/features/translator/ayu_translator.h"
|
||||
#include "base/weak_ptr.h"
|
||||
#include "data/data_msg_id.h"
|
||||
#include "data/data_peer.h"
|
||||
#include "data/data_session.h"
|
||||
@@ -17,7 +18,9 @@
|
||||
|
||||
namespace {
|
||||
|
||||
class AyuTranslateProvider final : public Ui::TranslateProvider {
|
||||
class AyuTranslateProvider final
|
||||
: public Ui::TranslateProvider
|
||||
, public base::has_weak_ptr {
|
||||
public:
|
||||
AyuTranslateProvider(
|
||||
not_null<Main::Session*> session,
|
||||
@@ -48,6 +51,18 @@ public:
|
||||
const LanguageId &to,
|
||||
Fn<void(int, Ui::TranslateProviderResult)> doneOne,
|
||||
Fn<void()> doneAll) override {
|
||||
doneOne = [weak = base::make_weak(this), doneOne = std::move(doneOne)](
|
||||
int index,
|
||||
Ui::TranslateProviderResult result) {
|
||||
if (weak) {
|
||||
doneOne(index, std::move(result));
|
||||
}
|
||||
};
|
||||
doneAll = [weak = base::make_weak(this), doneAll = std::move(doneAll)] {
|
||||
if (weak) {
|
||||
doneAll();
|
||||
}
|
||||
};
|
||||
if (requests.empty()) {
|
||||
doneAll();
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user