srecord noeq G22AutoStarter(G22Utils g22utils) > MetaWithChangeListeners { settableWithVar volatile bool enabled; settable double initialDelay = 2; settableWithVar int nScriptsRun; new Flag started; new Flag waited; new Flag done; L scripts = syncL(); record noeq AutoStartScript(G22LeftArrowScript script) > RunResultWithTimestamps { run { LASCompileResult cr = script.compileForAutoRun(); if (cr == null) cr = script.compileSaved(); reMutable cr; run(-> { G22AutoStarter.this.change(); if (cr == null) fail("Script is not saved: " + script); var parsed = cr.parsedScriptMandatory(); ret parsed!; }); nScriptsRun.set(nScriptsRun+1); } } void init() { scripts.clear(); var scripts = conceptsWhere(g22utils.concepts, G22LeftArrowScript, runOnProjectOpen := true); for (script : scripts) this.scripts.add(new AutoStartScript(script)); change(); } void start { if (enabled && started.raise()) thread { change(); temp g22utils.backgroundProcessesUI.tempAdd("Auto-Start Scripts", ); sleepSeconds(initialDelay); waited.raise(); change(); for (script : scripts) pcall { if (!enabled) break; script.run(); } done.raise(); change(); } } void cancel { setEnabled(false); } S status() { ret !enabled ? "Cancelled" : done! ? "Done" : waited! ? "Started" : started! ? "Pre-start wait (" + initialDelay + "s)" : "Not started"; } S stats() { ret status() + ". Scripts run: " + nScriptsRun() + "/" + l(scripts); } }