2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-22 02:07:24 +00:00

Proof-of-concept macOS app icon change.

This commit is contained in:
John Preston 2022-02-08 15:21:06 +03:00
parent 666251f23e
commit 2ae5fc0fac
2 changed files with 81 additions and 22 deletions

View File

@ -50,6 +50,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/platform/base_platform_info.h" #include "base/platform/base_platform_info.h"
#include "platform/platform_specific.h" #include "platform/platform_specific.h"
#include "base/call_delayed.h" #include "base/call_delayed.h"
#include "base/custom_app_icon.h"
#include "support/support_common.h" #include "support/support_common.h"
#include "support/support_templates.h" #include "support/support_templates.h"
#include "main/main_session.h" #include "main/main_session.h"
@ -75,6 +76,11 @@ public:
explicit ColorsPalette(not_null<Ui::VerticalLayout*> container); explicit ColorsPalette(not_null<Ui::VerticalLayout*> container);
void show(Type type); void show(Type type);
void show(
std::vector<QColor> &&colors,
int selected,
int customLightnessMin,
int customLightnessMax);
rpl::producer<QColor> selected() const; rpl::producer<QColor> selected() const;
@ -102,11 +108,9 @@ private:
}; };
void show( void selectCustom(
not_null<const Scheme*> scheme, int customLightnessMin,
std::vector<QColor> &&colors, int customLightnessMax);
int selected);
void selectCustom(not_null<const Scheme*> scheme);
void updateInnerGeometry(); void updateInnerGeometry();
not_null<Ui::SlideWrap<>*> _outer; not_null<Ui::SlideWrap<>*> _outer;
@ -267,21 +271,25 @@ void ColorsPalette::show(Type type) {
0, 0,
int(list.size()) - 1); int(list.size()) - 1);
_outer->show(anim::type::instant); const auto colorizer = Window::Theme::ColorizerFrom(
*scheme,
show(&*scheme, std::move(list), selected); scheme->accentColor);
show(
const auto inner = _outer->entity(); std::move(list),
inner->resize(_outer->width(), inner->height()); selected,
updateInnerGeometry(); colorizer.lightnessMin,
colorizer.lightnessMax);
} }
void ColorsPalette::show( void ColorsPalette::show(
not_null<const Scheme*> scheme,
std::vector<QColor> &&colors, std::vector<QColor> &&colors,
int selected) { int selected,
int customLightnessMin,
int customLightnessMax) {
Expects(selected >= 0 && selected < colors.size()); Expects(selected >= 0 && selected < colors.size());
_outer->show(anim::type::instant);
while (_buttons.size() > colors.size()) { while (_buttons.size() > colors.size()) {
_buttons.pop_back(); _buttons.pop_back();
} }
@ -321,25 +329,27 @@ void ColorsPalette::show(
std::move( std::move(
clicks clicks
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
selectCustom(scheme); selectCustom(customLightnessMin, customLightnessMax);
}, inner->lifetime()); }, 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); const auto selected = ranges::find(_buttons, true, &Button::selected);
Assert(selected != end(_buttons)); Assert(selected != end(_buttons));
const auto colorizer = Window::Theme::ColorizerFrom(
*scheme,
scheme->accentColor);
auto box = Box<EditColorBox>( auto box = Box<EditColorBox>(
tr::lng_settings_theme_accent_title(tr::now), tr::lng_settings_theme_accent_title(tr::now),
EditColorBox::Mode::HSL, EditColorBox::Mode::HSL,
(*selected)->color()); (*selected)->color());
box->setLightnessLimits( box->setLightnessLimits(
colorizer.lightnessMin, customLightnessMin,
colorizer.lightnessMax); customLightnessMax);
box->setSaveCallback(crl::guard(_outer, [=](QColor result) { box->setSaveCallback(crl::guard(_outer, [=](QColor result) {
_selected.fire_copy(result); _selected.fire_copy(result);
})); }));
@ -1013,6 +1023,51 @@ void SetupChatBackground(
}, adaptive->lifetime()); }, 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);
AddSubsectionTitle(container, rpl::single(u"App Icon"_q));
const auto palette = Ui::CreateChild<ColorsPalette>(
container.get(),
container.get());
auto list = Window::Theme::DefaultAccentColors(
Window::Theme::EmbeddedType::Night);
const auto original = QColor(29, 148, 208);
list[0] = original;
palette->show(std::move(list), 0, 0, 255);
const auto logo = QImage(":/gui/art/logo_256.png").convertToFormat(
QImage::Format_ARGB32);
palette->selected(
) | rpl::start_with_next([=](QColor color) {
if (color == original) {
base::ClearCustomAppIcon();
} 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);
base::SetCustomAppIcon(std::move(image));
}
}, container->lifetime());
AddSkip(container);
}
#endif // Q_OS_MAC && !OS_MAC_STORE
void SetupDefaultThemes( void SetupDefaultThemes(
not_null<Window::Controller*> window, not_null<Window::Controller*> window,
not_null<Ui::VerticalLayout*> container) { not_null<Ui::VerticalLayout*> container) {
@ -1483,6 +1538,10 @@ Chat::Chat(QWidget *parent, not_null<Window::SessionController*> controller)
void Chat::setupContent(not_null<Window::SessionController*> controller) { void Chat::setupContent(not_null<Window::SessionController*> controller) {
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this); 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); SetupThemeOptions(controller, content);
SetupAutoNightMode(controller, content); SetupAutoNightMode(controller, content);
SetupCloudThemes(controller, content); SetupCloudThemes(controller, content);

@ -1 +1 @@
Subproject commit 2aebd29afcad5929bde456dfcd3bf71a7bf25760 Subproject commit 7253d8f09883df51705c358b1f8ff50ba7eda8e6