Browse Source

1、自动检测下载商店脚本

2、详情点击可以使用
master
vito 9 years ago
parent
commit
6ce793663d
  1. 4
      designer_base/src/com/fr/design/extra/PluginHelper.java
  2. 71
      designer_base/src/com/fr/design/extra/PluginManagerPane.java
  3. 14
      designer_base/src/com/fr/design/extra/PluginWebBridge.java
  4. 25
      designer_base/src/com/fr/design/extra/PluginWebPane.java

4
designer_base/src/com/fr/design/extra/PluginHelper.java

@ -31,8 +31,8 @@ import java.util.concurrent.ExecutionException;
*/ */
public class PluginHelper { public class PluginHelper {
private static final String TEMP_PATH = System.getProperty("user.dir") + "/tmp"; private static final String TEMP_PATH = System.getProperty("user.dir") + "/tmp";
private static final String DOWNLOAD_PATH = System.getProperty("user.dir") + "/download"; public static final String DOWNLOAD_PATH = System.getProperty("user.dir") + "/download";
private static final String TEMP_FILE = "temp.zip"; public static final String TEMP_FILE = "temp.zip";
/** /**
* 下载插件 * 下载插件

71
designer_base/src/com/fr/design/extra/PluginManagerPane.java

@ -1,10 +1,17 @@
package com.fr.design.extra; 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.dialog.BasicPane;
import com.fr.design.gui.frpane.UITabbedPane; import com.fr.design.gui.frpane.UITabbedPane;
import com.fr.general.IOUtils;
import com.fr.general.Inter; import com.fr.general.Inter;
import com.fr.stable.StableUtils;
import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.io.File;
import java.net.URL; import java.net.URL;
/** /**
@ -24,10 +31,29 @@ public class PluginManagerPane extends BasicPane {
public PluginManagerPane() { public PluginManagerPane() {
setLayout(new BorderLayout()); setLayout(new BorderLayout());
if (System.getProperty("java.version").startsWith("1.8")) { if (System.getProperty("java.version").startsWith("1.8")) {
URL url = ClassLoader.getSystemResource(""); String installHome;
String installHome = url.getPath(); if(StableUtils.isDebug()){
PluginWebPane webPane = new PluginWebPane(installHome); URL url = ClassLoader.getSystemResource("");
installHome = url.getPath() + "scripts";
}else{
installHome = StableUtils.getInstallHome() + File.separator + "scripts";
File file = new File(installHome);
if (!file.exists()) {
int rv = JOptionPane.showConfirmDialog(
null,
"您还没有插件商店的资源,是否下载?",
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); add(webPane, BorderLayout.CENTER);
} else { } else {
initTraditionalStore(); initTraditionalStore();
} }
@ -42,6 +68,45 @@ public class PluginManagerPane extends BasicPane {
tabbedPane.addTab(Inter.getLocText("FR-Designer-Plugin_All_Plugins"), new PluginFromStorePane(tabbedPane)); tabbedPane.addTab(Inter.getLocText("FR-Designer-Plugin_All_Plugins"), new PluginFromStorePane(tabbedPane));
} }
private void downloadShopScripts() {
new SwingWorker<Void, Void>() {
@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<Double>() {
@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_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 @Override
protected String title4PopupWindow() { protected String title4PopupWindow() {
return Inter.getLocText("FR-Designer-Plugin_Manager"); return Inter.getLocText("FR-Designer-Plugin_Manager");

14
designer_base/src/com/fr/design/extra/PluginWebBridge.java

@ -261,6 +261,16 @@ public class PluginWebBridge {
} }
} }
/**
* 在本地浏览器里打开url
* tips:重载的时候,需要给js调用的方法需要放在前面,否则可能不会被调用(此乃坑)
*
* @param url 要打开的地址
*/
public void openUrlAtLocalWebBrowser(String url) {
openUrlAtLocalWebBrowser(webEngine, url);
}
/** /**
* 在本地浏览器里打开url * 在本地浏览器里打开url
* *
@ -289,10 +299,6 @@ public class PluginWebBridge {
} }
} }
public void openUrlAtLocalWebBrowser(String url) {
openUrlAtLocalWebBrowser(webEngine, url);
}
/** /**
* 从硬盘升级 * 从硬盘升级
* *

25
designer_base/src/com/fr/design/extra/PluginWebPane.java

@ -1,9 +1,6 @@
package com.fr.design.extra; package com.fr.design.extra;
import com.fr.general.FRLogger;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.embed.swing.JFXPanel; import javafx.embed.swing.JFXPanel;
import javafx.event.EventHandler; import javafx.event.EventHandler;
import javafx.scene.Scene; import javafx.scene.Scene;
@ -32,20 +29,13 @@ 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:///" + installHome + "/scripts/store/web/index.html"); webEngine.load("file:///" + installHome + "/store/web/index.html");
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) {
showAlert(event.getData()); showAlert(event.getData());
} }
}); });
webEngine.locationProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, final String oldValue, String newValue) {
disableLink(webEngine);
PluginWebBridge.getHelper().openUrlAtLocalWebBrowser(webEngine, newValue);
}
});
JSObject obj = (JSObject) webEngine.executeScript("window"); JSObject obj = (JSObject) webEngine.executeScript("window");
obj.setMember("PluginHelper", PluginWebBridge.getHelper(webEngine)); obj.setMember("PluginHelper", PluginWebBridge.getHelper(webEngine));
webView.setContextMenuEnabled(false);//屏蔽右键 webView.setContextMenuEnabled(false);//屏蔽右键
@ -54,19 +44,6 @@ public class PluginWebPane extends JFXPanel {
}); });
} }
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) { private void showAlert(final String message) {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override @Override

Loading…
Cancel
Save