1 | lib 1400521 // FlatLAF |
2 | |
3 | set flag PingV3. |
4 | set flag NotifyingPrintLog. |
5 | set flag SymbolAsString. |
6 | |
7 | // Do the JavaX init |
8 | svoid standaloneInit {
|
9 | __javax = x30.class; |
10 | x30.__javax = x30.class; // for hotwire |
11 | x30_pkg.x30_util.__setJavaX(x30.class); |
12 | x30.cleanKillMsg = ""; |
13 | callOnLoadMethods(mc()); |
14 | } |
15 | |
16 | concept Stem {
|
17 | DynModule module; |
18 | Rect frameRect; |
19 | bool alwaysOnTop, autoUpdate; |
20 | |
21 | transient JFrame window; |
22 | |
23 | Rect getFrameRect() {
|
24 | ret toRect(getBounds(window)); |
25 | } |
26 | |
27 | void saveFrameRect {
|
28 | setField(frameRect := getFrameRect()); |
29 | } |
30 | |
31 | void setAlwaysOnTop(bool alwaysOnTop) {
|
32 | this.alwaysOnTop = alwaysOnTop; |
33 | change(); |
34 | alwaysOnTop(window, alwaysOnTop); |
35 | } |
36 | |
37 | void setWindow(JFrame window) {
|
38 | this.window = window; |
39 | if (frameRect != null) |
40 | setBounds(window, frameRect); |
41 | onWindowClosing(window, r cleanExit); |
42 | onBoundsChange(window, r saveFrameRect); |
43 | alwaysOnTop(window, alwaysOnTop); |
44 | } |
45 | } |
46 | |
47 | transient sclass GazelleHost {
|
48 | Stem stem; |
49 | DynModule gazelle; |
50 | |
51 | transient S windowTitle = "November Gazelle v1"; |
52 | transient S downloadURL = "https://botcompany.de/jar/" |
53 | + psI(programID()) + "?withLibs=1&noCompiler=1"; |
54 | transient S trayIconImageID = #1103047; |
55 | transient int borderSize = 5; |
56 | transient Color color1 = awtColor("ADD8E6");
|
57 | transient Color color2 = awtColor("EEEEEE");
|
58 | transient Color color3 = awtColor("A3C0AA");
|
59 | transient IF0<DynModule> moduleMaker; |
60 | transient ThreadPool threadPool; |
61 | |
62 | transient TrayIcon trayIcon; |
63 | transient JFrame mainWindow; |
64 | transient Set<S> argsSet; |
65 | |
66 | transient Concepts concepts; |
67 | |
68 | *(ThreadPool *threadPool, IF0<DynModule> *moduleMaker) {}
|
69 | |
70 | void trayIconLeftClick {
|
71 | activateFrame_v3(mainWindow); |
72 | } |
73 | |
74 | void makeTrayIcon {
|
75 | pcall-short {
|
76 | trayIcon_imageAutoSize = false; |
77 | trayIcon = installTrayIcon(trayIconImageID, windowTitle, |
78 | r trayIconLeftClick, |
79 | "Show Gazelle", r { activateFrame(mainWindow) },
|
80 | "Exit Gazelle", r cleanExit |
81 | ); |
82 | } |
83 | } |
84 | |
85 | void run(S[] args) {
|
86 | argsSet = asSet(args); |
87 | |
88 | if (!argsSet.contains("noflatlaf"))
|
89 | com.formdev.flatlaf.FlatLightLaf.setup(); |
90 | |
91 | if (contains(args, "profile")) |
92 | profileToConsole(() -> actualMain(args)); |
93 | else |
94 | actualMain(args); |
95 | |
96 | if (argsSet.contains("brexit")) System.exit(0);
|
97 | } |
98 | |
99 | void actualMain(S... args) {
|
100 | vm_generalMap_put(stefansOS := this); |
101 | |
102 | System.out.println(hmsWithColonsAndMS() + ": Init"); |
103 | //x30.coreInit(); |
104 | |
105 | // Ready to roll |
106 | |
107 | if (containsOneOf(argsSet, "upgrade", "update")) |
108 | ret with upgradeGazelle(); |
109 | |
110 | makeTrayIcon(); |
111 | |
112 | initAutoUpdate(); |
113 | |
114 | // Test classFinder sanity |
115 | |
116 | set flag defaultDefaultClassFinder_debug. |
117 | assertEquals(callF(_defaultClassFinder(), "main$Stem"), Stem.class); |
118 | |
119 | // Start DB |
120 | |
121 | concepts = newConceptsWithClassFinder(programID); |
122 | concepts.fileLock().lockOrFail(); |
123 | concepts.fileLock().deleteOnExit(); |
124 | concepts.persist(); |
125 | |
126 | print("Concepts loaded: " + map className(allConcepts(concepts));
|
127 | |
128 | var stems = findConcepts(concepts, Stem); |
129 | print("Stems in DB: " + l(stems));
|
130 | stem = first(stems); |
131 | if (stem == null) {
|
132 | print("Starting new module");
|
133 | stem = registerConcept(concepts, new Stem); |
134 | makeModule(); |
135 | cset(stem, module := gazelle); |
136 | } else {
|
137 | gazelle = stem.module; |
138 | print("Depersisted module " + gazelle);
|
139 | } |
140 | |
141 | gazelle._host = stem; |
142 | setOpt_raw(gazelle, +threadPool); // only if the field exists |
143 | copyLocalLog(gazelle, mc()); |
144 | |
145 | JComponent vis; |
146 | {
|
147 | temp gazelle.enter(); |
148 | gazelle.start(); |
149 | |
150 | printWithMS("Visualize");
|
151 | vis = swing(-> {
|
152 | temp gazelle.enter(); |
153 | ret gazelle.visualize(); |
154 | }); |
155 | } |
156 | |
157 | vis = makeWindowBorderAndTitle(vis, windowTitle); |
158 | printWithMS("Show frame");
|
159 | //stem.window = showMainFrame("Gazella", vis);
|
160 | JFrame frame = makeUndecoratedFrame(windowTitle, vis); |
161 | setFrameIcon(frame, trayIconImageID); |
162 | stem.setWindow(mainWindow = frame); |
163 | showWindow(stem.window); |
164 | printWithMS("Dudadoneski");
|
165 | } |
166 | |
167 | void minimize {
|
168 | if (trayIcon == null) |
169 | minimizeWindow(mainWindow); |
170 | else |
171 | hideWindow(mainWindow); |
172 | } |
173 | |
174 | JComponent makeWindowBorderAndTitle(JComponent contents, S title) {
|
175 | //ret jCenteredSection_fontSizePlus(10, title, vis); |
176 | |
177 | var icons = jline(); |
178 | icons.add(jbutton("Minimize", r minimize));
|
179 | icons.add(jbutton("Close", r cleanExit /*{ disposeWindow(icons) }*/));
|
180 | icons.add(jPopDownButton_noText( |
181 | "Update Gazelle", rThread upgradeGazelle, |
182 | "Restart Gazelle", rThread restart, |
183 | jCheckBoxMenuItem_dyn("Auto-Update",
|
184 | -> stem.autoUpdate, |
185 | b -> cset(stem, autoUpdate := b)), |
186 | "Dump threads", rThread { showText("User threads", renderUserThreadsWithStackTraces()); },
|
187 | jCheckBoxMenuItem_dyn("Always on top",
|
188 | -> stem.alwaysOnTop, |
189 | alwaysOnTop -> stem.setAlwaysOnTop(alwaysOnTop)) |
190 | )); |
191 | |
192 | var actualTitle = fontSizePlus(7, jCenteredLabel(title)); |
193 | var spacer = gazelle_wavySpacer(); |
194 | var titleBarMain = setOpaqueBackground(color1, |
195 | westCenterAndEastWithMargin( |
196 | jImage_scaledToHeight(24, trayIconImageID), |
197 | actualTitle, |
198 | setOpaqueBackground(color2, spacer)); |
199 | |
200 | installWindowDragger(actualTitle); |
201 | installWindowDragger(spacer); |
202 | |
203 | var titleBar = setBackground(color2, centerAndEast( |
204 | titleBarMain, |
205 | icons)); |
206 | |
207 | var border = |
208 | // createBevelBorder(); |
209 | BorderFactory.createLineBorder(color1, borderSize); |
210 | |
211 | var outerPanel = withBorder(border, |
212 | northAndCenter(titleBar, contents)); |
213 | |
214 | installWindowResizeDraggerOnBorder(outerPanel); |
215 | ret outerPanel; |
216 | } |
217 | |
218 | O dm_getStem(O moduleOrID) {
|
219 | ret stem; |
220 | } |
221 | |
222 | O resolveModule(O moduleOrID) { ret moduleOrID == stem ? gazelle : moduleOrID; }
|
223 | |
224 | void cleanExit {
|
225 | thread {
|
226 | print("Saving DB for exit");
|
227 | dispose concepts; |
228 | System.exit(0); |
229 | } |
230 | } |
231 | |
232 | File myJar() { ret getBytecodePathForClass(this); }
|
233 | |
234 | void upgradeGazelle {
|
235 | File myJar = myJar(); |
236 | print(+myJar); |
237 | |
238 | S date = ymdMinusHMS(); |
239 | File f = javaxCodeDir("Downloaded Updates/" + "gazelle-" + date + ".jar");
|
240 | infoBox("Downloading Update...");
|
241 | loadBinaryPageToFile(downloadURL, f); |
242 | printFileInfo(f); |
243 | if (!isNonEmptySingleZip_byMagicHeader(f)) |
244 | ret with infoBox("Bad file downloaded... :(");
|
245 | |
246 | bool replaced; |
247 | if (isFile(myJar)) {
|
248 | print("Loaded " + nClasses(loadAllClassesInByteCodePath(myJar)));
|
249 | print("Replacing with new version: " + myJar);
|
250 | renameFile(myJar, appendToBaseName(myJar, ".bak." + date)); |
251 | copyFile(f, myJar); |
252 | printFileInfo(myJar); |
253 | set replaced; |
254 | } |
255 | |
256 | infoBox(replaced |
257 | ? "Installed update, replaced " + f2s(myJar) + " - now starting" |
258 | : "Starting update, but could not replace originally downloaded jar"); |
259 | |
260 | restart(replaced ? myJar : f); |
261 | } |
262 | |
263 | void restart(File jar default myJar()) {
|
264 | S javaCmd = or2(currentProcessCommand(), "java"); |
265 | S cmd = pqO(javaCmd) + " -jar " + pqO(jar); |
266 | print(cmd); |
267 | nohup(cmd); |
268 | cleanExit(); |
269 | } |
270 | |
271 | void makeModule() {
|
272 | if (gazelle == null) |
273 | gazelle = callF(moduleMaker); |
274 | } |
275 | |
276 | void reloadModuleInBackground(Stem mod) {
|
277 | restart(); |
278 | } |
279 | |
280 | void initAutoUpdate {
|
281 | print("Making SnippetUpdateConnector.");
|
282 | snippetUpdateConnector(verbose := true); |
283 | |
284 | vmBus_onMessage snippetUpdate(voidfunc(L l) {
|
285 | S uri = getString(l, 1); |
286 | new Matches m; |
287 | if (swic(uri, "/transpileOK/", m)) |
288 | if (sameSnippetID(programID(), firstIntAsString(m.rest()))) {
|
289 | if (stem.autoUpdate) |
290 | upgradeGazelle(); |
291 | //infoBox("Gazelle can be updated!");
|
292 | } |
293 | }); |
294 | } |
295 | } |
Began life as a copy of #1033540
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
| Snippet ID: | #1033707 |
| Snippet name: | GazelleHost backup |
| Eternal ID of this version: | #1033707/1 |
| Text MD5: | 024a97f7632b295fc466643939d02a9d |
| Author: | stefan |
| Category: | javax / gazelle v |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2021-12-28 18:02:18 |
| Source code size: | 8175 bytes / 295 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 369 / 377 |
| Referenced in: | [show references] |