From 6963b99daec0f7368a0ad859772f76f1fd95ad9f Mon Sep 17 00:00:00 2001 From: hades Date: Fri, 17 Apr 2020 18:11:36 +0800 Subject: [PATCH] REPORT-29118 && REPORT-29117 --- .../os/impl/MacOsAddListenerAction.java | 67 ++++++++++++++----- .../com/fr/start/module/DesignerStartup.java | 8 +-- 2 files changed, 54 insertions(+), 21 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/os/impl/MacOsAddListenerAction.java b/designer-base/src/main/java/com/fr/design/os/impl/MacOsAddListenerAction.java index bc09dbf6a..f33527ccb 100644 --- a/designer-base/src/main/java/com/fr/design/os/impl/MacOsAddListenerAction.java +++ b/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}, - new InvocationHandler() { - @Override - public Object invoke(Object proxy, Method method, - Object[] args) throws Throwable { - if ("handleQuitRequestWith".equals(method.getName())) { - 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); + 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 (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(); + } + } + } + + private class AboutAction implements Action { + + @Override + public void execute() { + AboutPane aboutPane = new AboutPane(); + AboutDialog aboutDialog = new AboutDialog(DesignerContext.getDesignerFrame(), aboutPane); + aboutDialog.setVisible(true); + } + } } diff --git a/designer-realize/src/main/java/com/fr/start/module/DesignerStartup.java b/designer-realize/src/main/java/com/fr/start/module/DesignerStartup.java index 60de86543..56af5583f 100644 --- a/designer-realize/src/main/java/com/fr/start/module/DesignerStartup.java +++ b/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(); - DesignUtils.clientSend(args); + if (ArrayUtils.isNotEmpty(args)) { + DesignUtils.clientSend(args); + } FineLoggerFactory.getLogger().info("The Designer Has Been Started"); if (args.length == 0) { TipDialog dialog = new TipDialog(null,