Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

54
LINES

< > BotCompany Repo | #1012256 // autoRestartOnSnippetChange - auto-restart program on change of a snippet

JavaX fragment (include)

static double autoRestartOnSnippetChange_interval = 10;
static bool autoRestartOnSnippetChange_on, autoRestartOnSnippetChange_debug, autoRestartOnSnippetChange_simulate;
sS autoRestartOnSnippetChange_snippetID;
static java.util.Timer autoRestartOnSnippetChange_timer;
sS autoRestartOnSnippetChange_localMD5;

static void autoRestartOnSnippetChange(double interval, S snippetID) {
  autoRestartOnSnippetChange_interval = interval;
  autoRestartOnSnippetChange(snippetID);
}

static void autoRestartOnSnippetChange(S snippetID) {
  snippetID = fsI(snippetID);
  if (autoRestartOnSnippetChange_on)
    if (eq(autoRestartOnSnippetChange_snippetID, snippetID)) ret;
    else fail("Watching multiple snippets not implemented");
  autoRestartOnSnippetChange_snippetID = snippetID;
  set autoRestartOnSnippetChange_on;
  autoRestartOnSnippetChange_schedule();
  preloadProgramTitle();
}

static void autoRestartOnSnippetChange_off() {
  if (!autoRestartOnSnippetChange_on) ret;
  stopTimer(autoRestartOnSnippetChange_timer);
  autoRestartOnSnippetChange_timer = null;
}

svoid autoRestartOnSnippetChange_schedule {
  autoRestartOnSnippetChange_timer = doLater_daemon(toMS(autoRestartOnSnippetChange_interval), f autoRestartOnSnippetChange_check);
}

svoid autoRestartOnSnippetChange_check ctex {
  try {
    S newMD5 = getSnippetMD5Silently(autoRestartOnSnippetChange_snippetID);
    if (!isMD5(newMD5)) { if (autoRestartOnSnippetChange_debug) print("autoRestartOnSnippetChange: no server value"); ret; }
    if (autoRestartOnSnippetChange_localMD5 == null)
      autoRestartOnSnippetChange_localMD5 = md5(DiskSnippetCache_get(psI(autoRestartOnSnippetChange_snippetID)));

    S localMD5 = autoRestartOnSnippetChange_localMD5;
    if (neq(localMD5, newMD5)) {
      if (autoRestartOnSnippetChange_simulate)
        print("Would upgrade now. " + localMD5 + " -> " + newMD5);
      else {
        infoBox("Upgrading " + programTitle() + " on snippet change");
        restartWithDelay(1000);
        sleep();
      }
    }
  } finally {
    if (autoRestartOnSnippetChange_debug) print("autoRestartOnSnippetChange: Done");
    autoRestartOnSnippetChange_schedule();
  }
}

Author comment

Began life as a copy of #1010683

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1012256
Snippet name: autoRestartOnSnippetChange - auto-restart program on change of a snippet
Eternal ID of this version: #1012256/7
Text MD5: 700e04e01f044a7f8f30c633fb4fcfc3
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-11-26 15:02:56
Source code size: 2213 bytes / 54 lines
Pitched / IR pitched: No / No
Views / Downloads: 474 / 495
Version history: 6 change(s)
Referenced in: [show references]