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

1925
LINES

< > BotCompany Repo | #1024932 - Stefan's OS v7 [LIVE]

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Uses 1177K of libraries. Click here for Pure Java version (35967L/269K).

1  
!7
2  
3  
set flag print_rst. // speed up printing a lot
4  
5  
set flag jCheckBoxMenuItem_dyn_debug.
6  
7  
set flag InOSCore.
8  
set flag NotifyingPrintLog.
9  
10  
sS defaultBackground = #1101488; //#1101303; //#1101465; //#1101438; //#1101355; // #1009931;
11  
sS background = defaultBackground;
12  
sS mainIconID = #1102666, moduleDefaultIconID = #1101337;
13  
sS laf;
14  
static double minLoadScreenShowingTime = 2;
15  
sbool loadBackgroundLater = true;
16  
static double backgroundLoadDelay = 2.0;
17  
sbool showLoadingScreen = false;
18  
static JDesktopPane desktop;
19  
sbool useCodeSharing = true; // share code between identical modules
20  
21  
static int autoSaveInterval = -10000; // 10 seconds plus slowdown logic
22  
static int persistenceDelayPerModule = 10000; // 10 seconds
23  
24  
static int systemErrorsToKeep = 10;
25  
26  
// OUTDATED
27  
static ReliableSingleThread rstUpdateModules = new(r { systemQ.add(r updateModules) });
28  
sS lastTopInput;
29  
static ReliableSingleThread rstTopInputChanged = rstWithDelay(250, r {
30  
  S s = getText(tfTopInput);
31  
  if (neq(lastTopInput, s))
32  
    vmBus_send('topInputChanged, lastTopInput = s);
33  
});
34  
35  
static volatile long updateCycles;
36  
static L systemErrors = synchroList();
37  
static int systemErrors_pointer;
38  
static new Flag stopRequested;
39  
static SimpleLiveValue<S> systemStatus = stringLiveValue("loading");
40  
static bool firstModuleShown;
41  
static Map<O, GhostModule> ghostModules = weakHashMap(); // key is main class (if dynamic module) or instance (if static module)
42  
static Q systemQ;
43  
static AccessControlContext globalACC;
44  
static volatile Module activeModule;
45  
static JTextField tfTopInput; // the input field in the OS menu bar
46  
static long tfTopInput_dontSelectAll; // sysNow timestamp
47  
static StefansOS_ConnectToServer connector;
48  
static Map generalMap = synchroMap();
49  
static L<Component> trayAreaComponents = synchroList();
50  
sbool printOnPersistContents, verboseCleanUp;
51  
static JMenuBar menuBar;
52  
sbool katze_send = true, katze_sendTyped;
53  
sO makeReloadingComponent; // F1<Module, Component>
54  
static long startTime;
55  
static NotTooOften backgroundGCFrequency = everyTenMinutes();
56  
static Set<S> hideFeatures;
57  
static LS standardModules;
58  
sS botName = "Stefan's OS.";
59  
sS osName;
60  
sbool showTopInput = true;
61  
static Runnable shutdownConsole; // instead of showConsole()
62  
sbool verboseModuleDeletes, cacheTranspilationsDuringBoot = true;
63  
sO confirmOSExit; // func -> bool or null
64  
sO gc_subcondition; // disable GC by module; func -> bool or null
65  
sbool showTimeInPrintLog = true;
66  
static JCheckBoxMenuItem miEnableQuickSearches;
67  
sbool debugFrameSizes;
68  
69  
// if you want other initial modules
70  
sO initialModules_override; // VF1<OS reference>
71  
72  
static Runnable restarter_override;
73  
static O onStart;
74  
75  
static S[] mainArgs;
76  
77  
static Set<S> disabledModuleIDs;
78  
static Set<DynamicModule> modulesBeingReloaded = syncSet();
79  
80  
p {
81  
  startTime = sysNow();
82  
  
83  
  // Just load all my classes so we are not dependent on jar or
84  
  // classes files on disk.
85  
  time "loadAllClasses" {
86  
    loadAllClasses();
87  
  }
88  
  
89  
  mainArgs = args;
90  
  vm_generalMap_put(stefansOS := mc());
91  
  callF(onStart, mc());
92  
  
93  
  //set getServerTranspiled_printStackTrace;
94  
  
95  
  print(headless() ? "We are headless." : "Starting GUI.");
96  
  
97  
  if (!headless()) showControls(jbutton("TROUBLESHOOTING", r { stopRequested.raise() }));
98  
  noRegularGC(); // not while we're loading
99  
  
100  
  /*if (onLocallyInferiorJavaX()) {
101  
    print("Restarting to use standard JavaX");
102  
    restart();
103  
  }*/
104  
  
105  
  checkMaxWindowBoundsBug();
106  
  
107  
  if (!eq("0", trim(loadTextFile(javaxDataDir("compile-on-server")))))
108  
    set hotwire_compileOnServer;
109  
  
110  
  /*if (isLinux() && isRoot())
111  
    addToDefaultVMArgs("-XX:ThreadPriorityPolicy");*/
112  
    
113  
  if (java10OrHigher()) {
114  
    addStandardAddOpensFlags();
115  
    addPermitIllegalAccessesFlag();
116  
    if (!hasPermitIllegalAccessesFlagInCurrentVM()) {
117  
      print("RESTARTING with proper JDK 11 arguments");
118  
      restart();
119  
    }
120  
  }
121  
  
122  
  if (java8OrHigher() && !containsOneOf(defaultVMArgs(), "+UseZGC", "+ShenandoahGC"))
123  
    addToDefaultVMArgs(smallHeapArgs());
124  
  
125  
  //laf = 'webLAF; // Let's not generally use it, is sluggish on my machine
126  
  //laf = 'nimbus;
127  
  laf = 'platform;
128  
  
129  
  //if (isMac()) laf = 'platform; // because https://github.com/michael-hagen/JTattoo/issues/1
130  
  if (isMac()) vmGeneralMap_set('iconifyBroken, true);
131  
  if (isLinux()) laf = 'jtattoo;
132  
  
133  
  /*if (vmArgs().contains("-XX:+PrintAssembly")) pcall {
134  
    teeSystemOutAndErrToFile(programFile("os.log"));
135  
  }*/
136  
  
137  
  if (!hasClass("x30_pkg.x30_util")) {
138  
    if (!zipFileContains_falseOnError(pathToJavaxJar(), "x30_pkg/x30_util.class"))
139  
      upgradeJavaXAndRestart();
140  
    else
141  
      restart();
142  
  }
143  
  
144  
  _handleException_addHandler(voidfunc(Throwable e) {
145  
    try {
146  
      synchronized(systemErrors) {
147  
        listSet(systemErrors, systemErrors_pointer, e);
148  
        systemErrors_pointer = (systemErrors_pointer+1) % systemErrorsToKeep;
149  
      }
150  
    } catch e2 {
151  
      printStackTrace(e2);
152  
    }
153  
    infoBox("Error: " + exceptionToStringShort(e));
154  
    LastErrors lastErrors = first(staticModulesOfType(LastErrors));
155  
    if (lastErrors != null) lastErrors.addError(e);
156  
  });
157  
  
158  
  timeJumpDetector();
159  
  
160  
  vm_generalMap_put('consoleInUse, true); // bots made by modules should not handle console
161  
162  
  monitorThreadAllocatedMemory();
163  
  
164  
  // Solve deadlocks every 10 to be sure
165  
  doEvery(10000, r printDeadlocksAndSolve);
166  
  
167  
  print("Data dir: " + javaxDataDir());
168  
  vm_setGlobalACC(globalACC = acc_current());
169  
  
170  
  if (swic(activateFramesOf(programIDPlusHome()), "OK")) {
171  
    print("OS already running!");
172  
    cleanKill();
173  
  }
174  
  
175  
  framesBot();
176  
  if (nempty(botName)) makeBot(botName);
177  
  
178  
  S printLogSize = trim(loadTextFile(javaxDataDir("os-print-log-size.txt")));
179  
  if (isInteger(printLogSize)) printLogMaxChars(parseInt(printLogSize));
180  
  
181  
  vm_generalMap_put('newSwingComponentRegistry, voidfunc(Component c) {
182  
    allAWTComponents_extraList.add(c)
183  
  });
184  
  
185  
  connector = new StefansOS_ConnectToServer;
186  
  connector.start();
187  
  
188  
  //substance();
189  
  final SimpleLiveValue<S> lvDetails = stringLiveValue();
190  
  lvDetails.onChange(r { print(lvDetails!) });
191  
  stefansOS_loadingAnimation_fullScreen = startInFullScreen() && !isWindows() /* bug */;
192  
  final Component loadingAnim = showLoadingScreen ? stefansOS_loadingAnimation(r {
193  
    stopRequested.raise()
194  
  }, lvDetails) : null;
195  
  
196  
  try {
197  
    long start = sysNow();
198  
    systemQ = startQ("System Q");
199  
    useDBOf(#1015871);
200  
    lvDetails.set("Loading database");
201  
    db(autoSaveInterval);
202  
    db_mainConcepts().quietSave = true;
203  
    if (!headless()) {
204  
      // if you use Processing
205  
      JPopupMenu.setDefaultLightWeightPopupEnabled(false);
206  
  
207  
      lvDetails.set("Loading background");
208  
      background = or2(trim(loadTextFile(javaxDataDir("os-background.txt"))), background);
209  
      if (!isSnippetID(background))
210  
        background = fileToURI(new File(background));
211  
      try {
212  
        if (eq(settings().backgroundMode, "fit"))
213  
          desktop = loadBackgroundLater
214  
            ? jDesktopPaneWithFitPicture_smooth_cacheScaled_loadLater(background, delay := backgroundLoadDelay)
215  
            : jDesktopPaneWithFitPicture_smooth_cacheScaled(background);
216  
        else if (eq(settings().backgroundMode, "center"))
217  
          desktop = setBackground(settings().backgroundColor,
218  
            jDesktopPaneWithCenteredPicture(background));
219  
        else
220  
          desktop = jDesktopPaneWithSkyPicture/*_autoUnload*/(background, settings().backgroundColor);
221  
      } catch print e {
222  
        try {
223  
          desktop = jDesktopPaneWithFitPicture_smooth(defaultBackground);
224  
        } catch print e2 {
225  
          desktop = jDesktopPane();
226  
        }
227  
      }
228  
      setMainDesktopPane(desktop);
229  
      autoFixDesktopPane(desktop);
230  
      
231  
      // Allow frame switching from AI bar & similar components
232  
      installInternalFrameSwitcher_v3(desktop).shouldSwitch =
233  
        func -> bool { sameComponentOrDeepChildOf(getFocusOwner(), menuBar) };
234  
    }
235  
    
236  
    long ms = consoleShowing() ? toMS(minLoadScreenShowingTime) : 0;
237  
    long remaining = start+ms-sysNow();
238  
    if (remaining <= 0)
239  
      lvDetails.set("Done loading");
240  
    else {
241  
      S seconds = formatDouble(toSeconds(remaining), 1);
242  
      lvDetails.set("Done loading, but will wait if you hit the troubleshooting button for " + seconds + " more second" + (eq(seconds, "1") ? "" : "s"));
243  
    }
244  
    //if (loadingAnim != null)
245  
      waitUntilSysTimeOrFlag(start+ms, stopRequested);
246  
  } catch e {
247  
    _handleException(e);
248  
    stopRequested.raise();
249  
  }
250  
  
251  
  try {
252  
    bool flag = stopRequested.isUp(); // get before closing animation
253  
    if (flag)
254  
      ret with showFrame("Stop screen",
255  
        centerAndSouthWithMargins(
256  
          jcenteredlabel("More troubleshooting options will go here."),
257  
          jcenteredbuttons(
258  
            "Start " + osName() + " normally", r restart,
259  
            //"Switch to " + otherVersionName(), r startOtherVersion,
260  
            eq(programID(), #1016478) ? null: "Switch to v6", r { nohupJavax(#1016478) },
261  
            eq(programID(), #1024932) ? null: "Switch to v7", r { nohupJavax(#1024932) },
262  
            "Use last session backup", rThread useLastSessionBackup,
263  
            jPopDownButton_noText(
264  
              "Delete session", disableButtonWhileCalcing(func -> bool {
265  
              if (!fileExists(conceptsFile()))
266  
                ret false with infoBox("Session already empty.");
267  
              if (!confirmOKCancel("Really delete your current session?")) false;
268  
              cleanMeUp_concepts();
269  
              renameFileToSomeBackupName(conceptsFile());
270  
              infoBox("Session deleted. Starting again.");
271  
              disableAllButtonsInWindow(heldInstance(JButton));
272  
              sleepSeconds(3);
273  
              restart();
274  
              false;
275  
            })))));
276  
  
277  
    //autoRestart();
278  
    thread { serverAutoRestartMD5(); } // just a short ping
279  
    
280  
    pcall { setLookAndFeel(); }
281  
    
282  
    showDesktop();
283  
  } finally {
284  
    disposeWindow(loadingAnim);
285  
  }
286  
    
287  
  initAfterDBLoad();
288  
  setOpt(javax(), regularGC_firstDelay := 60000);
289  
  call(javax(), 'regularGC);
290  
  if (!headless()) {
291  
    setOpt(javax(), regularGC_condition := func -> bool {
292  
      if (isFalse(callF(gc_subcondition))) false;
293  
      if (backgroundGCFrequency! || vmHasActiveFrame())
294  
        ret true /*with print("GC")*/;
295  
      else
296  
        ret false /* with print("Skipping GC (not in foreground)") */;
297  
    });
298  
  }
299  
  hideConsole();
300  
  manualConsole();
301  
  //clearConsole();
302  
  if (headless()) sleep();
303  
}
304  
305  
sbool startInFullScreen() {
306  
  ret eq("1", trim(loadTextFile(javaxDataDir("start-os-in-full-screen.txt"))));
307  
}
308  
309  
svoid setStartInFullScreen(bool b) {
310  
  saveTextFile(javaxDataDir("start-os-in-full-screen.txt"), b ? "1" : "0");
311  
}
312  
sbool showDesktop_first = true;
313  
314  
svoid showDesktop {
315  
  if (headless()) ret;
316  
  bool done = false;
317  
  
318  
  S title;
319  
  if (nempty(osName)) title = osName;
320  
  else {
321  
    title = osName(); //programName();
322  
    S subDir = javaxVirtualSpaceName();
323  
    if (subDir != null) title = "[" + subDir + "] " + title;
324  
  }
325  
326  
  if (showDesktop_first && startInFullScreen()) pcall {
327  
    showFullScreen(title, desktop);
328  
    done = true;
329  
  }
330  
331  
  if (!done) {
332  
    showMaximizedFrame(title, desktop);
333  
    titlePopupMenu_top(desktop, voidfunc(JPopupMenu menu) {
334  
      addMenuItems(menu,
335  
        "New Session", rThreadPcallMessageBox(r deleteAllModules),
336  
        "Restore Initial Modules", r initialModules,
337  
      );
338  
    });
339  
  }
340  
  
341  
  if (showTopInput)
342  
    registerFunctionKey(getFrame(desktop), 1, r { requestFocus(tfTopInput) });
343  
  
344  
  fillMenuBar();
345  
  doNothingOnClose(getFrame(desktop));
346  
  frameIcon(mainIconID, desktop);
347  
  showDesktop_first = false;
348  
  cleanExitOnFrameClose_ifStillInSameFrame(desktop,
349  
    () -> (Bool) callF(confirmOSExit));
350  
}
351  
352  
sbool inFullScreen() {
353  
  ret isFullScreen(desktop);
354  
}
355  
356  
svoid fullScreenOff() {
357  
  if (inFullScreen()) fullScreenOnOff();
358  
}
359  
360  
svoid fullScreenOnOff {
361  
  // Don't screw up window positions while adjusting from/to fullscreen
362  
  autoFixDesktopPane_exclude.add(desktop);
363  
  temp tempAfterwards(r { autoFixDesktopPane_exclude.remove(desktop) });
364  
  
365  
  Window w = getWindow(desktop);
366  
  if (!inFullScreen()) {
367  
    showFullScreen(frameTitle(desktop), desktop);
368  
    pcall { frameIcon(mainIconID, desktop); }
369  
    cleanExitOnFrameClose_ifStillInSameFrame(desktop);
370  
    fillMenuBar();
371  
    setStartInFullScreen(true);
372  
  } else {
373  
    removeFromParent(desktop);
374  
    showDesktop();
375  
    setStartInFullScreen(false);
376  
  }
377  
  
378  
  // Allow closing empty "zombie" windows (why do we have these?)
379  
  final JFrame f = getFrame(desktop);
380  
  onFrameClosing(f, r { if (isEmptyFrame(f)) {
381  
    removeListener();
382  
    disposeWindow(f);
383  
  }});
384  
  
385  
  disposeWindow(w);
386  
  fixDesktopPane(desktop);
387  
}
388  
389  
svoid updateMenuBar() swing {
390  
  //temp tempRememberFocusedComponent();
391  
  JMenuBar mb = getMenuBar(desktop);
392  
  if (mb == null) {
393  
    mb = addMenuBar(desktop);
394  
    mb.setLayout(new javax.swing.plaf.basic.DefaultMenuLayout(menuBar, BoxLayout.X_AXIS));
395  
  } 
396  
  keepComponentsByPred(mb, func(Component c) -> bool {
397  
    c instanceof JMenu || c == tfTopInput
398  
  });
399  
  //clearMenuBar();
400  
  fillMenuBar();
401  
}
402  
403  
svoid fillMenuBar() swing {
404  
  menuBar = addMenuBar(desktop);
405  
  set jmenuItem_newThreads;
406  
  S version = version();
407  
  S name = osName();
408  
  //S subDir = userHomeSubDirName();
409  
  //if (subDir != null) name += " [" + subDir + "]";
410  
  addMenuIfNempty(desktop, empty(osName) ? "OS" : trim(name),
411  
    featureMenuItem("Screenshot"), r stefansOS_screenshot,
412  
    featureMenuItem("Full screen on/off"), r fullScreenOnOff,
413  
    featureMenuItem("Switch OS version", "Switch to " + otherVersionName()), r {
414  
      innerCleanUp();
415  
      startOtherVersion();
416  
      cleanKill();
417  
    },
418  
    "---",
419  
    featureMenuItem("Restart OS", "Restart " + or2(osName, "Stefan's OS")), r { showConsole(); restart(); },
420  
    featureMenuItem("Exit"), r cleanKill
421  
  );
422  
  
423  
  L moduleMenu = ll(
424  
    featureMenuItem("Other Module..."), r stefansOS_addDynamicModuleDialog,
425  
    "Show selected module's menu", r showCurrentModuleMenu
426  
  );
427  
    
428  
  for (int i = 0; i+1 < l(standardModules); i += 2) {
429  
    moduleMenu.add(standardModules.get(i));
430  
    S id = standardModules.get(i+1);
431  
    moduleMenu.add(r { makeOrShowModule(id) });
432  
  }
433  
    
434  
  moduleMenu.addAll(ll(
435  
    featureMenuItem("Welcome Screen"), r { makeOrShowModule("#1016067/WelcomeScreen") },
436  
    featureMenuItem("Quick Module Search"), r addQuickModuleSearch,
437  
    //"Hello (input field for everything)", r { makeOrShowModule("Hello") },
438  
    featureMenuItem("Auto Module Upgrade"), r { makeOrShowModule("#1021905/AutoReloadButtons") },
439  
    featureMenuItem("Task Bar"), r { makeOrShowModule("#1019954/TaskBar_dev") },
440  
    featureMenuItem("System Print Log"), r { makeOrShowModule("#1018866/SystemPrintLog") },
441  
    hideFeature("Internal Types") ? null : jmenu("Internal Types", map(myNonAbstractClassesImplementing(Module), func(final Class c) -> JMenuItem {
442  
      jMenuItem(shortClassName(c), rThread { makeOrShowStaticModuleOfType(c) })
443  
    })),
444  
    featureMenuItem("Module Classes"), r {  makeOrShowStaticModuleOfType(ModuleClasses) },
445  
    "---",
446  
    jDynamicScrollingMenu("Loaded Modules", voidfunc(JPopupMenu menu) {
447  
      for (final Module m : sortedByMethodIC('moduleName, onModules()))
448  
        addMenuItem(menu, m.moduleName(), rThread { showModule(m) });
449  
    })
450  
  ));
451  
  
452  
  addMenu(desktop, "Modules", asObjectArray(moduleMenu));
453  
  
454  
  // TODO - need to generate menu items differently in enhanceFrame
455  
  //addFullyDynamicMenu(desktop, "Current module",
456  
  
457  
  addMenu(desktop, "More",
458  
    featureMenuItem("Start External JavaX Program..."), r stefansOS_startExternalJavaXProgram,
459  
    "---",
460  
    featureMenuItem("Run 10 Second Profiler"), r tenSecondProfileAndShowInFrame,
461  
    featureMenuItem("Find memory leaks", "Find memory leaks (PID: " + getPID() + ")"), r stefansOS_findMemoryLeaks,
462  
    "Computer ID: " + computerID(), r { copyTextToClipboard_infoBox(computerID()) },
463  
    featureMenuItem("Show console"), rThread showConsole,
464  
    featureMenuItem("System Version"), r { makeOrShowModule_early("#1016442/SystemVersion") },
465  
    featureMenuItem("Remove moduleless frames"), rThread dm_closeModuleLessFrames,
466  
    featureMenuItem("Clean disk caches"), rThread stefansOS_cleanDiskCaches,
467  
    hideFeature("Enable quick searches") ? null : (miEnableQuickSearches = menuItem_enableQuickSearches()),
468  
    featureMenuItem("Hard exit"), rHardExit(),
469  
  );
470  
    
471  
  // Add the fancy stuff
472  
  
473  
  JMenuBar menuBar = cast call(getFrame(desktop), 'getJMenuBar);
474  
  
475  
  if (tfTopInput == null && showTopInput) {
476  
    tfTopInput = jcenteredtextfield(uniq(TopInput).text);
477  
    setFontSize(tfTopInput, 16);
478  
    selectAllOnFocusIf(tfTopInput, func -> bool {
479  
      elapsedTime(tfTopInput_dontSelectAll) >= 2000
480  
    });
481  
    onChange(tfTopInput, r {
482  
      cset(uniq(TopInput), text := getText(tfTopInput));
483  
      rstTopInputChanged.trigger();
484  
    });
485  
    onEnter(tfTopInput, r {
486  
      S info = cast generalMap.get('topInputInfo);
487  
      temp dm_generalMap_tempPut(topInputInfo := or2(info, "typed"));
488  
      S text = getText(tfTopInput);
489  
      vmBus_send('topInput, text);
490  
      logQuotedWithDate(topInputsLogFile(), text);
491  
      if (katze_send)
492  
        if (nempty(info))
493  
          katze_userSaid(info, text);
494  
        else if (katze_sendTyped)
495  
          katze_userTyped(text);
496  
    });
497  
    componentPopupMenu(tfTopInput, voidfunc(JPopupMenu menu) {
498  
      menu.add(menuItem_enableQuickSearches());
499  
    });
500  
  }
501  
    
502  
  if (showTopInput && getParent(tfTopInput) == null) {
503  
    menuBar.add(Box.createHorizontalStrut(20));
504  
    menuBar.add(tfTopInput);
505  
  }
506  
  
507  
  if (!containsChildOfType(menuBar, JLabel.class)) { // look for clock label
508  
    if (!showTopInput)
509  
      menuBar.add(Box.createHorizontalGlue());
510  
    else {
511  
      menuBar.add(Box.createHorizontalStrut(5));
512  
      menuBar.add(onClick(setToolTip([[Simulate pressing Enter key in input field to the left ("AI bar")]], jimage(#1101426)), r { simulateEnter(tfTopInput) }));
513  
    }
514  
    //menuBar.add(jhgrid(null, tfTopInput));
515  
    //menuBar.add(jhgrid(tfTopInput, null));
516  
    menuBar.add(Box.createHorizontalStrut(20));
517  
    for i over trayAreaComponents: {
518  
      Component c = trayAreaComponents.get(i);
519  
      continue if c == null;
520  
      menuBar.add(c);
521  
      menuBar.add(Box.createHorizontalStrut(i == l(trayAreaComponents)-1 ? 20 : 6));
522  
    }
523  
    menuBar.add(jLiveValueLabel(clockTimeLiveValue()));
524  
    menuBar.add(Box.createHorizontalStrut(6));
525  
  }
526  
}
527  
528  
svoid addQuickModuleSearch {
529  
  makeOrShowModule("#1016702/LoadedModuleSearch");
530  
  makeOrShowModule("#1016932/ServerModuleSearch");
531  
}
532  
533  
static JCheckBoxMenuItem menuItem_enableQuickSearches() {
534  
  ret jCheckBoxMenuItem("Enable quick searches", quickSearchesEnabled(), voidfunc(bool b) {
535  
    cset(uniq(TopInput), quickSearchesEnabled := b);
536  
    setChecked(miEnableQuickSearches, b);
537  
  });
538  
}
539  
540  
static tempDisposeInternalFrame_obj<JLabel> tempBusyAnimation(fS text) {
541  
  ret vmExiting() ? null : tempBusyAnimation(stringLiveValue(text));
542  
}
543  
544  
static tempDisposeInternalFrame_obj<JLabel> tempBusyAnimation(LiveValue<S> text) {
545  
  if (headless()) null;
546  
  final JLabel anim = jBackground(Color.white, jAnimation_liveValueText(#1101316, text));
547  
  swing {
548  
    addInternalFrame_dontSelect.set(true);
549  
    addInternalFrame_layer.set(JLayeredPane.POPUP_LAYER);
550  
    addInternalFrame(desktop, "", null, anim);
551  
    packInternalFrameInTopRightCorner(anim);
552  
    JInternalFrame f = getInternalFrame(anim);
553  
    //print("Have busy animation: " + f + " in " + getParent(f));
554  
  }
555  
  ret tempDisposeInternalFrame(anim);
556  
}
557  
558  
svoid allRegularFixes {
559  
  applyStandardSwingFixes();
560  
  cleanDefunctACCsInAllThreads();
561  
  cleanDefunctACCsInAllSwingComponents();
562  
}
563  
564  
svoid gcWithFixes {
565  
  allRegularFixes();
566  
  gc();
567  
  allRegularFixes();
568  
}
569  
570  
svoid initAfterDBLoad {
571  
  doEvery(30000, r allRegularFixes);
572  
  doEvery(600000, r clearSnippetTitleCacheIfOnline);
573  
  set cleanUp_interruptThreads; 
574  
  
575  
  // for Java Chrome
576  
  classForNameOpt("java.util.prefs.FileSystemPreferences");
577  
  
578  
  SimpleLiveValue<S> lvText = stringLiveValue(jlabel_textAsHTML_center("Restoring Session"));
579  
  temp final tempDisposeInternalFrame_obj<JLabel> anim = tempBusyAnimation(lvText);
580  
  JLabel animComponent = anim == null ? null : anim.component;
581  
  if (anim != null) {
582  
    onResizeAndNow(animComponent, r {
583  
      setVerticalAlignment(
584  
        animComponent.getHeight() >= 150 ? JLabel.CENTER : JLabel.TOP,
585  
        animComponent)
586  
    });
587  
    growInternalFrameLeft(animComponent, 50);
588  
    growInternalFrameSouth(animComponent, 50);
589  
  }
590  
  
591  
  disabledModuleIDs = asSet(tlft(loadTextFile(javaxDataDir("stefans-os/disabled-modules.txt"))));
592  
  
593  
  initialModules();
594  
  
595  
  UpdateCycles uc = conceptWhere(UpdateCycles);
596  
  if (uc != null) updateCycles = uc.value;
597  
  
598  
  stefansOS_installQuickSearchHelper();
599  
  
600  
  // START MODULES
601  
  
602  
  L<Module> modules = startOrder(onModules());
603  
  
604  
  AutoCloseable disposeTempCache2 = cacheTranspilationsDuringBoot ? tempSetMCOpt(getServerTranspiled2_tempCache :=  syncMap()) : null;
605  
  
606  
  if (cacheTranspilationsDuringBoot) thread {
607  
    for (Module m : modules) pcall {
608  
      if (m cast DynamicModule) {
609  
        print("Preloading " + m.moduleID);
610  
        getServerTranspiled2(m.moduleID);
611  
      }
612  
    }
613  
    print("Preloading done");
614  
  }
615  
616  
  AutoCloseable disposeTempCache = tempSetTL(loadLibraryOrSrcLib_tempCache, new Map);
617  
  
618  
  int i = 0;
619  
  for (Module m : modules) {
620  
    ++i;
621  
    int _i = i;
622  
    systemQ.add(new Runnable { 
623  
      run {
624  
        if (isShuttingDown()) ret;
625  
        lvText.set(jlabel_textAsHTML_center(
626  
          "Starting module " + _i + "/" + l(modules) + ":\n"
627  
          + m.moduleName()));
628  
        startModule(m);
629  
      }
630  
      
631  
      toString { ret "Start module " + m.id; }
632  
    });
633  
  }
634  
  
635  
  if (anim != null) anim.disableAutoDisposal();
636  
  systemQ.add(r {
637  
    close(disposeTempCache);
638  
    close(disposeTempCache2);
639  
    disposeInternalFrame(animComponent);
640  
    if (isShuttingDown()) ret;
641  
    systemStatus.set("running");
642  
    print("== STARTED IN " + iceil(elapsedSeconds(/*vmStartTime_sys()*/startTime)) + " SECONDS ==");
643  
  });
644  
}
645  
646  
static L<Module> startOrder(L<Module> modules) {
647  
  ret sortedByComparator(
648  
    combineComparators(
649  
      main.<Module> descFieldComparator('visible),
650  
      main.<Module> fieldComparator('zOrder)),
651  
    modules);
652  
}
653  
654  
svoid initialModules {
655  
  if (initialModules_override != null)
656  
    ret with pcallF(initialModules_override, mc());
657  
  initialModules_base();
658  
}
659  
660  
svoid initialModules_base {
661  
  if (headless()) {
662  
    makeOrShowModule("#1016576/ConnectToServer");
663  
    ret;
664  
  }
665  
    
666  
  if (empty(onModules())) {
667  
    //makeOrShowModule(#1016081/WelcomeScreen");
668  
    showModule_noFocus(getModuleByID(makeModule("#1018866/SystemPrintLog")));
669  
    showModule_noFocus(getModuleByID(makeModule("#1019954/TaskBar_dev")));
670  
    //makeModule("#1016872/SnippetsDB");
671  
    makeModule("#1016932/ServerModuleSearch");
672  
    makeModule("#1016702/LoadedModuleSearch");
673  
    //makeModule("#1018602/QuickAudioRecord");
674  
    makeModule("#1019326/WitAILastRecording");
675  
    makeModule("#1019400/SpeechRecogConfirmation");
676  
    makeModule("#1021905/AutoReloadButtons");
677  
  }
678  
}
679  
680  
svoid triggerUpdate { rstUpdateModules.trigger(); }
681  
682  
// not done anymore
683  
svoid updateModules {
684  
  /*++updateCycles;
685  
  for (Module m : onModules())
686  
    updateModule(m);*/
687  
}
688  
689  
svoid updateModule(Module m) {
690  
  if (m == null) ret;
691  
  temp m.enter();
692  
  pcall { m.update(); }
693  
}
694  
695  
svoid updateModules(final Collection<Module> l) {
696  
  systemQ.add(r {
697  
    for (Module m : unnull(l)) updateModule(m);
698  
  });
699  
}
700  
701  
svoid saveZOrder {
702  
  for (Module m)
703  
    cset(m, zOrder := getComponentZOrder(getInternalFrame(m.vis)));
704  
}
705  
706  
svoid cleanMeUp {
707  
  saveZOrder();
708  
  autoConsole();
709  
  if (shutdownConsole == null) showConsole(); else pcallF(shutdownConsole);
710  
  killProgram(#1019683); // stop watch dog
711  
  systemStatus.set("shutting down");
712  
  temp tempBusyAnimation("Shutting Down");
713  
  
714  
  print("PRE-CLEAN UP");
715  
  preCleanUp(list(Module));
716  
  for (Module m) {
717  
    if (m.vis != null) pcall {
718  
      print("UNVISUALIZING " + moduleIDAndName(m));
719  
      m.unvisualize();
720  
      print("UNVISUALIZED " + moduleIDAndName(m));
721  
    }
722  
    print("CLEANING UP " + moduleIDAndName(m));
723  
    cleanUp(m);
724  
    print("CLEANED UP " + moduleIDAndName(m));
725  
  }
726  
  print("CLEAN UP DONE");
727  
  cleanedUp = true;
728  
}
729  
730  
static L<Module> onModules() { ret asList(conceptsWhere(Module, on := true)); }
731  
732  
sbool hasModuleWithFields(Class<? extends Module> c, O... params) {
733  
  ret hasConcept(c, concatArrays(new O[] {on := true}, params));
734  
}
735  
736  
sbool startModule_reloading, startModule_doShare;
737  
sO startModule_beforeStart;
738  
739  
svoid startModule(Module m) {
740  
  runInSystemQAndWait(r-pcall {
741  
    //addIfNotThere(modules, m);
742  
    temp m.enter();
743  
    if (m.started || m.startedWithError) ret;
744  
    temp tempSet(m, starting := true);
745  
    print("Starting module " + m.moduleName());
746  
    try {
747  
      if (m cast DynamicModule)
748  
        if (contains(disabledModuleIDs, m.moduleID))
749  
          failWithInfoBox("Not starting disabled module " + m);
750  
      m.start();
751  
      m.started = true;
752  
    } catch e {
753  
      m.startedWithError = true;
754  
      m.setError(e);
755  
      _handleException(e);
756  
    }
757  
    vmBus_send('moduleStarted, m.moduleID());
758  
    //rstUpdateModules.trigger();
759  
    if (m.visible) showModule(m);
760  
  });
761  
}
762  
763  
static Module showModule(final Module m) {
764  
  ret showModule(m, true);
765  
}
766  
767  
static Module showModule_noFocus(final Module m) {
768  
  ret showModule(m, false);
769  
}
770  
771  
svoid runInSystemQAndWait(Runnable r) {
772  
  if (isAWTThread()) ret with callF(r);
773  
  runInQAndWait(systemQ, r);
774  
}
775  
776  
sO evalInSystemQ_gen(O f) {
777  
  ret evalInSystemQ(toF0(f));
778  
}
779  
780  
static <A> A evalInSystemQ(F0<A> f) {
781  
  if (isAWTThread()) ret callF(f);
782  
  ret evalInQ(systemQ, f);
783  
}
784  
785  
static Module showModule(final Module m, final bool focus) {
786  
  if (m == null) ret m;
787  
  runInSystemQAndWait(r {
788  
    startModule(m);
789  
    if (headless()) ret;
790  
    temp m.enter();
791  
    if (m.vis != null) {
792  
      if (focus && !isLoading())
793  
        if (stefansOS_moduleIsPoppedOut(m))
794  
          activateFrame(m.vis);
795  
        else
796  
          activateInternalFrame(m.vis);
797  
      ret;
798  
    }
799  
    csetAndStatusChange(m, visible := true);
800  
    visualizeModule(m);
801  
    if (m.vis != null) swing {
802  
      Rect r = m.frameRect;
803  
      /*if (r == null) r = randomRect(desktop.getWidth(), desktop.getHeight(), 10, 150, 100);
804  
      if (r == null) r = makeDefaultRectForModule(m);
805  
      print("Showing frame at " + r);*/
806  
      S frameTitle = m.moduleName();
807  
      final JInternalFrame f;
808  
      bool toBack = isLoading() && firstModuleShown;
809  
      bool activate = focus && !toBack;
810  
      {
811  
        temp tempSetThreadLocal(addInternalFrame_toBack, toBack);
812  
        temp tempSetThreadLocal(addInternalFrame_dontSelect, !activate);
813  
        f = showInternalFrame(desktop, frameTitle, r, m.vis);
814  
        set firstModuleShown;
815  
      }
816  
      if (r == null) {
817  
        if (debugFrameSizes) print("Setting initial size for module " + m);
818  
        Pt p = m.getMinSize();
819  
        if (debugFrameSizes) print("Minimum size: " + p);
820  
        if (isTrue(callOpt(resolveModule(m), "_usePreferredSizeInitially"))) {
821  
          p = toPt(getPreferredSize(m.vis));
822  
          if (debugFrameSizes) print("Using preferred size: " + p);
823  
        }
824  
          
825  
        centerPackInternalFrameWithMinSize(f, p);
826  
      }
827  
      f.setDefaultCloseOperation(JInternalFrame.DO_NOTHING_ON_CLOSE);
828  
      
829  
      onInternalFrameIconified(f, r { hideModule(m) });
830  
      onInternalFrameClosing(f, rThread { deleteModule(m) });
831  
      onInternalFrameActivated(f, r { setActiveModule(m) });
832  
      onInternalFrameDeactivated(f, r { if (activeModule == m) setActiveModule(null) });
833  
      onBoundsChange(f, r { m.grabFrameRect() });
834  
      internalFrameIcon(f, or2(m.iconID, moduleDefaultIconID));
835  
      m.enhanceFrame(f);
836  
      if (activate) setActiveModule(m);
837  
    }
838  
  });
839  
  ret m;
840  
}
841  
842  
static Rect makeDefaultRectForModule(Module m) {
843  
  ret Rect(10, 10, 200, 100);
844  
}
845  
846  
svoid showModules(L<? extends Module> l) {
847  
  for (Module m : unnull(l)) showModule(m);
848  
}
849  
850  
sbool deleteModule(Module m) {
851  
  pcall {
852  
    bool warn = isTrue(callOpt(resolveModule(m), 'warnOnDelete));
853  
    if (warn && !confirmOKCancel("Really delete module " + m + "?"))
854  
      false;
855  
  }
856  
  deleteModule_noConfirm(m);
857  
  true;
858  
}
859  
860  
svoid deleteModule_noConfirm(Module m) {
861  
  runInSystemQAndWait(r {
862  
    if (verboseModuleDeletes) print("delete phase 1");
863  
    O m2 = unwrapDynamicModule(m);
864  
    vmBus_send('deletingModule, m2);
865  
    ghostModules.put(m == m2 ? m : m2.getClass(), nu(GhostModule,
866  
      name := m.moduleName(),
867  
      created := m.created,
868  
      deleted := now(),
869  
      instance := new WeakReference(m2)));
870  
    if (verboseModuleDeletes) print("delete phase 2");
871  
    pcall { m.unvisualize(); }
872  
    if (verboseModuleDeletes) print("delete phase 3");
873  
    removeConcept(m); // generates oStruct
874  
    vmBus_send('moduleDeleted, m);
875  
    if (verboseModuleDeletes) print("delete phase 4");
876  
    pcall {
877  
      S snippetID = m instanceof DynamicModule ? m/DynamicModule.moduleID : "internal_" + shortClassName(m);
878  
      logStructure(deletedModulesLogFile(snippetID), litmap(
879  
        globalID := aGlobalID(),
880  
        deleted := now(),
881  
        module := m));
882  
    }
883  
    //triggerUpdate();
884  
  });
885  
}
886  
887  
svoid visualizeModule(Module m) {
888  
  pcall {
889  
    if (m.vis == null) m.vis = m.visualize();
890  
  }
891  
  pcall {
892  
    if (m.vis == null) m.vis = defaultVisualize(m);
893  
  }
894  
  vmBus_send('moduleVisualized, m);
895  
}
896  
897  
svoid hideModule(final Module m) {
898  
  if (m == null) ret;
899  
  runInSystemQAndWait(r {
900  
    temp m.enter();
901  
    csetAndStatusChange(m, visible := false);
902  
    pcall { m.unvisualize(); }
903  
  });
904  
}
905  
906  
svoid csetAndStatusChange(Module m, O... params) {
907  
  if (cset(m, params) > 0)
908  
    vmBus_send('moduleStatusChange, m, params);
909  
}
910  
911  
svoid revisualizeModule(Module m) {
912  
  pcall {
913  
    if (m == null) ret;
914  
    temp m.enter();
915  
    JInternalFrame frame = getInternalFrame(m.vis);
916  
    if (frame == null) ret;
917  
    m.unvisualize1b();
918  
    m.unvisualize2();
919  
    visualizeModule(m);
920  
    setInternalFrameContents(frame, m.vis);
921  
  }
922  
}
923  
924  
abstract concept Module {
925  
  transient JComponent vis;
926  
  transient bool starting, started, startedWithError;
927  
  transient Lock lock = lock();
928  
  
929  
  static int ALWAYSONTOPWHENPOPPEDOUT = 1;
930  
931  
  bool on = true, visible;
932  
  int flags;
933  
  Rect frameRect;
934  
  int zOrder;
935  
  S iconID;
936  
  PersistableThrowable error;
937  
  
938  
  //transient Set timers;
939  
  
940  
  JComponent visualize() { null; }
941  
  void unvisualize() {
942  
    pcall { unvisualize1(); }
943  
    pcall { unvisualize2(); }
944  
    vmBus_send('moduleUnvisualized, this);
945  
  }
946  
  void enhanceFrame(JInternalFrame frame) {}
947  
  void start() {}
948  
  void unvisualize1() {
949  
    disposeInternalFrame(getInternalFrame(vis));
950  
    unvisualize1b();
951  
  }
952  
  
953  
  void unvisualize1b() {
954  
    grabFrameRect();
955  
    vis = null;
956  
  }
957  
  void unvisualize2() {}
958  
  void update() {}
959  
  
960  
  void grabFrameRect() {
961  
    JInternalFrame f = getInternalFrame(vis);
962  
    if (f != null)
963  
      cset(this, frameRect := toRect(getBounds(f)));
964  
  }
965  
  
966  
  Rect getFrameRect() {
967  
    grabFrameRect();
968  
    ret frameRect;
969  
  }
970  
  
971  
  void cleanMeUp_started() { started = startedWithError = false; }
972  
973  
  void delete() {
974  
    unvisualize();
975  
    cleanUp(this);
976  
    super.delete();
977  
  }
978  
979  
  S sourceCode() {  
980  
    ret javaxSourceOfMyClass1(shortClassName(this));
981  
  }
982  
  
983  
  // for all modules
984  
  void triggerUpdate { rstUpdateModules.trigger(); }
985  
  
986  
  void setModuleIcon(S iconID) {
987  
    if (eq(iconID, this.iconID)) ret;
988  
    this.iconID = iconID;
989  
    internalFrameIcon(vis, iconID);
990  
  }
991  
  
992  
  O resolve() { ret this; }
993  
  O getError() { ret error; }
994  
  S moduleID() { ret str(id); }
995  
  
996  
  void setError(Throwable e) {
997  
    cset(this, error := persistableThrowable(e));
998  
  }
999  
  
1000  
  AutoCloseable enter() { null; }
1001  
  
1002  
  JComponent vis() { ret vis; }
1003  
  
1004  
  static bool needsParameters() { false; }
1005  
  
1006  
  S moduleName() {
1007  
    ret humanizeFormLabel(shortClassName(this));
1008  
  }
1009  
  
1010  
  bool hasFlag(int flag) { ret anyCommonBits(flags, flag); }
1011  
  void setFlag(int flag) { _setField(flags := flags | flag); }
1012  
  void clearFlag(int flag) { _setField(flags := flags & ~flag); }
1013  
  
1014  
  // minimum size of JInternalFrame
1015  
  Pt getMinSize() { null; }
1016  
} // END CONCEPT MODULE
1017  
1018  
static JComponent defaultVisualize(Module m) {
1019  
  ret jCenteredMultiLineLabel(renderConcept(m)); 
1020  
}
1021  
1022  
static <A extends Module> A findModule(Class<A> c) {
1023  
  ret findConcept(c, on := true);
1024  
}
1025  
1026  
// ignores snippet ID, just checks for module (inner) class name
1027  
// returns module ID
1028  
sS findDynModuleOfType(S type) {
1029  
  S suffix = "$" + type;
1030  
  DynamicModule m = firstThat(conceptsWhere DynamicModule(on := true), mod -> endsWith(mod._className, suffix));
1031  
  ret m?.moduleID();
1032  
}
1033  
1034  
sbool moduleTypeIs(Module m, S type) {
1035  
  if (m == null) false;
1036  
  ret endsWith(moduleResolvedClassName(m), "$" + type);
1037  
}
1038  
1039  
sS moduleResolvedClassName(Module m) {
1040  
  if (m == null) null;
1041  
  if (m instanceof DynamicModule)
1042  
    ret m/DynamicModule._className;
1043  
  ret className(m);
1044  
}
1045  
1046  
// returns module ID
1047  
sS findClosestModuleTo(O searcher, S type) {
1048  
  JInternalFrame f = getInternalFrame(dm_getVisualization(searcher));
1049  
  if (f == null) null;
1050  
  Pt p = centerOfRect(toRect(getBounds(f)));
1051  
  new Lowest<S> best;
1052  
  for (Module m : onModules()) {
1053  
    JInternalFrame f2 = getInternalFrame(m.vis);
1054  
    if (f2 == null || f2 == f) continue;
1055  
    if (type != null && !moduleTypeIs(m, type)) continue;
1056  
    Rect r2 = toRect(getBounds(f2));
1057  
    best.put(m.moduleID(), rectPointDistance(r2, p));
1058  
  }
1059  
  ret best!;
1060  
}
1061  
1062  
static <A extends Module> L<A> staticModulesOfType(Class<A> type) {
1063  
  ret asList(conceptsWhere(type, on := true));
1064  
}
1065  
1066  
static <A extends Module> L<A> staticModulesOfExactType(Class<A> type) {
1067  
  ret filterByExactType(type, staticModulesOfType(type));
1068  
}
1069  
1070  
static L listModules() {
1071  
  ret map unwrapDynamicModule(onModules());
1072  
}
1073  
1074  
static int moduleCount() {
1075  
  ret l(onModules());
1076  
}
1077  
1078  
static L visibleModules() {
1079  
  ret map unwrapDynamicModule(objectsWhere(onModules(), visible := true));
1080  
}
1081  
1082  
static O unwrapDynamicModule(Module m) {
1083  
  ret m instanceof DynamicModule ? or(m/DynamicModule.o, m) : m;
1084  
}
1085  
1086  
sbool moduleStillThere(O o) {
1087  
  Module m = o instanceof Module ? o/Module : (Module) get(o, '_host);
1088  
  ret isConceptRegistered(mainConcepts, m);
1089  
}
1090  
1091  
static O getDynModuleByID(S moduleID) {
1092  
  if (moduleID == null) null;
1093  
  ret resolveModule(getConcept(Module, parseLong(moduleID)));
1094  
}
1095  
  
1096  
static Module getModuleByID(S moduleID) {
1097  
  if (moduleID == null) null;
1098  
  ret getConcept(Module, parseLong(moduleID));
1099  
}
1100  
  
1101  
sS getInterestingString {
1102  
  InterestingString m = findModule(InterestingString);
1103  
  ret m == null ? getText(tfTopInput) : m.theString;
1104  
}
1105  
1106  
sS modulesSessionGrab() {
1107  
  grabFrameRects();
1108  
  ret struct(ll(programID(), localDateWithMilliseconds())) + "\n"
1109  
    + mainConcepts.xfullgrab();
1110  
}
1111  
1112  
svoid autoSaveModulesSession() {
1113  
  infoBox("Auto-saving session.");
1114  
  S grab;
1115  
  logQuoted(javaxBackupDir(fsI(programID()) + "/auto-saved-sessions.txt"), grab = modulesSessionGrab());
1116  
  infoBox("Auto-save done (" + l(grab) + " chars)");
1117  
}
1118  
1119  
svoid deleteAllModules() {
1120  
  autoSaveModulesSession();
1121  
  deleteConcepts(Module);
1122  
  initialModules();
1123  
}
1124  
1125  
svoid restoreModulesSession(S text) {
1126  
  autoSaveModulesSession();
1127  
  systemStatus.set("shutting down");
1128  
  infoBox("Releasing session");
1129  
  cleanMeUp();
1130  
  cleanUp(mainConcepts);
1131  
  mainConcepts = null;
1132  
  //sleepSeconds(1);
1133  
  infoBox("Loading session");
1134  
  systemStatus.set("loading");
1135  
  mainConcepts = new Concepts().load(dropFirstLine(text));
1136  
  initAfterDBLoad();
1137  
  infoBox("Session restore done");
1138  
}
1139  
1140  
svoid grabFrameRects {
1141  
  for (Module m : onModules()) m.grabFrameRect();
1142  
}
1143  
1144  
concept DynamicModule extends Module {
1145  
  // moduleID is the snippet ID
1146  
  // "className" is taken by DynamicObject; _className == null for old-style dyn module
1147  
  S moduleID, _className;
1148  
  S oStruct; // serialized dynamic object
1149  
  sbool reload_replaceFrame = true;
1150  
  
1151  
  transient Class c;
1152  
  transient O o;
1153  
  transient bool contentsDirty = true;
1154  
  transient ReliableSingleThread rstPersist = rstWithDelay(persistenceDelayPerModule, r persistContents);
1155  
  transient O reloadData; // data held for module during reload
1156  
1157  
  *() {}
1158  
  *(S *moduleID, S *_className) {}
1159  
  *(S *moduleID, S *_className, Class *c) {}
1160  
  
1161  
  static bool needsParameters() { true; }
1162  
    
1163  
  AutoCloseable enter() {
1164  
    ret castForTemp(callOpt(o, 'enter));
1165  
  }
1166  
1167  
  JComponent visualize() {
1168  
    temp enter();
1169  
    ret (JComponent) callOpt(o, 'visualize);
1170  
  }
1171  
  
1172  
  void enhanceFrame(final JInternalFrame f) {
1173  
    final WeakReference<JInternalFrame> fRef = new(f);
1174  
    final WeakReference<DynamicModule> mRef = new(this);
1175  
    S idText = str(id);
1176  
    
1177  
    if (isTrue(vmGeneralMap_get('iconifyBroken)))
1178  
      internalFrameTitlePopupMenuItem(f, "Hide/Minimize", r { hideModule(mRef!) });
1179  
    
1180  
    idText += "/" + moduleLibID();
1181  
    if (!hideFeature("Show source code"))
1182  
      internalFrameTitlePopupMenuItem(f, "Source code [Module ID: " + idText + "]", r-thread { pcall {
1183  
        if (empty(mRef->moduleID)) ret with infoBox("No source code found");
1184  
        dm_openSnippetInEditor(mRef->moduleID);
1185  
      }});
1186  
    
1187  
    internalFrameTitlePopupMenuItem(f, "Reload", r reload);
1188  
    internalFrameTitlePopupMenuItem(f, "Duplicate", rThread { duplicateModule(DynamicModule.this) });
1189  
    if (!hideFeature("Retranspile"))
1190  
      internalFrameTitlePopupMenuItem(f, "Medium Retranspile", rThread { transpileOnServerWithErrorWindow(moduleID, true, r reload) });
1191  
    if (!hideFeature("Pop Out")) internalFrameTitlePopupMenuItem(f, "Pop Out", r {
1192  
      clearFlag(ALWAYSONTOPWHENPOPPEDOUT);
1193  
      stefansOS_popOutModule(DynamicModule.this);
1194  
    });
1195  
    if (!hideFeature("Pop Out + Always On Top")) internalFrameTitlePopupMenuItem(f, "Pop Out + Always On Top", r {
1196  
      setFlag(ALWAYSONTOPWHENPOPPEDOUT);
1197  
      stefansOS_popOutModule(DynamicModule.this);
1198  
    });
1199  
    
1200  
    internalFrameTitlePopupMenu(f, (IVF1<JPopupMenu>) menu -> {
1201  
      LS sisterModules = dm_sisterModules(this);
1202  
      if (empty(sisterModules)) ret;
1203  
      JMenu subMenu = jmenu("Sister modules");
1204  
      for (S mod : sisterModules)
1205  
        addMenuItem(subMenu, dm_moduleName(mod), rThread { dm_showModule(mod) });
1206  
      menu.add(subMenu);
1207  
    });
1208  
    
1209  
    {
1210  
      temp enter();
1211  
      pcallOpt(o, 'enhanceFrame, f);
1212  
    }
1213  
    internalFrameTitle(f, moduleName());
1214  
  }
1215  
  
1216  
  S moduleLibID() {
1217  
    ret moduleID + "/" + afterLastDollar(_className);
1218  
  }
1219  
  
1220  
  S moduleName() {
1221  
    S name = (S) callOpt(o, 'moduleName);
1222  
    if (nempty(name)) ret name;
1223  
    ret originalModuleName();
1224  
  }
1225  
  
1226  
  S originalModuleName() {
1227  
    S title = snippetTitle_cached(moduleID);
1228  
    //ret dropSuffixICTrimOneOf(title, "[Dyn Module]", "[Dyn Module, OK]", "[Dyn Module, shortened]");
1229  
    ret stefansOS_cleanModuleName(title);
1230  
  }
1231  
  
1232  
  void start() {
1233  
    try {
1234  
      start_impl();
1235  
    } catch e {
1236  
      setError(e);
1237  
      _handleException(e);
1238  
    }
1239  
  }
1240  
  
1241  
  void start_impl {
1242  
    if (moduleID == null) ret;
1243  
    if (c == null)
1244  
      c = startModule_reloading && !startModule_doShare
1245  
        ? hotwireModule(moduleID)
1246  
        : hotwireModule_withSharing(moduleID);
1247  
    replaceACCInClassLoader(c, globalACC);
1248  
    if (oStruct != null) pcall {
1249  
      Map<S, O> renames = cast getOpt(c, '_renameClasses);
1250  
      //print("Class renames: " + sfu(renames));
1251  
      S renamed = migrateClassesInStructureText(oStruct, renames);
1252  
      //print("Renamed: " + renamed);
1253  
      
1254  
      // notify module that we are loading (dev.)
1255  
      /*ThreadLocal tlLoading = cast getOpt(getClass(c, "loadableUtils.utils"), 'dynamicObjectIsLoading);
1256  
      temp tempSetTL(tlLoading, true);*/
1257  
      
1258  
      // load
1259  
      o = unstructureInRealm(renamed, c);
1260  
    }
1261  
    if (o == null)
1262  
      if (_className == null)
1263  
        o = c; // old-style - just a class
1264  
      else {
1265  
        o = nu(getClass_vmName(c, _className)); // new-style (module is an object)
1266  
        if (!stefansOS_checkModuleInstance(o)) { // TODO: doesn't seem to trigger for modules with wrong class name
1267  
          o = null;
1268  
          S msg = this + " failed to load - " + className(o) + " not an instance of DynModule";
1269  
          infoBox(msg);
1270  
          error = persistableThrowable(new RuntimeException(msg));
1271  
          ret;
1272  
        }
1273  
      }
1274  
    setOptAll(o, _host := this, lock := lock);
1275  
    
1276  
    // call module's start() method
1277  
    
1278  
    temp enter();
1279  
1280  
    // this is set when making a module with params
1281  
    callF(startModule_beforeStart, this);
1282  
    
1283  
    // some modules need the reload data before starting
1284  
    if (reloadData != null)
1285  
      callOpt(o, '_setReloadData_early, reloadData);
1286  
1287  
    if (o instanceof Class)
1288  
      callMain(o);
1289  
    else
1290  
      callOpt(o, 'start);
1291  
  }
1292  
  
1293  
  void unvisualize2() { callOpt(o, 'unvisualize); }
1294  
  
1295  
  void update() { callOpt(o, 'update); }
1296  
  
1297  
  // TODO - only when called from DynModule
1298  
  // (works for now, but should be renamed)
1299  
  void _change() {
1300  
    super._change();
1301  
    vmBus_send moduleChanged(this);
1302  
    contentsDirty = true;
1303  
    if (rstPersist != null)
1304  
      rstPersist.trigger();
1305  
  }
1306  
  
1307  
  void persistContents() enter {
1308  
    if (_concepts != null && contentsDirty) {
1309  
      vmBus_send persistingModuleContents(this);
1310  
      contentsDirty = false;
1311  
      //oStruct = null;
1312  
      pcall {
1313  
        if (o != null && !o instanceof Class) {
1314  
          cset(this, oStruct := struct(o));
1315  
          if (printOnPersistContents)
1316  
            print("Persisted contents: " + moduleID + " - " + l(oStruct) + " chars");
1317  
          callOpt(o, 'onPersisted);
1318  
        }
1319  
      }
1320  
    }
1321  
  }
1322  
  
1323  
  void cleanMeUp() {
1324  
    persistContents();
1325  
    if (verboseCleanUp)
1326  
      print("o: " + className(o) + ". Cleaning up main class: " + mainClass(o));
1327  
    if (mainClass(o) == mc()) // anomalous object
1328  
      cleanUp(o);
1329  
    else enter {
1330  
      if (classLoadedInOtherModule(mainClass(o), this)) {
1331  
        print("KEEPING code (loaded in other module)");
1332  
        cleanUp(o);
1333  
      } else
1334  
        cleanUpObjectAndItsMainClass(o);
1335  
    }
1336  
    o = null;
1337  
    c = null;
1338  
  }
1339  
  
1340  
  void reload() {
1341  
    reloadModuleInBackground(this);
1342  
  }
1343  
  
1344  
  // don't call directly - runs in system queue
1345  
  void reload_impl() {
1346  
    temp tempAddToCollection(modulesBeingReloaded, this);
1347  
    
1348  
    if (reloadData == null) {
1349  
      temp enter();
1350  
      reloadData = callOpt(o, '_getReloadData);
1351  
    }
1352  
1353  
    bool poppedOut = stefansOS_moduleIsPoppedOut(this);
1354  
    if (poppedOut) stefansOS_popInModule(this);
1355  
    JInternalFrame frame = getInternalFrame(vis);
1356  
    unvisualize1b();
1357  
    unvisualize2();
1358  
    
1359  
    if (o != null)
1360  
      ghostModules.put(o.getClass(), nu(GhostModule,
1361  
        name := moduleName(),
1362  
        created := created,
1363  
        deleted := now(),
1364  
        instance := new WeakReference(o)));
1365  
1366  
    cleanUp(this); // also sets started to false
1367  
    
1368  
    if (frame != null)
1369  
      setInternalFrameContents(frame,
1370  
        makeReloadingComponent != null
1371  
          ? callF(makeReloadingComponent, this)
1372  
          : makeStandardReloadingComponent(this));
1373  
          
1374  
    visible = false;
1375  
    
1376  
    {
1377  
      temp tempSetMC(startModule_reloading := true);
1378  
      startModule(this);
1379  
    }
1380  
    
1381  
    if (reloadData != null) {
1382  
      temp enter();
1383  
      callOpt(o, '_setReloadData, reloadData);
1384  
      reloadData = null;
1385  
    }
1386  
    
1387  
    if (frame != null) {
1388  
      if (reload_replaceFrame) { // avoids some bugs
1389  
        cset(this, frameRect := toRect(getBounds(frame)));
1390  
        disposeInternalFrame(frame);
1391  
        showModule(this);
1392  
      } else {
1393  
        csetAndStatusChange(this, visible := true);
1394  
        visualizeModule(this);
1395  
        //print("New content: " + vis);
1396  
        setInternalFrameContents(frame, vis);
1397  
      }
1398  
    }
1399  
    
1400  
    if (poppedOut) stefansOS_popOutModule(this);
1401  
1402  
    vmBus_send moduleReloaded(this);
1403  
  }
1404  
  
1405  
  S sourceCode() {  
1406  
    ret loadSnippet(moduleID);
1407  
  }
1408  
  
1409  
  O resolve() { ret o; }
1410  
  O getError() {
1411  
    if (o != null) {
1412  
      O error = callOpt(o, 'getError);
1413  
      if (error != null) ret error;
1414  
    }
1415  
    ret super.getError();
1416  
  }
1417  
  
1418  
  toString {
1419  
    ret "DynModule " + moduleID + "/" + shortenClassName(_className);
1420  
  }
1421  
  
1422  
  void setError(Throwable e) {
1423  
    if (o != null && isTrue(callOpt(o, 'setError, e))) ret;
1424  
    super.setError(e);
1425  
  }
1426  
  
1427  
  Pt getMinSize() {
1428  
    ret shallowCloneToClass Pt(callOpt(o, 'minimumSize));
1429  
  }
1430  
} // END CONCEPT DYNAMICMODULE
1431  
1432  
/*static L resolvedModules() {
1433  
  new L l;
1434  
  for (Module m : onModules())
1435  
    l.add(m.resolve());
1436  
  ret l;
1437  
}*/
1438  
1439  
static S moduleID(Module m) {
1440  
  ret m == null ? null : m.moduleID();
1441  
}
1442  
1443  
static O resolveModule(O m) {
1444  
  ret m instanceof Module ? m/Module.resolve() : m;
1445  
}
1446  
1447  
static S makeModule(Class<? extends Module> moduleClass) {
1448  
  ret makeModule(shortClassName(moduleClass));
1449  
}
1450  
1451  
static S makeModule(S moduleLibID) {
1452  
  ret makeOrShowModule(moduleLibID, false);
1453  
}
1454  
1455  
static S makeOrShowModule(S moduleLibID) {
1456  
  ret makeOrShowModule(moduleLibID, true);
1457  
}
1458  
1459  
sS makeOrShowModule_early(S moduleLibID) {
1460  
  ret makeOrShowModule_early(moduleLibID, true);
1461  
}
1462  
1463  
sS makeOrShowModule(fS moduleLibID, final bool orShow) {
1464  
  ret evalInQ(systemQ, func -> S { // XXX - changed 2019/07/10
1465  
    makeOrShowModule_impl(moduleLibID, orShow)
1466  
  });
1467  
}
1468  
1469  
// add to beginning of system queue
1470  
sS makeOrShowModule_early(fS moduleLibID, bool orShow) {
1471  
  ret evalInQ_first(systemQ, func -> S {
1472  
    makeOrShowModule_impl(moduleLibID, orShow)
1473  
  });
1474  
}
1475  
1476  
sS makeOrShowModule_impl(fS moduleLibID, final bool orShow) {
1477  
  // makes dynamic & static modules
1478  
  
1479  
  if (isIdentifier(moduleLibID))
1480  
    ret moduleID(makeOrShowStaticModuleOfType(moduleLibID, orShow));
1481  
  
1482  
  L<S> l = splitAtSlash(moduleLibID);
1483  
  if (!isSnippetID(first(l)))
1484  
    fail("Unknown module lib ID: " + moduleLibID);
1485  
    
1486  
    
1487  
  // TODO: handle dm_require cycles
1488  
  //if (makingModuleLibIDs.contains(moduleLibID))
1489  
  //temp tempAdd(makingModuleLibIDs, moduleLibID);
1490  
  
1491  
  S snippetID = fsI(first(l)), className = second(l);
1492  
  S classNameSuffix = className == null ? null : "$" + className;
1493  
  DynamicModule m = firstThat(conceptsWhere DynamicModule(on := true, moduleID := snippetID), 
1494  
    mod -> className == null ? mod._className == null : endsWith(mod._className, classNameSuffix));
1495  
  if (m == null) {
1496  
    Class c = hotwireModule_withSharing(snippetID);
1497  
    S fullClassName = c.getName() + classNameSuffix;
1498  
    printVars(+snippetID, +fullClassName, +classNameSuffix, +c);
1499  
    m = cregister( DynamicModule(snippetID, fullClassName, c));
1500  
    print("Made module: " + m.id);
1501  
    vmBus_send('moduleLoaded, m);
1502  
  }
1503  
  if (orShow) showModule(m); else startModule(m);
1504  
  ret moduleID(m);
1505  
}
1506  
1507  
// beforeStart: voidfunc(DynamicModule)
1508  
sS makeNewModule(fS moduleLibID, final bool show, O... _) {
1509  
  temp tempSetMC(startModule_beforeStart := optPar beforeStart(_));
1510  
  ret evalInSystemQ(func -> S {
1511  
    print("Loading module " + moduleLibID);
1512  
    
1513  
    if (isIdentifier(moduleLibID))
1514  
      ret moduleID(makeNewStaticModuleOfType(moduleLibID, show));
1515  
    
1516  
    L<S> l = splitAtSlash(moduleLibID);
1517  
    if (!isSnippetID(first(l)))
1518  
      fail("Unknown module lib ID: " + moduleLibID);
1519  
      
1520  
    S snippetID = first(l), className = second(l);
1521  
1522  
    Class c = hotwireModule_withSharing(snippetID);
1523  
    className = className == null ? null : c.getName() + "$" + className;
1524  
    print(+className);
1525  
    Module m = cregister(DynamicModule(snippetID, className, c));
1526  
    print("Made module: " + m.id);
1527  
    startModule(m);
1528  
    if (show && !stefansOS_shouldStartMinimized(m))
1529  
      showModule(m);
1530  
    ret moduleID(m);
1531  
  });
1532  
}
1533  
1534  
// dynamic only
1535  
sS findModuleByLibID(S moduleLibID) {
1536  
  LS l = splitAtSlash(moduleLibID);
1537  
  if (!isSnippetID(first(l)))
1538  
    fail("Unknown module lib ID: " + moduleLibID);
1539  
    
1540  
  S snippetID = first(l), className = second(l);
1541  
  
1542  
  Cl<DynamicModule> list = findConcepts(DynamicModule, on := true, moduleID := snippetID);
1543  
  S classNameSuffix = className == null ? null : "$" + className;
1544  
  DynamicModule m = firstThat(list, mod -> className == null ? mod._className == null : endsWith(mod._className, classNameSuffix));
1545  
  if (m != null) ret moduleID(m);
1546  
  if (className != null) null;
1547  
  ret moduleID(first(list));
1548  
}
1549  
1550  
static Module makeOrShowStaticModuleOfType(S s) {
1551  
  ret makeOrShowStaticModuleOfType(s, true);
1552  
}
1553  
1554  
static Module makeOrShowStaticModuleOfType(S s, bool orShow) {
1555  
  ret makeOrShowStaticModuleOfType(classForName("main$" + s), orShow);
1556  
}
1557  
  
1558  
static Module makeOrShowStaticModuleOfType(Class<? extends Module> c) {
1559  
  ret makeOrShowStaticModuleOfType(c, true);
1560  
}
1561  
1562  
static Module makeOrShowStaticModuleOfType(Class<? extends Module> c, bool orShow) {
1563  
  final L<? extends Module> l = staticModulesOfExactType(c);
1564  
  Module m = empty(l) ? nu(c) : first(l);
1565  
  if (orShow) showModule(m); else startModule(m);
1566  
  ret m;
1567  
}
1568  
1569  
static Module makeNewStaticModuleOfType(S type, bool show) {
1570  
  Class c = classForName("main$" + type);
1571  
  Module m = cast nu(c);
1572  
  if (show) showModule(m); else startModule(m);
1573  
  ret m;
1574  
}
1575  
1576  
//!include once #1016217 // Sticky Libs
1577  
!include once #1020744 // Sticky Libs & Src Libs
1578  
1579  
static Class hotwireModule(S snippetID) {
1580  
  hotwire_autoStickyLibs();
1581  
  ret hotwire(snippetID, lambda1 mainClassNameForClassLoader);
1582  
}
1583  
1584  
static Class hotwireModule_withSharing(S snippetID) {
1585  
  Class c = null;
1586  
  if (useCodeSharing) {
1587  
    c = findLoadedCodeBySnippetID(snippetID);
1588  
    if (c != null)
1589  
      print("SHARING code for " + snippetID);
1590  
  }
1591  
  if (c == null)
1592  
    c = hotwireModule(snippetID);
1593  
  ret c;
1594  
}
1595  
1596  
// Make modules print with their module ID
1597  
1598  
set flag hotwire_copyOver_extend.
1599  
svoid hotwire_copyOver_extend(Class c) {
1600  
  S progID = getProgramID(c);
1601  
  if (nempty(progID) && fieldType(c, 'print_log) == Appendable.class)
1602  
    setOpt(c, 'print_log, makeSubModulePrint(c, progID));
1603  
}
1604  
1605  
static swappable _SubModulePrint makeSubModulePrint(Class c, S progID) {
1606  
  _SubModulePrint p = new("[" + progID + "] ");
1607  
  p.makePrefix = () ->
1608  
    showTimeInPrintLog ? "[" + progID + " " + timeWithMilliseconds() + "] " : p.prefix;
1609  
  ret p;
1610  
}
1611  
1612  
sbool isLoading() {
1613  
  ret eq(systemStatus!, "loading");
1614  
}
1615  
1616  
sbool isShuttingDown() {
1617  
  ret eq(systemStatus!, "shutting down");
1618  
}
1619  
1620  
svoid doInGlobalContext(final Runnable r) {
1621  
  final new Flag flag;
1622  
  systemQ.add(r {
1623  
    callF(r);
1624  
    flag.raise();
1625  
  });
1626  
  flag.waitUntilUp();
1627  
}
1628  
1629  
!include once #1015842 // SavedSessions
1630  
!include once #1015885 // Standard Modules
1631  
!include once #1015959 // More Standard Modules
1632  
1633  
please include function renderConcept.
1634  
please include function restart.
1635  
1636  
svoid setLookAndFeel() {
1637  
  if (cic(mainArgs, "-nolaf")) ret;
1638  
  new Matches m;
1639  
  S laf = or2(getLAF(), main.laf);
1640  
  if (isSnippetID(laf))
1641  
    runDependent(laf);
1642  
  else if (eq(laf, 'webLAF))
1643  
    installWebLAF();
1644  
  else if (eq(laf, 'nimbus))
1645  
    nimbus();
1646  
  else if (eq(laf, 'jtattoo))
1647  
    jtattoo_mcWin();
1648  
  else if (eq(laf, 'platform))
1649  
    systemLAF();
1650  
  else if (eq(laf, 'substance))
1651  
    call(hotwire(#1025722), 'substance);
1652  
  else if (startsWith_trim(laf, "substance ", m))
1653  
    call(hotwire(#1025722), 'substance, $1);
1654  
  else
1655  
    print("Unknown LAF: " + laf);
1656  
    
1657  
  pcall {
1658  
    S scale = trim(loadTextFile(javaxDataDir("os-font-scale.txt")));
1659  
    if (nempty(scale))
1660  
      swingFontScale(parseDouble(scale));
1661  
  }
1662  
}
1663  
1664  
please include function myTranspilationDate.
1665  
1666  
// should happen in swing thread
1667  
svoid setActiveModule(Module m) {
1668  
  if (activeModule != m) {
1669  
    activeModule = m;
1670  
    vmBus_send('newActiveModule, m);
1671  
  }
1672  
}
1673  
1674  
static O unwrappedActiveModule() {
1675  
  ret unwrapDynamicModule(activeModule);
1676  
}
1677  
1678  
concept TopInput {
1679  
  S text;
1680  
  bool quickSearchesEnabled = true;
1681  
}
1682  
1683  
concept LAF {
1684  
  S laf; // 'platform etc. or module ID
1685  
}
1686  
1687  
svoid nohupJavax(S javaxArgs) {
1688  
  nohupJavax(javaxArgs, javaxDefaultVMArgs());
1689  
}
1690  
1691  
sbool cleanedUp;
1692  
1693  
svoid nohupJavax(S javaxArgs, S vmArgs) {
1694  
  if (desktop != null && !cleanedUp) pcall { fullScreenOff(); }
1695  
  directNohupJavax(javaxArgs, vmArgs);
1696  
}
1697  
1698  
sbool isDevVersion() {
1699  
  ret neq(programID(), #1016478);
1700  
}
1701  
1702  
svoid startOtherVersion {
1703  
  nohupJavax(isDevVersion() ? #1016478 : #1024932);
1704  
}
1705  
1706  
sS otherVersionName() {
1707  
  ret isDevVersion() ? "v6" : "v7";
1708  
}
1709  
1710  
sS restoreModule(S structure) {
1711  
  if (structure == null) null;
1712  
  
1713  
  print(shorten(500, structure));
1714  
  
1715  
  O mod = safeUnstructure(structure);
1716  
  if (mod instanceof Map)
1717  
    mod = get((Map) mod, 'module);
1718  
    
1719  
  S shortName = dynShortName(mod);
1720  
  if (!eq(shortName, "DynamicModule"))
1721  
    fail("Can't restore static modules yet [" + shortName + "]");
1722  
    
1723  
  S snippetID = getString(mod, "moduleID");
1724  
  S className = getString(mod, "_className");
1725  
  
1726  
  print("Restoring " + snippetID + "/" + className);
1727  
  
1728  
  Class c = hotwireModule_withSharing(snippetID);
1729  
  DynamicModule m = cregister(DynamicModule(snippetID, className, c));
1730  
  copyFields(mod, m, 'iconID);
1731  
  m.frameRect = (Rect) restruct(getOpt(m, 'frameRect));
1732  
  m.oStruct = getString(mod, "oStruct");
1733  
  showModule(m);
1734  
  ret moduleID(m);
1735  
}
1736  
1737  
sS moduleStructForDuplication(DynamicModule m) {
1738  
  if (m == null) null;
1739  
  m.persistContents();
1740  
  S struct = struct(m);
1741  
  fO resolved = resolveModule(m);
1742  
  
1743  
  if (hasMethod(resolved, '_modifyStructForDuplication, struct))
1744  
    struct = jreplace_first_dyn(struct, "oStruct=*", func(LS tok, int i) -> S {
1745  
      S s = unquote(tok.get(i+4));
1746  
      s = callOpt(resolved, '_modifyStructForDuplication, s);
1747  
      if (s == null) fail("Module does not want to be duplicated");
1748  
      ret "oStruct=" + quote(s);
1749  
    });
1750  
    
1751  
  ret struct;
1752  
}
1753  
1754  
sS duplicateModule(DynamicModule m) {
1755  
  ret restoreModule(moduleStructForDuplication(m));
1756  
}
1757  
1758  
static O dm_current_mandatory() { fail(); }
1759  
1760  
// for modules
1761  
please include function mechList_opt_raw.
1762  
please include function mechList_clearCache.
1763  
please include function mechLists_clearCache.
1764  
1765  
// This is only answered from localhost
1766  
answer {
1767  
  if "is stefan's os" ret "yes";
1768  
  
1769  
  if "show module * with params *" {
1770  
    ret dm_showModuleWithParams(unstructString($1), unstructObjectArray($2));
1771  
  }
1772  
  
1773  
  if (swic(s, "restore module:", m))
1774  
    ret ok2(restoreModule(m.rest()));
1775  
1776  
  if "swing latency" { ret str(swingLatency()); }
1777  
  
1778  
  if "activate frames" {
1779  
    awt { activateMyFrames(); }
1780  
    ret "OK";
1781  
  }
1782  
  
1783  
  if "program id" ret programID();
1784  
  if "main program id" ret mainProgramID();
1785  
  
1786  
  if "enable remote control from *" {
1787  
    O mod = getDynModuleByID(makeOrShowModule("#1017127/RemoteControlled"));
1788  
    call(mod, 'setFields, new O[] {new O[] {controllingComputers := $1, enabled := true}});
1789  
    ret "OK";
1790  
  }
1791  
  
1792  
  if "stack traces"
1793  
    ret renderAllThreadsWithStackTraces();
1794  
}
1795  
1796  
srecord Service(O module, O worker) {}
1797  
1798  
static new MultiMap<S, Service> registeredServices;
1799  
1800  
static bool callService(S name, O... args) {
1801  
  for (Service service : cloneList(registeredServices.get(name)))
1802  
    if (isTrue(pcallF(service.worker, name, args))) true;
1803  
  false;
1804  
}
1805  
1806  
static void registerService(O module, S name, O service) {
1807  
  registeredServices.put(name, Service(module, service));
1808  
}
1809  
1810  
static void unregisterService(O module, S name, O service) {
1811  
  registeredServices.remove(name, Service(module, service));
1812  
}
1813  
1814  
static O dm_os() { ret main.class; }
1815  
1816  
please include function robot_keyPress.
1817  
please include function robot_keyRelease.
1818  
please include function robot_safetyKeyReleaser.
1819  
1820  
svoid showCurrentModuleMenu {
1821  
  swing {
1822  
    showInternalFramePopupMenu(desktop.getSelectedFrame());
1823  
  }
1824  
}
1825  
1826  
svoid inSystemQ(Runnable r) {
1827  
  systemQ.add(r);
1828  
}
1829  
1830  
svoid reloadModuleInBackground(final DynamicModule m) {
1831  
  if (m == null) ret;
1832  
  vmBus_send reloadingModule(m);
1833  
  inSystemQ(r { m.reload_impl() });
1834  
}
1835  
1836  
svoid deleteModuleInBackground(final DynamicModule m) {
1837  
  if (m == null) ret;
1838  
  inSystemQ(r { deleteModule(m) });
1839  
}
1840  
1841  
svoid restart {
1842  
  if (restarter_override != null)
1843  
    ret with callF(restarter_override);
1844  
  restartWithDefaultVMArgs();
1845  
  sleep();
1846  
}
1847  
1848  
static Component makeStandardReloadingComponent(Module m) {
1849  
  ret jcenteredlabel("Reloading...");
1850  
}
1851  
1852  
sbool classLoadedInOtherModule(Class mainClass, Module mod) {
1853  
  for (DynamicModule m)
1854  
    if (m != mod && mainClass(m.o) == mainClass)
1855  
      true;
1856  
  false;
1857  
}
1858  
1859  
static Class findLoadedCodeBySnippetID(S snippetID) {
1860  
  for (Module m : onModules())
1861  
    if (m cast DynamicModule)
1862  
      if (sameSnippetID(m.moduleID, snippetID) && m.c != null)
1863  
        ret m.c;
1864  
  null;
1865  
}
1866  
1867  
svoid cleanKill {
1868  
  setOpt(javax(), cleanKill_verbose := true);
1869  
  cleanKillVM();
1870  
}
1871  
1872  
sS moduleIDAndName(Module m) {
1873  
  ret m == null ? "-" : m.id + " - " + rcall_pcall moduleName(m);
1874  
}
1875  
1876  
sbool hideFeature(S name) {
1877  
  ret contains(hideFeatures, name);
1878  
}
1879  
1880  
sS featureMenuItem(S name) {
1881  
  ret featureMenuItem(name, name);
1882  
}
1883  
1884  
sS featureMenuItem(S feature, S name) {
1885  
  ret hideFeature(feature) ? null : name;
1886  
}
1887  
1888  
sS osName() { ret or2(osName, "Stefan's OS " + version()); }
1889  
1890  
sS version() { ret ai_versionFromName(programName()); }
1891  
1892  
static IF0<Bool> standardOSExitConfirm() {
1893  
  ret () -> confirmOKCancel("Really exit " + osName() + "?");
1894  
}
1895  
1896  
svoid setLAF(S laf) {
1897  
  cset(uniq(LAF), +laf);
1898  
}
1899  
1900  
sS getLAF() {
1901  
  ret getString laf(conceptWhere(LAF));
1902  
}
1903  
1904  
static TopInput topInputConcept() {
1905  
  ret uniq(TopInput);
1906  
}
1907  
1908  
sbool quickSearchesEnabled() {
1909  
  ret topInputConcept().quickSearchesEnabled;
1910  
}
1911  
1912  
svoid useLastSessionBackup {
1913  
  restoreNextToLastConceptsBackup(dbProgramID());
1914  
  restart();
1915  
}
1916  
1917  
static Settings settings() { ret uniq(Settings); }
1918  
1919  
concept Settings {
1920  
  S backgroundMode = "fit";
1921  
  Color backgroundColor = Color.white;
1922  
}
1923  
1924  
svoid setBackgroundMode(S backgroundMode) { cset(settings(), +backgroundMode); }
1925  
svoid setBackgroundColor(Color backgroundColor) { cset(settings(), +backgroundColor); }

Author comment

Began life as a copy of #1016478

download  show line numbers  debug dex  old transpilations   

Travelled to 34 computer(s): abdkfuuuzlrh, aijbjpqedjjc, axwnutwaxmlh, bhatertpkbcr, dbzfplsxganw, ekrmjmnbrukm, hhusmcjygydo, ilgbwaciyqrp, ishqpsrjomds, jcllbfdqhrgy, kanivhkedcyu, ktbwgngfmivo, lastaxpxduqo, lqnftawlhpir, mplzucoataeu, mqqgnosmbjvj, ofpaelxlmzfo, omdjrrnzbjjv, onxytkatvevr, preudubyouod, pyentgdyhuwx, pzhvpgtvlbxg, qgvkllrfbgaw, skddmizpvtmy, snaazhdonpnp, tvejysmllsmz, unoaxrwscvea, vdksuejmluqn, vouqrxazstgt, vtpnfdczhzww, whxojlpjdney, xjedlqssgqex, xrpafgyirdlv, zmkyvqxnmjhp

No comments. add comment

Snippet ID: #1024932
Snippet name: Stefan's OS v7 [LIVE]
Eternal ID of this version: #1024932/136
Text MD5: 316f7bf06c6db03ed1d07aa09cd98044
Transpilation MD5: 4db045550823da2f8771296aec282996
Author: stefan
Category: javax / stefan's os
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-06-14 03:29:11
Source code size: 58654 bytes / 1925 lines
Pitched / IR pitched: No / No
Views / Downloads: 770 / 36345
Version history: 135 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1024932 & http://1024932.tinybrain.de