pass logger to showUserAgreementAndConsentsIfNeeded to reduce getLogger (not because of performance, but to make clear that logger here is required)

This commit is contained in:
Vladimir Krivosheev
2019-03-19 17:55:18 +01:00
parent f3b8bda847
commit ef2ee9683d
3 changed files with 20 additions and 14 deletions
@@ -172,7 +172,7 @@ public class StartupUtil {
}
if (!Main.isHeadless()) {
AppUIUtil.showUserAgreementAndConsentsIfNeeded();
AppUIUtil.showUserAgreementAndConsentsIfNeeded(log);
}
if (newConfigFolder && !ConfigImportHelper.isConfigImported()) {
@@ -1,18 +1,19 @@
// Copyright 2000-2019 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.
package com.intellij.internal.statistic.updater;
import com.intellij.internal.statistic.connect.StatisticsService;
import com.intellij.internal.statistic.persistence.UsageStatisticsPersistenceComponent;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.ui.AppUIUtil;
import org.jetbrains.annotations.NotNull;
public class StatisticsNotificationManager {
final class StatisticsNotificationManager {
private StatisticsNotificationManager() {
}
public static void showNotification(@NotNull StatisticsService statisticsService) {
if (AppUIUtil.showConsentsAgreementIfNeed()) {
if (AppUIUtil.showConsentsAgreementIfNeed(Logger.getInstance(StatisticsNotificationManager.class))) {
ApplicationManager.getApplication().executeOnPooledThread((Runnable)statisticsService::send);
UsageStatisticsPersistenceComponent.getInstance().setShowNotification(false);
}
@@ -62,11 +62,15 @@ import static javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
* @author yole
*/
public class AppUIUtil {
private static final Logger LOG = Logger.getInstance(AppUIUtil.class);
private static final String VENDOR_PREFIX = "jetbrains-";
private static final boolean DEBUG_MODE = PluginManagerCore.isRunningFromSources();
private static boolean ourMacDocIconSet = false;
@NotNull
private static Logger getLogger() {
return Logger.getInstance(AppUIUtil.class);
}
public static void updateWindowIcon(@NotNull Window window) {
// todo[tav] 'jbre.win.app.icon.supported' is defined by JBRE, remove when OpenJDK supports it as well
if (SystemInfo.isWindows && Boolean.getBoolean("ide.native.launcher") && Boolean.getBoolean("jbre.win.app.icon.supported")) {
@@ -114,7 +118,7 @@ public class AppUIUtil {
SVGLoader.load(url, AppUIUtil.class.getResourceAsStream(svgIconUrl), ScaleContext.create(window), size, size);
}
catch (IOException e) {
LOG.info("Cannot load svg application icon from " + svgIconUrl, e);
getLogger().info("Cannot load svg application icon from " + svgIconUrl, e);
}
}
else if (fallbackImageResourcePath != null) {
@@ -215,7 +219,7 @@ public class AppUIUtil {
if (fontDir == null) {
URL url = AppUIUtil.class.getResource("/fonts/" + name);
if (url == null) {
Logger.getInstance(AppUIUtil.class).warn("Resource missing: " + name);
getLogger().warn("Resource missing: " + name);
return;
}
@@ -229,7 +233,7 @@ public class AppUIUtil {
GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(font);
}
catch (Throwable t) {
Logger.getInstance(AppUIUtil.class).warn("Cannot register font: " + name, t);
getLogger().warn("Cannot register font: " + name, t);
}
}
@@ -279,7 +283,7 @@ public class AppUIUtil {
return iconPath;
}
public static void showUserAgreementAndConsentsIfNeeded() {
public static void showUserAgreementAndConsentsIfNeeded(@NotNull Logger log) {
if (ApplicationInfoImpl.getShadowInstance().isVendorJetBrains()) {
EndUserAgreement.Document agreement = EndUserAgreement.getLatestDocument();
if (!agreement.isAccepted()) {
@@ -289,14 +293,14 @@ public class AppUIUtil {
EndUserAgreement.setAccepted(agreement);
}
catch (Exception e) {
Logger.getInstance(AppUIUtil.class).warn(e);
log.warn(e);
}
}
showConsentsAgreementIfNeed();
showConsentsAgreementIfNeed(log);
}
}
public static boolean showConsentsAgreementIfNeed() {
public static boolean showConsentsAgreementIfNeed(@NotNull Logger log) {
final Pair<List<Consent>, Boolean> consentsToShow = ConsentOptions.getInstance().getConsents();
AtomicBoolean result = new AtomicBoolean();
if (consentsToShow.second) {
@@ -309,12 +313,13 @@ public class AppUIUtil {
};
if (SwingUtilities.isEventDispatchThread()) {
runnable.run();
} else {
}
else {
try {
SwingUtilities.invokeAndWait(runnable);
}
catch (Exception e) {
Logger.getInstance(AppUIUtil.class).warn(e);
log.warn(e);
}
}
}