From 9d7cd51d6ca279edabdf3d646e56b64b177259c0 Mon Sep 17 00:00:00 2001 From: richie Date: Tue, 21 May 2019 10:29:31 +0800 Subject: [PATCH] =?UTF-8?q?KERNEL-594=20=E6=9B=B4=E6=96=B0=E5=A5=BD?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E7=AE=A1=E7=90=86=E5=99=A8=E5=90=8E=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=88=B7=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/fr/design/ui/ModernUIPane.java | 10 ++++++++++ .../main/java/com/fr/design/upm/UpmBridge.java | 15 ++++++++++++--- .../main/java/com/fr/design/upm/UpmShowPane.java | 8 +++++++- .../com/fr/design/upm/event/DownloadEvent.java | 2 +- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/ui/ModernUIPane.java b/designer-base/src/main/java/com/fr/design/ui/ModernUIPane.java index 3e94fe6bef..4a92d3715c 100644 --- a/designer-base/src/main/java/com/fr/design/ui/ModernUIPane.java +++ b/designer-base/src/main/java/com/fr/design/ui/ModernUIPane.java @@ -116,6 +116,16 @@ public class ModernUIPane extends BasicPane { browser.loadURL(url); } + /** + * 转向一个新的地址,相当于重新加载 + * @param url 新的地址 + * @param map 初始化参数 + */ + public void redirect(String url, Map map) { + Assistant.setEmbProtocolHandler(browser, new EmbProtocolHandler(map)); + browser.loadURL(url); + } + @Override protected String title4PopupWindow() { return "Modern"; diff --git a/designer-base/src/main/java/com/fr/design/upm/UpmBridge.java b/designer-base/src/main/java/com/fr/design/upm/UpmBridge.java index 6ebedd706a..7f36c2b8d9 100644 --- a/designer-base/src/main/java/com/fr/design/upm/UpmBridge.java +++ b/designer-base/src/main/java/com/fr/design/upm/UpmBridge.java @@ -43,6 +43,7 @@ import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.FutureTask; import java.util.concurrent.RunnableFuture; +import java.util.concurrent.TimeUnit; /** * @author richie @@ -68,7 +69,16 @@ public class UpmBridge { */ @JSBridge public void update(final JSFunction callback) { - startDownload(callback); + callback.invoke(window, "start", Toolkit.i18nText("Fine-Design_Basic_Update_Plugin_Manager_Download_Start")); + try { + UpmResourceLoader.INSTANCE.download(); + UpmResourceLoader.INSTANCE.install(); + callback.invoke(window, "success", Toolkit.i18nText("Fine-Design_Basic_Update_Plugin_Manager_Download_Success")); + EventDispatcher.fire(DownloadEvent.UPDATE, "success"); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + callback.invoke(window, "error", Toolkit.i18nText("Fine-Design_Basic_Update_Plugin_Manager_Download_Error")); + } } /** @@ -77,11 +87,10 @@ public class UpmBridge { */ @JSBridge public void startDownload(final JSFunction callback) { - + callback.invoke(window, "start", Toolkit.i18nText("Fine-Design_Basic_Update_Plugin_Manager_Download_Start")); new SwingWorker(){ @Override protected Void doInBackground() throws Exception { - callback.invoke(window, "start", Toolkit.i18nText("Fine-Design_Basic_Update_Plugin_Manager_Download_Start")); UpmResourceLoader.INSTANCE.download(); UpmResourceLoader.INSTANCE.install(); return null; diff --git a/designer-base/src/main/java/com/fr/design/upm/UpmShowPane.java b/designer-base/src/main/java/com/fr/design/upm/UpmShowPane.java index 09c8d54b71..57b225920a 100644 --- a/designer-base/src/main/java/com/fr/design/upm/UpmShowPane.java +++ b/designer-base/src/main/java/com/fr/design/upm/UpmShowPane.java @@ -40,6 +40,12 @@ public class UpmShowPane extends BasicPane { }) .withURL(UpmFinder.getMainResourcePath(), UpmUtils.renderMap()) .build(); + EventDispatcher.listen(DownloadEvent.UPDATE, new Listener() { + @Override + public void on(Event event, String param) { + modernUIPane.redirect(UpmFinder.getMainResourcePath(), UpmUtils.renderMap()); + } + }); } else { modernUIPane = new ModernUIPane.Builder<>() .withComponent(WarnComponent.KEY) @@ -53,7 +59,7 @@ public class UpmShowPane extends BasicPane { EventDispatcher.listen(DownloadEvent.SUCCESS, new Listener() { @Override public void on(Event event, String param) { - modernUIPane.redirect(UpmFinder.getMainResourcePath()); + modernUIPane.redirect(UpmFinder.getMainResourcePath(), UpmUtils.renderMap()); } }); } diff --git a/designer-base/src/main/java/com/fr/design/upm/event/DownloadEvent.java b/designer-base/src/main/java/com/fr/design/upm/event/DownloadEvent.java index e07156b83e..25b4f0a9ea 100644 --- a/designer-base/src/main/java/com/fr/design/upm/event/DownloadEvent.java +++ b/designer-base/src/main/java/com/fr/design/upm/event/DownloadEvent.java @@ -9,5 +9,5 @@ import com.fr.event.Event; */ public enum DownloadEvent implements Event { - SUCCESS, ERROR + SUCCESS, ERROR, UPDATE }