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)

1  
static double autoRestartOnSnippetChange_interval = 10;
2  
static bool autoRestartOnSnippetChange_on, autoRestartOnSnippetChange_debug, autoRestartOnSnippetChange_simulate;
3  
sS autoRestartOnSnippetChange_snippetID;
4  
static java.util.Timer autoRestartOnSnippetChange_timer;
5  
sS autoRestartOnSnippetChange_localMD5;
6  
7  
static void autoRestartOnSnippetChange(double interval, S snippetID) {
8  
  autoRestartOnSnippetChange_interval = interval;
9  
  autoRestartOnSnippetChange(snippetID);
10  
}
11  
12  
static void autoRestartOnSnippetChange(S snippetID) {
13  
  snippetID = fsI(snippetID);
14  
  if (autoRestartOnSnippetChange_on)
15  
    if (eq(autoRestartOnSnippetChange_snippetID, snippetID)) ret;
16  
    else fail("Watching multiple snippets not implemented");
17  
  autoRestartOnSnippetChange_snippetID = snippetID;
18  
  set autoRestartOnSnippetChange_on;
19  
  autoRestartOnSnippetChange_schedule();
20  
  preloadProgramTitle();
21  
}
22  
23  
static void autoRestartOnSnippetChange_off() {
24  
  if (!autoRestartOnSnippetChange_on) ret;
25  
  stopTimer(autoRestartOnSnippetChange_timer);
26  
  autoRestartOnSnippetChange_timer = null;
27  
}
28  
29  
svoid autoRestartOnSnippetChange_schedule {
30  
  autoRestartOnSnippetChange_timer = doLater_daemon(toMS(autoRestartOnSnippetChange_interval), f autoRestartOnSnippetChange_check);
31  
}
32  
33  
svoid autoRestartOnSnippetChange_check ctex {
34  
  try {
35  
    S newMD5 = getSnippetMD5Silently(autoRestartOnSnippetChange_snippetID);
36  
    if (!isMD5(newMD5)) { if (autoRestartOnSnippetChange_debug) print("autoRestartOnSnippetChange: no server value"); ret; }
37  
    if (autoRestartOnSnippetChange_localMD5 == null)
38  
      autoRestartOnSnippetChange_localMD5 = md5(DiskSnippetCache_get(psI(autoRestartOnSnippetChange_snippetID)));
39  
40  
    S localMD5 = autoRestartOnSnippetChange_localMD5;
41  
    if (neq(localMD5, newMD5)) {
42  
      if (autoRestartOnSnippetChange_simulate)
43  
        print("Would upgrade now. " + localMD5 + " -> " + newMD5);
44  
      else {
45  
        infoBox("Upgrading " + programTitle() + " on snippet change");
46  
        restartWithDelay(1000);
47  
        sleep();
48  
      }
49  
    }
50  
  } finally {
51  
    if (autoRestartOnSnippetChange_debug) print("autoRestartOnSnippetChange: Done");
52  
    autoRestartOnSnippetChange_schedule();
53  
  }
54  
}

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: 476 / 497
Version history: 6 change(s)
Referenced in: [show references]