Use special webview storage for tonsite.

This commit is contained in:
John Preston 2024-07-29 12:26:22 +02:00
parent 2dcf40817e
commit 4f37343e8b
7 changed files with 55 additions and 10 deletions

View file

@ -220,7 +220,8 @@ QByteArray Settings::serialize() const {
+ Serialize::bytearraySize(ivPosition) + Serialize::bytearraySize(ivPosition)
+ Serialize::stringSize(noWarningExtensions) + Serialize::stringSize(noWarningExtensions)
+ Serialize::stringSize(_customFontFamily) + Serialize::stringSize(_customFontFamily)
+ sizeof(qint32) * 3; + sizeof(qint32) * 3
+ Serialize::bytearraySize(_tonsiteStorageToken);
auto result = QByteArray(); auto result = QByteArray();
result.reserve(size); result.reserve(size);
@ -373,7 +374,8 @@ QByteArray Settings::serialize() const {
0, 0,
1000000)) 1000000))
<< qint32(_systemUnlockEnabled ? 1 : 0) << qint32(_systemUnlockEnabled ? 1 : 0)
<< qint32(!_weatherInCelsius ? 0 : *_weatherInCelsius ? 1 : 2); << qint32(!_weatherInCelsius ? 0 : *_weatherInCelsius ? 1 : 2)
<< _tonsiteStorageToken;
} }
Ensures(result.size() == size); Ensures(result.size() == size);
@ -495,6 +497,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
QString customFontFamily = _customFontFamily; QString customFontFamily = _customFontFamily;
qint32 systemUnlockEnabled = _systemUnlockEnabled ? 1 : 0; qint32 systemUnlockEnabled = _systemUnlockEnabled ? 1 : 0;
qint32 weatherInCelsius = !_weatherInCelsius ? 0 : *_weatherInCelsius ? 1 : 2; qint32 weatherInCelsius = !_weatherInCelsius ? 0 : *_weatherInCelsius ? 1 : 2;
QByteArray tonsiteStorageToken = _tonsiteStorageToken;
stream >> themesAccentColors; stream >> themesAccentColors;
if (!stream.atEnd()) { if (!stream.atEnd()) {
@ -798,6 +801,9 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
if (!stream.atEnd()) { if (!stream.atEnd()) {
stream >> weatherInCelsius; stream >> weatherInCelsius;
} }
if (!stream.atEnd()) {
stream >> tonsiteStorageToken;
}
if (stream.status() != QDataStream::Ok) { if (stream.status() != QDataStream::Ok) {
LOG(("App Error: " LOG(("App Error: "
"Bad data for Core::Settings::constructFromSerialized()")); "Bad data for Core::Settings::constructFromSerialized()"));
@ -1009,6 +1015,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
_weatherInCelsius = !weatherInCelsius _weatherInCelsius = !weatherInCelsius
? std::optional<bool>() ? std::optional<bool>()
: (weatherInCelsius == 1); : (weatherInCelsius == 1);
_tonsiteStorageToken = tonsiteStorageToken;
} }
QString Settings::getSoundPath(const QString &key) const { QString Settings::getSoundPath(const QString &key) const {

View file

@ -898,6 +898,13 @@ public:
_weatherInCelsius = value; _weatherInCelsius = value;
} }
[[nodiscard]] QByteArray tonsiteStorageToken() const {
return _tonsiteStorageToken;
}
void setTonsiteStorageToken(const QByteArray &value) {
_tonsiteStorageToken = value;
}
[[nodiscard]] static bool ThirdColumnByDefault(); [[nodiscard]] static bool ThirdColumnByDefault();
[[nodiscard]] static float64 DefaultDialogsWidthRatio(); [[nodiscard]] static float64 DefaultDialogsWidthRatio();
@ -1030,6 +1037,7 @@ private:
QString _customFontFamily; QString _customFontFamily;
bool _systemUnlockEnabled = false; bool _systemUnlockEnabled = false;
std::optional<bool> _weatherInCelsius; std::optional<bool> _weatherInCelsius;
QByteArray _tonsiteStorageToken;
bool _tabbedReplacedWithInfo = false; // per-window bool _tabbedReplacedWithInfo = false; // per-window
rpl::event_stream<bool> _tabbedReplacedWithInfoValue; // per-window rpl::event_stream<bool> _tabbedReplacedWithInfoValue; // per-window

View file

@ -254,10 +254,24 @@ void Controller::update(Prepared page) {
void Controller::showTonSite( void Controller::showTonSite(
const Webview::StorageId &storageId, const Webview::StorageId &storageId,
QString uri) { QString uri) {
auto part = uri.mid(u"tonsite://"_q.size()); const auto url = [&] {
part = part.replace('-', "-h"); auto parsed = QUrl(uri);
part = part.replace('.', "-d"); if (parsed.isValid()) {
const auto url = "https://" + part + ".magic.org"; 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) { if (!_webview) {
createWebview(storageId); createWebview(storageId);
} }

View file

@ -800,9 +800,7 @@ void TonSite::showWindowed() {
createController(); createController();
} }
_controller->showTonSite( _controller->showTonSite(Storage::TonSiteStorageId(), _uri);
{},//_session->local().resolveStorageIdOther(),
_uri);
} }
bool TonSite::active() const { bool TonSite::active() const {

View file

@ -34,7 +34,7 @@ SessionSettings::SessionSettings()
QByteArray SessionSettings::serialize() const { QByteArray SessionSettings::serialize() const {
const auto autoDownload = _autoDownload.serialize(); const auto autoDownload = _autoDownload.serialize();
auto size = sizeof(qint32) * 4 const auto size = sizeof(qint32) * 4
+ _groupStickersSectionHidden.size() * sizeof(quint64) + _groupStickersSectionHidden.size() * sizeof(quint64)
+ sizeof(qint32) * 4 + sizeof(qint32) * 4
+ Serialize::bytearraySize(autoDownload) + Serialize::bytearraySize(autoDownload)
@ -103,6 +103,8 @@ QByteArray SessionSettings::serialize() const {
<< qint32(_lastNonPremiumLimitDownload) << qint32(_lastNonPremiumLimitDownload)
<< qint32(_lastNonPremiumLimitUpload); << qint32(_lastNonPremiumLimitUpload);
} }
Ensures(result.size() == size);
return result; return result;
} }

View file

@ -3198,4 +3198,18 @@ bool Account::decrypt(
return true; 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 } // namespace Storage

View file

@ -327,4 +327,6 @@ private:
}; };
[[nodiscard]] Webview::StorageId TonSiteStorageId();
} // namespace Storage } // namespace Storage