2019-09-08 22:27:57 +02:00
|
|
|
#include "InitUpdateButton.hpp"
|
|
|
|
|
|
|
|
#include "widgets/dialogs/UpdateDialog.hpp"
|
|
|
|
#include "widgets/helper/Button.hpp"
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
|
|
|
void initUpdateButton(Button &button,
|
|
|
|
pajlada::Signals::SignalHolder &signalHolder)
|
|
|
|
{
|
|
|
|
button.hide();
|
|
|
|
|
|
|
|
// show update prompt when clicking the button
|
|
|
|
QObject::connect(&button, &Button::leftClicked, [&button] {
|
|
|
|
auto dialog = new UpdateDialog();
|
|
|
|
dialog->setActionOnFocusLoss(BaseWindow::Delete);
|
|
|
|
dialog->move(button.mapToGlobal(
|
|
|
|
QPoint(int(-100 * button.scale()), button.height())));
|
|
|
|
dialog->show();
|
|
|
|
dialog->raise();
|
|
|
|
|
|
|
|
dialog->buttonClicked.connect([&button](auto buttonType) {
|
|
|
|
switch (buttonType)
|
|
|
|
{
|
2019-09-26 00:51:05 +02:00
|
|
|
case UpdateDialog::Dismiss: {
|
2019-09-08 22:27:57 +02:00
|
|
|
button.hide();
|
|
|
|
}
|
|
|
|
break;
|
2019-09-26 00:51:05 +02:00
|
|
|
case UpdateDialog::Install: {
|
2019-09-08 22:27:57 +02:00
|
|
|
Updates::getInstance().installUpdates();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// handle.reset(dialog);
|
|
|
|
// dialog->closing.connect([&handle] { handle.release(); });
|
|
|
|
});
|
|
|
|
|
|
|
|
// update image when state changes
|
|
|
|
auto updateChange = [&button](auto) {
|
|
|
|
button.setVisible(Updates::getInstance().shouldShowUpdateButton());
|
|
|
|
|
|
|
|
auto imageUrl = Updates::getInstance().isError()
|
|
|
|
? ":/buttons/updateError.png"
|
|
|
|
: ":/buttons/update.png";
|
|
|
|
button.setPixmap(QPixmap(imageUrl));
|
|
|
|
};
|
|
|
|
|
2019-10-03 22:17:59 +02:00
|
|
|
updateChange(Updates::getInstance().getStatus());
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-10-03 22:17:59 +02:00
|
|
|
signalHolder.managedConnect(
|
|
|
|
Updates::getInstance().statusUpdated,
|
|
|
|
[updateChange](auto status) { updateChange(status); });
|
2019-09-08 22:27:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace chatterino
|