MCPcopy Index your code
hub / github.com/benfry/processing4 / ThinkDifferent

Class ThinkDifferent

core/src/processing/core/ThinkDifferent.java:44–158  ·  view source on GitHub ↗

Deal with issues related to macOS application behavior. We have to register a quit handler to safely shut down the sketch, otherwise OS X will just kill the sketch when a user hits Cmd-Q. In addition, we have a method to set the dock icon image, so we look more like a native application. This is a

Source from the content-addressed store, hash-verified

42 * <a href="https://github.com/processing/processing/issues/3301">3301</a>.
43 */
44public class ThinkDifferent {
45 static private Desktop desktop;
46 static private Taskbar taskbar;
47
48 // True if user has tried to quit once. Prevents us from canceling the quit
49 // call if the sketch is held up for some reason, like an exception that's
50 // managed to put the sketch in a bad state.
51 static boolean attemptedQuit;
52
53
54 /**
55 * Initialize the sketch with the quit handler.
56 *
57 * Initialize the sketch with the quit handler such that, if there is no known
58 * crash, the application will not exit on its own if this is the first quit
59 * attempt.
60 *
61 * @param sketch The sketch whose quit handler callback should be set.
62 */
63 static public void init(final PApplet sketch) {
64 getDesktop().setQuitHandler((event, quitResponse) -> {
65 sketch.exit();
66
67 boolean noKnownCrash = PApplet.uncaughtThrowable == null;
68
69 if (noKnownCrash && !attemptedQuit) { // haven't tried yet
70 quitResponse.cancelQuit(); // tell OS X we'll handle this
71 attemptedQuit = true;
72 } else {
73 quitResponse.performQuit(); // just force it this time
74 }
75 });
76 }
77
78
79 /**
80 * Remove the quit handler.
81 */
82 static public void cleanup() {
83 getDesktop().setQuitHandler(null);
84 }
85
86
87 /**
88 * Called via reflection from PSurfaceAWT and others, set the dock icon image.
89 * @param image The image to provide for Processing icon.
90 */
91 static public void setIconImage(Image image) {
92 getTaskbar().setIconImage(image);
93 }
94
95
96 /**
97 * Get the taskbar where OS visual settings can be provided.
98 * @return Cached taskbar singleton instance.
99 */
100 static private Taskbar getTaskbar() {
101 if (taskbar == null) {

Callers

nothing calls this directly

Calls 6

saveStreamMethod · 0.95
createTempFileMethod · 0.80
deleteMethod · 0.45
loadMethod · 0.45
printlnMethod · 0.45
printStackTraceMethod · 0.45

Tested by

no test coverage detected