Skip to content

Commit

Permalink
Merge pull request #29 from b952426/add-news-notification
Browse files Browse the repository at this point in the history
add news notification
  • Loading branch information
jumperchen authored Sep 14, 2021
2 parents f5b89e2 + e026c4c commit 708b8f7
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group 'org.zkoss.zkidea'
version '0.1.12'
version '0.1.13'

repositories {
mavenCentral()
Expand All @@ -15,6 +15,10 @@ repositories {

}

dependencies {
'org.jsoup:jsoup:1.13.1'
}

intellij {
version = '2021.2'
plugins = ['maven', 'com.intellij.java']
Expand Down
66 changes: 66 additions & 0 deletions src/main/java/org/zkoss/zkidea/newsNotification/ZKNews.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/* ZKNews.java
Purpose:
Description:
History:
Thu Sep 09 16:35:58 CST 2021, Created by katherine
Copyright (C) 2021 Potix Corporation. All Rights Reserved.
*/
package org.zkoss.zkidea.newsNotification;

import com.intellij.notification.NotificationGroupManager;
import com.intellij.notification.NotificationListener;
import com.intellij.notification.NotificationType;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.startup.StartupActivity;
import com.intellij.openapi.util.io.FileUtil;
import org.jetbrains.annotations.NotNull;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.zkoss.zkidea.project.ZKPathManager;
import java.io.File;
import java.io.IOException;

public class ZKNews implements StartupActivity {
public static final String ZK_WEBSITE_URL = "http://www.zkoss.org";

@Override
public void runActivity(@NotNull Project project) {
try {
if (!project.isDefault()) {
newsNotificationPopup(project);
}
} catch (IOException e) {
e.printStackTrace();
}
}

private void newsNotificationPopup(Project project) throws IOException {
File zkNewsFile = new File(ZKPathManager.getPluginTempPath() + File.separator + "zkNews.txt");
if (!zkNewsFile.exists())
zkNewsFile.createNewFile();
String news = newsLoader(ZK_WEBSITE_URL);
String newsCache = FileUtil.loadFile(zkNewsFile);
if(!news.equals(newsCache)) {
FileUtil.writeToFile(zkNewsFile, news);
NotificationGroupManager.getInstance().getNotificationGroup("news notification")
.createNotification(news + " Visit <a href=\"" + ZK_WEBSITE_URL + "\">zkoss.org</a> for detail.", NotificationType.INFORMATION)
.setListener(new NotificationListener.UrlOpeningListener(true))
.notify(project);
}
}

private String newsLoader(String url) throws IOException {
Document doc = Jsoup.connect(url).get();
Element element = doc.select("#row-news-inner-box .desc span").get(0);
String tagName = element.tagName();
String news = element.toString().replace("<" + tagName + ">","").replace("</" + tagName + ">","");
if (!news.endsWith("!") && !news.endsWith("."))
news.concat(".");
return news;
}
}
14 changes: 14 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
]]></description>

<change-notes><![CDATA[
<p>0.1.13</p>
<ul>
<li> fix deprecated API usage </li>
<li> add news notification </li>
</ul>
<br>
<p>0.1.12</p>
<ul>
<li> [bug] #28 - Plugin dont work in Intellij 2021.2 </li>
Expand Down Expand Up @@ -116,6 +122,14 @@
<postStartupActivity implementation="org.zkoss.zkidea.project.ZKProjectsManager"/>
</extensions>

<extensions defaultExtensionNs="com.intellij">
<postStartupActivity implementation="org.zkoss.zkidea.newsNotification.ZKNews"/>
</extensions>

<extensions defaultExtensionNs="com.intellij">
<notificationGroup id="news notification" displayType="BALLOON"/>
</extensions>

<actions>
<!-- Add your actions here -->
</actions>
Expand Down

0 comments on commit 708b8f7

Please sign in to comment.