Browse Source

REPORT-29118 && REPORT-29117

feature/big-screen
hades 5 years ago
parent
commit
6963b99dae
  1. 49
      designer-base/src/main/java/com/fr/design/os/impl/MacOsAddListenerAction.java
  2. 6
      designer-realize/src/main/java/com/fr/start/module/DesignerStartup.java

49
designer-base/src/main/java/com/fr/design/os/impl/MacOsAddListenerAction.java

@ -1,7 +1,10 @@
package com.fr.design.os.impl;
import com.fr.design.actions.help.AboutDialog;
import com.fr.design.actions.help.AboutPane;
import com.fr.design.mainframe.DesignerContext;
import com.fr.exit.DesignerExiter;
import com.fr.general.ComparatorUtils;
import com.fr.invoke.Reflect;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.os.support.OSBasedAction;
@ -21,25 +24,55 @@ public class MacOsAddListenerAction implements OSBasedAction {
public void execute(final Object... objects) {
try {
Class app = Class.forName("com.apple.eawt.Application");
Class handler = Class.forName("com.apple.eawt.QuitHandler");
Object instance = Proxy.newProxyInstance(handler.getClassLoader(), new Class[]{handler},
Class quitHandler = Class.forName("com.apple.eawt.QuitHandler");
Object quitInstance = getProxy(quitHandler, "handleQuitRequestWith", new QuitAction());
Class aboutHandler = Class.forName("com.apple.eawt.AboutHandler");
Object aboutInstance = getProxy(aboutHandler, "", new AboutAction());
Reflect.on(Reflect.on(app).call("getApplication").get()).call("setQuitHandler", quitInstance)
.call("setAboutHandler", aboutInstance);
} catch (ClassNotFoundException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
private Object getProxy(Class clazz, final String methodName, final Action action) {
return Proxy.newProxyInstance(clazz.getClassLoader(), new Class[]{clazz},
new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method,
Object[] args) throws Throwable {
if ("handleQuitRequestWith".equals(method.getName())) {
if (ComparatorUtils.equals(methodName, method.getName())) {
action.execute();
}
return null;
}
});
}
interface Action {
void execute();
}
private class QuitAction implements Action {
@Override
public void execute() {
if (DesignerContext.getDesignerFrame() != null && DesignerContext.getDesignerFrame().isShowing()) {
DesignerContext.getDesignerFrame().exit();
} else {
DesignerExiter.getInstance().execute();
}
}
return null;
}
});
Reflect.on(Reflect.on(app).call("getApplication").get()).call("setQuitHandler", instance);
} catch (ClassNotFoundException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
private class AboutAction implements Action {
@Override
public void execute() {
AboutPane aboutPane = new AboutPane();
AboutDialog aboutDialog = new AboutDialog(DesignerContext.getDesignerFrame(), aboutPane);
aboutDialog.setVisible(true);
}
}
}

6
designer-realize/src/main/java/com/fr/start/module/DesignerStartup.java

@ -16,11 +16,11 @@ import com.fr.design.utils.DesignUtils;
import com.fr.design.utils.DesignerPort;
import com.fr.exit.DesignerExiter;
import com.fr.general.ComparatorUtils;
import com.fr.general.IOUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.module.Activator;
import com.fr.record.analyzer.EnableMetrics;
import com.fr.record.analyzer.Metrics;
import com.fr.stable.ArrayUtils;
import com.fr.stable.BuildContext;
import com.fr.stable.ProductConstants;
import com.fr.stable.StableUtils;
@ -35,8 +35,6 @@ import com.fr.start.server.FineEmbedServer;
import com.fr.value.NotNullLazyValue;
import org.jetbrains.annotations.NotNull;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import java.io.File;
import java.util.concurrent.ExecutorService;
@ -71,7 +69,9 @@ public class DesignerStartup extends Activator {
if (DesignUtils.isStarted()) {
// 如果端口被占用了 说明程序已经运行了一次,也就是说,已经建立一个监听服务器,现在只要给服务器发送命令就好了
final String[] args = startupArgsValue.getValue().get();
if (ArrayUtils.isNotEmpty(args)) {
DesignUtils.clientSend(args);
}
FineLoggerFactory.getLogger().info("The Designer Has Been Started");
if (args.length == 0) {
TipDialog dialog = new TipDialog(null,

Loading…
Cancel
Save