Browse Source

Pull request #7871: REPORT-66263 【组件商城风格优化】商城上保存主题调用设计器后,主题没有保存成功

Merge in DESIGN/design from ~STARRYI/design:REPORT-62688 to feature/x

* commit '9f17196a5bf49d66e6cdc51a3502e8d3535ad4db':
  REPORT-66263 【组件商城风格优化】商城上保存主题调用设计器后,主题没有保存成功
feature/x
starryi 3 years ago
parent
commit
36c4efec05
  1. 0
      designer-base/src/main/java/com/fr/design/deeplink/DeepLink.java
  2. 184
      designer-base/src/main/java/com/fr/design/deeplink/DeepLinkCore.java
  3. 14
      designer-base/src/main/java/com/fr/design/utils/DesignUtils.java
  4. 144
      designer-realize/src/main/java/com/fr/design/deeplink/DeepLinkManager.java
  5. 3
      designer-realize/src/main/java/com/fr/start/MainDesigner.java

0
designer-realize/src/main/java/com/fr/design/deeplink/DeepLink.java → designer-base/src/main/java/com/fr/design/deeplink/DeepLink.java

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

@ -0,0 +1,184 @@
package com.fr.design.deeplink;
import com.fr.design.constants.DesignerLaunchStatus;
import com.fr.design.startup.FineStartupNotificationFactory;
import com.fr.design.startup.FineStartupNotificationProvider;
import com.fr.event.Event;
import com.fr.event.EventDispatcher;
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.awt.Color;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
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.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author Starryi
* @version 1.0
* Created by Starryi on 2022/1/6
*/
public class DeepLinkCore {
protected DeepLinkCore(){}
private static final DeepLinkCore instance = new DeepLinkCore();
public static DeepLinkCore getInstance(){
return instance;
}
private String pendingURL;
private final List<DeepLink> deepLinkList = new ArrayList<>();
private boolean isDesignerStartupCompleted = false;
public void register(DeepLink deepLink) {
if (deepLink != null) {
deepLinkList.add(deepLink);
}
}
public void start(String[] args) {
if (OperatingSystem.isWindows()) {
if (args.length > 0) {
receiveDeeplink(args[0]);
}
}
if (OperatingSystem.isWindows() && args.length > 0) {
receiveDeeplink(args[0]);
}
FineStartupNotificationFactory.getNotification()
.registerStartupListener(new FineStartupNotificationProvider.Listener() {
@Override
public void startupPerformed(String parameters) {
receiveDeeplink(parameters);
}
});
EventDispatcher.listen(DesignerLaunchStatus.STARTUP_COMPLETE, new Listener<Null>() {
@Override
public void on(Event event, Null param) {
EventDispatcher.stopListen(this);
isDesignerStartupCompleted = true;
if (canConsumePendingURL()) {
consumePendingURL();
}
}
});
}
public void receiveDeeplink(String url) {
if (canAcceptNewURL()) {
acceptNewURL(url);
if (canConsumePendingURL()) {
consumePendingURL();
}
}
}
public void receiveDeeplink2(String url) {
if (canAcceptNewURL()) {
acceptNewURL(url);
if (canConsumePendingURL()) {
consumePendingURL();
} else {
Frame frame = new Frame("can not ConsumePendingURL");
frame.setSize(400, 400);
frame.setBackground(Color.BLACK);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent windowEvent){
frame.dispose();
}
});
frame.setVisible(true);
}
} else {
Frame frame = new Frame("can not AcceptNewURL");
frame.setSize(400, 400);
frame.setBackground(Color.BLACK);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent windowEvent){
frame.dispose();
}
});
frame.setVisible(true);
}
}
private boolean canAcceptNewURL() {
return StringUtils.isEmpty(this.pendingURL);
}
private void acceptNewURL(String url) {
this.pendingURL = url;
}
private boolean canConsumePendingURL() {
return StringUtils.isNotEmpty(this.pendingURL) && isDesignerStartupCompleted;
}
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());
}
}
FineLoggerFactory.getLogger().info("consume deep link: " + this.pendingURL);
performDeepLinks(this.pendingURL, host, path, params);
markPendingURLConsumed();
}
private void performDeepLinks(String url, String host, String path, Map<String, Object> params) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
for (DeepLink deepLink: deepLinkList) {
if (deepLink.accept(url, host, path, params)) {
deepLink.run(url, host, path, params);
}
}
}
});
}
private void markPendingURLConsumed() {
this.pendingURL = null;
}
}

14
designer-base/src/main/java/com/fr/design/utils/DesignUtils.java

