remove notifications

This commit is contained in:
sneedium 2022-02-20 19:10:53 -05:00
parent c757785829
commit a320adb072
Signed by: sneedium
GPG Key ID: 906F66490FBE722F
14 changed files with 3 additions and 489 deletions

View File

@ -58,10 +58,7 @@ set(Launcher_VERSION_HOTFIX 6)
set(Launcher_VERSION_BUILD -1 CACHE STRING "Build number. -1 for no build number.") set(Launcher_VERSION_BUILD -1 CACHE STRING "Build number. -1 for no build number.")
# Build platform. # Build platform.
set(Launcher_BUILD_PLATFORM "" CACHE STRING "A short string identifying the platform that this build was built for. Only used by the notification system and to display in the about dialog.") set(Launcher_BUILD_PLATFORM "" CACHE STRING "A short string identifying the platform that this build was built for. Only used to display in the about dialog.")
# Notification URL
set(Launcher_NOTIFICATION_URL "" CACHE STRING "URL for checking for notifications.")
# The metadata server # The metadata server
set(Launcher_META_URL "https://meta.multimc.org/v1/" CACHE STRING "URL to fetch Launcher's meta files from.") set(Launcher_META_URL "https://meta.multimc.org/v1/" CACHE STRING "URL to fetch Launcher's meta files from.")

View File

@ -24,7 +24,6 @@ Config::Config()
VERSION_BUILD = @Launcher_VERSION_BUILD@; VERSION_BUILD = @Launcher_VERSION_BUILD@;
BUILD_PLATFORM = "@Launcher_BUILD_PLATFORM@"; BUILD_PLATFORM = "@Launcher_BUILD_PLATFORM@";
NOTIFICATION_URL = "@Launcher_NOTIFICATION_URL@";
FULL_VERSION_STR = "@Launcher_VERSION_MAJOR@.@Launcher_VERSION_MINOR@.@Launcher_VERSION_BUILD@"; FULL_VERSION_STR = "@Launcher_VERSION_MAJOR@.@Launcher_VERSION_MINOR@.@Launcher_VERSION_BUILD@";
GIT_COMMIT = "@Launcher_GIT_COMMIT@"; GIT_COMMIT = "@Launcher_GIT_COMMIT@";

View File

@ -36,10 +36,6 @@ public:
QString VERSION_CHANNEL; QString VERSION_CHANNEL;
/// URL for notifications
QString NOTIFICATION_URL;
/// Used for matching notifications
QString FULL_VERSION_STR; QString FULL_VERSION_STR;
/// The git commit hash of this build /// The git commit hash of this build

View File

@ -546,9 +546,6 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
m_settings->registerSetting("IconTheme", QString("pe_colored")); m_settings->registerSetting("IconTheme", QString("pe_colored"));
m_settings->registerSetting("ApplicationTheme", QString("system")); m_settings->registerSetting("ApplicationTheme", QString("system"));
// Notifications
m_settings->registerSetting("ShownNotifications", QString());
// Remembered state // Remembered state
m_settings->registerSetting("LastUsedGroupForNewInstance", QString()); m_settings->registerSetting("LastUsedGroupForNewInstance", QString());

View File

