fix: relayout tabs when update button visibility changes (#6447)

This commit is contained in:
pajlada
2025-09-06 12:48:27 +02:00
committed by GitHub
parent 6a0ca0bff8
commit 36ebb19469
7 changed files with 39 additions and 19 deletions
+19 -14
View File
@@ -7,12 +7,13 @@
namespace chatterino {
void initUpdateButton(PixmapButton &button,
const std::function<void()> &relayout,
pajlada::Signals::SignalHolder &signalHolder)
{
button.hide();
// show update prompt when clicking the button
QObject::connect(&button, &Button::leftClicked, [&button] {
QObject::connect(&button, &Button::leftClicked, [&button, relayout] {
auto *dialog = new UpdateDialog();
auto globalPoint = button.mapToGlobal(
@@ -32,32 +33,36 @@ void initUpdateButton(PixmapButton &button,
// be destroyed before the button is destroyed, since it is destroyed on focus loss
//
// The button is either attached to a Notebook, or a Window frame
std::ignore = dialog->buttonClicked.connect([&button](auto buttonType) {
switch (buttonType)
{
case UpdateDialog::Dismiss: {
button.hide();
std::ignore =
dialog->buttonClicked.connect([&button, relayout](auto buttonType) {
switch (buttonType)
{
case UpdateDialog::Dismiss: {
button.hide();
relayout();
}
break;
case UpdateDialog::Install: {
getApp()->getUpdates().installUpdates();
}
break;
}
break;
case UpdateDialog::Install: {
getApp()->getUpdates().installUpdates();
}
break;
}
});
});
// handle.reset(dialog);
// dialog->closing.connect([&handle] { handle.release(); });
});
// update image when state changes
auto updateChange = [&button](auto) {
auto updateChange = [&button, relayout](auto) {
button.setVisible(getApp()->getUpdates().shouldShowUpdateButton());
const auto *imageUrl = getApp()->getUpdates().isError()
? ":/buttons/updateError.png"
: ":/buttons/update.png";
button.setPixmap(QPixmap(imageUrl));
relayout();
};
updateChange(getApp()->getUpdates().getStatus());
+6 -1
View File
@@ -1,5 +1,7 @@
#pragma once
#include <functional>
namespace pajlada::Signals {
class SignalHolder;
} // namespace pajlada::Signals
@@ -7,9 +9,12 @@ class SignalHolder;
namespace chatterino {
class PixmapButton;
class UpdateDialog;
/// Initializes the update button
///
/// The `relayout` function gets called whenever the button visibility changes
void initUpdateButton(PixmapButton &button,
const std::function<void()> &relayout,
pajlada::Signals::SignalHolder &signalHolder);
} // namespace chatterino