autostart feature now takes CLI arguments into account on windows, TODO on linux
This commit is contained in:
parent
4ddee5d32d
commit
d91b2927ce
@ -26,7 +26,7 @@
|
||||
<url type="donation">https://github.com/sponsors/martinrotter</url>
|
||||
<content_rating type="oars-1.1" />
|
||||
<releases>
|
||||
<release version="4.2.2" date="2022-05-02"/>
|
||||
<release version="4.2.2" date="2022-05-04"/>
|
||||
</releases>
|
||||
<content_rating type="oars-1.0">
|
||||
<content_attribute id="violence-cartoon">none</content_attribute>
|
||||
|
@ -63,7 +63,7 @@
|
||||
#endif
|
||||
|
||||
Application::Application(const QString& id, int& argc, char** argv, const QStringList& raw_cli_args)
|
||||
: SingleApplication(id, argc, argv), m_updateFeedsLock(new Mutex()) {
|
||||
: SingleApplication(id, argc, argv), m_rawCliArgs(raw_cli_args), m_updateFeedsLock(new Mutex()) {
|
||||
parseCmdArgumentsFromMyInstance(raw_cli_args);
|
||||
qInstallMessageHandler(performLogging);
|
||||
|
||||
@ -359,11 +359,14 @@ void Application::eliminateFirstRuns() {
|
||||
settings()->setValue(GROUP(General), QString(General::FirstRun) + QL1C('_') + APP_VERSION, false);
|
||||
}
|
||||
|
||||
QStringList Application::rawCliArgs() const {
|
||||
return m_rawCliArgs;
|
||||
}
|
||||
|
||||
#if defined(USE_WEBENGINE)
|
||||
bool Application::forcedNoWebEngine() const {
|
||||
return m_forcedNoWebEngine;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
NodeJs* Application::nodejs() const {
|
||||
|
@ -144,19 +144,27 @@ class RSSGUARD_DLLSPEC Application : public SingleApplication {
|
||||
|
||||
void setMainForm(FormMain* main_form);
|
||||
|
||||
void backupDatabaseSettings(bool backup_database, bool backup_settings, const QString& target_path,
|
||||
void backupDatabaseSettings(bool backup_database,
|
||||
bool backup_settings,
|
||||
const QString& target_path,
|
||||
const QString& backup_name);
|
||||
void restoreDatabaseSettings(bool restore_database, bool restore_settings,
|
||||
void restoreDatabaseSettings(bool restore_database,
|
||||
bool restore_settings,
|
||||
const QString& source_database_file_path = QString(),
|
||||
const QString& source_settings_file_path = QString());
|
||||
|
||||
void showTrayIcon();
|
||||
void deleteTrayIcon();
|
||||
|
||||
QStringList rawCliArgs() const;
|
||||
|
||||
// Displays given simple message in tray icon bubble or OSD
|
||||
// or in message box if tray icon is disabled.
|
||||
void showGuiMessage(Notification::Event event, const GuiMessage& msg, const GuiMessageDestination& dest = {},
|
||||
const GuiAction& action = {}, QWidget* parent = nullptr);
|
||||
void showGuiMessage(Notification::Event event,
|
||||
const GuiMessage& msg,
|
||||
const GuiMessageDestination& dest = {},
|
||||
const GuiAction& action = {},
|
||||
QWidget* parent = nullptr);
|
||||
|
||||
WebViewer* createWebView();
|
||||
|
||||
@ -209,6 +217,7 @@ class RSSGUARD_DLLSPEC Application : public SingleApplication {
|
||||
void eliminateFirstRuns();
|
||||
|
||||
private:
|
||||
QStringList m_rawCliArgs;
|
||||
QCommandLineParser m_cmdParser;
|
||||
FeedReader* m_feedReader;
|
||||
|
||||
@ -256,6 +265,8 @@ class RSSGUARD_DLLSPEC Application : public SingleApplication {
|
||||
#endif
|
||||
};
|
||||
|
||||
inline Application* Application::instance() { return static_cast<Application*>(QCoreApplication::instance()); }
|
||||
inline Application* Application::instance() {
|
||||
return static_cast<Application*>(QCoreApplication::instance());
|
||||
}
|
||||
|
||||
#endif // APPLICATION_H
|
||||
|
@ -2,11 +2,12 @@
|
||||
|
||||
#include "miscellaneous/systemfactory.h"
|
||||
|
||||
#include "3rd-party/boolinq/boolinq.h"
|
||||
#include "exceptions/applicationexception.h"
|
||||
#include "gui/dialogs/formmain.h"
|
||||
#include "gui/dialogs/formupdate.h"
|
||||
#include "miscellaneous/application.h"
|
||||
#include "miscellaneous/systemfactory.h"
|
||||
#include "exceptions/applicationexception.h"
|
||||
#include "network-web/networkfactory.h"
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
@ -49,9 +50,7 @@ SystemFactory::AutoStartStatus SystemFactory::autoStartStatus() const {
|
||||
#if defined(Q_OS_WIN)
|
||||
QSettings registry_key(QSL("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run"),
|
||||
QSettings::Format::NativeFormat);
|
||||
const bool autostart_enabled =
|
||||
registry_key.value(QSL(APP_LOW_NAME), QString()).toString().replace(QL1C('\\'), QL1C('/')) ==
|
||||
Application::applicationFilePath();
|
||||
const bool autostart_enabled = registry_key.contains(QSL(APP_LOW_NAME));
|
||||
|
||||
if (autostart_enabled) {
|
||||
return AutoStartStatus::Enabled;
|
||||
@ -126,9 +125,24 @@ bool SystemFactory::setAutoStartStatus(AutoStartStatus new_status) {
|
||||
QSettings::NativeFormat);
|
||||
|
||||
switch (new_status) {
|
||||
case AutoStartStatus::Enabled:
|
||||
registry_key.setValue(QSL(APP_LOW_NAME), Application::applicationFilePath().replace(QL1C('/'), QL1C('\\')));
|
||||
case AutoStartStatus::Enabled: {
|
||||
QStringList args = qApp->rawCliArgs();
|
||||
auto std_args = boolinq::from(args)
|
||||
.select([](const QString& arg) {
|
||||
if (arg.contains(QL1S(" ")) && !arg.startsWith(QL1S("\""))) {
|
||||
return QSL("\"%1\"").arg(arg);
|
||||
}
|
||||
else {
|
||||
return arg;
|
||||
}
|
||||
})
|
||||
.toStdList();
|
||||
args = FROM_STD_LIST(QStringList, std_args);
|
||||
|
||||
QString app_run_line = args.join(QL1C(' '));
|
||||
registry_key.setValue(QSL(APP_LOW_NAME), app_run_line);
|
||||
return true;
|
||||
}
|
||||
|
||||
case AutoStartStatus::Disabled:
|
||||
registry_key.remove(QSL(APP_LOW_NAME));
|
||||
@ -159,12 +173,12 @@ bool SystemFactory::setAutoStartStatus(AutoStartStatus new_status) {
|
||||
QString(APP_DESKTOP_ENTRY_PATH) + QDir::separator() + APP_DESKTOP_SOURCE_ENTRY_FILE;
|
||||
|
||||
try {
|
||||
QString desktop_file_contents = QString::fromUtf8(IOFactory::readFile(source_autostart_desktop_file));
|
||||
QString desktop_file_contents = QString::fromUtf8(IOFactory::readFile(source_autostart_desktop_file));
|
||||
|
||||
#if defined(IS_FLATPAK_BUILD)
|
||||
desktop_file_contents = desktop_file_contents.arg(QSL("flatpak run %1").arg(QSL(APP_REVERSE_NAME)));
|
||||
desktop_file_contents = desktop_file_contents.arg(QSL("flatpak run %1").arg(QSL(APP_REVERSE_NAME)));
|
||||
#else
|
||||
desktop_file_contents = desktop_file_contents.arg(QSL(APP_LOW_NAME));
|
||||
desktop_file_contents = desktop_file_contents.arg(QSL(APP_LOW_NAME));
|
||||
#endif
|
||||
|
||||
IOFactory::writeFile(destination_file, desktop_file_contents.toUtf8());
|
||||
|
Loading…
x
Reference in New Issue
Block a user