use of com.intellij.openapi.application.Application in project ideavim by JetBrains.
the class VimPlugin method setupStatisticsReporter.
/**
* Reports statistics about installed IdeaVim and enabled Vim emulation.
*
* See https://github.com/go-lang-plugin-org/go-lang-idea-plugin/commit/5182ab4a1d01ad37f6786268a2fe5e908575a217
*/
private void setupStatisticsReporter(@NotNull EventFacade eventFacade) {
final Application application = ApplicationManager.getApplication();
eventFacade.addEditorFactoryListener(new EditorFactoryAdapter() {
@Override
public void editorCreated(@NotNull EditorFactoryEvent event) {
final PropertiesComponent propertiesComponent = PropertiesComponent.getInstance();
final long lastUpdate = propertiesComponent.getOrInitLong(IDEAVIM_STATISTICS_TIMESTAMP_KEY, 0);
final boolean outOfDate = lastUpdate == 0 || System.currentTimeMillis() - lastUpdate > TimeUnit.DAYS.toMillis(1);
if (outOfDate && isEnabled()) {
application.executeOnPooledThread(new Runnable() {
@Override
public void run() {
try {
final String buildNumber = ApplicationInfo.getInstance().getBuild().asString();
final String pluginId = IDEAVIM_PLUGIN_ID;
final String version = URLEncoder.encode(getVersion(), CharsetToolkit.UTF8);
final String os = URLEncoder.encode(SystemInfo.OS_NAME + " " + SystemInfo.OS_VERSION, CharsetToolkit.UTF8);
final String uid = UpdateChecker.getInstallationUID(PropertiesComponent.getInstance());
final String url = "https://plugins.jetbrains.com/plugins/list" + "?pluginId=" + pluginId + "&build=" + buildNumber + "&pluginVersion=" + version + "&os=" + os + "&uuid=" + uid;
PropertiesComponent.getInstance().setValue(IDEAVIM_STATISTICS_TIMESTAMP_KEY, String.valueOf(System.currentTimeMillis()));
HttpRequests.request(url).connect(new HttpRequests.RequestProcessor<Object>() {
@Override
public Object process(@NotNull HttpRequests.Request request) throws IOException {
LOG.info("Sending statistics: " + url);
try {
JDOMUtil.load(request.getInputStream());
} catch (JDOMException e) {
LOG.warn(e);
}
return null;
}
});
} catch (IOException e) {
LOG.warn(e);
}
}
});
}
}
}, application);
}
use of com.intellij.openapi.application.Application in project ideavim by JetBrains.
the class ActionHandler method execute.
public boolean execute(@NotNull Editor editor, @NotNull final DataContext context, @NotNull ExCommand cmd) throws ExException {
final String actionName = cmd.getArgument().trim();
final AnAction action = ActionManager.getInstance().getAction(actionName);
if (action == null) {
VimPlugin.showMessage("Action not found: " + actionName);
return false;
}
final Application application = ApplicationManager.getApplication();
if (application.isUnitTestMode()) {
executeAction(action, context, actionName);
} else {
UiHelper.runAfterGotFocus(new Runnable() {
@Override
public void run() {
executeAction(action, context, actionName);
}
});
}
return true;
}
use of com.intellij.openapi.application.Application in project intellij-community by JetBrains.
the class CertificateManager method showAcceptDialog.
public static boolean showAcceptDialog(@NotNull final Callable<? extends DialogWrapper> dialogFactory) {
Application app = ApplicationManager.getApplication();
final CountDownLatch proceeded = new CountDownLatch(1);
final AtomicBoolean accepted = new AtomicBoolean();
final AtomicReference<DialogWrapper> dialogRef = new AtomicReference<>();
Runnable showDialog = () -> {
// skip if certificate was already rejected due to timeout or interrupt
if (proceeded.getCount() == 0) {
return;
}
try {
DialogWrapper dialog = dialogFactory.call();
dialogRef.set(dialog);
accepted.set(dialog.showAndGet());
} catch (Exception e) {
LOG.error(e);
} finally {
proceeded.countDown();
}
};
if (app.isDispatchThread()) {
showDialog.run();
} else {
app.invokeLater(showDialog, ModalityState.any());
}
try {
// IDEA-123467 and IDEA-123335 workaround
boolean inTime = proceeded.await(DIALOG_VISIBILITY_TIMEOUT, TimeUnit.MILLISECONDS);
if (!inTime) {
DialogWrapper dialog = dialogRef.get();
if (dialog == null || !dialog.isShowing()) {
LOG.debug("After " + DIALOG_VISIBILITY_TIMEOUT + " ms dialog was not shown. " + "Rejecting certificate. Current thread: " + Thread.currentThread().getName());
proceeded.countDown();
return false;
} else {
// if dialog is already shown continue waiting
proceeded.await();
}
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
proceeded.countDown();
}
return accepted.get();
}
use of com.intellij.openapi.application.Application in project intellij-community by JetBrains.
the class ConfirmingTrustManager method confirmAndUpdate.
private boolean confirmAndUpdate(final X509Certificate[] chain, boolean addToKeyStore, boolean askUser) {
Application app = ApplicationManager.getApplication();
final X509Certificate endPoint = chain[0];
// IDEA-123467 and IDEA-123335 workaround
String threadClassName = StringUtil.notNullize(Thread.currentThread().getClass().getCanonicalName());
if (threadClassName.equals("sun.awt.image.ImageFetcher")) {
LOG.debug("Image Fetcher thread is detected. Certificate check will be skipped.");
return true;
}
if (app.isUnitTestMode() || app.isHeadlessEnvironment() || CertificateManager.getInstance().getState().ACCEPT_AUTOMATICALLY) {
LOG.debug("Certificate will be accepted automatically");
if (addToKeyStore) {
myCustomManager.addCertificate(endPoint);
}
return true;
}
boolean accepted = askUser && CertificateManager.showAcceptDialog(() -> {
// TODO may be another kind of warning, if default trust store is missing
return CertificateWarningDialog.createUntrustedCertificateWarning(endPoint);
});
if (accepted) {
LOG.info("Certificate was accepted by user");
if (addToKeyStore) {
myCustomManager.addCertificate(endPoint);
}
}
return accepted;
}
use of com.intellij.openapi.application.Application in project intellij-community by JetBrains.
the class WaitForProgressToShow method runOrInvokeAndWaitAboveProgress.
public static void runOrInvokeAndWaitAboveProgress(final Runnable command, @Nullable final ModalityState modalityState) {
final Application application = ApplicationManager.getApplication();
if (application.isDispatchThread()) {
command.run();
} else {
final ProgressIndicator pi = ProgressManager.getInstance().getProgressIndicator();
if (pi != null) {
execute(pi);
application.invokeAndWait(command);
} else {
final ModalityState notNullModalityState = modalityState == null ? ModalityState.NON_MODAL : modalityState;
application.invokeAndWait(command, notNullModalityState);
}
}
}
Aggregations