Merge pull request #3251

ea1fee2f main: Linux - ask to create desktop entry on the first start (xiphon)
This commit is contained in:
Alexander Blair 2020-12-03 12:23:01 -08:00
commit 2eeeadfd10
No known key found for this signature in database
GPG Key ID: C64552D877C32479
6 changed files with 48 additions and 24 deletions

View File

@ -1332,6 +1332,11 @@ ApplicationWindow {
appWindow.fiatApiRefresh(); appWindow.fiatApiRefresh();
appWindow.fiatTimerStart(); appWindow.fiatTimerStart();
} }
if (persistentSettings.askDesktopShortcut && !persistentSettings.portable) {
persistentSettings.askDesktopShortcut = false;
oshelper.createDesktopEntry();
}
} }
MoneroSettings { MoneroSettings {

View File

@ -319,11 +319,6 @@ Verify update binary using 'shasum'-compatible (SHA256 algo) output signed by tw
return 1; return 1;
} }
// Desktop entry
#ifdef Q_OS_LINUX
registerXdgMime(app);
#endif
IPC *ipc = new IPC(&app); IPC *ipc = new IPC(&app);
QStringList posArgs = parser.positionalArguments(); QStringList posArgs = parser.positionalArguments();

View File

@ -46,11 +46,13 @@
#endif #endif
#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) #if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
#include <X11/XKBlib.h> #include <X11/XKBlib.h>
#undef Bool
#undef KeyPress #undef KeyPress
#undef KeyRelease #undef KeyRelease
#undef FocusIn #undef FocusIn
#undef FocusOut #undef FocusOut
// #undef those Xlib #defines that conflict with QEvent::Type enum // #undef those Xlib #defines that conflict with QEvent::Type enum
#include "qt/utils.h"
#endif #endif
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
@ -85,6 +87,13 @@ OSHelper::OSHelper(QObject *parent) : QObject(parent)
} }
void OSHelper::createDesktopEntry() const
{
#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
registerXdgMime();
#endif
}
QString OSHelper::downloadLocation() const QString OSHelper::downloadLocation() const
{ {
return QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); return QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);

View File

@ -41,6 +41,7 @@ class OSHelper : public QObject
public: public:
explicit OSHelper(QObject *parent = 0); explicit OSHelper(QObject *parent = 0);
Q_INVOKABLE void createDesktopEntry() const;
Q_INVOKABLE QString downloadLocation() const; Q_INVOKABLE QString downloadLocation() const;
Q_INVOKABLE bool openContainingFolder(const QString &filePath) const; Q_INVOKABLE bool openContainingFolder(const QString &filePath) const;
Q_INVOKABLE QString openSaveFileDialog(const QString &title, const QString &folder, const QString &filename) const; Q_INVOKABLE QString openSaveFileDialog(const QString &title, const QString &folder, const QString &filename) const;

View File

@ -27,7 +27,8 @@
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <QtCore> #include <QtCore>
#include <QApplication> #include <QCoreApplication>
#include <QMessageBox>
#include <QtGlobal> #include <QtGlobal>
#include "TailsOS.h" #include "TailsOS.h"
@ -88,7 +89,18 @@ QString getAccountName(){
} }
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
QString xdgMime(QApplication &app){ bool askInstallDesktopEntry()
{
QMessageBox msgBox(
QMessageBox::Question,
QObject::tr("Monero GUI"),
QObject::tr("Would you like to register Monero GUI Desktop entry?"),
QMessageBox::Yes | QMessageBox::No);
msgBox.setDefaultButton(QMessageBox::Yes);
return msgBox.exec() == QMessageBox::Yes;
}
QString xdgMime(){
return QString( return QString(
"[Desktop Entry]\n" "[Desktop Entry]\n"
"Name=Monero GUI\n" "Name=Monero GUI\n"
@ -105,32 +117,34 @@ QString xdgMime(QApplication &app){
"StartupNotify=true\n" "StartupNotify=true\n"
"X-GNOME-Bugzilla-Bugzilla=GNOME\n" "X-GNOME-Bugzilla-Bugzilla=GNOME\n"
"X-GNOME-UsesNotifications=true\n" "X-GNOME-UsesNotifications=true\n"
).arg(app.applicationFilePath()); ).arg(QCoreApplication::applicationFilePath());
} }
void registerXdgMime(QApplication &app){ void registerXdgMime(){
// Register desktop entry // Register desktop entry
// - MacOS handled via Info.plist // - MacOS handled via Info.plist
// - Windows handled in the installer by rbrunner7 // - Windows handled in the installer by rbrunner7
// - Linux written to `QStandardPaths::ApplicationsLocation` // - Linux written to `QStandardPaths::ApplicationsLocation`
// - Tails written to persistent dotfiles // - Tails written to persistent dotfiles
QString mime = xdgMime(app); QString mime = xdgMime();
QString appPath = QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation); QString appPath = QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation);
QString filePath = QString("%1/monero-gui.desktop").arg(appPath); QString filePath = QString("%1/monero-gui.desktop").arg(appPath);
if (TailsOS::detect() && TailsOS::detectDotPersistence() && TailsOS::usePersistence) { if (TailsOS::detect())
{
if (TailsOS::detectDotPersistence() && TailsOS::usePersistence)
{
TailsOS::persistXdgMime(filePath, mime); TailsOS::persistXdgMime(filePath, mime);
return;
} }
}
QFileInfo file(filePath); else
QDir().mkpath(file.path()); // ensure directory exists {
if (askInstallDesktopEntry())
#ifdef QT_DEBUG {
qDebug() << "Writing xdg mime: " << filePath; QDir().mkpath(QFileInfo(filePath).path());
#endif
fileWrite(filePath, mime); fileWrite(filePath, mime);
}
}
} }
#endif #endif

View File

@ -39,8 +39,8 @@ QByteArray fileOpen(QString path);
bool fileWrite(QString path, QString data); bool fileWrite(QString path, QString data);
QString getAccountName(); QString getAccountName();
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
QString xdgMime(QApplication &app); QString xdgMime();
void registerXdgMime(QApplication &app); void registerXdgMime();
#endif #endif
const static QRegExp reURI = QRegExp("^\\w+:\\/\\/([\\w+\\-?\\-_\\-=\\-&]+)"); const static QRegExp reURI = QRegExp("^\\w+:\\/\\/([\\w+\\-?\\-_\\-=\\-&]+)");
QString randomUserAgent(); QString randomUserAgent();