diff --git a/designer_base/src/com/fr/design/extra/PluginHelper.java b/designer_base/src/com/fr/design/extra/PluginHelper.java index b50b904a02..86e5f49ebb 100644 --- a/designer_base/src/com/fr/design/extra/PluginHelper.java +++ b/designer_base/src/com/fr/design/extra/PluginHelper.java @@ -31,8 +31,8 @@ import java.util.concurrent.ExecutionException; */ public class PluginHelper { private static final String TEMP_PATH = System.getProperty("user.dir") + "/tmp"; - private static final String DOWNLOAD_PATH = System.getProperty("user.dir") + "/download"; - private static final String TEMP_FILE = "temp.zip"; + public static final String DOWNLOAD_PATH = System.getProperty("user.dir") + "/download"; + public static final String TEMP_FILE = "temp.zip"; /** * 下载插件 diff --git a/designer_base/src/com/fr/design/extra/PluginManagerPane.java b/designer_base/src/com/fr/design/extra/PluginManagerPane.java index 3a63c685ba..26374d8818 100644 --- a/designer_base/src/com/fr/design/extra/PluginManagerPane.java +++ b/designer_base/src/com/fr/design/extra/PluginManagerPane.java @@ -1,10 +1,18 @@ package com.fr.design.extra; +import com.fr.base.FRContext; +import com.fr.design.DesignerEnvManager; +import com.fr.design.RestartHelper; import com.fr.design.dialog.BasicPane; import com.fr.design.gui.frpane.UITabbedPane; +import com.fr.general.GeneralUtils; +import com.fr.general.IOUtils; import com.fr.general.Inter; +import com.fr.stable.StableUtils; +import javax.swing.*; import java.awt.*; +import java.io.File; import java.net.URL; /** @@ -24,9 +32,27 @@ public class PluginManagerPane extends BasicPane { public PluginManagerPane() { setLayout(new BorderLayout()); if (System.getProperty("java.version").startsWith("1.8")) { - URL url = ClassLoader.getSystemResource(""); - String installHome = url.getPath(); - PluginWebPane webPane = new PluginWebPane(installHome); + String installHome; + if (StableUtils.isDebug()) { + URL url = ClassLoader.getSystemResource(""); + installHome = url.getPath(); + } else { + installHome = StableUtils.getInstallHome(); + File file = new File(StableUtils.pathJoin(installHome, "scripts")); + if (!file.exists()) { + int rv = JOptionPane.showConfirmDialog( + null, + Inter.getLocText("FR-Designer-Plugin_Shop_Need_Install"), + Inter.getLocText("FR-Designer-Plugin_Warning"), + JOptionPane.OK_CANCEL_OPTION, + JOptionPane.INFORMATION_MESSAGE + ); + if (rv == JOptionPane.OK_OPTION) { + downloadShopScripts(); + } + } + } + PluginWebPane webPane = new PluginWebPane(new File(installHome).getAbsolutePath()); add(webPane, BorderLayout.CENTER); } else { initTraditionalStore(); @@ -42,6 +68,45 @@ public class PluginManagerPane extends BasicPane { tabbedPane.addTab(Inter.getLocText("FR-Designer-Plugin_All_Plugins"), new PluginFromStorePane(tabbedPane)); } + private void downloadShopScripts() { + new SwingWorker() { + @Override + protected Void doInBackground() throws Exception { + String id = "shop_scripts"; + String username = DesignerEnvManager.getEnvManager().getBBSName(); + String password = DesignerEnvManager.getEnvManager().getBBSPassword(); + try { + PluginHelper.downloadPluginFile(id, username, password, new Process() { + @Override + public void process(Double integer) { + } + }); + } catch (Exception e) { + FRContext.getLogger().error(e.getMessage(), e); + } + return null; + } + + @Override + protected void done() { + IOUtils.unzip(new File(StableUtils.pathJoin(PluginHelper.DOWNLOAD_PATH, PluginHelper.TEMP_FILE)), StableUtils.getInstallHome()); + int rv = JOptionPane.showOptionDialog( + null, + Inter.getLocText("FR-Designer-Plugin_Shop_Installed"), + Inter.getLocText("FR-Designer-Plugin_Warning"), + JOptionPane.YES_NO_OPTION, + JOptionPane.INFORMATION_MESSAGE, + null, + new String[]{Inter.getLocText("FR-Designer-Basic_Restart_Designer"), Inter.getLocText("FR-Designer-Basic_Restart_Designer_Later")}, + null + ); + if (rv == JOptionPane.OK_OPTION) { + RestartHelper.restart(); + } + } + }.execute(); + } + @Override protected String title4PopupWindow() { return Inter.getLocText("FR-Designer-Plugin_Manager"); diff --git a/designer_base/src/com/fr/design/extra/PluginTask.java b/designer_base/src/com/fr/design/extra/PluginTask.java index 5efcdd1d41..eb4a997291 100644 --- a/designer_base/src/com/fr/design/extra/PluginTask.java +++ b/designer_base/src/com/fr/design/extra/PluginTask.java @@ -71,6 +71,9 @@ public class PluginTask extends Task { * @return 处理之后的字符串 */ private String changText(String old) { - return old.replaceAll("\"", "\\\\\"").replaceAll("\n", ""); + if(StringUtils.isNotBlank(old)){ + return old.replaceAll("\"", "\\\\\"").replaceAll("\n", ""); + } + return StringUtils.EMPTY; } } diff --git a/designer_base/src/com/fr/design/extra/PluginWebBridge.java b/designer_base/src/com/fr/design/extra/PluginWebBridge.java index 90fcd2af07..69f65075fc 100644 --- a/designer_base/src/com/fr/design/extra/PluginWebBridge.java +++ b/designer_base/src/com/fr/design/extra/PluginWebBridge.java @@ -6,6 +6,7 @@ import com.fr.design.dialog.UIDialog; import com.fr.design.extra.exe.*; import com.fr.general.FRLogger; import com.fr.general.Inter; +import com.fr.general.SiteCenter; import com.fr.plugin.Plugin; import com.fr.plugin.PluginLoader; import com.fr.stable.ArrayUtils; @@ -33,7 +34,7 @@ public class PluginWebBridge { private UIDialog uiDialog; - public static final String PLUGIN_SHOP = "http://192.168.101.20/ShopServer?pg=plist"; + public static final String PLUGIN_SHOP = SiteCenter.getInstance().acquireUrlByKind("plugin.plist"); public static PluginWebBridge getHelper() { if (helper != null) { @@ -261,6 +262,17 @@ public class PluginWebBridge { } } + /** + * 在本地浏览器里打开url + * tips:重载的时候,需要给js调用的方法需要放在前面,否则可能不会被调用(此乃坑) + * 所以最好的是不要重载在js可以访问的接口文件中 + * + * @param url 要打开的地址 + */ + public void openShopUrlAtWebBrowser(String url) { + openUrlAtLocalWebBrowser(webEngine, url); + } + /** * 在本地浏览器里打开url * @@ -289,10 +301,6 @@ public class PluginWebBridge { } } - public void openUrlAtLocalWebBrowser(String url) { - openUrlAtLocalWebBrowser(webEngine, url); - } - /** * 从硬盘升级 * diff --git a/designer_base/src/com/fr/design/extra/PluginWebPane.java b/designer_base/src/com/fr/design/extra/PluginWebPane.java index 4278dd77ce..0f2bd07608 100644 --- a/designer_base/src/com/fr/design/extra/PluginWebPane.java +++ b/designer_base/src/com/fr/design/extra/PluginWebPane.java @@ -1,9 +1,6 @@ package com.fr.design.extra; -import com.fr.general.FRLogger; import javafx.application.Platform; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; import javafx.embed.swing.JFXPanel; import javafx.event.EventHandler; import javafx.scene.Scene; @@ -39,33 +36,14 @@ public class PluginWebPane extends JFXPanel { showAlert(event.getData()); } }); - webEngine.locationProperty().addListener(new ChangeListener() { - @Override - public void changed(ObservableValue observable, final String oldValue, String newValue) { - disableLink(webEngine); - PluginWebBridge.getHelper().openUrlAtLocalWebBrowser(webEngine, newValue); - } - }); JSObject obj = (JSObject) webEngine.executeScript("window"); obj.setMember("PluginHelper", PluginWebBridge.getHelper(webEngine)); + webView.setContextMenuEnabled(false);//屏蔽右键 root.setCenter(webView); } }); } - private void disableLink(final WebEngine webEngine) { - try { - Platform.runLater(new Runnable() { - @Override - public void run() { - webEngine.executeScript("history.go(0)"); - } - }); - } catch (Exception e) { - FRLogger.getLogger().error(e.getMessage()); - } - } - private void showAlert(final String message) { SwingUtilities.invokeLater(new Runnable() { @Override