Browse Source

REPORT-64406 直接通过点击模板文件启动设计器

【问题原因】
Mac端在设计器未启动状态下,直接点击模板文件,触发设计器启动,
但启动成功后,设计器里并没有打开对应的模板。查看install4j的
文档后发现还需要使用install4j运行时jar中的API注册监听函数,
才能拿到文件路径。

点击文件启动应用的API与点击网页链接启动应用的API,恰好是一个,
所以就可以在之前迭代的URL启动设计器功能基础上修复这个BUG。

【改动思路】
实现一个用于mac端文件打开的DeepLink
feature/x
Starryi 3 years ago
parent
commit
7b9663bcb7
  1. 22
      designer-realize/src/main/java/com/fr/design/deeplink/DeepLinkManager.java
  2. 29
      designer-realize/src/main/java/com/fr/design/deeplink/FileOpen4MacDeepLink.java
  3. 1
      designer-realize/src/main/java/com/fr/start/MainDesigner.java

22
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.event.Null;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.stable.os.OperatingSystem;
import com.fr.third.org.apache.http.NameValuePair; import com.fr.third.org.apache.http.NameValuePair;
import com.fr.web.URLUtils; import com.fr.web.URLUtils;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.net.URLStreamHandler; import java.net.URLStreamHandler;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -49,6 +52,7 @@ public class DeepLinkManager {
} }
public void prepare() { public void prepare() {
register(new FileOpen4MacDeepLink());
register(new TemplateThemeInstallationDeepLink()); register(new TemplateThemeInstallationDeepLink());
FineStartupNotificationFactory.getNotification() FineStartupNotificationFactory.getNotification()
@ -115,7 +119,7 @@ public class DeepLinkManager {
FineLoggerFactory.getLogger().info("consume deep link: " + this.pendingURL); FineLoggerFactory.getLogger().info("consume deep link: " + this.pendingURL);
performDeepLinks(this.pendingURL, host, path, params); performDeepLinks(this.pendingURL, host, path, params);
this.pendingURL = null; markPendingURLConsumed();
} }
private void performDeepLinks(String url, String host, String path, Map<String, Object> params) { private void performDeepLinks(String url, String host, String path, Map<String, Object> 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<String> argList = Arrays.asList(args);
argList.add(filePath);
markPendingURLConsumed();
return argList.toArray(new String[]{});
} else {
return args;
}
}
private void markPendingURLConsumed() {
this.pendingURL = null;
}
} }

29
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<String, Object> params) {
return OperatingSystem.isMacos() && StringUtils.isEmpty(host) && StringUtils.isEmpty(path) && params.isEmpty();
}
@Override
public void run(String url, String host, String path, Map<String, Object> params) {
File file = new File(url);
if (file.exists()) {
DesignerContext.getDesignerFrame().openTemplate(new FileFILE(file));
}
}
}

1
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"); Module designerRoot = ModuleContext.parseRoot("designer-startup.xml");
//传递启动参数 //传递启动参数
args = DeepLinkManager.getInstance().createNewArgs(args);
designerRoot.setSingleton(StartupArgs.class, new StartupArgs(args)); designerRoot.setSingleton(StartupArgs.class, new StartupArgs(args));
try { try {
designerRoot.start(); designerRoot.start();

Loading…
Cancel
Save