Browse Source

Pull request #9837: REPORT-78877 && REPORT-78881 && REPORT-78886

Merge in DESIGN/design from ~HARRISON/design:feature/x to feature/x

* commit 'd19dc922019f61f0b4ec38925f62d9a7ab1f7f38':
  REPORT-78886【迭代】【起始页】起始页配置问题 1、兼容 1107 2、起始页逻辑补充
  REPORT-78881【迭代】【起始页】先选择一个会失败的工作目录,再选择本地目录启动,预览模板失败 让内置服务器晚点启动
  REPORT-78881【迭代】【起始页】先选择一个会失败的工作目录,再选择本地目录启动,预览模板失败 添加验证方案,确认有效值
  REPORT-78877【迭代】【起始页】mac直接双击模板打不开设计器 mac 支持双击模板打开,也支持在启动页打开
feature/x
Harrison 2 years ago
parent
commit
818f57f42f
  1. 102
      designer-base/src/main/java/com/fr/design/deeplink/DeepLinkCore.java
  2. 17
      designer-base/src/main/java/com/fr/design/deeplink/DeepLinkPrepare.java
  3. 9
      designer-base/src/main/java/com/fr/start/common/DesignerStartupConfig.java
  4. 35
      designer-base/src/main/java/com/fr/start/common/DesignerStartupContext.java
  5. 21
      designer-realize/src/main/java/com/fr/design/deeplink/FileOpen4MacDeepLink.java
  6. 3
      designer-realize/src/main/java/com/fr/start/module/DesignerStartup.java
  7. 4
      designer-realize/src/main/java/com/fr/start/module/optimized/DesignerStartupPageActivator.java

102
designer-base/src/main/java/com/fr/design/deeplink/DeepLinkCore.java

