Skip to content

Commit

Permalink
feat: add --safe-mode command line option (Chatterino#4985)
Browse files Browse the repository at this point in the history
This ensures the settings button isn't hidden, and disables plugins from being loaded to make sure the user can always recover from messing things up
  • Loading branch information
Mm2PL authored Dec 5, 2023
1 parent 44abe6b commit c3d3903
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- Minor: The `/reply` command now replies to the latest message of the user. (#4919)
- Minor: All sound capabilities can now be disabled by setting your "Sound backend" setting to "Null" and restarting Chatterino. (#4978)
- Minor: Add an option to use new experimental smarter emote completion. (#4987)
- Minor: Add `--safe-mode` command line option that can be used for troubleshooting when Chatterino is misbehaving or is misconfigured. It disables hiding the settings button & prevents plugins from loading. (#4985)
- Bugfix: Fixed an issue where certain emojis did not send to Twitch chat correctly. (#4840)
- Bugfix: Fixed capitalized channel names in log inclusion list not being logged. (#4848)
- Bugfix: Trimmed custom streamlink paths on all platforms making sure you don't accidentally add spaces at the beginning or end of its path. (#4834)
Expand Down
8 changes: 8 additions & 0 deletions src/common/Args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@ Args::Args(const QApplication &app)
"Attaches to the Console on windows, "
"allowing you to see debug output."});
crashRecoveryOption.setFlags(QCommandLineOption::HiddenFromHelp);
QCommandLineOption safeModeOption(
"safe-mode", "Starts Chatterino without loading Plugins and always "
"show the settings button.");

parser.addOptions({
{{"V", "version"}, "Displays version information."},
crashRecoveryOption,
parentWindowOption,
parentWindowIdOption,
verboseOption,
safeModeOption,
});
parser.addOption(QCommandLineOption(
{"c", "channels"},
Expand Down Expand Up @@ -89,6 +93,10 @@ Args::Args(const QApplication &app)

this->parentWindowId = parser.value(parentWindowIdOption).toULongLong();
}
if (parser.isSet(safeModeOption))
{
this->safeMode = true;
}
}

void Args::applyCustomChannelLayout(const QString &argValue)
Expand Down
1 change: 1 addition & 0 deletions src/common/Args.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Args
bool dontLoadMainWindow{};
std::optional<WindowLayout> customChannelLayout;
bool verbose{};
bool safeMode{};

private:
void applyCustomChannelLayout(const QString &argValue);
Expand Down
15 changes: 12 additions & 3 deletions src/controllers/plugins/PluginController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# include "controllers/plugins/PluginController.hpp"

# include "Application.hpp"
# include "common/Args.hpp"
# include "common/QLogging.hpp"
# include "controllers/commands/CommandContext.hpp"
# include "controllers/commands/CommandController.hpp"
Expand Down Expand Up @@ -194,12 +195,20 @@ void PluginController::openLibrariesFor(lua_State *L,
void PluginController::load(const QFileInfo &index, const QDir &pluginDir,
const PluginMeta &meta)
{
lua_State *l = luaL_newstate();
PluginController::openLibrariesFor(l, meta);

auto pluginName = pluginDir.dirName();
lua_State *l = luaL_newstate();
auto plugin = std::make_unique<Plugin>(pluginName, l, meta, pluginDir);
this->plugins_.insert({pluginName, std::move(plugin)});

if (getArgs().safeMode)
{
// This isn't done earlier to ensure the user can disable a misbehaving plugin
qCWarning(chatterinoLua) << "Skipping loading plugin " << meta.name
<< " because safe mode is enabled.";
return;
}
PluginController::openLibrariesFor(l, meta);

if (!PluginController::isPluginEnabled(pluginName) ||
!getSettings()->pluginsEnabled)
{
Expand Down
24 changes: 17 additions & 7 deletions src/widgets/Notebook.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "widgets/Notebook.hpp"

#include "Application.hpp"
#include "common/Args.hpp"
#include "common/QLogging.hpp"
#include "controllers/hotkeys/HotkeyCategory.hpp"
#include "controllers/hotkeys/HotkeyController.hpp"
Expand Down Expand Up @@ -1345,13 +1346,22 @@ void SplitNotebook::addCustomButtons()
// settings
auto settingsBtn = this->addCustomButton();

settingsBtn->setVisible(!getSettings()->hidePreferencesButton.getValue());

getSettings()->hidePreferencesButton.connect(
[settingsBtn](bool hide, auto) {
settingsBtn->setVisible(!hide);
},
this->signalHolder_);
// This is to ensure you can't lock yourself out of the settings
if (getArgs().safeMode)
{
settingsBtn->setVisible(true);
}
else
{
settingsBtn->setVisible(
!getSettings()->hidePreferencesButton.getValue());

getSettings()->hidePreferencesButton.connect(
[settingsBtn](bool hide, auto) {
settingsBtn->setVisible(!hide);
},
this->signalHolder_);
}

settingsBtn->setIcon(NotebookButton::Settings);

Expand Down
6 changes: 6 additions & 0 deletions src/widgets/Window.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "widgets/Window.hpp"

#include "Application.hpp"
#include "common/Args.hpp"
#include "common/Credentials.hpp"
#include "common/Modes.hpp"
#include "common/QLogging.hpp"
Expand Down Expand Up @@ -736,6 +737,11 @@ void Window::onAccountSelected()
}
#endif

if (getArgs().safeMode)
{
windowTitle += " (safe mode)";
}

this->setWindowTitle(windowTitle);

// update user
Expand Down
14 changes: 14 additions & 0 deletions src/widgets/settingspages/PluginsPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# include "widgets/settingspages/PluginsPage.hpp"

# include "Application.hpp"
# include "common/Args.hpp"
# include "controllers/plugins/PluginController.hpp"
# include "singletons/Paths.hpp"
# include "singletons/Settings.hpp"
Expand Down Expand Up @@ -52,6 +53,15 @@ PluginsPage::PluginsPage()
this->rebuildContent();
});
groupLayout->addRow(box);
if (getArgs().safeMode)
{
box->setEnabled(false);
auto *disabledLabel = new QLabel(this);
disabledLabel->setText("Plugins will not be fully loaded because "
"Chatterino is in safe mode. You can still "
"enable and disable them.");
groupLayout->addRow(disabledLabel);
}
}

this->rebuildContent();
Expand Down Expand Up @@ -177,6 +187,10 @@ void PluginsPage::rebuildContent()
this->rebuildContent();
});
pluginEntry->addRow(reloadButton);
if (getArgs().safeMode)
{
reloadButton->setEnabled(false);
}
}
}

Expand Down

0 comments on commit c3d3903

Please sign in to comment.