Override existing startup entry in wizard; show remark about it in summary
This commit is contained in:
parent
878e973c9d
commit
29ada0f040
|
@ -926,18 +926,19 @@ bool isAutostartEnabled()
|
|||
* \remarks
|
||||
* - Only implemented under Linux/Windows/Mac. Does nothing on other platforms.
|
||||
* - If a startup entry already exists and \a enabled is true, this function will not touch the existing entry - even if it points
|
||||
* to another application. Delete the existing entry first if it is no longer wanted. If the currently configured path cannot be
|
||||
* determined it will always be overridden, though.
|
||||
* to another application. Delete the existing entry first if it is no longer wanted or set \a force to true.
|
||||
* - Note that is might not be possible to determine the currently configured path. If the path cannot be determined an
|
||||
* existing autostart entry will always be overridden (despite \a force being false).
|
||||
* - If no startup entry could be detected via isAutostartEnabled() and \a enabled is false this function doesn't touch anything.
|
||||
*/
|
||||
bool setAutostartEnabled(bool enabled)
|
||||
bool setAutostartEnabled(bool enabled, bool force)
|
||||
{
|
||||
const auto configuredPath = configuredAutostartPath();
|
||||
if (!(configuredPath.has_value() ? !configuredPath.value().isEmpty() : isAutostartEnabled()) && !enabled) {
|
||||
return true;
|
||||
}
|
||||
const auto supposedPath = supposedAutostartPath();
|
||||
if (enabled && configuredPath.has_value() && !configuredPath.value().isEmpty() && configuredPath.value() != supposedPath) {
|
||||
if (!force && enabled && configuredPath.has_value() && !configuredPath.value().isEmpty() && configuredPath.value() != supposedPath) {
|
||||
return true; // don't touch existing entry
|
||||
}
|
||||
return setAutostartPath(enabled ? supposedPath : QString());
|
||||
|
|
|
@ -112,7 +112,7 @@ SYNCTHINGWIDGETS_EXPORT std::optional<QString> configuredAutostartPath();
|
|||
SYNCTHINGWIDGETS_EXPORT QString supposedAutostartPath();
|
||||
SYNCTHINGWIDGETS_EXPORT bool setAutostartPath(const QString &path);
|
||||
SYNCTHINGWIDGETS_EXPORT bool isAutostartEnabled();
|
||||
SYNCTHINGWIDGETS_EXPORT bool setAutostartEnabled(bool enabled);
|
||||
SYNCTHINGWIDGETS_EXPORT bool setAutostartEnabled(bool enabled, bool force = false);
|
||||
|
||||
BEGIN_DECLARE_TYPEDEF_UI_FILE_BASED_OPTION_PAGE(LauncherOptionPage)
|
||||
class QT_UTILITIES_EXPORT LauncherOptionPage : public QObject, public ::QtUtilities::UiFileBasedOptionPage<Ui::LauncherOptionPage> {
|
||||
|
|
|
@ -89,6 +89,7 @@ void SetupDetection::reset()
|
|||
timedOut = false;
|
||||
configOk = false;
|
||||
autostartEnabled = false;
|
||||
autostartConfiguredPath.reset();
|
||||
config.guiAddress.clear();
|
||||
config.guiApiKey.clear();
|
||||
connection.disconnect();
|
||||
|
@ -111,7 +112,9 @@ void SetupDetection::startTest()
|
|||
initConnection();
|
||||
connection.reconnect();
|
||||
launcher.launch(launcherSettings);
|
||||
autostartEnabled = isAutostartEnabled();
|
||||
autostartConfiguredPath = configuredAutostartPath();
|
||||
autostartEnabled = autostartConfiguredPath.has_value() ? !autostartConfiguredPath.value().isEmpty() : isAutostartEnabled();
|
||||
autostartSupposedPath = supposedAutostartPath();
|
||||
timeout.start();
|
||||
}
|
||||
|
||||
|
|
|
@ -67,6 +67,8 @@ public:
|
|||
bool timedOut = false;
|
||||
bool configOk = false;
|
||||
bool autostartEnabled = false;
|
||||
std::optional<QString> autostartConfiguredPath;
|
||||
QString autostartSupposedPath;
|
||||
|
||||
private:
|
||||
bool m_testStarted = false;
|
||||
|
|
|
@ -188,8 +188,8 @@ bool Wizard::changeSettings()
|
|||
|
||||
// enable/disable auto start
|
||||
#ifdef SETTINGS_WIZARD_AUTOSTART
|
||||
if (!settings.isPlasmoid && autoStart() != detection.autostartEnabled) {
|
||||
setAutostartEnabled(autoStart());
|
||||
if (!settings.isPlasmoid) {
|
||||
setAutostartEnabled(autoStart(), true);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -314,6 +314,9 @@ void Wizard::showDetailsFromSetupDetection()
|
|||
#ifdef SETTINGS_WIZARD_AUTOSTART
|
||||
addParagraph(tr("Autostart:"));
|
||||
infoItems << tr("Currently %1").arg(detection.autostartEnabled ? tr("enabled") : tr("disabled"));
|
||||
if (detection.autostartConfiguredPath.has_value()) {
|
||||
infoItems << tr("Points to \"%1\"").arg(detection.autostartConfiguredPath.value());
|
||||
}
|
||||
addList(infoItems);
|
||||
#endif
|
||||
|
||||
|
@ -917,14 +920,25 @@ void ApplyWizardPage::initializePage()
|
|||
const auto &detection = wizard->setupDetection();
|
||||
const auto ¤tSettings = Settings::values();
|
||||
auto html = QStringLiteral("<p><b>%1</b></p><ul>").arg(tr("Summary:"));
|
||||
auto addListItem = [&html](const QString &text) {
|
||||
html.append(QStringLiteral("<li>"));
|
||||
html.append(text);
|
||||
html.append(QStringLiteral("</li>"));
|
||||
auto makeListItem = [](QString &output, const QString &text) {
|
||||
output.append(QStringLiteral("<li>"));
|
||||
output.append(text);
|
||||
output.append(QStringLiteral("</li>"));
|
||||
};
|
||||
auto logFeature = [&addListItem](const QString &feature, bool enabled, bool enabledBefore) {
|
||||
addListItem(enabled == enabledBefore ? (tr("Keep %1 %2").arg(feature, enabled ? tr("enabled") : tr("disabled")))
|
||||
: (tr("%1 %2").arg(enabled ? tr("Enable") : tr("Disable"), feature)));
|
||||
auto makeNestedListItem = [](QString &output, const QString &text) {
|
||||
output.append(QStringLiteral("<ul><li>"));
|
||||
output.append(text);
|
||||
output.append(QStringLiteral("</li></ul>"));
|
||||
};
|
||||
auto addListItem = [&makeListItem, &html](const QString &text) {
|
||||
makeListItem(html, text);
|
||||
};
|
||||
auto logFeature = [&makeNestedListItem, &addListItem](const QString &feature, bool enabled, bool enabledBefore, const QString &remark = QString()) {
|
||||
auto text = enabled == enabledBefore ? (tr("Keep %1 %2").arg(feature, enabled ? tr("enabled") : tr("disabled"))) : (tr("%1 %2").arg(enabled ? tr("Enable") : tr("Disable"), feature));
|
||||
if (!remark.isEmpty()) {
|
||||
makeNestedListItem(text, remark);
|
||||
}
|
||||
addListItem(text);
|
||||
};
|
||||
auto mainConfig = QString();
|
||||
auto extraInfo = QString();
|
||||
|
@ -954,9 +968,7 @@ void ApplyWizardPage::initializePage()
|
|||
break;
|
||||
}
|
||||
if (!extraInfo.isEmpty()) {
|
||||
mainConfig.append(QStringLiteral("<ul><li>"));
|
||||
mainConfig.append(extraInfo);
|
||||
mainConfig.append(QStringLiteral("</li></ul>"));
|
||||
makeNestedListItem(mainConfig, extraInfo);
|
||||
}
|
||||
addListItem(mainConfig);
|
||||
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
||||
|
@ -965,7 +977,13 @@ void ApplyWizardPage::initializePage()
|
|||
#endif
|
||||
#ifdef SETTINGS_WIZARD_AUTOSTART
|
||||
if (!currentSettings.isPlasmoid) {
|
||||
logFeature(tr("autostart of Syncthing Tray"), wizard->autoStart(), detection.autostartEnabled);
|
||||
auto remark = QString();
|
||||
auto action = QString();
|
||||
if (detection.autostartConfiguredPath.has_value() && !detection.autostartConfiguredPath.value().isEmpty() && detection.autostartConfiguredPath.value() != detection.autostartSupposedPath) {
|
||||
action = wizard->autoStart() ? tr("Override") : tr("Delete");
|
||||
remark = tr("%1 existing autostart entry for \"%2\"").arg(action, detection.autostartConfiguredPath.value());
|
||||
}
|
||||
logFeature(tr("autostart of Syncthing Tray"), wizard->autoStart(), detection.autostartEnabled, remark);
|
||||
}
|
||||
#endif
|
||||
html.append(QStringLiteral("</ul><p><b>%1</b></p><ul><li>%2</li><li>%3</li><li>%4</li></ul>")
|
||||
|
|
Loading…
Reference in New Issue