mirror of
https://github.com/feather-wallet/feather.git
synced 2025-01-05 18:39:30 +00:00
utils: use tray for desktop notification
This commit is contained in:
parent
6b065acdae
commit
37153356ee
5 changed files with 21 additions and 36 deletions
|
@ -432,7 +432,7 @@ void MainWindow::initWalletContext() {
|
||||||
connect(m_wallet, &Wallet::unconfirmedMoneyReceived, this, [this](const QString &txId, uint64_t amount){
|
connect(m_wallet, &Wallet::unconfirmedMoneyReceived, this, [this](const QString &txId, uint64_t amount){
|
||||||
if (m_wallet->isSynchronized()) {
|
if (m_wallet->isSynchronized()) {
|
||||||
auto notify = QString("%1 XMR (pending)").arg(WalletManager::displayAmount(amount, false));
|
auto notify = QString("%1 XMR (pending)").arg(WalletManager::displayAmount(amount, false));
|
||||||
Utils::desktopNotify("Payment received", notify, 5000);
|
m_windowManager->notify("Payment received", notify, 5000);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -579,6 +579,18 @@ void WindowManager::buildTrayMenu() {
|
||||||
menu->addAction("Exit Feather", this, &WindowManager::close);
|
menu->addAction("Exit Feather", this, &WindowManager::close);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WindowManager::notify(const QString &title, const QString &message, int duration) {
|
||||||
|
if (!m_tray || !QSystemTrayIcon::supportsMessages()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config()->get(Config::hideNotifications).toBool()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_tray->showMessage(title, message, icons()->icon("appicons/64x64.png"), duration);
|
||||||
|
}
|
||||||
|
|
||||||
// ######################## NETWORKING ########################
|
// ######################## NETWORKING ########################
|
||||||
|
|
||||||
void WindowManager::onInitialNetworkConfigured() {
|
void WindowManager::onInitialNetworkConfigured() {
|
||||||
|
|
|
@ -30,6 +30,8 @@ public:
|
||||||
|
|
||||||
void showSettings(Nodes *nodes, QWidget *parent, bool showProxyTab = false);
|
void showSettings(Nodes *nodes, QWidget *parent, bool showProxyTab = false);
|
||||||
|
|
||||||
|
void notify(const QString &title, const QString &message, int duration);
|
||||||
|
|
||||||
EventFilter *eventFilter;
|
EventFilter *eventFilter;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
|
@ -465,7 +465,7 @@ QString blockExplorerLink(const QString &blockExplorer, NetworkType::Type nettyp
|
||||||
return QString("https://testnet.xmrchain.net/tx/%1").arg(txid);
|
return QString("https://testnet.xmrchain.net/tx/%1").arg(txid);
|
||||||
}
|
}
|
||||||
|
|
||||||
return QString("");
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void externalLinkWarning(QWidget *parent, const QString &url){
|
void externalLinkWarning(QWidget *parent, const QString &url){
|
||||||
|
@ -493,33 +493,6 @@ void externalLinkWarning(QWidget *parent, const QString &url){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void desktopNotify(const QString &title, const QString &message, int duration) {
|
|
||||||
if (config()->get(Config::hideNotifications).toBool()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList notify_send = QStringList() << title << message << "-t" << QString::number(duration);
|
|
||||||
QStringList kdialog = QStringList() << title << message;
|
|
||||||
QStringList macos = QStringList() << "-e" << QString(R"(display notification "%1" with title "%2")").arg(message).arg(title);
|
|
||||||
#if defined(Q_OS_LINUX)
|
|
||||||
QProcess process;
|
|
||||||
if (fileExists("/usr/bin/kdialog"))
|
|
||||||
process.start("/usr/bin/kdialog", kdialog);
|
|
||||||
else if (fileExists("/usr/bin/notify-send"))
|
|
||||||
process.start("/usr/bin/notify-send", notify_send);
|
|
||||||
process.waitForFinished(-1);
|
|
||||||
QString stdout = process.readAllStandardOutput();
|
|
||||||
QString stderr = process.readAllStandardError();
|
|
||||||
#elif defined(Q_OS_MACOS)
|
|
||||||
QProcess process;
|
|
||||||
// @TODO: need to escape special chars with "\"
|
|
||||||
process.start("osascript", macos);
|
|
||||||
process.waitForFinished(-1);
|
|
||||||
QString stdout = process.readAllStandardOutput();
|
|
||||||
QString stderr = process.readAllStandardError();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
QString displayAddress(const QString& address, int sections, const QString& sep) {
|
QString displayAddress(const QString& address, int sections, const QString& sep) {
|
||||||
QStringList list;
|
QStringList list;
|
||||||
if (sections < 1) sections = 1;
|
if (sections < 1) sections = 1;
|
||||||
|
@ -557,23 +530,23 @@ void applicationLogHandler(QtMsgType type, const QMessageLogContext &context, co
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case QtDebugMsg:
|
case QtDebugMsg:
|
||||||
line = QString("[%1 D] %2(:%3) %4\n").arg(date).arg(fn).arg(context.line).arg(msg);
|
line = QString("[%1 D] %2(:%3) %4\n").arg(date, fn, QString::number(context.line), msg);
|
||||||
fprintf(stderr, "%s", line.toLatin1().data());
|
fprintf(stderr, "%s", line.toLatin1().data());
|
||||||
break;
|
break;
|
||||||
case QtInfoMsg:
|
case QtInfoMsg:
|
||||||
line = QString("[%1 I] %2\n").arg(date).arg(msg);
|
line = QString("[%1 I] %2\n").arg(date, msg);
|
||||||
fprintf(stdout, "%s", line.toLatin1().data());
|
fprintf(stdout, "%s", line.toLatin1().data());
|
||||||
break;
|
break;
|
||||||
case QtWarningMsg:
|
case QtWarningMsg:
|
||||||
line = QString("[%1 W] %2(:%3) %4\n").arg(date).arg(fn).arg(context.line).arg(msg);
|
line = QString("[%1 W] %2(:%3) %4\n").arg(date, fn, QString::number(context.line), msg);
|
||||||
fprintf(stdout, "%s", line.toLatin1().data());
|
fprintf(stdout, "%s", line.toLatin1().data());
|
||||||
break;
|
break;
|
||||||
case QtCriticalMsg:
|
case QtCriticalMsg:
|
||||||
line = QString("[%1 C] %2(:%3) %4\n").arg(date).arg(fn).arg(context.line).arg(msg);
|
line = QString("[%1 C] %2(:%3) %4\n").arg(date, fn, QString::number(context.line), msg);
|
||||||
fprintf(stderr, "%s", line.toLatin1().data());
|
fprintf(stderr, "%s", line.toLatin1().data());
|
||||||
break;
|
break;
|
||||||
case QtFatalMsg:
|
case QtFatalMsg:
|
||||||
line = QString("[%1 F] %2(:%3) %4\n").arg(date).arg(fn).arg(context.line).arg(msg);
|
line = QString("[%1 F] %2(:%3) %4\n").arg(date, fn, QString::number(context.line), msg);
|
||||||
fprintf(stderr, "%s", line.toLatin1().data());
|
fprintf(stderr, "%s", line.toLatin1().data());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,8 +59,6 @@ namespace Utils
|
||||||
QString blockExplorerLink(const QString &blockExplorer, NetworkType::Type nettype, const QString &txid);
|
QString blockExplorerLink(const QString &blockExplorer, NetworkType::Type nettype, const QString &txid);
|
||||||
void externalLinkWarning(QWidget *parent, const QString &url);
|
void externalLinkWarning(QWidget *parent, const QString &url);
|
||||||
|
|
||||||
void desktopNotify(const QString &title, const QString &message, int duration);
|
|
||||||
|
|
||||||
QString displayAddress(const QString& address, int sections = 3, const QString & sep = " ");
|
QString displayAddress(const QString& address, int sections = 3, const QString & sep = " ");
|
||||||
QTextCharFormat addressTextFormat(const SubaddressIndex &index, quint64 amount);
|
QTextCharFormat addressTextFormat(const SubaddressIndex &index, quint64 amount);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue