From 7b9663bcb761f55af191ed37a970a4c561a5f816 Mon Sep 17 00:00:00 2001 From: Starryi Date: Thu, 13 Jan 2022 14:50:19 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-64406=20=E7=9B=B4=E6=8E=A5=E9=80=9A?= =?UTF-8?q?=E8=BF=87=E7=82=B9=E5=87=BB=E6=A8=A1=E6=9D=BF=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E8=AE=BE=E8=AE=A1=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【问题原因】 Mac端在设计器未启动状态下,直接点击模板文件,触发设计器启动, 但启动成功后,设计器里并没有打开对应的模板。查看install4j的 文档后发现还需要使用install4j运行时jar中的API注册监听函数, 才能拿到文件路径。 点击文件启动应用的API与点击网页链接启动应用的API,恰好是一个, 所以就可以在之前迭代的URL启动设计器功能基础上修复这个BUG。 【改动思路】 实现一个用于mac端文件打开的DeepLink --- .../fr/design/deeplink/DeepLinkManager.java | 22 +++++++++++++- .../design/deeplink/FileOpen4MacDeepLink.java | 29 +++++++++++++++++++ .../main/java/com/fr/start/MainDesigner.java | 1 + 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 designer-realize/src/main/java/com/fr/design/deeplink/FileOpen4MacDeepLink.java diff --git a/designer-realize/src/main/java/com/fr/design/deeplink/DeepLinkManager.java b/designer-realize/src/main/java/com/fr/design/deeplink/DeepLinkManager.java index b50bc2cbcd..a1de69db4f 100644 --- a/designer-realize/src/main/java/com/fr/design/deeplink/DeepLinkManager.java +++ b/designer-realize/src/main/java/com/fr/design/deeplink/DeepLinkManager.java @@ -9,16 +9,19 @@ import com.fr.event.Listener; import com.fr.event.Null; import com.fr.log.FineLoggerFactory; import com.fr.stable.StringUtils; +import com.fr.stable.os.OperatingSystem; import com.fr.third.org.apache.http.NameValuePair; import com.fr.web.URLUtils; import javax.swing.SwingUtilities; +import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.net.URLStreamHandler; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -49,6 +52,7 @@ public class DeepLinkManager { } public void prepare() { + register(new FileOpen4MacDeepLink()); register(new TemplateThemeInstallationDeepLink()); FineStartupNotificationFactory.getNotification() @@ -115,7 +119,7 @@ public class DeepLinkManager { FineLoggerFactory.getLogger().info("consume deep link: " + this.pendingURL); performDeepLinks(this.pendingURL, host, path, params); - this.pendingURL = null; + markPendingURLConsumed(); } private void performDeepLinks(String url, String host, String path, Map params) { @@ -130,4 +134,20 @@ public class DeepLinkManager { } }); } + + public String[] createNewArgs(String[] args) { + String filePath = this.pendingURL; + if (OperatingSystem.isMacos() && StringUtils.isNotEmpty(filePath) && new File(filePath).exists()) { + List argList = Arrays.asList(args); + argList.add(filePath); + markPendingURLConsumed(); + return argList.toArray(new String[]{}); + } else { + return args; + } + } + + private void markPendingURLConsumed() { + this.pendingURL = null; + } } diff --git a/designer-realize/src/main/java/com/fr/design/deeplink/FileOpen4MacDeepLink.java b/designer-realize/src/main/java/com/fr/design/deeplink/FileOpen4MacDeepLink.java new file mode 100644 index 0000000000..5709aabd6f --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/deeplink/FileOpen4MacDeepLink.java @@ -0,0 +1,29 @@ +package com.fr.design.deeplink; + +import com.fr.design.mainframe.DesignerContext; +import com.fr.file.FileFILE; +import com.fr.stable.StringUtils; +import com.fr.stable.os.OperatingSystem; + +import java.io.File; +import java.util.Map; + +/** + * @author Starryi + * @version 1.0 + * Created by Starryi on 2022/1/13 + */ +public class FileOpen4MacDeepLink extends DeepLink { + @Override + public boolean accept(String url, String host, String path, Map params) { + return OperatingSystem.isMacos() && StringUtils.isEmpty(host) && StringUtils.isEmpty(path) && params.isEmpty(); + } + + @Override + public void run(String url, String host, String path, Map params) { + File file = new File(url); + if (file.exists()) { + DesignerContext.getDesignerFrame().openTemplate(new FileFILE(file)); + } + } +} diff --git a/designer-realize/src/main/java/com/fr/start/MainDesigner.java b/designer-realize/src/main/java/com/fr/start/MainDesigner.java index 3e461af0ab..4b66c362c2 100644 --- a/designer-realize/src/main/java/com/fr/start/MainDesigner.java +++ b/designer-realize/src/main/java/com/fr/start/MainDesigner.java @@ -122,6 +122,7 @@ public class MainDesigner extends BaseDesigner { }); Module designerRoot = ModuleContext.parseRoot("designer-startup.xml"); //传递启动参数 + args = DeepLinkManager.getInstance().createNewArgs(args); designerRoot.setSingleton(StartupArgs.class, new StartupArgs(args)); try { designerRoot.start();