@ -43,6 +43,8 @@ public class DeepLinkCore {
}
private String pendingURL;
private final List<DeepLinkPrepare> deepLinkPrepareList = new ArrayList<>();
private final List<DeepLink> deepLinkList = new ArrayList<>();
@ -51,6 +53,9 @@ public class DeepLinkCore {
public void register(DeepLink deepLink) {
if (deepLink != null) {
deepLinkList.add(deepLink);
if (deepLink instanceof DeepLinkPrepare) {
deepLinkPrepareList.add((DeepLinkPrepare) deepLink);
}
}
}
@ -129,6 +134,11 @@ public class DeepLinkCore {
private void acceptNewURL(String url) {
this.pendingURL = url;
UrlBean urlBean = UrlBean.create(this.pendingURL);
for (DeepLinkPrepare deepLinkPrepare : deepLinkPrepareList) {
deepLinkPrepare.prepare(urlBean.getUrl(), urlBean.getHost(), urlBean.getPath(), urlBean.getParams());
}
}
private boolean canConsumePendingURL() {
@ -148,32 +158,11 @@ public class DeepLinkCore {
}
private void consumePendingURL() {
String host = null;
String path = null;
Map<String, Object> params = new HashMap<>();
URL url = null;
try {
url = new URL(null, this.pendingURL, new URLStreamHandler() {
@Override
protected URLConnection openConnection(URL u) throws IOException {
return null;
}
});
} catch (MalformedURLException ignored) {}
if (url != null) {
host = url.getHost();
path = url.getPath();
List<NameValuePair> pairs = URLUtils.parse(url.getQuery());
for (NameValuePair pair: pairs) {
params.put(pair.getName(), pair.getValue());
}
}
UrlBean urlBean = UrlBean.create(this.pendingURL);
FineLoggerFactory.getLogger().info("consume deep link: " + this.pendingURL);
performDeepLinks(this.pendingURL, host, path, params);
performDeepLinks(urlBean.getUrl(), urlBean.getHost(), urlBean.getPath(), urlBean.getParams());
markPendingURLConsumed();
}
@ -194,4 +183,67 @@ public class DeepLinkCore {
private void markPendingURLConsumed() {
this.pendingURL = null;
}
private static class UrlBean {
private String url;
private String host;
private String path;
private Map<String, Object> params;
public UrlBean(String url, String host, String path, Map<String, Object> params) {
this.url = url;
this.host = host;
this.path = path;
this.params = params;
}
public String getUrl() {
return url;
}
public String getHost() {
return host;
}
public String getPath() {
return path;
}
public Map<String, Object> getParams() {
return params;
}
public static UrlBean create(String pendingUrl) {
String host = null;
String path = null;
Map<String, Object> params = new HashMap<>();
URL url = null;
try {
url = new URL(null, pendingUrl, new URLStreamHandler() {
@Override
protected URLConnection openConnection(URL u) throws IOException {
return null;
}
});
} catch (MalformedURLException ignored) {
}
if (url != null) {
host = url.getHost();
path = url.getPath();
List<NameValuePair> pairs = URLUtils.parse(url.getQuery());
for (NameValuePair pair : pairs) {
params.put(pair.getName(), pair.getValue());
}
}
return new UrlBean(pendingUrl, host, path, params);
}
}
}

17
designer-base/src/main/java/com/fr/design/deeplink/DeepLinkPrepare.java

@ -0,0 +1,17 @@
package com.fr.design.deeplink;
import java.util.Map;
/**
* created by Harrison on 2022/08/23
**/
public interface DeepLinkPrepare {
/**
* 准备
*
* @param url 链接
* @return 成功/失败
*/
boolean prepare(String url, String host, String path, Map<String, Object> params);
}

9
designer-base/src/main/java/com/fr/start/common/DesignerStartupConfig.java

@ -12,6 +12,11 @@ public class DesignerStartupConfig implements XMLable {
private static final DesignerStartupConfig INSTANCE = new DesignerStartupConfig();
/**
* 加上版本不然回滚到 1107 会有兼容问题
*/
private static final String TAG_ENABLED = "isEnabled1108";
public static DesignerStartupConfig getInstance() {
return INSTANCE;
@ -40,14 +45,14 @@ public class DesignerStartupConfig implements XMLable {
@Override
public void readXML(XMLableReader reader) {
if (reader.isAttr()) {
this.setEnabled(reader.getAttrAsBoolean("isEnabled", true));
this.setEnabled(reader.getAttrAsBoolean(TAG_ENABLED, true));
}
}
@Override
public void writeXML(XMLPrintWriter writer) {
writer.startTAG(XML_TAG);
writer.attr("isEnabled", this.isEnabled());
writer.attr(TAG_ENABLED, this.isEnabled());
writer.end();
}

35
designer-base/src/main/java/com/fr/start/common/DesignerStartupContext.java

@ -20,6 +20,12 @@ import java.util.Iterator;
**/
public class DesignerStartupContext {
/**
* 可以启动
* 当遇到 mac 双击启动时需要将这里置为 false, {@link FileOpen4MacDeepLink}
*/
private boolean enabled = true;
/**
* 启动参数
*/
@ -79,6 +85,14 @@ public class DesignerStartupContext {
return StartupContextHolder.INSTANCE;
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
private static class StartupContextHolder {
private static final DesignerStartupContext INSTANCE = new DesignerStartupContext();
}
@ -103,7 +117,7 @@ public class DesignerStartupContext {
/**
* 展示启动页
* 1. 判断当前的工作目录数量
* 1. 判断当前的工作目录数量为空或者为1
* 2. 判断是否是 demo还是打开目标文件
* 3. 功能是否开启
*
@ -111,10 +125,20 @@ public class DesignerStartupContext {
*/
public boolean isShowStartupPage() {
DesignerEnvManager envManager = DesignerEnvManager.getEnvManager();
return !startupArgs.isDemo() && DesignerStartupUtil.convertArgs2FILE(startupArgs.get()) == null
// 见该 field 的注释
&& enabled
&& isWorkspaceValid()
&& envManager.isStartupPageEnabled();
}
private boolean isWorkspaceValid() {
DesignerEnvManager envManager = DesignerEnvManager.getEnvManager();
Iterator<String> envNameIterator = envManager.getEnvNameIterator();
ArrayList<String> envs = Lists.newArrayList(envNameIterator);
return !startupArgs.isDemo() && DesignerStartupUtil.convertArgs2FILE(startupArgs.get()) == null && !envs.isEmpty() && envManager.isStartupPageEnabled();
return !envs.isEmpty() && (envs.size() != 1);
}
/* 预热相关 */
@ -128,7 +152,12 @@ public class DesignerStartupContext {
String curEnvName = DesignerEnvManager.getEnvManager().getCurEnvName();
DesignerWorkspaceInfo workspaceInfo = DesignerEnvManager.getEnvManager().getWorkspaceInfo(curEnvName);
return workspaceInfo.getType() == DesignerWorkspaceType.Local;
boolean valid = false;
try {
valid = workspaceInfo.checkValid();
} catch (Exception ignore) {
}
return workspaceInfo.getType() == DesignerWorkspaceType.Local && valid;
}
public void setStartupPageModel(StartupPageModel startupPageModel) {

21
designer-realize/src/main/java/com/fr/design/deeplink/FileOpen4MacDeepLink.java

@ -4,6 +4,7 @@ import com.fr.design.mainframe.DesignerContext;
import com.fr.file.FileFILE;
import com.fr.stable.StringUtils;
import com.fr.stable.os.OperatingSystem;
import com.fr.start.common.DesignerStartupContext;
import com.fr.start.common.DesignerStartupUtil;
import java.io.File;
@ -14,10 +15,11 @@ import java.util.Map;
* @version 1.0
* Created by Starryi on 2022/1/13
*/
public class FileOpen4MacDeepLink extends DeepLink {
public class FileOpen4MacDeepLink extends DeepLink implements DeepLinkPrepare{
@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();
return support(url, host, path, params);
}
@Override
@ -30,4 +32,19 @@ public class FileOpen4MacDeepLink extends DeepLink {
DesignerContext.getDesignerFrame().openTemplate(new FileFILE(file));
}
}
@Override
public boolean prepare(String url, String host, String path, Map<String, Object> params) {
if (support(url, host, path, params)) {
DesignerStartupContext.getInstance().setEnabled(false);
return true;
}
return false;
}
public static boolean support(String url, String host, String path, Map<String, Object> params) {
return OperatingSystem.isMacos() && StringUtils.isEmpty(host) && StringUtils.isEmpty(path) && params.isEmpty();
}
}

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

@ -33,6 +33,7 @@ import com.fr.stable.StringUtils;
import com.fr.stable.project.ProjectConstants;
import com.fr.start.DesignerProcessType;
import com.fr.start.ServerStarter;
import com.fr.start.common.DesignerStartupContext;
import com.fr.start.event.LazyStartupEvent;
import com.fr.start.preload.PreLoadService;
import com.fr.start.server.FineEmbedServer;
@ -120,7 +121,7 @@ public class DesignerStartup extends Activator {
|| FineEmbedServer.isRunning()) {
return;
}
if (DaoSelectorFactory.getDaoSelector().useCacheDao()) {
if (DaoSelectorFactory.getDaoSelector().useCacheDao() || DesignerStartupContext.getInstance().isOnStartup()) {
listenEvent(LazyStartupEvent.INSTANCE, new Listener<Null>(Integer.MIN_VALUE) {
@Override
public void on(Event event, Null param) {

4
designer-realize/src/main/java/com/fr/start/module/optimized/DesignerStartupPageActivator.java

@ -1,6 +1,7 @@
package com.fr.start.module.optimized;
import com.fr.design.DesignerEnvManager;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.ui.util.UIUtil;
import com.fr.log.FineLoggerFactory;
import com.fr.module.Activator;
@ -110,6 +111,9 @@ public class DesignerStartupPageActivator extends Activator {
// 将选中的环境设置为当前环境
StartupWorkspaceBean selectWorkspaceInfo = model.getSelectWorkspaceInfo();
DesignerEnvManager.getEnvManager().setCurEnvName(selectWorkspaceInfo.getName());
UIUtil.invokeLaterIfNeeded(() -> {
DesignerContext.getDesignerFrame().setTitle();
});
}
private void launchAfterWarmup(DesignerPreWarmTask warmTask) {

Loading…
Cancel
Save