MCPcopy Create free account
hub / github.com/HumbleUI/JWM / App

Class App

shared/java/App.java:12–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10import io.github.humbleui.jwm.impl.*;
11
12public class App {
13 @ApiStatus.Internal
14 public static List<Window> _windows = Collections.synchronizedList(new ArrayList<Window>());
15 @ApiStatus.Internal
16 public static long _uiThreadId;
17
18 /**
19 * <p>Start the JWM application, blocking until completion.</p>
20 * <p>User init should be handled inside the `launcher` callback (on the main thread).</p>
21 *
22 * <p>This method must be the first method called in the JWM library.</p>
23 * <p>After this method call, library API can be safely accessed for creating windows and querying system info.</p>
24 */
25 public static void start(@NotNull Runnable launcher) {
26 Library.load();
27 ClassLoader cl = Thread.currentThread().getContextClassLoader();
28 _nStart(() -> {
29 Thread t = Thread.currentThread();
30 t.setContextClassLoader(cl);
31 _uiThreadId = t.getId();
32 Log.setVerbose("true".equals(System.getenv("JWM_VERBOSE")));
33 long t0 = System.currentTimeMillis();
34 Log.setLogger((s) -> System.out.println("[ " + (System.currentTimeMillis() - t0) + " ] " + s));
35 launcher.run();
36 });
37 }
38
39 /**
40 * <p>Make new native platform-specific window.</p>
41 * <p>Note: must be called only after or inside {@link #start(Runnable)} successful method call.</p>
42 *
43 * @return new window instance
44 */
45 @NotNull @SneakyThrows
46 public static Window makeWindow() {
47 assert _onUIThread() : "Should be run on UI thread";
48 Window window;
49 if (Platform.CURRENT == Platform.WINDOWS)
50 window = new WindowWin32();
51 else if (Platform.CURRENT == Platform.MACOS)
52 window = new WindowMac();
53 else if (Platform.CURRENT == Platform.X11)
54 window = new WindowX11();
55 else
56 throw new RuntimeException("Unsupported platform: " + Platform.CURRENT);
57 _windows.add(window);
58 return window;
59 }
60
61 /**
62 * <p>Request application terminate.</p>
63 * <p>Note: must be called only after or inside {@link #start(Runnable)} successful method call.</p>
64 */
65 public static void terminate() {
66 assert _onUIThread() : "Should be run on UI thread";
67 _nTerminate();
68 }
69

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected