Browse Source

Merge pull request #61 in DESIGN/design from ~KERRY/design_10.0:feature/10.0 to feature/10.0

* commit '1070f78c4d17f96bc514649a688a56728606d9a3':
  代码修改
  REPORT-8349 适配平台插件管理
master
superman 7 years ago
parent
commit
b42214e856
  1. 47
      designer-base/src/com/fr/design/extra/PluginUtils.java
  2. 7
      designer-base/src/com/fr/design/extra/PluginWebBridge.java
  3. 76
      designer-base/src/com/fr/design/extra/PluginWebPane.java
  4. 6
      designer-base/src/com/fr/design/extra/WebViewDlgHelper.java
  5. 40
      designer-base/src/com/fr/design/extra/exe/GetInstalledPluginsExecutor.java

47
designer-base/src/com/fr/design/extra/PluginUtils.java

@ -24,6 +24,8 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -205,4 +207,49 @@ public class PluginUtils {
private static boolean isCompatibleCurrentEnv(String envVersion){ private static boolean isCompatibleCurrentEnv(String envVersion){
return VersionIntervalFactory.create(envVersion).contain(Version.currentEnvVersion()); return VersionIntervalFactory.create(envVersion).contain(Version.currentEnvVersion());
} }
public static JSONArray transferPluginToJson(PluginContext [] pluginContexts){
JSONArray ja = JSONArray.create();
try {
for(PluginContext pluginContext : pluginContexts){
JSONObject jo = JSONObject.create();
jo.put("id", pluginContext.getID());
jo.put("name", pluginContext.getName());
jo.put("version", pluginContext.getVersion());
jo.put("envVersion", pluginContext.getEnvVersion());
jo.put("description", pluginContext.getDescription());
jo.put("changeNotes", pluginContext.getChangeNotes());
jo.put("vendor", pluginContext.getVendor());
jo.put("price", pluginContext.getPrice());
jo.put("jarTime", pluginContext.getRequiredJarTime());
jo.put("isActive", pluginContext.isActive());
jo.put("isHidden", pluginContext.isHidden());
jo.put("isFree", pluginContext.isFree());
jo.put("isLicDamage", pluginContext.isLicDamaged());
jo.put("isAvailable", pluginContext.isAvailable());
jo.put("leftTime", String.valueOf(pluginContext.getLeftDays()));
jo.put("isTrial", pluginContext.isOnTrial());
jo.put("deadline", getDeadline(pluginContext));
jo.put("isRegisterFailed", pluginContext.isRegisterFailed());
ja.put(jo);
}
}catch (Exception e){
}
return ja;
}
private static String getDeadline(PluginContext plugin) {
int leftDays = plugin.getLeftDays();
if (leftDays == Integer.MAX_VALUE) {
return Inter.getLocText("FR-Plugin-Store_Permanent");
}
Calendar deadline = Calendar.getInstance();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
deadline.add(Calendar.DATE, leftDays);
return format.format(deadline.getTime());
}
} }

7
designer-base/src/com/fr/design/extra/PluginWebBridge.java

