Set macos quitStrategy to CLOSE_ALL_WINDOWS

The quit strategy API existed in com.apple.eawt prior to Java 9, and was moved
into java.desktop in 9. This move makes our orange-extensions API incompatiable
with the 9 eawt package too, so we can not use Application.setQuitStrategy on
9+ either, without making orange-extensions multi-release too.

Since Desktop.setQuitStrategy is the new standard way of doing this, use it if
available, and otherwise use the Java 8 Application.setQuitStrategy instead.
This commit is contained in:
Adam
2022-01-01 17:52:39 -05:00
parent cb8788c38f
commit 31dc32c225
3 changed files with 91 additions and 0 deletions

View File

@@ -332,6 +332,12 @@ public class ClientUI
frame.setResizable(true);
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
if (OSType.getOSType() == OSType.MacOS)
{
// Change the default quit strategy to CLOSE_ALL_WINDOWS so that ctrl+q
// triggers the listener below instead of exiting.
MacOSQuitStrategy.setup();
}
frame.addWindowListener(new WindowAdapter()
{
@Override

View File

@@ -0,0 +1,48 @@
/*
* Copyright (c) 2022, Adam <Adam@sigterm.info>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.ui;
import com.apple.eawt.Application;
import com.apple.eawt.QuitStrategy;
class MacOSQuitStrategy
{
public static void setup()
{
try
{
// com.apple.eawt.QuitStrategy was moved to java.desktop in Java 9,
// but our OrangeExtensions API targets 1.6, so this code is only valid
// on 8 below.
Application.getApplication()
.setQuitStrategy(QuitStrategy.CLOSE_ALL_WINDOWS);
}
catch (NoClassDefFoundError ex)
{
// IntelliJ doesn't handle our multi-release Maven setup well, and will run
// this class on 11+. Ignore the error so the client can launch.
}
}
}

View File

@@ -0,0 +1,37 @@
/*
* Copyright (c) 2022, Adam <Adam@sigterm.info>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.ui;
import java.awt.Desktop;
import java.awt.desktop.QuitStrategy;
class MacOSQuitStrategy
{
public static void setup()
{
Desktop.getDesktop()
.setQuitStrategy(QuitStrategy.CLOSE_ALL_WINDOWS);
}
}