|
|
|
@ -21,8 +21,7 @@ import com.fr.form.share.group.DefaultShareGroupManager;
|
|
|
|
|
import com.fr.json.JSONObject; |
|
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
|
import com.teamdev.jxbrowser.chromium.JSAccessible; |
|
|
|
|
import com.teamdev.jxbrowser.chromium.JSFunction; |
|
|
|
|
import com.teamdev.jxbrowser.chromium.JSObject; |
|
|
|
|
import com.teamdev.jxbrowser.js.JsAccessible; |
|
|
|
|
|
|
|
|
|
import javax.swing.JOptionPane; |
|
|
|
|
import javax.swing.SwingUtilities; |
|
|
|
@ -38,20 +37,21 @@ import java.util.Set;
|
|
|
|
|
* Created by Starryi on 2021/12/20 |
|
|
|
|
*/ |
|
|
|
|
public class NativeProductBridge { |
|
|
|
|
private final JSObject window; |
|
|
|
|
private final Object window; |
|
|
|
|
private static final Map<String, ComponentInstallationTask> executingComponentInstallationTasks = new HashMap<>(); |
|
|
|
|
private static final Map<String, ComponentsPackageInstallationTask> executingComponentsPackageInstallationTasks = new HashMap<>(); |
|
|
|
|
private static final Map<String, TemplateThemeInstallationTask> executingTemplateThemeInstallationTasks = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
private final Map<String, Set<JSFunction>> componentDownloadTaskStartListeners = new HashMap<>(); |
|
|
|
|
private final Map<String, Set<JSFunction>> componentsPackageDownloadTaskStartListeners = new HashMap<>(); |
|
|
|
|
private final Map<String, Set<JSFunction>> themeDownloadTaskStartListeners = new HashMap<>(); |
|
|
|
|
private final Map<String, Set<Object>> componentDownloadTaskStartListeners = new HashMap<>(); |
|
|
|
|
private final Map<String, Set<Object>> componentsPackageDownloadTaskStartListeners = new HashMap<>(); |
|
|
|
|
private final Map<String, Set<Object>> themeDownloadTaskStartListeners = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
public NativeProductBridge(JSObject window) { |
|
|
|
|
public NativeProductBridge(Object window) { |
|
|
|
|
this.window = window; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@JSAccessible |
|
|
|
|
@JsAccessible |
|
|
|
|
@JSBridge |
|
|
|
|
public boolean isProductDownloaded(String uuid) { |
|
|
|
|
for (Group group : DefaultShareGroupManager.getInstance().getAllGroup()) { |
|
|
|
@ -66,16 +66,17 @@ public class NativeProductBridge {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@JSAccessible |
|
|
|
|
@JsAccessible |
|
|
|
|
@JSBridge |
|
|
|
|
public void addProductDownloadTaskStartListener(String json, JSFunction function) { |
|
|
|
|
public void addProductDownloadTaskStartListener(String json, Object function) { |
|
|
|
|
JSONObject object = new JSONObject(json); |
|
|
|
|
OnlineShareWidget widget = OnlineShareWidget.parseFromJSONObject(object); |
|
|
|
|
String uuid = widget.getUuid(); |
|
|
|
|
boolean isPackage = widget.isWidgetPackage(); |
|
|
|
|
|
|
|
|
|
Map<String, Set<JSFunction>> downloadTaskGetters = |
|
|
|
|
Map<String, Set<Object>> downloadTaskGetters = |
|
|
|
|
isPackage ? componentsPackageDownloadTaskStartListeners : componentDownloadTaskStartListeners; |
|
|
|
|
Set<JSFunction> startListeners = downloadTaskGetters.get(widget.getUuid()); |
|
|
|
|
Set<Object> startListeners = downloadTaskGetters.get(widget.getUuid()); |
|
|
|
|
if (startListeners == null) { |
|
|
|
|
startListeners = new HashSet<>(); |
|
|
|
|
} |
|
|
|
@ -86,16 +87,17 @@ public class NativeProductBridge {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@JSAccessible |
|
|
|
|
@JsAccessible |
|
|
|
|
@JSBridge |
|
|
|
|
public void removeProductDownloadTaskStartListener(String json, JSFunction function) { |
|
|
|
|
public void removeProductDownloadTaskStartListener(String json, Object function) { |
|
|
|
|
JSONObject object = new JSONObject(json); |
|
|
|
|
OnlineShareWidget widget = OnlineShareWidget.parseFromJSONObject(object); |
|
|
|
|
String uuid = widget.getUuid(); |
|
|
|
|
boolean isPackage = widget.isWidgetPackage(); |
|
|
|
|
|
|
|
|
|
Map<String, Set<JSFunction>> downloadTaskGetters = isPackage ? componentsPackageDownloadTaskStartListeners : componentDownloadTaskStartListeners; |
|
|
|
|
Map<String, Set<Object>> downloadTaskGetters = isPackage ? componentsPackageDownloadTaskStartListeners : componentDownloadTaskStartListeners; |
|
|
|
|
|
|
|
|
|
Set<JSFunction> startListeners = downloadTaskGetters.get(uuid); |
|
|
|
|
Set<Object> startListeners = downloadTaskGetters.get(uuid); |
|
|
|
|
if (startListeners == null) { |
|
|
|
|
startListeners = new HashSet<>(); |
|
|
|
|
} |
|
|
|
@ -104,6 +106,7 @@ public class NativeProductBridge {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@JSAccessible |
|
|
|
|
@JsAccessible |
|
|
|
|
@JSBridge |
|
|
|
|
public Object getExecutingProductDownloadTask(String json) { |
|
|
|
|
JSONObject object = new JSONObject(json); |
|
|
|
@ -121,22 +124,24 @@ public class NativeProductBridge {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@JSAccessible |
|
|
|
|
@JsAccessible |
|
|
|
|
@JSBridge |
|
|
|
|
public Object createProductDownloadTask(String json) { |
|
|
|
|
JSONObject object = new JSONObject(json); |
|
|
|
|
OnlineShareWidget widget = OnlineShareWidget.parseFromJSONObject(object); |
|
|
|
|
int childrenCount = object.optInt("pkgsize", 0); |
|
|
|
|
if (childrenCount > 0) { |
|
|
|
|
return new ComponentsPackageInstallationTask(window, widget, childrenCount); |
|
|
|
|
return new ComponentsPackageInstallationTask(this, window, widget, childrenCount); |
|
|
|
|
} else { |
|
|
|
|
return new ComponentInstallationTask(window, widget); |
|
|
|
|
return new ComponentInstallationTask(this, window, widget); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@JSAccessible |
|
|
|
|
@JsAccessible |
|
|
|
|
@JSBridge |
|
|
|
|
public void addThemeDownloadTaskStartListener(String themePath, JSFunction function) { |
|
|
|
|
Set<JSFunction> startListeners = themeDownloadTaskStartListeners.get(themePath); |
|
|
|
|
public void addThemeDownloadTaskStartListener(String themePath, Object function) { |
|
|
|
|
Set<Object> startListeners = themeDownloadTaskStartListeners.get(themePath); |
|
|
|
|
if (startListeners == null) { |
|
|
|
|
startListeners = new HashSet<>(); |
|
|
|
|
} |
|
|
|
@ -145,9 +150,10 @@ public class NativeProductBridge {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@JSAccessible |
|
|
|
|
@JsAccessible |
|
|
|
|
@JSBridge |
|
|
|
|
public void removeThemeDownloadTaskStartListener(String themePath, JSFunction function) { |
|
|
|
|
Set<JSFunction> startListeners = themeDownloadTaskStartListeners.get(themePath); |
|
|
|
|
public void removeThemeDownloadTaskStartListener(String themePath, Object function) { |
|
|
|
|
Set<Object> startListeners = themeDownloadTaskStartListeners.get(themePath); |
|
|
|
|
if (startListeners == null) { |
|
|
|
|
startListeners = new HashSet<>(); |
|
|
|
|
} |
|
|
|
@ -156,9 +162,10 @@ public class NativeProductBridge {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@JSAccessible |
|
|
|
|
@JsAccessible |
|
|
|
|
@JSBridge |
|
|
|
|
public Object getExecutingThemeDownloadTask(String themePath) { |
|
|
|
|
NativeTaskBridge task = executingTemplateThemeInstallationTasks.get(themePath); |
|
|
|
|
NativeTaskBridge task = (NativeTaskBridge) executingTemplateThemeInstallationTasks.get(themePath); |
|
|
|
|
if (task != null) { |
|
|
|
|
task.checkJSEnvChange(this.window); |
|
|
|
|
} |
|
|
|
@ -166,17 +173,20 @@ public class NativeProductBridge {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@JSAccessible |
|
|
|
|
@JsAccessible |
|
|
|
|
@JSBridge |
|
|
|
|
public Object createTemplateThemeDownloadTask(String themePath) { |
|
|
|
|
return new TemplateThemeInstallationTask(window, themePath); |
|
|
|
|
return new TemplateThemeInstallationTask(this, window, themePath); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public class ComponentInstallationTask extends NativeTaskBridge { |
|
|
|
|
public static class ComponentInstallationTask extends NativeTaskBridge { |
|
|
|
|
private final NativeProductBridge env; |
|
|
|
|
private final OnlineShareWidget widget; |
|
|
|
|
private final ComponentInstallation action; |
|
|
|
|
|
|
|
|
|
public ComponentInstallationTask(JSObject window, OnlineShareWidget widget) { |
|
|
|
|
public ComponentInstallationTask(NativeProductBridge env, Object window, OnlineShareWidget widget) { |
|
|
|
|
super(window); |
|
|
|
|
this.env = env; |
|
|
|
|
this.widget = widget; |
|
|
|
|
action = new ComponentInstallation(widget); |
|
|
|
|
action.setActionListener(new AsyncInstallation.AsyncActionListener() { |
|
|
|
@ -203,6 +213,7 @@ public class NativeProductBridge {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@JSAccessible |
|
|
|
|
@JsAccessible |
|
|
|
|
@JSBridge |
|
|
|
|
@Override |
|
|
|
|
public void execute() { |
|
|
|
@ -231,6 +242,7 @@ public class NativeProductBridge {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@JSAccessible |
|
|
|
|
@JsAccessible |
|
|
|
|
@JSBridge |
|
|
|
|
@Override |
|
|
|
|
public void cancel() { |
|
|
|
@ -246,8 +258,8 @@ public class NativeProductBridge {
|
|
|
|
|
@Override |
|
|
|
|
protected void fireStartEvent(String event) { |
|
|
|
|
executingComponentInstallationTasks.put(widget.getUuid(), this); |
|
|
|
|
Set<JSFunction> startListeners = componentDownloadTaskStartListeners.get(widget.getUuid()); |
|
|
|
|
SafeJSFunctionInvoker.invoke(startListeners, window); |
|
|
|
|
Set<Object> startListeners = env.componentDownloadTaskStartListeners.get(widget.getUuid()); |
|
|
|
|
SafeJSFunctionInvoker.invoke(startListeners, env.window); |
|
|
|
|
super.fireStartEvent(event); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -264,14 +276,16 @@ public class NativeProductBridge {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public class ComponentsPackageInstallationTask extends NativeTaskBridge { |
|
|
|
|
public static class ComponentsPackageInstallationTask extends NativeTaskBridge { |
|
|
|
|
|
|
|
|
|
private final NativeProductBridge env; |
|
|
|
|
private final ComponentsPackageInstallation action; |
|
|
|
|
private final OnlineShareWidget widget; |
|
|
|
|
private final int childrenCount; |
|
|
|
|
|
|
|
|
|
public ComponentsPackageInstallationTask(JSObject window, OnlineShareWidget widget, int childrenCount) { |
|
|
|
|
public ComponentsPackageInstallationTask(NativeProductBridge env, Object window, OnlineShareWidget widget, int childrenCount) { |
|
|
|
|
super(window); |
|
|
|
|
this.env = env; |
|
|
|
|
this.widget = widget; |
|
|
|
|
this.childrenCount = childrenCount; |
|
|
|
|
action = new ComponentsPackageInstallation(widget, childrenCount); |
|
|
|
@ -299,6 +313,7 @@ public class NativeProductBridge {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@JSAccessible |
|
|
|
|
@JsAccessible |
|
|
|
|
@JSBridge |
|
|
|
|
@Override |
|
|
|
|
public void execute() { |
|
|
|
@ -343,6 +358,7 @@ public class NativeProductBridge {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@JSAccessible |
|
|
|
|
@JsAccessible |
|
|
|
|
@JSBridge |
|
|
|
|
@Override |
|
|
|
|
public void cancel() { |
|
|
|
@ -360,8 +376,8 @@ public class NativeProductBridge {
|
|
|
|
|
executingComponentsPackageInstallationTasks.put(widget.getUuid(), this); |
|
|
|
|
super.fireStartEvent(event); |
|
|
|
|
|
|
|
|
|
Set<JSFunction> startListeners = componentsPackageDownloadTaskStartListeners.get(widget.getUuid()); |
|
|
|
|
SafeJSFunctionInvoker.invoke(startListeners, window); |
|
|
|
|
Set<Object> startListeners = env.componentsPackageDownloadTaskStartListeners.get(widget.getUuid()); |
|
|
|
|
SafeJSFunctionInvoker.invoke(startListeners, env.window); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@ -377,11 +393,13 @@ public class NativeProductBridge {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public class TemplateThemeInstallationTask extends NativeTaskBridge { |
|
|
|
|
public static class TemplateThemeInstallationTask extends NativeTaskBridge { |
|
|
|
|
private final NativeProductBridge env; |
|
|
|
|
private final String themePath; |
|
|
|
|
private final TemplateThemeInstallation action; |
|
|
|
|
public TemplateThemeInstallationTask(JSObject window, String themePath) { |
|
|
|
|
public TemplateThemeInstallationTask(NativeProductBridge env, Object window, String themePath) { |
|
|
|
|
super(window); |
|
|
|
|
this.env = env; |
|
|
|
|
this.themePath = themePath; |
|
|
|
|
Window miniShopWindow = MiniComponentShopDialog.getInstance().getWindow(); |
|
|
|
|
action = new TemplateThemeInstallation(miniShopWindow, themePath); |
|
|
|
@ -404,6 +422,7 @@ public class NativeProductBridge {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@JSAccessible |
|
|
|
|
@JsAccessible |
|
|
|
|
@JSBridge |
|
|
|
|
@Override |
|
|
|
|
public void execute() { |
|
|
|
@ -418,6 +437,7 @@ public class NativeProductBridge {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@JSAccessible |
|
|
|
|
@JsAccessible |
|
|
|
|
@JSBridge |
|
|
|
|
@Override |
|
|
|
|
public void cancel() { |
|
|
|
@ -433,8 +453,8 @@ public class NativeProductBridge {
|
|
|
|
|
@Override |
|
|
|
|
protected void fireStartEvent(String event) { |
|
|
|
|
executingTemplateThemeInstallationTasks.put(themePath, this); |
|
|
|
|
Set<JSFunction> startListeners = themeDownloadTaskStartListeners.get(themePath); |
|
|
|
|
SafeJSFunctionInvoker.invoke(startListeners, window); |
|
|
|
|
Set<Object> startListeners = env.themeDownloadTaskStartListeners.get(themePath); |
|
|
|
|
SafeJSFunctionInvoker.invoke(startListeners, env.window); |
|
|
|
|
super.fireStartEvent(event); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|