mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
Use special webview storage for tonsite.
This commit is contained in:
parent
2dcf40817e
commit
4f37343e8b
7 changed files with 55 additions and 10 deletions
|
@ -220,7 +220,8 @@ QByteArray Settings::serialize() const {
|
|||
+ Serialize::bytearraySize(ivPosition)
|
||||
+ Serialize::stringSize(noWarningExtensions)
|
||||
+ Serialize::stringSize(_customFontFamily)
|
||||
+ sizeof(qint32) * 3;
|
||||
+ sizeof(qint32) * 3
|
||||
+ Serialize::bytearraySize(_tonsiteStorageToken);
|
||||
|
||||
auto result = QByteArray();
|
||||
result.reserve(size);
|
||||
|
@ -373,7 +374,8 @@ QByteArray Settings::serialize() const {
|
|||
0,
|
||||
1000000))
|
||||
<< qint32(_systemUnlockEnabled ? 1 : 0)
|
||||
<< qint32(!_weatherInCelsius ? 0 : *_weatherInCelsius ? 1 : 2);
|
||||
<< qint32(!_weatherInCelsius ? 0 : *_weatherInCelsius ? 1 : 2)
|
||||
<< _tonsiteStorageToken;
|
||||
}
|
||||
|
||||
Ensures(result.size() == size);
|
||||
|
@ -495,6 +497,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
|
|||
QString customFontFamily = _customFontFamily;
|
||||
qint32 systemUnlockEnabled = _systemUnlockEnabled ? 1 : 0;
|
||||
qint32 weatherInCelsius = !_weatherInCelsius ? 0 : *_weatherInCelsius ? 1 : 2;
|
||||
QByteArray tonsiteStorageToken = _tonsiteStorageToken;
|
||||
|
||||
stream >> themesAccentColors;
|
||||
if (!stream.atEnd()) {
|
||||
|
@ -798,6 +801,9 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
|
|||
if (!stream.atEnd()) {
|
||||
stream >> weatherInCelsius;
|
||||
}
|
||||
if (!stream.atEnd()) {
|
||||
stream >> tonsiteStorageToken;
|
||||
}
|
||||
if (stream.status() != QDataStream::Ok) {
|
||||
LOG(("App Error: "
|
||||
"Bad data for Core::Settings::constructFromSerialized()"));
|
||||
|
@ -1009,6 +1015,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
|
|||
_weatherInCelsius = !weatherInCelsius
|
||||
? std::optional<bool>()
|
||||
: (weatherInCelsius == 1);
|
||||
_tonsiteStorageToken = tonsiteStorageToken;
|
||||
}
|
||||
|
||||
QString Settings::getSoundPath(const QString &key) const {
|
||||
|
|
|
@ -898,6 +898,13 @@ public:
|
|||
_weatherInCelsius = value;
|
||||
}
|
||||
|
||||
[[nodiscard]] QByteArray tonsiteStorageToken() const {
|
||||
return _tonsiteStorageToken;
|
||||
}
|
||||
void setTonsiteStorageToken(const QByteArray &value) {
|
||||
_tonsiteStorageToken = value;
|
||||
}
|
||||
|
||||
[[nodiscard]] static bool ThirdColumnByDefault();
|
||||
[[nodiscard]] static float64 DefaultDialogsWidthRatio();
|
||||
|
||||
|
@ -1030,6 +1037,7 @@ private:
|
|||
QString _customFontFamily;
|
||||
bool _systemUnlockEnabled = false;
|
||||
std::optional<bool> _weatherInCelsius;
|
||||
QByteArray _tonsiteStorageToken;
|
||||
|
||||
bool _tabbedReplacedWithInfo = false; // per-window
|
||||
rpl::event_stream<bool> _tabbedReplacedWithInfoValue; // per-window
|
||||
|
|
|
@ -254,10 +254,24 @@ void Controller::update(Prepared page) {
|
|||
void Controller::showTonSite(
|
||||
const Webview::StorageId &storageId,
|
||||
QString uri) {
|
||||
auto part = uri.mid(u"tonsite://"_q.size());
|
||||
part = part.replace('-', "-h");
|
||||
part = part.replace('.', "-d");
|
||||
const auto url = "https://" + part + ".magic.org";
|
||||
const auto url = [&] {
|
||||
auto parsed = QUrl(uri);
|
||||
if (parsed.isValid()) {
|
||||
auto host = parsed.host();
|
||||
host = host.replace('-', "-h");
|
||||
host = host.replace('.', "-d");
|
||||
parsed.setHost(host + ".magic.org");
|
||||
parsed.setScheme("https");
|
||||
return parsed.toString();
|
||||
}
|
||||
auto part = uri.mid(u"tonsite://"_q.size());
|
||||
const auto split = part.indexOf('/');
|
||||
auto host = (split < 0) ? part : part.left(split);
|
||||
host = host.replace('-', "-h");
|
||||
host = host.replace('.', "-d");
|
||||
part = (split < 0) ? QString() : part.mid(split);
|
||||
return "https://" + host + ".magic.org" + part;
|
||||
}();
|
||||
if (!_webview) {
|
||||
createWebview(storageId);
|
||||
}
|
||||
|
|
|
@ -800,9 +800,7 @@ void TonSite::showWindowed() {
|
|||
createController();
|
||||
}
|
||||
|
||||
_controller->showTonSite(
|
||||
{},//_session->local().resolveStorageIdOther(),
|
||||
_uri);
|
||||
_controller->showTonSite(Storage::TonSiteStorageId(), _uri);
|
||||
}
|
||||
|
||||
bool TonSite::active() const {
|
||||
|
|
|
@ -34,7 +34,7 @@ SessionSettings::SessionSettings()
|
|||
|
||||
QByteArray SessionSettings::serialize() const {
|
||||
const auto autoDownload = _autoDownload.serialize();
|
||||
auto size = sizeof(qint32) * 4
|
||||
const auto size = sizeof(qint32) * 4
|
||||
+ _groupStickersSectionHidden.size() * sizeof(quint64)
|
||||
+ sizeof(qint32) * 4
|
||||
+ Serialize::bytearraySize(autoDownload)
|
||||
|
@ -103,6 +103,8 @@ QByteArray SessionSettings::serialize() const {
|
|||
<< qint32(_lastNonPremiumLimitDownload)
|
||||
<< qint32(_lastNonPremiumLimitUpload);
|
||||
}
|
||||
|
||||
Ensures(result.size() == size);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -3198,4 +3198,18 @@ bool Account::decrypt(
|
|||
return true;
|
||||
}
|
||||
|
||||
Webview::StorageId TonSiteStorageId() {
|
||||
auto result = Webview::StorageId{
|
||||
.path = BaseGlobalPath() + u"webview-tonsite"_q,
|
||||
.token = Core::App().settings().tonsiteStorageToken(),
|
||||
};
|
||||
if (result.token.isEmpty()) {
|
||||
result.token = QByteArray::fromStdString(
|
||||
Webview::GenerateStorageToken());
|
||||
Core::App().settings().setTonsiteStorageToken(result.token);
|
||||
Core::App().saveSettingsDelayed();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace Storage
|
||||
|
|
|
@ -327,4 +327,6 @@ private:
|
|||
|
||||
};
|
||||
|
||||
[[nodiscard]] Webview::StorageId TonSiteStorageId();
|
||||
|
||||
} // namespace Storage
|
||||
|
|
Loading…
Add table
Reference in a new issue