diff --git a/adapters/standalone.cpp b/adapters/standalone.cpp index 0c9ae76c..37f21682 100644 --- a/adapters/standalone.cpp +++ b/adapters/standalone.cpp @@ -74,8 +74,11 @@ int main(int argc, char* argv[]) { // Parse command line arguments int c; opterr = 0; - while ((c = getopt(argc, argv, "dht:s:u:p:")) != -1) { + while ((c = getopt(argc, argv, "adht:s:u:p:")) != -1) { switch (c) { + case 'a': { + settings::safeMode = true; + } break; case 'd': { settings::devMode = true; } break; diff --git a/include/settings.hpp b/include/settings.hpp index fde47990..deb4dd7a 100644 --- a/include/settings.hpp +++ b/include/settings.hpp @@ -27,6 +27,8 @@ extern bool isPlugin; // Persistent state, serialized to settings.json. +/** Launches Rack without loading plugins or the autosave patch. Always set to false when settings are saved. */ +extern bool safeMode; /** vcvrack.com user token */ extern std::string token; /** Whether the window is maximized */ diff --git a/src/patch.cpp b/src/patch.cpp index 6a8b288a..851c53da 100644 --- a/src/patch.cpp +++ b/src/patch.cpp @@ -47,6 +47,10 @@ void Manager::launch(std::string pathArg) { return; } + // Don't load autosave or template if safe mode is enabled + if (settings::safeMode) + return; + // Try loading the autosave patch if (hasAutosave()) { try { diff --git a/src/plugin.cpp b/src/plugin.cpp index 17c86a5d..6bd99a15 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -256,6 +256,10 @@ void init() { // Get user plugins directory system::createDirectory(pluginsPath); + // Don't load plugins if safe mode is enabled + if (settings::safeMode) + return; + // Extract packages and load plugins extractPackages(pluginsPath); loadPlugins(pluginsPath); diff --git a/src/settings.cpp b/src/settings.cpp index be4ed43e..59d91ec2 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -19,6 +19,7 @@ bool devMode = false; bool headless = false; bool isPlugin = false; +bool safeMode = false; std::string token; bool windowMaximized = false; math::Vec windowSize = math::Vec(1024, 720); @@ -107,6 +108,9 @@ void destroy() { json_t* toJson() { json_t* rootJ = json_object(); + // Always disable safe mode when settings are saved. + json_object_set_new(rootJ, "safeMode", json_boolean(false)); + json_object_set_new(rootJ, "token", json_string(token.c_str())); json_object_set_new(rootJ, "windowMaximized", json_boolean(windowMaximized)); @@ -241,6 +245,13 @@ json_t* toJson() { } void fromJson(json_t* rootJ) { + json_t* safeModeJ = json_object_get(rootJ, "safeMode"); + if (safeModeJ) { + // If safe mode is enabled (e.g. by command line flag), don't disable it when loading. + if (json_boolean_value(safeModeJ)) + safeMode = true; + } + json_t* tokenJ = json_object_get(rootJ, "token"); if (tokenJ) token = json_string_value(tokenJ);