Browse Source

REPORT-8349 适配平台插件管理

master
kerry 7 years ago
parent
commit
0a683ff5a0
  1. 47
      designer-base/src/com/fr/design/extra/PluginUtils.java
  2. 7
      designer-base/src/com/fr/design/extra/PluginWebBridge.java
  3. 45
      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

@ -25,6 +25,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;
@ -206,4 +208,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;
@ -303,9 +304,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) {

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

@ -1,5 +1,9 @@
package com.fr.design.extra; package com.fr.design.extra;
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,7 +14,15 @@ 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.
@ -19,7 +31,7 @@ public class PluginWebPane extends JFXPanel {
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,7 +41,30 @@ 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{
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("servletURL", "file:///" + URLEncoder.encode(installHome, "UTF-8"));
while ((line = read.readLine()) != null) {
if (sb.length() > 0) {
sb.append('\n');
}
sb.append(line);
}
String htmlString = TemplateUtils.renderParameter4Tpl(sb.toString(), map4Tpl);
reader.close();
inp.close();
webEngine.loadContent(htmlString);
webEngine.setOnAlert(new EventHandler<WebEvent<String>>() { webEngine.setOnAlert(new EventHandler<WebEvent<String>>() {
@Override @Override
public void handle(WebEvent<String> event) { public void handle(WebEvent<String> event) {
@ -40,6 +75,10 @@ public class PluginWebPane extends JFXPanel {
obj.setMember("PluginHelper", PluginWebBridge.getHelper(webEngine)); obj.setMember("PluginHelper", PluginWebBridge.getHelper(webEngine));
webView.setContextMenuEnabled(false);//屏蔽右键 webView.setContextMenuEnabled(false);//屏蔽右键
root.setCenter(webView); root.setCenter(webView);
}catch (Exception e){
}
} }
}); });
} }

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

@ -70,7 +70,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 {
@ -167,8 +167,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