@ -5,6 +5,7 @@ import com.fr.config.MarketConfig;
import com.fr.design.RestartHelper; import com.fr.design.RestartHelper;
import com.fr.design.bbs.BBSLoginUtils; import com.fr.design.bbs.BBSLoginUtils;
import com.fr.design.dialog.UIDialog; import com.fr.design.dialog.UIDialog;
import com.fr.design.extra.exe.GetInstalledPluginsExecutor;
import com.fr.design.extra.exe.GetPluginCategoriesExecutor; import com.fr.design.extra.exe.GetPluginCategoriesExecutor;
import com.fr.design.extra.exe.GetPluginFromStoreExecutor; import com.fr.design.extra.exe.GetPluginFromStoreExecutor;
import com.fr.design.extra.exe.GetPluginPrefixExecutor; import com.fr.design.extra.exe.GetPluginPrefixExecutor;
@ -301,9 +302,9 @@ public class PluginWebBridge {
* *
* @return 已安装的插件组成的数组 * @return 已安装的插件组成的数组
*/ */
public PluginContext[] getInstalledPlugins() { public void getInstalledPlugins(final JSObject callback) {
List<PluginContext> plugins = PluginManager.getContexts(); Task<Void> task = new PluginTask<>(webEngine, callback, new GetInstalledPluginsExecutor());
return plugins.toArray(new PluginContext[plugins.size()]); threadPoolExecutor.submit(task);
} }
private String[] jsObjectToStringArray(JSObject obj) { private String[] jsObjectToStringArray(JSObject obj) {

76
designer-base/src/com/fr/design/extra/PluginWebPane.java

@ -1,5 +1,10 @@
package com.fr.design.extra; package com.fr.design.extra;
import com.fr.base.FRContext;
import com.fr.base.TemplateUtils;
import com.fr.general.IOUtils;
import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.embed.swing.JFXPanel; import javafx.embed.swing.JFXPanel;
import javafx.event.EventHandler; import javafx.event.EventHandler;
@ -10,16 +15,24 @@ import javafx.scene.web.WebEvent;
import javafx.scene.web.WebView; import javafx.scene.web.WebView;
import netscape.javascript.JSObject; import netscape.javascript.JSObject;
import javax.swing.*; import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
/** /**
* Created by richie on 16/3/19. * Created by richie on 16/3/19.
*/ */
public class PluginWebPane extends JFXPanel { public class PluginWebPane extends JFXPanel {
private static final String RESOURCE_URL = "resourceURL";
private WebEngine webEngine; private WebEngine webEngine;
public PluginWebPane(final String mainJs) { public PluginWebPane(final String installHome, final String mainJs) {
Platform.setImplicitExit(false); Platform.setImplicitExit(false);
Platform.runLater(new Runnable() { Platform.runLater(new Runnable() {
@Override @Override
@ -29,21 +42,56 @@ public class PluginWebPane extends JFXPanel {
PluginWebPane.this.setScene(scene); PluginWebPane.this.setScene(scene);
WebView webView = new WebView(); WebView webView = new WebView();
webEngine = webView.getEngine(); webEngine = webView.getEngine();
webEngine.load("file:///" + mainJs); try{
webEngine.setOnAlert(new EventHandler<WebEvent<String>>() { String htmlString = getRenderedHtml(installHome, mainJs);
@Override webEngine.loadContent(htmlString);
public void handle(WebEvent<String> event) { webEngine.setOnAlert(new EventHandler<WebEvent<String>>() {
showAlert(event.getData()); @Override
} public void handle(WebEvent<String> event) {
}); showAlert(event.getData());
JSObject obj = (JSObject) webEngine.executeScript("window"); }
obj.setMember("PluginHelper", PluginWebBridge.getHelper(webEngine)); });
webView.setContextMenuEnabled(false);//屏蔽右键 JSObject obj = (JSObject) webEngine.executeScript("window");
root.setCenter(webView); obj.setMember("PluginHelper", PluginWebBridge.getHelper(webEngine));
webView.setContextMenuEnabled(false);//屏蔽右键
root.setCenter(webView);
}catch (Exception e){
FRContext.getLogger().error(e.getMessage(), e);
}
} }
}); });
} }
private String getRenderedHtml(String installHome, String mainJs) throws IOException {
InputStream inp = IOUtils.readResource(StableUtils.pathJoin(installHome, mainJs));
if (inp == null) {
throw new IOException("Not found template: " + mainJs);
}
BufferedReader reader = new BufferedReader(new InputStreamReader(inp, StableUtils.RESOURCE_ENCODER));
BufferedReader read = new BufferedReader(reader);
StringBuffer sb = new StringBuffer();
String line;
Map<String, Object> map4Tpl = new HashMap<String, Object>();
map4Tpl.put(RESOURCE_URL, "file:///" + URLEncoder.encode(installHome, "UTF-8"));
while ((line = read.readLine()) != null) {
if (sb.length() > 0) {
sb.append('\n');
}
sb.append(line);
}
String htmlString = StringUtils.EMPTY;
try{
htmlString = TemplateUtils.renderParameter4Tpl(sb.toString(), map4Tpl);
}catch (Exception e){
FRContext.getLogger().error(e.getMessage(), e);
}
reader.close();
inp.close();
return htmlString;
}
private void showAlert(final String message) { private void showAlert(final String message) {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override @Override

6
designer-base/src/com/fr/design/extra/WebViewDlgHelper.java

@ -73,7 +73,7 @@ public class WebViewDlgHelper {
String indexPath = "plugin.html"; String indexPath = "plugin.html";
String mainIndexPath = StableUtils.pathJoin(installHome, indexPath); String mainIndexPath = StableUtils.pathJoin(installHome, indexPath);
checkAndCopyMainFile(mainIndexPath, mainJsPath); checkAndCopyMainFile(mainIndexPath, mainJsPath);
showPluginDlg(mainIndexPath); showPluginDlg(indexPath);
updateShopScripts(SHOP_SCRIPTS); updateShopScripts(SHOP_SCRIPTS);
} }
} else { } else {
@ -188,8 +188,8 @@ public class WebViewDlgHelper {
private static void showPluginDlg(String mainJsPath) { private static void showPluginDlg(String mainJsPath) {
try { try {
Class<?> clazz = Class.forName("com.fr.design.extra.PluginWebPane"); Class<?> clazz = Class.forName("com.fr.design.extra.PluginWebPane");
Constructor constructor = clazz.getConstructor(String.class); Constructor constructor = clazz.getConstructor(String.class, String.class);
Component webPane = (Component) constructor.newInstance(mainJsPath); Component webPane = (Component) constructor.newInstance(installHome, mainJsPath);
BasicPane managerPane = new ShopManagerPane(webPane); BasicPane managerPane = new ShopManagerPane(webPane);
UIDialog dlg = new ShopDialog(DesignerContext.getDesignerFrame(), managerPane); UIDialog dlg = new ShopDialog(DesignerContext.getDesignerFrame(), managerPane);

40
designer-base/src/com/fr/design/extra/exe/GetInstalledPluginsExecutor.java

@ -0,0 +1,40 @@
package com.fr.design.extra.exe;
import com.fr.design.extra.PluginUtils;
import com.fr.design.extra.Process;
import com.fr.json.JSONArray;
import com.fr.plugin.context.PluginContext;
import com.fr.plugin.manage.PluginManager;
import java.util.List;
/**
* @author kerry
* @date 2018/6/1
*/
public class GetInstalledPluginsExecutor implements Executor {
private String result ="[]";
@Override
public String getTaskFinishMessage() {
return result;
}
@Override
public Command[] getCommands() {
return new Command[]{
new Command() {
@Override
public String getExecuteMessage() {
return null;
}
@Override
public void run(Process<String> process) {
List<PluginContext> plugins = PluginManager.getContexts();
JSONArray ja = PluginUtils.transferPluginToJson(plugins.toArray(new PluginContext[plugins.size()]));
result = ja.toString();
}
}
};
}
}
Loading…
Cancel
Save