@ -152,13 +152,6 @@ set(LAUNCH_SOURCES
launch/LogModel.h launch/LogModel.h
) )
# Rarely used notifications
set(NOTIFICATIONS_SOURCES
# Notifications - short warning messages
notifications/NotificationChecker.h
notifications/NotificationChecker.cpp
)
# Backend for the news bar... there's usually no news. # Backend for the news bar... there's usually no news.
set(NEWS_SOURCES set(NEWS_SOURCES
# News System # News System
@ -545,7 +538,6 @@ set(LOGIC_SOURCES
${PATHMATCHER_SOURCES} ${PATHMATCHER_SOURCES}
${NET_SOURCES} ${NET_SOURCES}
${LAUNCH_SOURCES} ${LAUNCH_SOURCES}
${NOTIFICATIONS_SOURCES}
${NEWS_SOURCES} ${NEWS_SOURCES}
${MINECRAFT_SOURCES} ${MINECRAFT_SOURCES}
${SCREENSHOTS_SOURCES} ${SCREENSHOTS_SOURCES}
@ -775,8 +767,6 @@ SET(LAUNCHER_SOURCES
ui/dialogs/NewComponentDialog.h ui/dialogs/NewComponentDialog.h
ui/dialogs/NewInstanceDialog.cpp ui/dialogs/NewInstanceDialog.cpp
ui/dialogs/NewInstanceDialog.h ui/dialogs/NewInstanceDialog.h
ui/dialogs/NotificationDialog.cpp
ui/dialogs/NotificationDialog.h
ui/pagedialog/PageDialog.cpp ui/pagedialog/PageDialog.cpp
ui/pagedialog/PageDialog.h ui/pagedialog/PageDialog.h
ui/dialogs/ProgressDialog.cpp ui/dialogs/ProgressDialog.cpp
@ -876,7 +866,6 @@ qt5_wrap_ui(LAUNCHER_UI
ui/dialogs/ProfileSetupDialog.ui ui/dialogs/ProfileSetupDialog.ui
ui/dialogs/ProgressDialog.ui ui/dialogs/ProgressDialog.ui
ui/dialogs/NewInstanceDialog.ui ui/dialogs/NewInstanceDialog.ui
ui/dialogs/NotificationDialog.ui
ui/dialogs/NewComponentDialog.ui ui/dialogs/NewComponentDialog.ui
ui/dialogs/ProfileSelectDialog.ui ui/dialogs/ProfileSelectDialog.ui
ui/dialogs/SkinUploadDialog.ui ui/dialogs/SkinUploadDialog.ui

View File

@ -1,129 +0,0 @@
#include "NotificationChecker.h"
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QDebug>
#include "net/Download.h"
#include "Application.h"
NotificationChecker::NotificationChecker(QObject *parent)
: QObject(parent)
{
}
void NotificationChecker::setNotificationsUrl(const QUrl &notificationsUrl)
{
m_notificationsUrl = notificationsUrl;
}
void NotificationChecker::setApplicationChannel(QString channel)
{
m_appVersionChannel = channel;
}
void NotificationChecker::setApplicationFullVersion(QString version)
{
m_appFullVersion = version;
}
void NotificationChecker::setApplicationPlatform(QString platform)
{
m_appPlatform = platform;
}
QList<NotificationChecker::NotificationEntry> NotificationChecker::notificationEntries() const
{
return m_entries;
}
void NotificationChecker::checkForNotifications()
{
if (!m_notificationsUrl.isValid())
{
qCritical() << "Failed to check for notifications. No notifications URL set."
<< "If you'd like to use SneedMC's notification system, please pass the "
"URL to CMake at compile time.";
return;
}
if (m_checkJob)
{
return;
}
m_checkJob = new NetJob("Checking for notifications", APPLICATION->network());
auto entry = APPLICATION->metacache()->resolveEntry("root", "notifications.json");
entry->setStale(true);
m_checkJob->addNetAction(m_download = Net::Download::makeCached(m_notificationsUrl, entry));
connect(m_download.get(), &Net::Download::succeeded, this, &NotificationChecker::downloadSucceeded);
m_checkJob->start();
}
void NotificationChecker::downloadSucceeded(int)
{
m_entries.clear();
QFile file(m_download->getTargetFilepath());
if (file.open(QFile::ReadOnly))
{
QJsonArray root = QJsonDocument::fromJson(file.readAll()).array();
for (auto it = root.begin(); it != root.end(); ++it)
{
QJsonObject obj = (*it).toObject();
NotificationEntry entry;
entry.id = obj.value("id").toDouble();
entry.message = obj.value("message").toString();
entry.channel = obj.value("channel").toString();
entry.platform = obj.value("platform").toString();
entry.from = obj.value("from").toString();
entry.to = obj.value("to").toString();
const QString type = obj.value("type").toString("critical");
if (type == "critical")
{
entry.type = NotificationEntry::Critical;
}
else if (type == "warning")
{
entry.type = NotificationEntry::Warning;
}
else if (type == "information")
{
entry.type = NotificationEntry::Information;
}
if(entryApplies(entry))
m_entries.append(entry);
}
}
m_checkJob.reset();
emit notificationCheckFinished();
}
bool versionLessThan(const QString &v1, const QString &v2)
{
QStringList l1 = v1.split('.');
QStringList l2 = v2.split('.');
while (!l1.isEmpty() && !l2.isEmpty())
{
int one = l1.isEmpty() ? 0 : l1.takeFirst().toInt();
int two = l2.isEmpty() ? 0 : l2.takeFirst().toInt();
if (one != two)
{
return one < two;
}
}
return false;
}
bool NotificationChecker::entryApplies(const NotificationChecker::NotificationEntry& entry) const
{
bool channelApplies = entry.channel.isEmpty() || entry.channel == m_appVersionChannel;
bool platformApplies = entry.platform.isEmpty() || entry.platform == m_appPlatform;
bool fromApplies =
entry.from.isEmpty() || entry.from == m_appFullVersion || !versionLessThan(m_appFullVersion, entry.from);
bool toApplies =
entry.to.isEmpty() || entry.to == m_appFullVersion || !versionLessThan(entry.to, m_appFullVersion);
return channelApplies && platformApplies && fromApplies && toApplies;
}

View File

@ -1,61 +0,0 @@
#pragma once
#include <QObject>
#include "net/NetJob.h"
#include "net/Download.h"
class NotificationChecker : public QObject
{
Q_OBJECT
public:
explicit NotificationChecker(QObject *parent = 0);
void setNotificationsUrl(const QUrl &notificationsUrl);
void setApplicationPlatform(QString platform);
void setApplicationChannel(QString channel);
void setApplicationFullVersion(QString version);
struct NotificationEntry
{
int id;
QString message;
enum
{
Critical,
Warning,
Information
} type;
QString channel;
QString platform;
QString from;
QString to;
};
QList<NotificationEntry> notificationEntries() const;
public
slots:
void checkForNotifications();
private
slots:
void downloadSucceeded(int);
signals:
void notificationCheckFinished();
private:
bool entryApplies(const NotificationEntry &entry) const;
private:
QList<NotificationEntry> m_entries;
QUrl m_notificationsUrl;
NetJob::Ptr m_checkJob;
Net::Download::Ptr m_download;
QString m_appVersionChannel;
QString m_appPlatform;
QString m_appFullVersion;
};

View File

@ -59,7 +59,6 @@
#include <net/NetJob.h> #include <net/NetJob.h>
#include <net/Download.h> #include <net/Download.h>
#include <news/NewsChecker.h> #include <news/NewsChecker.h>
#include <notifications/NotificationChecker.h>
#include <tools/BaseProfiler.h> #include <tools/BaseProfiler.h>
#include <DesktopServices.h> #include <DesktopServices.h>
#include "InstanceWindow.h" #include "InstanceWindow.h"
@ -79,7 +78,6 @@
#include "ui/dialogs/IconPickerDialog.h" #include "ui/dialogs/IconPickerDialog.h"
#include "ui/dialogs/CopyInstanceDialog.h" #include "ui/dialogs/CopyInstanceDialog.h"
#include "ui/dialogs/EditAccountDialog.h" #include "ui/dialogs/EditAccountDialog.h"
#include "ui/dialogs/NotificationDialog.h"
#include "ui/dialogs/ExportInstanceDialog.h" #include "ui/dialogs/ExportInstanceDialog.h"
#include "KonamiCode.h" #include "KonamiCode.h"
@ -800,17 +798,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new MainWindow
} }
{
auto checker = new NotificationChecker();
checker->setNotificationsUrl(QUrl(BuildConfig.NOTIFICATION_URL));
checker->setApplicationChannel(BuildConfig.VERSION_CHANNEL);
checker->setApplicationPlatform(BuildConfig.BUILD_PLATFORM);
checker->setApplicationFullVersion(BuildConfig.FULL_VERSION_STR);
m_notificationChecker.reset(checker);
connect(m_notificationChecker.get(), &NotificationChecker::notificationCheckFinished, this, &MainWindow::notificationsChanged);
checker->checkForNotifications();
}
setSelectedInstanceById(APPLICATION->settings()->get("SelectedInstance").toString()); setSelectedInstanceById(APPLICATION->settings()->get("SelectedInstance").toString());
// removing this looks stupid // removing this looks stupid
@ -1187,24 +1174,6 @@ QString intListToString(const QList<int> &list)
} }
return slist.join(','); return slist.join(',');
} }
void MainWindow::notificationsChanged()
{
QList<NotificationChecker::NotificationEntry> entries = m_notificationChecker->notificationEntries();
QList<int> shownNotifications = stringToIntList(APPLICATION->settings()->get("ShownNotifications").toString());
for (auto it = entries.begin(); it != entries.end(); ++it)
{
NotificationChecker::NotificationEntry entry = *it;
if (!shownNotifications.contains(entry.id))
{
NotificationDialog dialog(entry, this);
if (dialog.exec() == NotificationDialog::DontShowAgain)
{
shownNotifications.append(entry.id);
}
}
}
APPLICATION->settings()->set("ShownNotifications", intListToString(shownNotifications));
}
void MainWindow::onCatToggled(bool state) void MainWindow::onCatToggled(bool state)
{ {
@ -1396,6 +1365,7 @@ void MainWindow::on_actionDISCORD_triggered()
DesktopServices::openUrl(QUrl(BuildConfig.DISCORD_URL)); DesktopServices::openUrl(QUrl(BuildConfig.DISCORD_URL));
} }
void MainWindow::on_actionChangeInstIcon_triggered() void MainWindow::on_actionChangeInstIcon_triggered()
{ {
if (!m_selectedInstance) if (!m_selectedInstance)

View File

@ -27,7 +27,6 @@
class LaunchController; class LaunchController;
class NewsChecker; class NewsChecker;
class NotificationChecker;
class QToolButton; class QToolButton;
class InstanceProxyModel; class InstanceProxyModel;
class LabeledToolButton; class LabeledToolButton;
@ -157,8 +156,6 @@ private slots:
void startTask(Task *task); void startTask(Task *task);
void notificationsChanged();
void defaultAccountChanged(); void defaultAccountChanged();
void changeActiveAccount(); void changeActiveAccount();
@ -199,7 +196,6 @@ private:
KonamiCode * secretEventFilter = nullptr; KonamiCode * secretEventFilter = nullptr;
unique_qobject_ptr<NewsChecker> m_newsChecker; unique_qobject_ptr<NewsChecker> m_newsChecker;
unique_qobject_ptr<NotificationChecker> m_notificationChecker;
InstancePtr m_selectedInstance; InstancePtr m_selectedInstance;
QString m_currentInstIcon; QString m_currentInstIcon;

View File

@ -1,86 +0,0 @@
#include "NotificationDialog.h"
#include "ui_NotificationDialog.h"
#include <QTimerEvent>
#include <QStyle>
NotificationDialog::NotificationDialog(const NotificationChecker::NotificationEntry &entry, QWidget *parent) :
QDialog(parent, Qt::MSWindowsFixedSizeDialogHint | Qt::WindowTitleHint | Qt::CustomizeWindowHint),
ui(new Ui::NotificationDialog)
{
ui->setupUi(this);
QStyle::StandardPixmap icon;
switch (entry.type)
{
case NotificationChecker::NotificationEntry::Critical:
icon = QStyle::SP_MessageBoxCritical;
break;
case NotificationChecker::NotificationEntry::Warning:
icon = QStyle::SP_MessageBoxWarning;
break;
default:
case NotificationChecker::NotificationEntry::Information:
icon = QStyle::SP_MessageBoxInformation;
break;
}
ui->iconLabel->setPixmap(style()->standardPixmap(icon, 0, this));
ui->messageLabel->setText(entry.message);
m_dontShowAgainText = tr("Don't show again");
m_closeText = tr("Close");
ui->dontShowAgainBtn->setText(m_dontShowAgainText + QString(" (%1)").arg(m_dontShowAgainTime));
ui->closeBtn->setText(m_closeText + QString(" (%1)").arg(m_closeTime));
startTimer(1000);
}
NotificationDialog::~NotificationDialog()
{
delete ui;
}
void NotificationDialog::timerEvent(QTimerEvent *event)
{
if (m_dontShowAgainTime > 0)
{
m_dontShowAgainTime--;
if (m_dontShowAgainTime == 0)
{
ui->dontShowAgainBtn->setText(m_dontShowAgainText);
ui->dontShowAgainBtn->setEnabled(true);
}
else
{
ui->dontShowAgainBtn->setText(m_dontShowAgainText + QString(" (%1)").arg(m_dontShowAgainTime));
}
}
if (m_closeTime > 0)
{
m_closeTime--;
if (m_closeTime == 0)
{
ui->closeBtn->setText(m_closeText);
ui->closeBtn->setEnabled(true);
}
else
{
ui->closeBtn->setText(m_closeText + QString(" (%1)").arg(m_closeTime));
}
}
if (m_closeTime == 0 && m_dontShowAgainTime == 0)
{
killTimer(event->timerId());
}
}
void NotificationDialog::on_dontShowAgainBtn_clicked()
{
done(DontShowAgain);
}
void NotificationDialog::on_closeBtn_clicked()
{
done(Normal);
}

View File

@ -1,44 +0,0 @@
#ifndef NOTIFICATIONDIALOG_H
#define NOTIFICATIONDIALOG_H
#include <QDialog>
#include "notifications/NotificationChecker.h"
namespace Ui {
class NotificationDialog;
}
class NotificationDialog : public QDialog
{
Q_OBJECT
public:
explicit NotificationDialog(const NotificationChecker::NotificationEntry &entry, QWidget *parent = 0);
~NotificationDialog();
enum ExitCode
{
Normal,
DontShowAgain
};
protected:
void timerEvent(QTimerEvent *event);
private:
Ui::NotificationDialog *ui;
int m_dontShowAgainTime = 10;
int m_closeTime = 5;
QString m_dontShowAgainText;
QString m_closeText;
private
slots:
void on_dontShowAgainBtn_clicked();
void on_closeBtn_clicked();
};
#endif // NOTIFICATIONDIALOG_H

View File

@ -1,85 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>NotificationDialog</class>
<widget class="QDialog" name="NotificationDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>320</width>
<height>240</height>
</rect>
</property>
<property name="windowTitle">
<string>Notification</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="1,0">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,1">
<item>
<widget class="QLabel" name="iconLabel">
<property name="text">
<string notr="true">TextLabel</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="messageLabel">
<property name="text">
<string notr="true">TextLabel</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::TextBrowserInteraction</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="dontShowAgainBtn">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Don't show again</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="closeBtn">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Close</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -143,11 +143,6 @@ void LauncherPage::applySettings()
{ {
auto s = APPLICATION->settings(); auto s = APPLICATION->settings();
if (ui->resetNotificationsBtn->isChecked())
{
s->set("ShownNotifications", QString());
}
auto original = s->get("IconTheme").toString(); auto original = s->get("IconTheme").toString();
//FIXME: make generic //FIXME: make generic
switch (ui->themeComboBox->currentIndex()) switch (ui->themeComboBox->currentIndex())

View File

@ -38,7 +38,7 @@
<enum>QTabWidget::Rounded</enum> <enum>QTabWidget::Rounded</enum>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>1</number>
</property> </property>
<widget class="QWidget" name="featuresTab"> <widget class="QWidget" name="featuresTab">
<attribute name="title"> <attribute name="title">
@ -141,25 +141,6 @@
<string>User Interface</string> <string>User Interface</string>
</attribute> </attribute>
<layout class="QVBoxLayout" name="verticalLayout_6"> <layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Launcher notifications</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QPushButton" name="resetNotificationsBtn">
<property name="text">
<string>Reset hidden notifications</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item> <item>
<widget class="QGroupBox" name="sortingModeBox"> <widget class="QGroupBox" name="sortingModeBox">
<property name="enabled"> <property name="enabled">
@ -454,7 +435,6 @@
<tabstop>modsDirBrowseBtn</tabstop> <tabstop>modsDirBrowseBtn</tabstop>
<tabstop>iconsDirTextBox</tabstop> <tabstop>iconsDirTextBox</tabstop>
<tabstop>iconsDirBrowseBtn</tabstop> <tabstop>iconsDirBrowseBtn</tabstop>
<tabstop>resetNotificationsBtn</tabstop>
<tabstop>sortLastLaunchedBtn</tabstop> <tabstop>sortLastLaunchedBtn</tabstop>
<tabstop>sortByNameBtn</tabstop> <tabstop>sortByNameBtn</tabstop>
<tabstop>themeComboBox</tabstop> <tabstop>themeComboBox</tabstop>