|
|
|
@ -37,10 +37,15 @@ import java.util.Set;
|
|
|
|
|
* Created by Starryi on 2021/12/20 |
|
|
|
|
*/ |
|
|
|
|
public class NativeProductBridge { |
|
|
|
|
private static final Map<String, ComponentInstallationTask> createdComponentInstallationTasks = new HashMap<>(); |
|
|
|
|
private static final Map<String, ComponentsPackageInstallationTask> createdComponentsPackageInstallationTasks = new HashMap<>(); |
|
|
|
|
private static final Map<String, TemplateThemeInstallationTask> createdTemplateThemeInstallationTasks = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
private static final Map<String, ComponentInstallationTask> startedComponentInstallationTasks = new HashMap<>(); |
|
|
|
|
private static final Map<String, ComponentsPackageInstallationTask> startedComponentsPackageInstallationTasks = new HashMap<>(); |
|
|
|
|
private static final Map<String, TemplateThemeInstallationTask> startedTemplateThemeInstallationTasks = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
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<Object>> componentDownloadTaskStartListeners = new HashMap<>(); |
|
|
|
|
private final Map<String, Set<Object>> componentsPackageDownloadTaskStartListeners = new HashMap<>(); |
|
|
|
@ -115,7 +120,7 @@ public class NativeProductBridge {
|
|
|
|
|
boolean isPackage = widget.isWidgetPackage(); |
|
|
|
|
|
|
|
|
|
Map<String, ? extends NativeTaskBridge> executingDownloadTask = |
|
|
|
|
isPackage ? executingComponentsPackageInstallationTasks : executingComponentInstallationTasks; |
|
|
|
|
isPackage ? startedComponentsPackageInstallationTasks : startedComponentInstallationTasks; |
|
|
|
|
NativeTaskBridge task = executingDownloadTask.get(uuid); |
|
|
|
|
if (task != null) { |
|
|
|
|
task.checkJSEnvChange(this.window); |
|
|
|
@ -131,9 +136,22 @@ public class NativeProductBridge {
|
|
|
|
|
OnlineShareWidget widget = OnlineShareWidget.parseFromJSONObject(object); |
|
|
|
|
int childrenCount = object.optInt("pkgsize", 0); |
|
|
|
|
if (childrenCount > 0) { |
|
|
|
|
return new ComponentsPackageInstallationTask(this, window, widget, childrenCount); |
|
|
|
|
if (createdComponentsPackageInstallationTasks.containsKey(widget.getUuid())) { |
|
|
|
|
return createdComponentsPackageInstallationTasks.get(widget.getUuid()); |
|
|
|
|
} else { |
|
|
|
|
ComponentsPackageInstallationTask task = new ComponentsPackageInstallationTask(this, window, widget, childrenCount); |
|
|
|
|
createdComponentsPackageInstallationTasks.put(widget.getUuid(), task); |
|
|
|
|
return task; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
return new ComponentInstallationTask(this, window, widget); |
|
|
|
|
if (createdComponentInstallationTasks.containsKey(widget.getUuid())) { |
|
|
|
|
return createdComponentInstallationTasks.get(widget.getUuid()); |
|
|
|
|
} else { |
|
|
|
|
ComponentInstallationTask task = new ComponentInstallationTask(this, window, widget); |
|
|
|
|
createdComponentInstallationTasks.put(widget.getUuid(), task); |
|
|
|
|
return task; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -165,7 +183,7 @@ public class NativeProductBridge {
|
|
|
|
|
@JsAccessible |
|
|
|
|
@JSBridge |
|
|
|
|
public Object getExecutingThemeDownloadTask(String themePath) { |
|
|
|
|
NativeTaskBridge task = (NativeTaskBridge) executingTemplateThemeInstallationTasks.get(themePath); |
|
|
|
|
NativeTaskBridge task = startedTemplateThemeInstallationTasks.get(themePath); |
|
|
|
|
if (task != null) { |
|
|
|
|
task.checkJSEnvChange(this.window); |
|
|
|
|
} |
|
|
|
@ -176,7 +194,13 @@ public class NativeProductBridge {
|
|
|
|
|
@JsAccessible |
|
|
|
|
@JSBridge |
|
|
|
|
public Object createTemplateThemeDownloadTask(String themePath) { |
|
|
|
|
return new TemplateThemeInstallationTask(this, window, themePath); |
|
|
|
|
if (createdTemplateThemeInstallationTasks.containsKey(themePath)) { |
|
|
|
|
return createdTemplateThemeInstallationTasks.get(themePath); |
|
|
|
|
} else { |
|
|
|
|
TemplateThemeInstallationTask task = new TemplateThemeInstallationTask(this, window, themePath); |
|
|
|
|
createdTemplateThemeInstallationTasks.put(themePath, task); |
|
|
|
|
return task; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static class ComponentInstallationTask extends NativeTaskBridge { |
|
|
|
@ -217,6 +241,9 @@ public class NativeProductBridge {
|
|
|
|
|
@JSBridge |
|
|
|
|
@Override |
|
|
|
|
public void execute() { |
|
|
|
|
if (isExecuting) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
super.execute(); |
|
|
|
|
SwingUtilities.invokeLater(new Runnable() { |
|
|
|
|
@Override |
|
|
|
@ -257,7 +284,7 @@ public class NativeProductBridge {
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void fireStartEvent(String event) { |
|
|
|
|
executingComponentInstallationTasks.put(widget.getUuid(), this); |
|
|
|
|
startedComponentInstallationTasks.put(widget.getUuid(), this); |
|
|
|
|
Set<Object> startListeners = env.componentDownloadTaskStartListeners.get(widget.getUuid()); |
|
|
|
|
SafeJSFunctionInvoker.invoke(startListeners, env.window); |
|
|
|
|
super.fireStartEvent(event); |
|
|
|
@ -265,13 +292,15 @@ public class NativeProductBridge {
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void fireFailureEvent(String event) { |
|
|
|
|
executingComponentInstallationTasks.remove(widget.getUuid()); |
|
|
|
|
startedComponentInstallationTasks.remove(widget.getUuid()); |
|
|
|
|
createdComponentInstallationTasks.remove(widget.getUuid()); |
|
|
|
|
super.fireFailureEvent(event); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void fireSuccessEvent(String event) { |
|
|
|
|
executingComponentInstallationTasks.remove(widget.getUuid()); |
|
|
|
|
startedComponentInstallationTasks.remove(widget.getUuid()); |
|
|
|
|
createdComponentInstallationTasks.remove(widget.getUuid()); |
|
|
|
|
super.fireSuccessEvent(event); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -317,6 +346,9 @@ public class NativeProductBridge {
|
|
|
|
|
@JSBridge |
|
|
|
|
@Override |
|
|
|
|
public void execute() { |
|
|
|
|
if (isExecuting) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
super.execute(); |
|
|
|
|
SwingUtilities.invokeLater(new Runnable() { |
|
|
|
|
@Override |
|
|
|
@ -373,7 +405,7 @@ public class NativeProductBridge {
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void fireStartEvent(String event) { |
|
|
|
|
executingComponentsPackageInstallationTasks.put(widget.getUuid(), this); |
|
|
|
|
startedComponentsPackageInstallationTasks.put(widget.getUuid(), this); |
|
|
|
|
super.fireStartEvent(event); |
|
|
|
|
|
|
|
|
|
Set<Object> startListeners = env.componentsPackageDownloadTaskStartListeners.get(widget.getUuid()); |
|
|
|
@ -382,13 +414,15 @@ public class NativeProductBridge {
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void fireFailureEvent(String event) { |
|
|
|
|
executingComponentsPackageInstallationTasks.remove(widget.getUuid()); |
|
|
|
|
startedComponentsPackageInstallationTasks.remove(widget.getUuid()); |
|
|
|
|
createdComponentsPackageInstallationTasks.remove(widget.getUuid()); |
|
|
|
|
super.fireFailureEvent(event); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void fireSuccessEvent(String event) { |
|
|
|
|
executingComponentsPackageInstallationTasks.remove(widget.getUuid()); |
|
|
|
|
startedComponentsPackageInstallationTasks.remove(widget.getUuid()); |
|
|
|
|
createdComponentsPackageInstallationTasks.remove(widget.getUuid()); |
|
|
|
|
super.fireSuccessEvent(event); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -426,6 +460,9 @@ public class NativeProductBridge {
|
|
|
|
|
@JSBridge |
|
|
|
|
@Override |
|
|
|
|
public void execute() { |
|
|
|
|
if (isExecuting) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
super.execute(); |
|
|
|
|
SwingUtilities.invokeLater(new Runnable() { |
|
|
|
|
@Override |
|
|
|
@ -452,7 +489,7 @@ public class NativeProductBridge {
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void fireStartEvent(String event) { |
|
|
|
|
executingTemplateThemeInstallationTasks.put(themePath, this); |
|
|
|
|
startedTemplateThemeInstallationTasks.put(themePath, this); |
|
|
|
|
Set<Object> startListeners = env.themeDownloadTaskStartListeners.get(themePath); |
|
|
|
|
SafeJSFunctionInvoker.invoke(startListeners, env.window); |
|
|
|
|
super.fireStartEvent(event); |
|
|
|
@ -460,13 +497,15 @@ public class NativeProductBridge {
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void fireFailureEvent(String event) { |
|
|
|
|
executingTemplateThemeInstallationTasks.remove(themePath); |
|
|
|
|
startedTemplateThemeInstallationTasks.remove(themePath); |
|
|
|
|
createdTemplateThemeInstallationTasks.remove(themePath); |
|
|
|
|
super.fireFailureEvent(event); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void fireSuccessEvent(String event) { |
|
|
|
|
executingTemplateThemeInstallationTasks.remove(themePath); |
|
|
|
|
startedTemplateThemeInstallationTasks.remove(themePath); |
|
|
|
|
createdTemplateThemeInstallationTasks.remove(themePath); |
|
|
|
|
super.fireSuccessEvent(event); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|