static double autoRestart_interval = 10; static bool autoRestart_on, autoRestart_debug, autoRestart_simulate; static java.util.Timer autoRestart_timer; static void autoRestart(double interval) { autoRestart_interval = interval; autoRestart(); } static void autoRestart() { if (!isMain() || autoRestart_on || vmHasResourceLoader()) ret; set autoRestart_on; autoRestart_schedule(); preloadProgramTitle(); } static void autoRestart_off() { if (!autoRestart_on) ret; stopTimer(autoRestart_timer); autoRestart_timer = null; } svoid autoRestart_schedule { autoRestart_timer = doLater_daemon(toMS(autoRestart_interval), r autoRestart_check); } svoid autoRestart_check { try { S newMD5; try { newMD5 = serverAutoRestartMD5(programID()); } catch e { ret; } if (!isMD5(newMD5)) { if (autoRestart_debug) print("autoRestart: no server transpilation"); ret; } if (autoRestart_localMD5 == null) autoRestart_localMD5 = md5(loadCachedTranspilation(programID())); S localMD5 = autoRestart_localMD5(); if (neq(localMD5, newMD5)) { if (autoRestart_simulate) print("Would upgrade now. " + localMD5 + " -> " + newMD5); else { infoBox("Upgrading " + programTitle()); restartWithDelay(500); sleep(); } } } finally { if (autoRestart_debug) print("autoRestart: Done"); autoRestart_schedule(); } }