|
| 1 | +/* |
| 2 | + * Copyright (c) 2019-present, Jim Kynde Meyer |
| 3 | + * All rights reserved. |
| 4 | + * <p> |
| 5 | + * This source code is licensed under the MIT license found in the |
| 6 | + * LICENSE file in the root directory of this source tree. |
| 7 | + */ |
| 8 | +package com.intellij.lang.jsgraphql.endpoint.ide.startup; |
| 9 | + |
| 10 | +import com.intellij.lang.jsgraphql.icons.JSGraphQLIcons; |
| 11 | +import com.intellij.notification.Notification; |
| 12 | +import com.intellij.notification.NotificationAction; |
| 13 | +import com.intellij.notification.NotificationType; |
| 14 | +import com.intellij.notification.Notifications; |
| 15 | +import com.intellij.openapi.actionSystem.AnActionEvent; |
| 16 | +import com.intellij.openapi.application.ApplicationManager; |
| 17 | +import com.intellij.openapi.options.ShowSettingsUtil; |
| 18 | +import com.intellij.openapi.project.Project; |
| 19 | +import com.intellij.openapi.startup.StartupActivity; |
| 20 | +import org.apache.commons.httpclient.HttpClient; |
| 21 | +import org.apache.commons.httpclient.methods.GetMethod; |
| 22 | +import org.apache.commons.httpclient.params.HttpClientParams; |
| 23 | +import org.jetbrains.annotations.NotNull; |
| 24 | + |
| 25 | +public class GraphQLBetaEndedStartupActivity implements StartupActivity { |
| 26 | + @Override |
| 27 | + public void runActivity(@NotNull Project project) { |
| 28 | + |
| 29 | + ApplicationManager.getApplication().executeOnPooledThread(() -> { |
| 30 | + |
| 31 | + final HttpClientParams params = new HttpClientParams(); |
| 32 | + final HttpClient httpClient = new HttpClient(params); |
| 33 | + final GetMethod method = new GetMethod("https://plugins.jetbrains.com/plugins/list?pluginId=8097"); |
| 34 | + |
| 35 | + try { |
| 36 | + final int responseCode = httpClient.executeMethod(method); |
| 37 | + if (responseCode == 200) { |
| 38 | + final String responseBody = method.getResponseBodyAsString(); |
| 39 | + if (responseBody != null && responseBody.contains("<version>2.0")) { // HACK but good enough to detect the end the beta :D |
| 40 | + // 2.0 made available by JetBrains |
| 41 | + final Notification notification = new Notification("GraphQL", JSGraphQLIcons.Logos.GraphQL, "Thank you for testing the GraphQL plugin", null, "The 2.0 beta is over. Please remove the custom GraphQL repository URL in \"Plugins\" > \"Manage plugin repositories\" to get upcoming updates.", NotificationType.INFORMATION, null); |
| 42 | + notification.setImportant(true).addAction(new NotificationAction("Edit plugin settings") { |
| 43 | + @Override |
| 44 | + public void actionPerformed(@NotNull AnActionEvent e, @NotNull Notification notification) { |
| 45 | + ShowSettingsUtil.getInstance().showSettingsDialog(project, "Plugins"); |
| 46 | + } |
| 47 | + }); |
| 48 | + |
| 49 | + Notifications.Bus.notify(notification); |
| 50 | + } |
| 51 | + |
| 52 | + } |
| 53 | + |
| 54 | + } catch (Exception ignored) { |
| 55 | + } |
| 56 | + |
| 57 | + }); |
| 58 | + |
| 59 | + } |
| 60 | +} |
0 commit comments