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