Browse Source

Add safe mode.

tags/v2.1.2
Andrew Belt 2 years ago
parent
commit
ed5a362911
5 changed files with 25 additions and 1 deletions
  1. +4
    -1
      adapters/standalone.cpp
  2. +2
    -0
      include/settings.hpp
  3. +4
    -0
      src/patch.cpp
  4. +4
    -0
      src/plugin.cpp
  5. +11
    -0
      src/settings.cpp

+ 4
- 1
adapters/standalone.cpp View File

@@ -74,8 +74,11 @@ int main(int argc, char* argv[]) {
// Parse command line arguments // Parse command line arguments
int c; int c;
opterr = 0; opterr = 0;
while ((c = getopt(argc, argv, "dht:s:u:p:")) != -1) {
while ((c = getopt(argc, argv, "adht:s:u:p:")) != -1) {
switch (c) { switch (c) {
case 'a': {
settings::safeMode = true;
} break;
case 'd': { case 'd': {
settings::devMode = true; settings::devMode = true;
} break; } break;


+ 2
- 0
include/settings.hpp View File

@@ -27,6 +27,8 @@ extern bool isPlugin;


// Persistent state, serialized to settings.json. // 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 */ /** vcvrack.com user token */
extern std::string token; extern std::string token;
/** Whether the window is maximized */ /** Whether the window is maximized */


+ 4
- 0
src/patch.cpp View File

@@ -47,6 +47,10 @@ void Manager::launch(std::string pathArg) {
return; return;
} }


// Don't load autosave or template if safe mode is enabled
if (settings::safeMode)
return;

// Try loading the autosave patch // Try loading the autosave patch
if (hasAutosave()) { if (hasAutosave()) {
try { try {


+ 4
- 0
src/plugin.cpp View File

@@ -256,6 +256,10 @@ void init() {
// Get user plugins directory // Get user plugins directory
system::createDirectory(pluginsPath); system::createDirectory(pluginsPath);


// Don't load plugins if safe mode is enabled
if (settings::safeMode)
return;

// Extract packages and load plugins // Extract packages and load plugins
extractPackages(pluginsPath); extractPackages(pluginsPath);
loadPlugins(pluginsPath); loadPlugins(pluginsPath);


+ 11
- 0
src/settings.cpp View File

@@ -19,6 +19,7 @@ bool devMode = false;
bool headless = false; bool headless = false;
bool isPlugin = false; bool isPlugin = false;


bool safeMode = false;
std::string token; std::string token;
bool windowMaximized = false; bool windowMaximized = false;
math::Vec windowSize = math::Vec(1024, 720); math::Vec windowSize = math::Vec(1024, 720);
@@ -107,6 +108,9 @@ void destroy() {
json_t* toJson() { json_t* toJson() {
json_t* rootJ = json_object(); 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, "token", json_string(token.c_str()));


json_object_set_new(rootJ, "windowMaximized", json_boolean(windowMaximized)); json_object_set_new(rootJ, "windowMaximized", json_boolean(windowMaximized));
@@ -241,6 +245,13 @@ json_t* toJson() {
} }


void fromJson(json_t* rootJ) { 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"); json_t* tokenJ = json_object_get(rootJ, "token");
if (tokenJ) if (tokenJ)
token = json_string_value(tokenJ); token = json_string_value(tokenJ);


Loading…
Cancel
Save