@ -5,6 +5,7 @@ import com.fr.base.ServerConfig;
import com.fr.concurrent.NamedThreadFactory; import com.fr.concurrent.NamedThreadFactory;
import com.fr.design.DesignerEnvManager; import com.fr.design.DesignerEnvManager;
import com.fr.design.ExtraDesignClassManager; import com.fr.design.ExtraDesignClassManager;
import com.fr.design.deeplink.DeepLinkCore;
import com.fr.design.dialog.FineJOptionPane; import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.fun.DesignerEnvProcessor; import com.fr.design.fun.DesignerEnvProcessor;
import com.fr.design.gui.UILookAndFeel; import com.fr.design.gui.UILookAndFeel;
@ -26,10 +27,15 @@ import com.fr.start.ServerStarter;
import com.fr.value.NotNullLazyValue; import com.fr.value.NotNullLazyValue;
import com.fr.workspace.WorkContext; import com.fr.workspace.WorkContext;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.UIManager; import javax.swing.UIManager;
import java.awt.Color;
import java.awt.Desktop; import java.awt.Desktop;
import java.awt.Font; import java.awt.Font;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.File; import java.io.File;
@ -213,6 +219,14 @@ public class DesignUtils {
DesignerContext.getDesignerFrame().openTemplate(new FileFILE(f)); DesignerContext.getDesignerFrame().openTemplate(new FileFILE(f));
} }
}); });
} else {
String url = line;
UIUtil.invokeLaterIfNeeded(new Runnable() {
@Override
public void run() {
DeepLinkCore.getInstance().receiveDeeplink2(url);
}
});
} }
} }
} }

144
designer-realize/src/main/java/com/fr/design/deeplink/DeepLinkManager.java

@ -1,153 +1,21 @@
package com.fr.design.deeplink; package com.fr.design.deeplink;
import com.fr.design.constants.DesignerLaunchStatus;
import com.fr.design.startup.FineStartupNotificationFactory;
import com.fr.design.startup.FineStartupNotificationProvider;
import com.fr.event.Event;
import com.fr.event.EventDispatcher;
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;
/** /**
* @author Starryi * @author Starryi
* @version 1.0 * @version 1.0
* Created by Starryi on 2022/1/6 * Created by Starryi on 2022/2/10
*/ */
public class DeepLinkManager { public class DeepLinkManager {
protected DeepLinkManager(){}
private DeepLinkManager(){}
private static final DeepLinkManager instance = new DeepLinkManager(); private static final DeepLinkManager instance = new DeepLinkManager();
public static DeepLinkManager getInstance(){ public static DeepLinkManager getInstance(){
return instance; return instance;
} }
private String pendingURL; public void start(String[] args) {
DeepLinkCore.getInstance().register(new FileOpen4MacDeepLink());
private final List<DeepLink> deepLinkList = new ArrayList<>(); DeepLinkCore.getInstance().register(new TemplateThemeInstallationDeepLink());
private boolean isDesignerStartUpCompleted = false;
private void register(DeepLink deepLink) {
if (deepLink != null) {
deepLinkList.add(deepLink);
}
}
public void prepare() {
register(new FileOpen4MacDeepLink());
register(new TemplateThemeInstallationDeepLink());
FineStartupNotificationFactory.getNotification()
.registerStartupListener(new FineStartupNotificationProvider.Listener() {
@Override
public void startupPerformed(String parameters) {
if (canAcceptNewURL()) {
acceptNewURL(parameters);
if (canConsumePendingURL()) {
consumePendingURL();
}
}
}
});
EventDispatcher.listen(DesignerLaunchStatus.STARTUP_COMPLETE, new Listener<Null>() {
@Override
public void on(Event event, Null param) {
isDesignerStartUpCompleted = true;
if (canConsumePendingURL()) {
consumePendingURL();
}
}
});
}
private boolean canAcceptNewURL() {
return StringUtils.isEmpty(this.pendingURL);
}
private void acceptNewURL(String url) {
this.pendingURL = url;
}
private boolean canConsumePendingURL() {
return StringUtils.isNotEmpty(this.pendingURL) && isDesignerStartUpCompleted;
}
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());
}
}
FineLoggerFactory.getLogger().info("consume deep link: " + this.pendingURL);
performDeepLinks(this.pendingURL, host, path, params);
markPendingURLConsumed();
}
private void performDeepLinks(String url, String host, String path, Map<String, Object> params) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
for (DeepLink deepLink: deepLinkList) {
if (deepLink.accept(url, host, path, params)) {
deepLink.run(url, host, path, params);
}
}
}
});
}
public String[] createNewArgs(String[] args) {
String filePath = this.pendingURL;
if (OperatingSystem.isMacos() && StringUtils.isNotEmpty(filePath) && new File(filePath).exists()) {
List<String> argList = new ArrayList<>(Arrays.asList(args));
argList.add(filePath);
markPendingURLConsumed();
return argList.toArray(new String[]{});
} else {
return args;
}
}
private void markPendingURLConsumed() { DeepLinkCore.getInstance().start(args);
this.pendingURL = null;
} }
} }

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

@ -107,7 +107,7 @@ public class MainDesigner extends BaseDesigner {
*/ */
public static void main(String[] args) { public static void main(String[] args) {
DeepLinkManager.getInstance().prepare(); DeepLinkManager.getInstance().start(args);
StopWatch watch = new StopWatch(); StopWatch watch = new StopWatch();
watch.start(); watch.start();
DesignerLifecycleMonitorContext.getMonitor().beforeStart(); DesignerLifecycleMonitorContext.getMonitor().beforeStart();
@ -122,7 +122,6 @@ 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