import com.intellij.ide.impl.ProjectUtil;
import com.intellij.ide.ui.UISettings;
import com.intellij.ide.util.PropertiesComponent;
+import com.intellij.notification.Notification;
+import com.intellij.notification.NotificationListener;
+import com.intellij.notification.NotificationType;
+import com.intellij.notification.Notifications;
import com.intellij.notification.impl.IdeNotificationArea;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.MnemonicHelper;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.SystemInfo;
+import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.wm.IdeFrame;
import com.intellij.openapi.wm.IdeRootPaneNorthExtension;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import org.jetbrains.io.PowerSupplyKit;
+import org.jetbrains.io.PowerSupplyKitCallback;
import javax.swing.*;
+import javax.swing.event.HyperlinkEvent;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
}
+ @Override
+ public void addNotify() {
+ super.addNotify();
+ checkPowerSupply();
+ }
+
+ private void checkPowerSupply() {
+
+ if (!shouldCheckDiscreteCard) return;
+
+ new Thread() {
+ @Override
+ public void run() {
+ PowerSupplyKit.startListenPowerSupply(new PowerSupplyKitCallback() {
+ @Override
+ public void call() {
+
+ final NotificationType type = NotificationType.INFORMATION;
+
+ final NotificationListener listener = new NotificationListener() {
+ @Override
+ public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
+ notification.expire();
+ }
+ };
+
+ final String message = "We have noticed that your computer power cord is disconnected and you are using" +
+ " a discrete video card on you MacBook Pro. You can switch " +
+ " to the integrated video card. This significantly extend your battery life." +
+ " <a href=\"doNotShow\">Do no show</a> this message anymore";
+
+ final Notification notification = new Notification("POWER_SUPPLY_GROUP_ID", "Discrete video card warning", message, type, listener);
+
+ ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
+ @Override
+ public void run() {
+ ApplicationManager.getApplication().getMessageBus().syncPublisher(Notifications.TOPIC).notify(notification);
+ }
+ });
+ }
+
+ });
+ }
+ }.start();
+
+ shouldCheckDiscreteCard = false;
+ }
+
+ private static boolean shouldCheckDiscreteCard = Registry.is("check.power.supply.for.mbp") && SystemInfo.isMacIntel64 && PowerSupplyKit.hasDiscreteCard();
+
+
private void updateBorder() {
int state = getExtendedState();
if (!WindowManager.getInstance().isFullScreenSupportedInCurrentOS() || !SystemInfo.isWindows || myRootPane == null) {
--- /dev/null
+/*
+ * Copyright 2000-2014 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jetbrains.io;
+
+import com.intellij.util.lang.UrlClassLoader;
+
+
+public class PowerSupplyKit {
+
+ static {
+ UrlClassLoader.loadPlatformLibrary("MacNativeKit");
+ }
+
+ public static native void startListenPowerSupply (PowerSupplyKitCallback callback);
+ private static native String[] getInfo ();
+
+ public static boolean hasDiscreteCard() {
+ String [] models = getInfo();
+
+ if (models.length > 1) {
+ return true;
+ //for (String model : models) {
+ // if (model.contains("Radeon")) return true;
+ //}
+ }
+
+ return false;
+ }
+}