FUS-450 add project as parameter to FileTypeUsageSchemaDescriptor
[idea/community.git] / platform / platform-impl / src / com / intellij / internal / statistic / EventLogApplicationLifecycleListener.java
1 // Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
2 package com.intellij.internal.statistic;
3
4 import com.intellij.ide.AppLifecycleListener;
5 import com.intellij.ide.plugins.PluginManagerCore;
6 import com.intellij.ide.util.PropertiesComponent;
7 import com.intellij.internal.statistic.eventLog.StatisticsEventLoggerProvider;
8 import com.intellij.internal.statistic.eventLog.fus.FeatureUsageLogger;
9 import com.intellij.internal.statistic.eventLog.uploader.EventLogExternalUploader;
10 import com.intellij.openapi.application.ApplicationInfo;
11 import com.intellij.openapi.progress.ProgressIndicator;
12 import com.intellij.openapi.progress.ProgressManager;
13 import com.intellij.openapi.progress.Task;
14 import com.intellij.openapi.util.registry.Registry;
15 import org.jetbrains.annotations.NotNull;
16
17 public class EventLogApplicationLifecycleListener implements AppLifecycleListener {
18
19   @Override
20   public void appWillBeClosed(boolean isRestart) {
21     if (!isRestart && !PluginManagerCore.isRunningFromSources() && isSendingOnExitEnabled()) {
22       StatisticsEventLoggerProvider config = FeatureUsageLogger.INSTANCE.getConfig();
23       if (config.isSendEnabled() && !isUpdateInProgress()) {
24         ProgressManager.getInstance().run(new Task.Modal(null, "Starting External Log Uploader", false) {
25           @Override
26           public void run(@NotNull ProgressIndicator indicator) {
27             EventLogExternalUploader.INSTANCE.startExternalUpload(config.getRecorderId(), false);
28           }
29         });
30       }
31     }
32   }
33
34   private static boolean isSendingOnExitEnabled() {
35     return Registry.get("feature.usage.event.log.send.on.ide.close").asBoolean();
36   }
37
38   private static boolean isUpdateInProgress() {
39     return ApplicationInfo.getInstance().getBuild().asString().
40       equals(PropertiesComponent.getInstance().getValue("ide.self.update.started.for.build"));
41   }
42 }