Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a7958f5235 | ||
|
|
2ae5fc0fac |
@@ -66,6 +66,21 @@ constexpr auto kRecentEmojiLimit = 42;
|
||||
return result;
|
||||
}
|
||||
|
||||
[[nodiscard]] quint32 SerializeColor(QColor color) {
|
||||
return (quint32(std::clamp(color.alpha(), 0, 255)) << 24)
|
||||
| (quint32(std::clamp(color.red(), 0, 255)) << 16)
|
||||
| (quint32(std::clamp(color.green(), 0, 255)) << 8)
|
||||
| quint32(std::clamp(color.blue(), 0, 255));
|
||||
}
|
||||
|
||||
[[nodiscard]] QColor DeserializeColor(quint32 value) {
|
||||
return QColor(
|
||||
(value >> 16) & 0xFF,
|
||||
(value >> 8) & 0xFF,
|
||||
value & 0xFF,
|
||||
(value >> 24) & 0xFF);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Settings::Settings()
|
||||
@@ -236,6 +251,10 @@ QByteArray Settings::serialize() const {
|
||||
for (const auto &id : _accountsOrder) {
|
||||
stream << quint64(id);
|
||||
}
|
||||
|
||||
stream
|
||||
<< SerializeColor(_customAppIcon.color)
|
||||
<< quint64(_customAppIcon.digest);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -325,6 +344,8 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
|
||||
qint32 macWarnBeforeQuit = _macWarnBeforeQuit ? 1 : 0;
|
||||
qint32 accountsOrderCount = 0;
|
||||
std::vector<uint64> accountsOrder;
|
||||
quint32 customAppIconColor = SerializeColor(_customAppIcon.color);
|
||||
quint64 customAppIconDigest = _customAppIcon.digest;
|
||||
|
||||
stream >> themesAccentColors;
|
||||
if (!stream.atEnd()) {
|
||||
@@ -506,6 +527,11 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!stream.atEnd()) {
|
||||
stream
|
||||
>> customAppIconColor
|
||||
>> customAppIconDigest;
|
||||
}
|
||||
if (stream.status() != QDataStream::Ok) {
|
||||
LOG(("App Error: "
|
||||
"Bad data for Core::Settings::constructFromSerialized()"));
|
||||
@@ -662,6 +688,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
|
||||
case Media::Player::OrderMode::Shuffle: _playerOrderMode = uncheckedPlayerOrderMode; break;
|
||||
}
|
||||
_macWarnBeforeQuit = macWarnBeforeQuit ? 1 : 0;
|
||||
_customAppIcon = { DeserializeColor(customAppIconColor), customAppIconDigest };
|
||||
}
|
||||
|
||||
QString Settings::getSoundPath(const QString &key) const {
|
||||
|
||||
@@ -51,6 +51,11 @@ struct WindowPosition {
|
||||
int h = 0;
|
||||
};
|
||||
|
||||
struct CustomAppIcon {
|
||||
QColor color;
|
||||
uint64 digest = 0;
|
||||
};
|
||||
|
||||
class Settings final {
|
||||
public:
|
||||
enum class ScreenCorner {
|
||||
@@ -669,6 +674,12 @@ public:
|
||||
[[nodiscard]] bool macWarnBeforeQuit() const {
|
||||
return _macWarnBeforeQuit;
|
||||
}
|
||||
void setCustomAppIcon(CustomAppIcon icon) {
|
||||
_customAppIcon = icon;
|
||||
}
|
||||
[[nodiscard]] CustomAppIcon customAppIcon() const {
|
||||
return _customAppIcon;
|
||||
}
|
||||
|
||||
[[nodiscard]] static bool ThirdColumnByDefault();
|
||||
[[nodiscard]] static float64 DefaultDialogsWidthRatio();
|
||||
@@ -775,6 +786,7 @@ private:
|
||||
rpl::variable<Media::Player::OrderMode> _playerOrderMode;
|
||||
bool _macWarnBeforeQuit = true;
|
||||
std::vector<uint64> _accountsOrder;
|
||||
CustomAppIcon _customAppIcon;
|
||||
|
||||
bool _tabbedReplacedWithInfo = false; // per-window
|
||||
rpl::event_stream<bool> _tabbedReplacedWithInfoValue; // per-window
|
||||
|
||||
@@ -50,6 +50,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "base/platform/base_platform_info.h"
|
||||
#include "platform/platform_specific.h"
|
||||
#include "base/call_delayed.h"
|
||||
#include "base/custom_app_icon.h"
|
||||
#include "support/support_common.h"
|
||||
#include "support/support_templates.h"
|
||||
#include "main/main_session.h"
|
||||
@@ -75,6 +76,11 @@ public:
|
||||
explicit ColorsPalette(not_null<Ui::VerticalLayout*> container);
|
||||
|
||||
void show(Type type);
|
||||
void show(
|
||||
std::vector<QColor> &&colors,
|
||||
int selected,
|
||||
int customLightnessMin,
|
||||
int customLightnessMax);
|
||||
|
||||
rpl::producer<QColor> selected() const;
|
||||
|
||||
@@ -102,11 +108,9 @@ private:
|
||||
|
||||
};
|
||||
|
||||
void show(
|
||||
not_null<const Scheme*> scheme,
|
||||
std::vector<QColor> &&colors,
|
||||
int selected);
|
||||
void selectCustom(not_null<const Scheme*> scheme);
|
||||
void selectCustom(
|
||||
int customLightnessMin,
|
||||
int customLightnessMax);
|
||||
void updateInnerGeometry();
|
||||
|
||||
not_null<Ui::SlideWrap<>*> _outer;
|
||||
@@ -267,20 +271,22 @@ void ColorsPalette::show(Type type) {
|
||||
0,
|
||||
int(list.size()) - 1);
|
||||
|
||||
_outer->show(anim::type::instant);
|
||||
|
||||
show(&*scheme, std::move(list), selected);
|
||||
|
||||
const auto inner = _outer->entity();
|
||||
inner->resize(_outer->width(), inner->height());
|
||||
updateInnerGeometry();
|
||||
const auto colorizer = Window::Theme::ColorizerFrom(
|
||||
*scheme,
|
||||
scheme->accentColor);
|
||||
show(
|
||||
std::move(list),
|
||||
selected,
|
||||
colorizer.lightnessMin,
|
||||
colorizer.lightnessMax);
|
||||
}
|
||||
|
||||
void ColorsPalette::show(
|
||||
not_null<const Scheme*> scheme,
|
||||
std::vector<QColor> &&colors,
|
||||
int selected) {
|
||||
Expects(selected >= 0 && selected < colors.size());
|
||||
int selected,
|
||||
int customLightnessMin,
|
||||
int customLightnessMax) {
|
||||
_outer->show(anim::type::instant);
|
||||
|
||||
while (_buttons.size() > colors.size()) {
|
||||
_buttons.pop_back();
|
||||
@@ -321,25 +327,27 @@ void ColorsPalette::show(
|
||||
std::move(
|
||||
clicks
|
||||
) | rpl::start_with_next([=] {
|
||||
selectCustom(scheme);
|
||||
selectCustom(customLightnessMin, customLightnessMax);
|
||||
}, inner->lifetime());
|
||||
}
|
||||
|
||||
inner->resize(_outer->width(), inner->height());
|
||||
updateInnerGeometry();
|
||||
}
|
||||
|
||||
void ColorsPalette::selectCustom(not_null<const Scheme*> scheme) {
|
||||
void ColorsPalette::selectCustom(
|
||||
int customLightnessMin,
|
||||
int customLightnessMax) {
|
||||
const auto selected = ranges::find(_buttons, true, &Button::selected);
|
||||
Assert(selected != end(_buttons));
|
||||
|
||||
const auto colorizer = Window::Theme::ColorizerFrom(
|
||||
*scheme,
|
||||
scheme->accentColor);
|
||||
auto box = Box<EditColorBox>(
|
||||
tr::lng_settings_theme_accent_title(tr::now),
|
||||
EditColorBox::Mode::HSL,
|
||||
(*selected)->color());
|
||||
box->setLightnessLimits(
|
||||
colorizer.lightnessMin,
|
||||
colorizer.lightnessMax);
|
||||
customLightnessMin,
|
||||
customLightnessMax);
|
||||
box->setSaveCallback(crl::guard(_outer, [=](QColor result) {
|
||||
_selected.fire_copy(result);
|
||||
}));
|
||||
@@ -1013,6 +1021,88 @@ void SetupChatBackground(
|
||||
}, adaptive->lifetime());
|
||||
}
|
||||
|
||||
#if defined Q_OS_MAC && !defined OS_MAC_STORE
|
||||
void SetupAppIcon(
|
||||
not_null<Window::Controller*> window,
|
||||
not_null<Ui::VerticalLayout*> container) {
|
||||
AddSkip(container, st::settingsPrivacySkip);
|
||||
|
||||
container->add(
|
||||
object_ptr<Ui::FlatLabel>(
|
||||
container,
|
||||
rpl::single(u"App Icon"_q),
|
||||
st::settingsSubsectionTitle),
|
||||
(st::settingsSubsectionTitlePadding
|
||||
- QMargins(0, 0, 0, st::settingsSubsectionTitlePadding.bottom())));
|
||||
|
||||
const auto palette = Ui::CreateChild<ColorsPalette>(
|
||||
container.get(),
|
||||
container.get());
|
||||
const auto original = QColor(29, 148, 208);
|
||||
const auto refresh = [=](uint64 currentDigest) {
|
||||
auto list = Window::Theme::DefaultAccentColors(
|
||||
Window::Theme::EmbeddedType::Night);
|
||||
list[0] = original;
|
||||
const auto current = Core::App().settings().customAppIcon();
|
||||
const auto selected = !currentDigest
|
||||
? 0
|
||||
: (currentDigest != current.digest)
|
||||
? -1
|
||||
: std::min(
|
||||
int(ranges::find(list, current.color) - begin(list)),
|
||||
int(size(list)) - 1);
|
||||
if (selected == size(list) - 1) {
|
||||
list[selected] = current.color;
|
||||
}
|
||||
palette->show(std::move(list), selected, 0, 255);
|
||||
};
|
||||
refresh(base::CurrentCustomAppIconDigest().value_or(0));
|
||||
|
||||
const auto logo = QImage(":/gui/art/logo_256.png").convertToFormat(
|
||||
QImage::Format_ARGB32);
|
||||
palette->selected(
|
||||
) | rpl::start_with_next([=](QColor color) {
|
||||
if (color == original) {
|
||||
const auto success = base::ClearCustomAppIcon();
|
||||
if (success) {
|
||||
Core::App().settings().setCustomAppIcon({});
|
||||
Core::App().saveSettingsDelayed();
|
||||
refresh(0);
|
||||
}
|
||||
Ui::Toast::Show(success
|
||||
? "Icon cleared. Restarting the Dock."
|
||||
: "Icon clear failed. See log.txt for details.");
|
||||
} else {
|
||||
auto colorizer = style::colorizer{
|
||||
.hueThreshold = 64,
|
||||
};
|
||||
original.getHsv(
|
||||
&colorizer.was.hue,
|
||||
&colorizer.was.saturation,
|
||||
&colorizer.was.value);
|
||||
color.getHsv(
|
||||
&colorizer.now.hue,
|
||||
&colorizer.now.saturation,
|
||||
&colorizer.now.value);
|
||||
auto image = logo;
|
||||
style::colorize(image, colorizer);
|
||||
const auto digest = base::SetCustomAppIcon(std::move(image));
|
||||
if (digest) {
|
||||
Core::App().settings().setCustomAppIcon({ color, *digest });
|
||||
Core::App().saveSettingsDelayed();
|
||||
refresh(*digest);
|
||||
}
|
||||
Ui::Toast::Show(digest
|
||||
? "Icon updated. Restarting the Dock."
|
||||
: "Icon update failed. See log.txt for details.");
|
||||
}
|
||||
}, container->lifetime());
|
||||
|
||||
AddSkip(container);
|
||||
AddDivider(container);
|
||||
}
|
||||
#endif // Q_OS_MAC && !OS_MAC_STORE
|
||||
|
||||
void SetupDefaultThemes(
|
||||
not_null<Window::Controller*> window,
|
||||
not_null<Ui::VerticalLayout*> container) {
|
||||
@@ -1483,6 +1573,10 @@ Chat::Chat(QWidget *parent, not_null<Window::SessionController*> controller)
|
||||
void Chat::setupContent(not_null<Window::SessionController*> controller) {
|
||||
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
||||
|
||||
#if defined Q_OS_MAC && !defined OS_MAC_STORE
|
||||
SetupAppIcon(&controller->window(), content);
|
||||
#endif // Q_OS_MAC && !OS_MAC_STORE
|
||||
|
||||
SetupThemeOptions(controller, content);
|
||||
SetupAutoNightMode(controller, content);
|
||||
SetupCloudThemes(controller, content);
|
||||
|
||||
Submodule Telegram/lib_base updated: 2aebd29afc...2461c5ad4a
Reference in New Issue
Block a user